Home | History | Annotate | Download | only in libGLESv2
      1 //
      2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 // Blit.cpp: Surface copy utility class.
      8 
      9 #ifndef LIBGLESV2_BLIT_H_
     10 #define LIBGLESV2_BLIT_H_
     11 
     12 #include <map>
     13 
     14 #define GL_APICALL
     15 #include <GLES2/gl2.h>
     16 
     17 #include <d3d9.h>
     18 
     19 #include "common/angleutils.h"
     20 
     21 namespace gl
     22 {
     23 class Context;
     24 
     25 class Blit
     26 {
     27   public:
     28     explicit Blit(Context *context);
     29     ~Blit();
     30 
     31     // Copy from source surface to dest surface.
     32     // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left)
     33     // source is interpreted as RGBA and destFormat specifies the desired result format. For example, if destFormat = GL_RGB, the alpha channel will be forced to 0.
     34     bool formatConvert(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest);
     35 
     36     // 2x2 box filter sample from source to dest.
     37     // Requires that source is RGB(A) and dest has the same format as source.
     38     bool boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest);
     39 
     40   private:
     41     Context *mContext;
     42 
     43     IDirect3DVertexBuffer9 *mQuadVertexBuffer;
     44     IDirect3DVertexDeclaration9 *mQuadVertexDeclaration;
     45 
     46     void initGeometry();
     47 
     48     bool setFormatConvertShaders(GLenum destFormat);
     49 
     50     IDirect3DTexture9 *copySurfaceToTexture(IDirect3DSurface9 *surface, const RECT &sourceRect);
     51     void setViewport(const RECT &sourceRect, GLint xoffset, GLint yoffset);
     52     void setCommonBlitState();
     53     RECT getSurfaceRect(IDirect3DSurface9 *surface) const;
     54 
     55     // This enum is used to index mCompiledShaders and mShaderSource.
     56     enum ShaderId
     57     {
     58         SHADER_VS_STANDARD,
     59         SHADER_VS_FLIPY,
     60         SHADER_PS_PASSTHROUGH,
     61         SHADER_PS_LUMINANCE,
     62         SHADER_PS_COMPONENTMASK,
     63         SHADER_COUNT
     64     };
     65 
     66     static const char * const mShaderSource[];
     67 
     68     // This actually contains IDirect3DVertexShader9 or IDirect3DPixelShader9 casted to IUnknown.
     69     IUnknown *mCompiledShaders[SHADER_COUNT];
     70 
     71     template <class D3DShaderType>
     72     bool setShader(ShaderId source, const char *profile,
     73                    HRESULT (WINAPI IDirect3DDevice9::*createShader)(const DWORD *, D3DShaderType **),
     74                    HRESULT (WINAPI IDirect3DDevice9::*setShader)(D3DShaderType*));
     75 
     76     bool setVertexShader(ShaderId shader);
     77     bool setPixelShader(ShaderId shader);
     78     void render();
     79 
     80     void saveState();
     81     void restoreState();
     82     IDirect3DStateBlock9 *mSavedStateBlock;
     83     IDirect3DSurface9 *mSavedRenderTarget;
     84     IDirect3DSurface9 *mSavedDepthStencil;
     85 
     86     DISALLOW_COPY_AND_ASSIGN(Blit);
     87 };
     88 }
     89 
     90 #endif   // LIBGLESV2_BLIT_H_
     91