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