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