gfx/angle/src/libGLESv2/renderer/TextureStorage9.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #include "precompiled.h"
michael@0 2 //
michael@0 3 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
michael@0 4 // Use of this source code is governed by a BSD-style license that can be
michael@0 5 // found in the LICENSE file.
michael@0 6 //
michael@0 7
michael@0 8 // TextureStorage9.cpp: Implements the abstract rx::TextureStorage9 class and its concrete derived
michael@0 9 // classes TextureStorage9_2D and TextureStorage9_Cube, which act as the interface to the
michael@0 10 // D3D9 texture.
michael@0 11
michael@0 12 #include "libGLESv2/main.h"
michael@0 13 #include "libGLESv2/renderer/Renderer9.h"
michael@0 14 #include "libGLESv2/renderer/TextureStorage9.h"
michael@0 15 #include "libGLESv2/renderer/SwapChain9.h"
michael@0 16 #include "libGLESv2/renderer/RenderTarget9.h"
michael@0 17 #include "libGLESv2/renderer/renderer9_utils.h"
michael@0 18 #include "libGLESv2/Texture.h"
michael@0 19
michael@0 20 namespace rx
michael@0 21 {
michael@0 22 TextureStorage9::TextureStorage9(Renderer *renderer, DWORD usage)
michael@0 23 : mLodOffset(0),
michael@0 24 mRenderer(Renderer9::makeRenderer9(renderer)),
michael@0 25 mD3DUsage(usage),
michael@0 26 mD3DPool(mRenderer->getTexturePool(usage))
michael@0 27 {
michael@0 28 }
michael@0 29
michael@0 30 TextureStorage9::~TextureStorage9()
michael@0 31 {
michael@0 32 }
michael@0 33
michael@0 34 TextureStorage9 *TextureStorage9::makeTextureStorage9(TextureStorage *storage)
michael@0 35 {
michael@0 36 ASSERT(HAS_DYNAMIC_TYPE(TextureStorage9*, storage));
michael@0 37 return static_cast<TextureStorage9*>(storage);
michael@0 38 }
michael@0 39
michael@0 40 DWORD TextureStorage9::GetTextureUsage(D3DFORMAT d3dfmt, GLenum glusage, bool forceRenderable)
michael@0 41 {
michael@0 42 DWORD d3dusage = 0;
michael@0 43
michael@0 44 if (d3dfmt == D3DFMT_INTZ)
michael@0 45 {
michael@0 46 d3dusage |= D3DUSAGE_DEPTHSTENCIL;
michael@0 47 }
michael@0 48 else if(forceRenderable || (TextureStorage9::IsTextureFormatRenderable(d3dfmt) && (glusage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE)))
michael@0 49 {
michael@0 50 d3dusage |= D3DUSAGE_RENDERTARGET;
michael@0 51 }
michael@0 52 return d3dusage;
michael@0 53 }
michael@0 54
michael@0 55 bool TextureStorage9::IsTextureFormatRenderable(D3DFORMAT format)
michael@0 56 {
michael@0 57 if (format == D3DFMT_INTZ)
michael@0 58 {
michael@0 59 return true;
michael@0 60 }
michael@0 61 switch(format)
michael@0 62 {
michael@0 63 case D3DFMT_L8:
michael@0 64 case D3DFMT_A8L8:
michael@0 65 case D3DFMT_DXT1:
michael@0 66 case D3DFMT_DXT3:
michael@0 67 case D3DFMT_DXT5:
michael@0 68 return false;
michael@0 69 case D3DFMT_A8R8G8B8:
michael@0 70 case D3DFMT_X8R8G8B8:
michael@0 71 case D3DFMT_A16B16G16R16F:
michael@0 72 case D3DFMT_A32B32G32R32F:
michael@0 73 return true;
michael@0 74 default:
michael@0 75 UNREACHABLE();
michael@0 76 }
michael@0 77
michael@0 78 return false;
michael@0 79 }
michael@0 80
michael@0 81 bool TextureStorage9::isRenderTarget() const
michael@0 82 {
michael@0 83 return (mD3DUsage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) != 0;
michael@0 84 }
michael@0 85
michael@0 86 bool TextureStorage9::isManaged() const
michael@0 87 {
michael@0 88 return (mD3DPool == D3DPOOL_MANAGED);
michael@0 89 }
michael@0 90
michael@0 91 D3DPOOL TextureStorage9::getPool() const
michael@0 92 {
michael@0 93 return mD3DPool;
michael@0 94 }
michael@0 95
michael@0 96 DWORD TextureStorage9::getUsage() const
michael@0 97 {
michael@0 98 return mD3DUsage;
michael@0 99 }
michael@0 100
michael@0 101 int TextureStorage9::getLodOffset() const
michael@0 102 {
michael@0 103 return mLodOffset;
michael@0 104 }
michael@0 105
michael@0 106 int TextureStorage9::levelCount()
michael@0 107 {
michael@0 108 return getBaseTexture() ? getBaseTexture()->GetLevelCount() - getLodOffset() : 0;
michael@0 109 }
michael@0 110
michael@0 111 TextureStorage9_2D::TextureStorage9_2D(Renderer *renderer, SwapChain9 *swapchain) : TextureStorage9(renderer, D3DUSAGE_RENDERTARGET)
michael@0 112 {
michael@0 113 IDirect3DTexture9 *surfaceTexture = swapchain->getOffscreenTexture();
michael@0 114 mTexture = surfaceTexture;
michael@0 115 mRenderTarget = NULL;
michael@0 116
michael@0 117 initializeRenderTarget();
michael@0 118 }
michael@0 119
michael@0 120 TextureStorage9_2D::TextureStorage9_2D(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height)
michael@0 121 : TextureStorage9(renderer, GetTextureUsage(Renderer9::makeRenderer9(renderer)->ConvertTextureInternalFormat(internalformat), usage, forceRenderable))
michael@0 122 {
michael@0 123 mTexture = NULL;
michael@0 124 mRenderTarget = NULL;
michael@0 125 // if the width or height is not positive this should be treated as an incomplete texture
michael@0 126 // we handle that here by skipping the d3d texture creation
michael@0 127 if (width > 0 && height > 0)
michael@0 128 {
michael@0 129 IDirect3DDevice9 *device = mRenderer->getDevice();
michael@0 130 gl::MakeValidSize(false, gl::IsCompressed(internalformat), &width, &height, &mLodOffset);
michael@0 131 HRESULT result = device->CreateTexture(width, height, levels ? levels + mLodOffset : 0, getUsage(),
michael@0 132 mRenderer->ConvertTextureInternalFormat(internalformat), getPool(), &mTexture, NULL);
michael@0 133
michael@0 134 if (FAILED(result))
michael@0 135 {
michael@0 136 ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
michael@0 137 gl::error(GL_OUT_OF_MEMORY);
michael@0 138 }
michael@0 139 }
michael@0 140
michael@0 141 initializeRenderTarget();
michael@0 142 }
michael@0 143
michael@0 144 TextureStorage9_2D::~TextureStorage9_2D()
michael@0 145 {
michael@0 146 if (mTexture)
michael@0 147 {
michael@0 148 mTexture->Release();
michael@0 149 }
michael@0 150
michael@0 151 delete mRenderTarget;
michael@0 152 }
michael@0 153
michael@0 154 TextureStorage9_2D *TextureStorage9_2D::makeTextureStorage9_2D(TextureStorage *storage)
michael@0 155 {
michael@0 156 ASSERT(HAS_DYNAMIC_TYPE(TextureStorage9_2D*, storage));
michael@0 157 return static_cast<TextureStorage9_2D*>(storage);
michael@0 158 }
michael@0 159
michael@0 160 // Increments refcount on surface.
michael@0 161 // caller must Release() the returned surface
michael@0 162 IDirect3DSurface9 *TextureStorage9_2D::getSurfaceLevel(int level, bool dirty)
michael@0 163 {
michael@0 164 IDirect3DSurface9 *surface = NULL;
michael@0 165
michael@0 166 if (mTexture)
michael@0 167 {
michael@0 168 HRESULT result = mTexture->GetSurfaceLevel(level + mLodOffset, &surface);
michael@0 169 ASSERT(SUCCEEDED(result));
michael@0 170
michael@0 171 // With managed textures the driver needs to be informed of updates to the lower mipmap levels
michael@0 172 if (level + mLodOffset != 0 && isManaged() && dirty)
michael@0 173 {
michael@0 174 mTexture->AddDirtyRect(NULL);
michael@0 175 }
michael@0 176 }
michael@0 177
michael@0 178 return surface;
michael@0 179 }
michael@0 180
michael@0 181 RenderTarget *TextureStorage9_2D::getRenderTarget()
michael@0 182 {
michael@0 183 return mRenderTarget;
michael@0 184 }
michael@0 185
michael@0 186 void TextureStorage9_2D::generateMipmap(int level)
michael@0 187 {
michael@0 188 IDirect3DSurface9 *upper = getSurfaceLevel(level - 1, false);
michael@0 189 IDirect3DSurface9 *lower = getSurfaceLevel(level, true);
michael@0 190
michael@0 191 if (upper != NULL && lower != NULL)
michael@0 192 {
michael@0 193 mRenderer->boxFilter(upper, lower);
michael@0 194 }
michael@0 195
michael@0 196 if (upper != NULL) upper->Release();
michael@0 197 if (lower != NULL) lower->Release();
michael@0 198 }
michael@0 199
michael@0 200 IDirect3DBaseTexture9 *TextureStorage9_2D::getBaseTexture() const
michael@0 201 {
michael@0 202 return mTexture;
michael@0 203 }
michael@0 204
michael@0 205 void TextureStorage9_2D::initializeRenderTarget()
michael@0 206 {
michael@0 207 ASSERT(mRenderTarget == NULL);
michael@0 208
michael@0 209 if (mTexture != NULL && isRenderTarget())
michael@0 210 {
michael@0 211 IDirect3DSurface9 *surface = getSurfaceLevel(0, false);
michael@0 212
michael@0 213 mRenderTarget = new RenderTarget9(mRenderer, surface);
michael@0 214 }
michael@0 215 }
michael@0 216
michael@0 217 TextureStorage9_Cube::TextureStorage9_Cube(Renderer *renderer, int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size)
michael@0 218 : TextureStorage9(renderer, GetTextureUsage(Renderer9::makeRenderer9(renderer)->ConvertTextureInternalFormat(internalformat), usage, forceRenderable))
michael@0 219 {
michael@0 220 mTexture = NULL;
michael@0 221 for (int i = 0; i < 6; ++i)
michael@0 222 {
michael@0 223 mRenderTarget[i] = NULL;
michael@0 224 }
michael@0 225
michael@0 226 // if the size is not positive this should be treated as an incomplete texture
michael@0 227 // we handle that here by skipping the d3d texture creation
michael@0 228 if (size > 0)
michael@0 229 {
michael@0 230 IDirect3DDevice9 *device = mRenderer->getDevice();
michael@0 231 int height = size;
michael@0 232 gl::MakeValidSize(false, gl::IsCompressed(internalformat), &size, &height, &mLodOffset);
michael@0 233 HRESULT result = device->CreateCubeTexture(size, levels ? levels + mLodOffset : 0, getUsage(),
michael@0 234 mRenderer->ConvertTextureInternalFormat(internalformat), getPool(), &mTexture, NULL);
michael@0 235
michael@0 236 if (FAILED(result))
michael@0 237 {
michael@0 238 ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
michael@0 239 gl::error(GL_OUT_OF_MEMORY);
michael@0 240 }
michael@0 241 }
michael@0 242
michael@0 243 initializeRenderTarget();
michael@0 244 }
michael@0 245
michael@0 246 TextureStorage9_Cube::~TextureStorage9_Cube()
michael@0 247 {
michael@0 248 if (mTexture)
michael@0 249 {
michael@0 250 mTexture->Release();
michael@0 251 }
michael@0 252
michael@0 253 for (int i = 0; i < 6; ++i)
michael@0 254 {
michael@0 255 delete mRenderTarget[i];
michael@0 256 }
michael@0 257 }
michael@0 258
michael@0 259 TextureStorage9_Cube *TextureStorage9_Cube::makeTextureStorage9_Cube(TextureStorage *storage)
michael@0 260 {
michael@0 261 ASSERT(HAS_DYNAMIC_TYPE(TextureStorage9_Cube*, storage));
michael@0 262 return static_cast<TextureStorage9_Cube*>(storage);
michael@0 263 }
michael@0 264
michael@0 265 // Increments refcount on surface.
michael@0 266 // caller must Release() the returned surface
michael@0 267 IDirect3DSurface9 *TextureStorage9_Cube::getCubeMapSurface(GLenum faceTarget, int level, bool dirty)
michael@0 268 {
michael@0 269 IDirect3DSurface9 *surface = NULL;
michael@0 270
michael@0 271 if (mTexture)
michael@0 272 {
michael@0 273 D3DCUBEMAP_FACES face = gl_d3d9::ConvertCubeFace(faceTarget);
michael@0 274 HRESULT result = mTexture->GetCubeMapSurface(face, level + mLodOffset, &surface);
michael@0 275 ASSERT(SUCCEEDED(result));
michael@0 276
michael@0 277 // With managed textures the driver needs to be informed of updates to the lower mipmap levels
michael@0 278 if (level != 0 && isManaged() && dirty)
michael@0 279 {
michael@0 280 mTexture->AddDirtyRect(face, NULL);
michael@0 281 }
michael@0 282 }
michael@0 283
michael@0 284 return surface;
michael@0 285 }
michael@0 286
michael@0 287 RenderTarget *TextureStorage9_Cube::getRenderTarget(GLenum faceTarget)
michael@0 288 {
michael@0 289 return mRenderTarget[gl::TextureCubeMap::faceIndex(faceTarget)];
michael@0 290 }
michael@0 291
michael@0 292 void TextureStorage9_Cube::generateMipmap(int face, int level)
michael@0 293 {
michael@0 294 IDirect3DSurface9 *upper = getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level - 1, false);
michael@0 295 IDirect3DSurface9 *lower = getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, true);
michael@0 296
michael@0 297 if (upper != NULL && lower != NULL)
michael@0 298 {
michael@0 299 mRenderer->boxFilter(upper, lower);
michael@0 300 }
michael@0 301
michael@0 302 if (upper != NULL) upper->Release();
michael@0 303 if (lower != NULL) lower->Release();
michael@0 304 }
michael@0 305
michael@0 306 IDirect3DBaseTexture9 *TextureStorage9_Cube::getBaseTexture() const
michael@0 307 {
michael@0 308 return mTexture;
michael@0 309 }
michael@0 310
michael@0 311 void TextureStorage9_Cube::initializeRenderTarget()
michael@0 312 {
michael@0 313 if (mTexture != NULL && isRenderTarget())
michael@0 314 {
michael@0 315 IDirect3DSurface9 *surface = NULL;
michael@0 316
michael@0 317 for (int i = 0; i < 6; ++i)
michael@0 318 {
michael@0 319 ASSERT(mRenderTarget[i] == NULL);
michael@0 320
michael@0 321 surface = getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, false);
michael@0 322
michael@0 323 mRenderTarget[i] = new RenderTarget9(mRenderer, surface);
michael@0 324 }
michael@0 325 }
michael@0 326 }
michael@0 327
michael@0 328 }

mercurial