1 // 2 // Copyright 2002 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 LIBANGLE_RENDERER_D3D_D3D9_BLIT9_H_ 10 #define LIBANGLE_RENDERER_D3D_D3D9_BLIT9_H_ 11 12 #include "common/PackedEnums.h" 13 #include "common/angleutils.h" 14 #include "libANGLE/Error.h" 15 #include "libANGLE/angletypes.h" 16 17 namespace gl 18 { 19 class Context; 20 class Framebuffer; 21 class Texture; 22 } // namespace gl 23 24 namespace rx 25 { 26 class Context9; 27 class Renderer9; 28 class TextureStorage; 29 30 namespace d3d 31 { 32 class Context; 33 } // namespace d3d 34 35 class Blit9 : angle::NonCopyable 36 { 37 public: 38 explicit Blit9(Renderer9 *renderer); 39 ~Blit9(); 40 41 angle::Result initialize(Context9 *context9); 42 43 // Copy from source surface to dest surface. 44 // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left) 45 angle::Result copy2D(const gl::Context *context, 46 const gl::Framebuffer *framebuffer, 47 const RECT &sourceRect, 48 GLenum destFormat, 49 const gl::Offset &destOffset, 50 TextureStorage *storage, 51 GLint level); 52 angle::Result copyCube(const gl::Context *context, 53 const gl::Framebuffer *framebuffer, 54 const RECT &sourceRect, 55 GLenum destFormat, 56 const gl::Offset &destOffset, 57 TextureStorage *storage, 58 gl::TextureTarget target, 59 GLint level); 60 angle::Result copyTexture(const gl::Context *context, 61 const gl::Texture *source, 62 GLint sourceLevel, 63 const RECT &sourceRect, 64 GLenum destFormat, 65 const gl::Offset &destOffset, 66 TextureStorage *storage, 67 gl::TextureTarget destTarget, 68 GLint destLevel, 69 bool flipY, 70 bool premultiplyAlpha, 71 bool unmultiplyAlpha); 72 73 // 2x2 box filter sample from source to dest. 74 // Requires that source is RGB(A) and dest has the same format as source. 75 angle::Result boxFilter(Context9 *context9, IDirect3DSurface9 *source, IDirect3DSurface9 *dest); 76 77 private: 78 Renderer9 *mRenderer; 79 80 bool mGeometryLoaded; 81 IDirect3DVertexBuffer9 *mQuadVertexBuffer; 82 IDirect3DVertexDeclaration9 *mQuadVertexDeclaration; 83 84 // Copy from source texture to dest surface. 85 // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left) 86 // source is interpreted as RGBA and destFormat specifies the desired result format. For 87 // example, if destFormat = GL_RGB, the alpha channel will be forced to 0. 88 angle::Result formatConvert(Context9 *context9, 89 IDirect3DBaseTexture9 *source, 90 const RECT &sourceRect, 91 const gl::Extents &sourceSize, 92 GLenum destFormat, 93 const gl::Offset &destOffset, 94 IDirect3DSurface9 *dest, 95 bool flipY, 96 bool premultiplyAlpha, 97 bool unmultiplyAlpha); 98 angle::Result setFormatConvertShaders(Context9 *context9, 99 GLenum destFormat, 100 bool flipY, 101 bool premultiplyAlpha, 102 bool unmultiplyAlpha); 103 104 angle::Result copy(Context9 *context9, 105 IDirect3DSurface9 *source, 106 IDirect3DBaseTexture9 *sourceTexture, 107 const RECT &sourceRect, 108 GLenum destFormat, 109 const gl::Offset &destOffset, 110 IDirect3DSurface9 *dest, 111 bool flipY, 112 bool premultiplyAlpha, 113 bool unmultiplyAlpha); 114 angle::Result copySurfaceToTexture(Context9 *context9, 115 IDirect3DSurface9 *surface, 116 const RECT &sourceRect, 117 angle::ComPtr<IDirect3DBaseTexture9> *outTexture); 118 void setViewportAndShaderConstants(const RECT &sourceRect, 119 const gl::Extents &sourceSize, 120 const RECT &destRect, 121 bool flipY); 122 void setCommonBlitState(); 123 RECT getSurfaceRect(IDirect3DSurface9 *surface) const; 124 gl::Extents getSurfaceSize(IDirect3DSurface9 *surface) const; 125 126 // This enum is used to index mCompiledShaders and mShaderSource. 127 enum ShaderId 128 { 129 SHADER_VS_STANDARD, 130 SHADER_PS_PASSTHROUGH, 131 SHADER_PS_LUMINANCE, 132 SHADER_PS_LUMINANCE_PREMULTIPLY_ALPHA, 133 SHADER_PS_LUMINANCE_UNMULTIPLY_ALPHA, 134 SHADER_PS_COMPONENTMASK, 135 SHADER_PS_COMPONENTMASK_PREMULTIPLY_ALPHA, 136 SHADER_PS_COMPONENTMASK_UNMULTIPLY_ALPHA, 137 SHADER_COUNT, 138 }; 139 140 // This actually contains IDirect3DVertexShader9 or IDirect3DPixelShader9 casted to IUnknown. 141 IUnknown *mCompiledShaders[SHADER_COUNT]; 142 143 template <class D3DShaderType> 144 angle::Result setShader(Context9 *, 145 ShaderId source, 146 const char *profile, 147 angle::Result (Renderer9::*createShader)(d3d::Context *context, 148 const DWORD *, 149 size_t length, 150 D3DShaderType **outShader), 151 HRESULT (WINAPI IDirect3DDevice9::*setShader)(D3DShaderType *)); 152 153 angle::Result setVertexShader(Context9 *context9, ShaderId shader); 154 angle::Result setPixelShader(Context9 *context9, ShaderId shader); 155 void render(); 156 157 void saveState(); 158 void restoreState(); 159 IDirect3DStateBlock9 *mSavedStateBlock; 160 IDirect3DSurface9 *mSavedRenderTarget; 161 IDirect3DSurface9 *mSavedDepthStencil; 162 }; 163 } // namespace rx 164 165 #endif // LIBANGLE_RENDERER_D3D_D3D9_BLIT9_H_ 166