Home | History | Annotate | Download | only in d3d9
      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 // Blit9.cpp: Surface copy utility class.
      8 
      9 #ifndef LIBGLESV2_BLIT9_H_
     10 #define LIBGLESV2_BLIT9_H_
     11 
     12 #include "common/angleutils.h"
     13 
     14 #include <GLES2/gl2.h>
     15 
     16 namespace gl
     17 {
     18 class Framebuffer;
     19 }
     20 
     21 namespace rx
     22 {
     23 class Renderer9;
     24 class TextureStorage;
     25 
     26 class Blit9
     27 {
     28   public:
     29     explicit Blit9(Renderer9 *renderer);
     30     ~Blit9();
     31 
     32     // Copy from source surface to dest surface.
     33     // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left)
     34     bool copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level);
     35     bool copyCube(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level);
     36 
     37     // Copy from source surface to dest surface.
     38     // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left)
     39     // 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.
     40     bool formatConvert(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest);
     41 
     42     // 2x2 box filter sample from source to dest.
     43     // Requires that source is RGB(A) and dest has the same format as source.
     44     bool boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest);
     45 
     46   private:
     47     rx::Renderer9 *mRenderer;
     48 
     49     IDirect3DVertexBuffer9 *mQuadVertexBuffer;
     50     IDirect3DVertexDeclaration9 *mQuadVertexDeclaration;
     51 
     52     void initGeometry();
     53 
     54     bool setFormatConvertShaders(GLenum destFormat);
     55 
     56     bool copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest);
     57     IDirect3DTexture9 *copySurfaceToTexture(IDirect3DSurface9 *surface, const RECT &sourceRect);
     58     void setViewport(const RECT &sourceRect, GLint xoffset, GLint yoffset);
     59     void setCommonBlitState();
     60     RECT getSurfaceRect(IDirect3DSurface9 *surface) const;
     61 
     62     // This enum is used to index mCompiledShaders and mShaderSource.
     63     enum ShaderId
     64     {
     65         SHADER_VS_STANDARD,
     66         SHADER_VS_FLIPY,
     67         SHADER_PS_PASSTHROUGH,
     68         SHADER_PS_LUMINANCE,
     69         SHADER_PS_COMPONENTMASK,
     70         SHADER_COUNT
     71     };
     72 
     73     // This actually contains IDirect3DVertexShader9 or IDirect3DPixelShader9 casted to IUnknown.
     74     IUnknown *mCompiledShaders[SHADER_COUNT];
     75 
     76     template <class D3DShaderType>
     77     bool setShader(ShaderId source, const char *profile,
     78                    D3DShaderType *(Renderer9::*createShader)(const DWORD *, size_t length),
     79                    HRESULT (WINAPI IDirect3DDevice9::*setShader)(D3DShaderType*));
     80 
     81     bool setVertexShader(ShaderId shader);
     82     bool setPixelShader(ShaderId shader);
     83     void render();
     84 
     85     void saveState();
     86     void restoreState();
     87     IDirect3DStateBlock9 *mSavedStateBlock;
     88     IDirect3DSurface9 *mSavedRenderTarget;
     89     IDirect3DSurface9 *mSavedDepthStencil;
     90 
     91     DISALLOW_COPY_AND_ASSIGN(Blit9);
     92 };
     93 }
     94 
     95 #endif   // LIBGLESV2_BLIT9_H_
     96