1 // 2 // Copyright 2012 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 // TextureStorage9.h: Defines the abstract rx::TextureStorage9 class and its concrete derived 8 // classes TextureStorage9_2D and TextureStorage9_Cube, which act as the interface to the 9 // D3D9 texture. 10 11 #ifndef LIBANGLE_RENDERER_D3D_D3D9_TEXTURESTORAGE9_H_ 12 #define LIBANGLE_RENDERER_D3D_D3D9_TEXTURESTORAGE9_H_ 13 14 #include "common/debug.h" 15 #include "libANGLE/renderer/d3d/TextureStorage.h" 16 17 namespace rx 18 { 19 class EGLImageD3D; 20 class Renderer9; 21 class SwapChain9; 22 class RenderTargetD3D; 23 class RenderTarget9; 24 25 class TextureStorage9 : public TextureStorage 26 { 27 public: 28 ~TextureStorage9() override; 29 30 static DWORD GetTextureUsage(GLenum internalformat, bool renderTarget); 31 32 D3DPOOL getPool() const; 33 DWORD getUsage() const; 34 35 virtual angle::Result getSurfaceLevel(const gl::Context *context, 36 gl::TextureTarget target, 37 int level, 38 bool dirty, 39 IDirect3DSurface9 **outSurface) = 0; 40 virtual angle::Result getBaseTexture(const gl::Context *context, 41 IDirect3DBaseTexture9 **outTexture) = 0; 42 43 int getTopLevel() const override; 44 bool isRenderTarget() const override; 45 bool isManaged() const override; 46 bool supportsNativeMipmapFunction() const override; 47 int getLevelCount() const override; 48 49 angle::Result setData(const gl::Context *context, 50 const gl::ImageIndex &index, 51 ImageD3D *image, 52 const gl::Box *destBox, 53 GLenum type, 54 const gl::PixelUnpackState &unpack, 55 const uint8_t *pixelData) override; 56 57 protected: 58 int mTopLevel; 59 size_t mMipLevels; 60 size_t mTextureWidth; 61 size_t mTextureHeight; 62 GLenum mInternalFormat; 63 D3DFORMAT mTextureFormat; 64 65 Renderer9 *mRenderer; 66 67 TextureStorage9(Renderer9 *renderer, DWORD usage, const std::string &label); 68 69 private: 70 const DWORD mD3DUsage; 71 const D3DPOOL mD3DPool; 72 }; 73 74 class TextureStorage9_2D : public TextureStorage9 75 { 76 public: 77 TextureStorage9_2D(Renderer9 *renderer, SwapChain9 *swapchain, const std::string &label); 78 TextureStorage9_2D(Renderer9 *renderer, 79 GLenum internalformat, 80 bool renderTarget, 81 GLsizei width, 82 GLsizei height, 83 int levels, 84 const std::string &label); 85 ~TextureStorage9_2D() override; 86 87 angle::Result getSurfaceLevel(const gl::Context *context, 88 gl::TextureTarget target, 89 int level, 90 bool dirty, 91 IDirect3DSurface9 **outSurface) override; 92 angle::Result findRenderTarget(const gl::Context *context, 93 const gl::ImageIndex &index, 94 GLsizei samples, 95 RenderTargetD3D **outRT) const override; 96 angle::Result getRenderTarget(const gl::Context *context, 97 const gl::ImageIndex &index, 98 GLsizei samples, 99 RenderTargetD3D **outRT) override; 100 angle::Result getBaseTexture(const gl::Context *context, 101 IDirect3DBaseTexture9 **outTexture) override; 102 angle::Result generateMipmap(const gl::Context *context, 103 const gl::ImageIndex &sourceIndex, 104 const gl::ImageIndex &destIndex) override; 105 angle::Result copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; 106 107 private: 108 IDirect3DTexture9 *mTexture; 109 std::vector<RenderTarget9 *> mRenderTargets; 110 }; 111 112 class TextureStorage9_EGLImage final : public TextureStorage9 113 { 114 public: 115 TextureStorage9_EGLImage(Renderer9 *renderer, 116 EGLImageD3D *image, 117 RenderTarget9 *renderTarget9, 118 const std::string &label); 119 ~TextureStorage9_EGLImage() override; 120 121 angle::Result getSurfaceLevel(const gl::Context *context, 122 gl::TextureTarget target, 123 int level, 124 bool dirty, 125 IDirect3DSurface9 **outSurface) override; 126 angle::Result findRenderTarget(const gl::Context *context, 127 const gl::ImageIndex &index, 128 GLsizei samples, 129 RenderTargetD3D **outRT) const override; 130 angle::Result getRenderTarget(const gl::Context *context, 131 const gl::ImageIndex &index, 132 GLsizei samples, 133 RenderTargetD3D **outRT) override; 134 angle::Result getBaseTexture(const gl::Context *context, 135 IDirect3DBaseTexture9 **outTexture) override; 136 angle::Result generateMipmap(const gl::Context *context, 137 const gl::ImageIndex &sourceIndex, 138 const gl::ImageIndex &destIndex) override; 139 angle::Result copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; 140 141 private: 142 EGLImageD3D *mImage; 143 }; 144 145 class TextureStorage9_Cube : public TextureStorage9 146 { 147 public: 148 TextureStorage9_Cube(Renderer9 *renderer, 149 GLenum internalformat, 150 bool renderTarget, 151 int size, 152 int levels, 153 bool hintLevelZeroOnly, 154 const std::string &label); 155 156 ~TextureStorage9_Cube() override; 157 158 angle::Result getSurfaceLevel(const gl::Context *context, 159 gl::TextureTarget target, 160 int level, 161 bool dirty, 162 IDirect3DSurface9 **outSurface) override; 163 angle::Result findRenderTarget(const gl::Context *context, 164 const gl::ImageIndex &index, 165 GLsizei samples, 166 RenderTargetD3D **outRT) const override; 167 angle::Result getRenderTarget(const gl::Context *context, 168 const gl::ImageIndex &index, 169 GLsizei samples, 170 RenderTargetD3D **outRT) override; 171 angle::Result getBaseTexture(const gl::Context *context, 172 IDirect3DBaseTexture9 **outTexture) override; 173 angle::Result generateMipmap(const gl::Context *context, 174 const gl::ImageIndex &sourceIndex, 175 const gl::ImageIndex &destIndex) override; 176 angle::Result copyToStorage(const gl::Context *context, TextureStorage *destStorage) override; 177 178 private: 179 IDirect3DCubeTexture9 *mTexture; 180 RenderTarget9 *mRenderTarget[gl::kCubeFaceCount]; 181 }; 182 183 } // namespace rx 184 185 #endif // LIBANGLE_RENDERER_D3D_D3D9_TEXTURESTORAGE9_H_ 186