gfx/layers/d3d10/ThebesLayerD3D10.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 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/layers/PLayerTransaction.h"
michael@0 7
michael@0 8 // This must occur *after* layers/PLayerTransaction.h to avoid
michael@0 9 // typedefs conflicts.
michael@0 10 #include "mozilla/ArrayUtils.h"
michael@0 11
michael@0 12 #include "ThebesLayerD3D10.h"
michael@0 13 #include "gfxPlatform.h"
michael@0 14
michael@0 15 #include "gfxWindowsPlatform.h"
michael@0 16 #ifdef CAIRO_HAS_D2D_SURFACE
michael@0 17 #include "gfxD2DSurface.h"
michael@0 18 #endif
michael@0 19
michael@0 20 #include "../d3d9/Nv3DVUtils.h"
michael@0 21 #include "gfxTeeSurface.h"
michael@0 22 #include "gfxUtils.h"
michael@0 23 #include "ReadbackLayer.h"
michael@0 24 #include "ReadbackProcessor.h"
michael@0 25
michael@0 26 #include "mozilla/Preferences.h"
michael@0 27 #include "mozilla/gfx/2D.h"
michael@0 28
michael@0 29 using namespace mozilla::gfx;
michael@0 30
michael@0 31 namespace mozilla {
michael@0 32 namespace layers {
michael@0 33
michael@0 34 ThebesLayerD3D10::ThebesLayerD3D10(LayerManagerD3D10 *aManager)
michael@0 35 : ThebesLayer(aManager, nullptr)
michael@0 36 , LayerD3D10(aManager)
michael@0 37 , mCurrentSurfaceMode(SurfaceMode::SURFACE_OPAQUE)
michael@0 38 {
michael@0 39 mImplData = static_cast<LayerD3D10*>(this);
michael@0 40 }
michael@0 41
michael@0 42 ThebesLayerD3D10::~ThebesLayerD3D10()
michael@0 43 {
michael@0 44 }
michael@0 45
michael@0 46 void
michael@0 47 ThebesLayerD3D10::InvalidateRegion(const nsIntRegion &aRegion)
michael@0 48 {
michael@0 49 mInvalidRegion.Or(mInvalidRegion, aRegion);
michael@0 50 mInvalidRegion.SimplifyOutward(20);
michael@0 51 mValidRegion.Sub(mValidRegion, mInvalidRegion);
michael@0 52 }
michael@0 53
michael@0 54 void ThebesLayerD3D10::CopyRegion(ID3D10Texture2D* aSrc, const nsIntPoint &aSrcOffset,
michael@0 55 ID3D10Texture2D* aDest, const nsIntPoint &aDestOffset,
michael@0 56 const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion)
michael@0 57 {
michael@0 58 nsIntRegion retainedRegion;
michael@0 59 nsIntRegionRectIterator iter(aCopyRegion);
michael@0 60 const nsIntRect *r;
michael@0 61 while ((r = iter.Next())) {
michael@0 62 // Calculate the retained rectangle's position on the old and the new
michael@0 63 // surface.
michael@0 64 D3D10_BOX box;
michael@0 65 box.left = r->x - aSrcOffset.x;
michael@0 66 box.top = r->y - aSrcOffset.y;
michael@0 67 box.right = box.left + r->width;
michael@0 68 box.bottom = box.top + r->height;
michael@0 69 box.back = 1;
michael@0 70 box.front = 0;
michael@0 71
michael@0 72 device()->CopySubresourceRegion(aDest, 0,
michael@0 73 r->x - aDestOffset.x,
michael@0 74 r->y - aDestOffset.y,
michael@0 75 0,
michael@0 76 aSrc, 0,
michael@0 77 &box);
michael@0 78
michael@0 79 retainedRegion.Or(retainedRegion, *r);
michael@0 80 }
michael@0 81
michael@0 82 // Areas which were valid and were retained are still valid
michael@0 83 aValidRegion->And(*aValidRegion, retainedRegion);
michael@0 84 }
michael@0 85
michael@0 86 void
michael@0 87 ThebesLayerD3D10::RenderLayer()
michael@0 88 {
michael@0 89 if (!mTexture) {
michael@0 90 return;
michael@0 91 }
michael@0 92
michael@0 93 SetEffectTransformAndOpacity();
michael@0 94
michael@0 95 ID3D10EffectTechnique *technique;
michael@0 96 switch (mCurrentSurfaceMode) {
michael@0 97 case SurfaceMode::SURFACE_COMPONENT_ALPHA:
michael@0 98 technique = SelectShader(SHADER_COMPONENT_ALPHA | LoadMaskTexture());
michael@0 99 break;
michael@0 100 case SurfaceMode::SURFACE_OPAQUE:
michael@0 101 technique = SelectShader(SHADER_RGB | SHADER_PREMUL | LoadMaskTexture());
michael@0 102 break;
michael@0 103 case SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA:
michael@0 104 technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | LoadMaskTexture());
michael@0 105 break;
michael@0 106 default:
michael@0 107 NS_ERROR("Unknown mode");
michael@0 108 return;
michael@0 109 }
michael@0 110
michael@0 111 nsIntRegionRectIterator iter(mVisibleRegion);
michael@0 112
michael@0 113 const nsIntRect *iterRect;
michael@0 114 if (mSRView) {
michael@0 115 effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(mSRView);
michael@0 116 }
michael@0 117 if (mSRViewOnWhite) {
michael@0 118 effect()->GetVariableByName("tRGBWhite")->AsShaderResource()->SetResource(mSRViewOnWhite);
michael@0 119 }
michael@0 120
michael@0 121 while ((iterRect = iter.Next())) {
michael@0 122 effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
michael@0 123 ShaderConstantRectD3D10(
michael@0 124 (float)iterRect->x,
michael@0 125 (float)iterRect->y,
michael@0 126 (float)iterRect->width,
michael@0 127 (float)iterRect->height)
michael@0 128 );
michael@0 129
michael@0 130 effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
michael@0 131 ShaderConstantRectD3D10(
michael@0 132 (float)(iterRect->x - mTextureRect.x) / (float)mTextureRect.width,
michael@0 133 (float)(iterRect->y - mTextureRect.y) / (float)mTextureRect.height,
michael@0 134 (float)iterRect->width / (float)mTextureRect.width,
michael@0 135 (float)iterRect->height / (float)mTextureRect.height)
michael@0 136 );
michael@0 137
michael@0 138 technique->GetPassByIndex(0)->Apply(0);
michael@0 139 device()->Draw(4, 0);
michael@0 140 }
michael@0 141
michael@0 142 // Set back to default.
michael@0 143 effect()->GetVariableByName("vTextureCoords")->AsVector()->
michael@0 144 SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
michael@0 145 }
michael@0 146
michael@0 147 void
michael@0 148 ThebesLayerD3D10::Validate(ReadbackProcessor *aReadback)
michael@0 149 {
michael@0 150 if (mVisibleRegion.IsEmpty()) {
michael@0 151 return;
michael@0 152 }
michael@0 153
michael@0 154 if (FAILED(gfxWindowsPlatform::GetPlatform()->GetD3D10Device()->GetDeviceRemovedReason())) {
michael@0 155 // Device removed, this will be discovered on the next rendering pass.
michael@0 156 // Do no validate.
michael@0 157 return;
michael@0 158 }
michael@0 159
michael@0 160 nsIntRect newTextureRect = mVisibleRegion.GetBounds();
michael@0 161
michael@0 162 SurfaceMode mode = GetSurfaceMode();
michael@0 163 if (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA &&
michael@0 164 (!mParent || !mParent->SupportsComponentAlphaChildren())) {
michael@0 165 mode = SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA;
michael@0 166 }
michael@0 167 // If we have a transform that requires resampling of our texture, then
michael@0 168 // we need to make sure we don't sample pixels that haven't been drawn.
michael@0 169 // We clamp sample coordinates to the texture rect, but when the visible region
michael@0 170 // doesn't fill the entire texture rect we need to make sure we draw all the
michael@0 171 // pixels in the texture rect anyway in case they get sampled.
michael@0 172 nsIntRegion neededRegion = mVisibleRegion;
michael@0 173 if (!neededRegion.GetBounds().IsEqualInterior(newTextureRect) ||
michael@0 174 neededRegion.GetNumRects() > 1) {
michael@0 175 if (MayResample()) {
michael@0 176 neededRegion = newTextureRect;
michael@0 177 if (mode == SurfaceMode::SURFACE_OPAQUE) {
michael@0 178 // We're going to paint outside the visible region, but layout hasn't
michael@0 179 // promised that it will paint opaquely there, so we'll have to
michael@0 180 // treat this layer as transparent.
michael@0 181 mode = SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA;
michael@0 182 }
michael@0 183 }
michael@0 184 }
michael@0 185 mCurrentSurfaceMode = mode;
michael@0 186
michael@0 187 VerifyContentType(mode);
michael@0 188
michael@0 189 nsTArray<ReadbackProcessor::Update> readbackUpdates;
michael@0 190 nsIntRegion readbackRegion;
michael@0 191 if (aReadback && UsedForReadback()) {
michael@0 192 aReadback->GetThebesLayerUpdates(this, &readbackUpdates, &readbackRegion);
michael@0 193 }
michael@0 194
michael@0 195 if (mTexture) {
michael@0 196 if (!mTextureRect.IsEqualInterior(newTextureRect)) {
michael@0 197 nsRefPtr<ID3D10Texture2D> oldTexture = mTexture;
michael@0 198 mTexture = nullptr;
michael@0 199 nsRefPtr<ID3D10Texture2D> oldTextureOnWhite = mTextureOnWhite;
michael@0 200 mTextureOnWhite = nullptr;
michael@0 201
michael@0 202 nsIntRegion retainRegion = mTextureRect;
michael@0 203 // Old visible region will become the region that is covered by both the
michael@0 204 // old and the new visible region.
michael@0 205 retainRegion.And(retainRegion, mVisibleRegion);
michael@0 206 // No point in retaining parts which were not valid.
michael@0 207 retainRegion.And(retainRegion, mValidRegion);
michael@0 208
michael@0 209 CreateNewTextures(gfx::IntSize(newTextureRect.width, newTextureRect.height), mode);
michael@0 210
michael@0 211 nsIntRect largeRect = retainRegion.GetLargestRectangle();
michael@0 212
michael@0 213 // If we had no hardware texture before, or have no retained area larger than
michael@0 214 // the retention threshold, we're not retaining and are done here.
michael@0 215 // If our texture creation failed this can mean a device reset is pending
michael@0 216 // and we should silently ignore the failure. In the future when device
michael@0 217 // failures are properly handled we should test for the type of failure
michael@0 218 // and gracefully handle different failures. See bug 569081.
michael@0 219 if (!oldTexture || !mTexture) {
michael@0 220 mValidRegion.SetEmpty();
michael@0 221 } else {
michael@0 222 CopyRegion(oldTexture, mTextureRect.TopLeft(),
michael@0 223 mTexture, newTextureRect.TopLeft(),
michael@0 224 retainRegion, &mValidRegion);
michael@0 225 if (oldTextureOnWhite) {
michael@0 226 CopyRegion(oldTextureOnWhite, mTextureRect.TopLeft(),
michael@0 227 mTextureOnWhite, newTextureRect.TopLeft(),
michael@0 228 retainRegion, &mValidRegion);
michael@0 229 }
michael@0 230 }
michael@0 231 }
michael@0 232 }
michael@0 233 mTextureRect = newTextureRect;
michael@0 234
michael@0 235 if (!mTexture || (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA && !mTextureOnWhite)) {
michael@0 236 CreateNewTextures(gfx::IntSize(newTextureRect.width, newTextureRect.height), mode);
michael@0 237 mValidRegion.SetEmpty();
michael@0 238 }
michael@0 239
michael@0 240 nsIntRegion drawRegion;
michael@0 241 drawRegion.Sub(neededRegion, mValidRegion);
michael@0 242
michael@0 243 if (!drawRegion.IsEmpty()) {
michael@0 244 LayerManagerD3D10::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
michael@0 245 if (!cbInfo.Callback) {
michael@0 246 NS_ERROR("D3D10 should never need to update ThebesLayers in an empty transaction");
michael@0 247 return;
michael@0 248 }
michael@0 249
michael@0 250 DrawRegion(drawRegion, mode);
michael@0 251
michael@0 252 if (readbackUpdates.Length() > 0) {
michael@0 253 CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
michael@0 254 newTextureRect.width, newTextureRect.height,
michael@0 255 1, 1, 0, D3D10_USAGE_STAGING,
michael@0 256 D3D10_CPU_ACCESS_READ);
michael@0 257
michael@0 258 nsRefPtr<ID3D10Texture2D> readbackTexture;
michael@0 259 HRESULT hr = device()->CreateTexture2D(&desc, nullptr, getter_AddRefs(readbackTexture));
michael@0 260 if (FAILED(hr)) {
michael@0 261 LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("ThebesLayerD3D10::Validate(): Failed to create texture"),
michael@0 262 hr);
michael@0 263 return;
michael@0 264 }
michael@0 265
michael@0 266 device()->CopyResource(readbackTexture, mTexture);
michael@0 267
michael@0 268 for (uint32_t i = 0; i < readbackUpdates.Length(); i++) {
michael@0 269 mD3DManager->readbackManager()->PostTask(readbackTexture,
michael@0 270 &readbackUpdates[i],
michael@0 271 gfxPoint(newTextureRect.x, newTextureRect.y));
michael@0 272 }
michael@0 273 }
michael@0 274
michael@0 275 mValidRegion = neededRegion;
michael@0 276 }
michael@0 277 }
michael@0 278
michael@0 279 void
michael@0 280 ThebesLayerD3D10::LayerManagerDestroyed()
michael@0 281 {
michael@0 282 mD3DManager = nullptr;
michael@0 283 }
michael@0 284
michael@0 285 Layer*
michael@0 286 ThebesLayerD3D10::GetLayer()
michael@0 287 {
michael@0 288 return this;
michael@0 289 }
michael@0 290
michael@0 291 void
michael@0 292 ThebesLayerD3D10::VerifyContentType(SurfaceMode aMode)
michael@0 293 {
michael@0 294 if (mD2DSurface) {
michael@0 295 gfxContentType type = aMode != SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA ?
michael@0 296 gfxContentType::COLOR : gfxContentType::COLOR_ALPHA;
michael@0 297
michael@0 298 if (type != mD2DSurface->GetContentType()) {
michael@0 299 mD2DSurface = new gfxD2DSurface(mTexture, type);
michael@0 300
michael@0 301 if (!mD2DSurface || mD2DSurface->CairoStatus()) {
michael@0 302 NS_WARNING("Failed to create surface for ThebesLayerD3D10.");
michael@0 303 mD2DSurface = nullptr;
michael@0 304 return;
michael@0 305 }
michael@0 306
michael@0 307 mValidRegion.SetEmpty();
michael@0 308 }
michael@0 309 } else if (mDrawTarget) {
michael@0 310 SurfaceFormat format = aMode != SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA ?
michael@0 311 SurfaceFormat::B8G8R8X8 : SurfaceFormat::B8G8R8A8;
michael@0 312
michael@0 313 if (format != mDrawTarget->GetFormat()) {
michael@0 314 mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, format);
michael@0 315
michael@0 316 if (!mDrawTarget) {
michael@0 317 NS_WARNING("Failed to create drawtarget for ThebesLayerD3D10.");
michael@0 318 return;
michael@0 319 }
michael@0 320
michael@0 321 mValidRegion.SetEmpty();
michael@0 322 }
michael@0 323 }
michael@0 324
michael@0 325 if (aMode != SurfaceMode::SURFACE_COMPONENT_ALPHA && mTextureOnWhite) {
michael@0 326 // If we've transitioned away from component alpha, we can delete those resources.
michael@0 327 mD2DSurfaceOnWhite = nullptr;
michael@0 328 mSRViewOnWhite = nullptr;
michael@0 329 mTextureOnWhite = nullptr;
michael@0 330 mValidRegion.SetEmpty();
michael@0 331 }
michael@0 332 }
michael@0 333
michael@0 334 void
michael@0 335 ThebesLayerD3D10::FillTexturesBlackWhite(const nsIntRegion& aRegion, const nsIntPoint& aOffset)
michael@0 336 {
michael@0 337 if (mTexture && mTextureOnWhite) {
michael@0 338 // It would be more optimal to draw the actual geometry, but more code
michael@0 339 // and probably not worth the win here as this will often be a single
michael@0 340 // rect.
michael@0 341 nsRefPtr<ID3D10RenderTargetView> oldRT;
michael@0 342 device()->OMGetRenderTargets(1, getter_AddRefs(oldRT), nullptr);
michael@0 343
michael@0 344 nsRefPtr<ID3D10RenderTargetView> viewBlack;
michael@0 345 nsRefPtr<ID3D10RenderTargetView> viewWhite;
michael@0 346 device()->CreateRenderTargetView(mTexture, nullptr, getter_AddRefs(viewBlack));
michael@0 347 device()->CreateRenderTargetView(mTextureOnWhite, nullptr, getter_AddRefs(viewWhite));
michael@0 348
michael@0 349 D3D10_RECT oldScissor;
michael@0 350 UINT numRects = 1;
michael@0 351 device()->RSGetScissorRects(&numRects, &oldScissor);
michael@0 352
michael@0 353 D3D10_TEXTURE2D_DESC desc;
michael@0 354 mTexture->GetDesc(&desc);
michael@0 355
michael@0 356 D3D10_RECT scissor = { 0, 0, desc.Width, desc.Height };
michael@0 357 device()->RSSetScissorRects(1, &scissor);
michael@0 358
michael@0 359 mD3DManager->SetupInputAssembler();
michael@0 360 nsIntSize oldVP = mD3DManager->GetViewport();
michael@0 361
michael@0 362 mD3DManager->SetViewport(nsIntSize(desc.Width, desc.Height));
michael@0 363
michael@0 364 ID3D10RenderTargetView *views[2] = { viewBlack, viewWhite };
michael@0 365 device()->OMSetRenderTargets(2, views, nullptr);
michael@0 366
michael@0 367 gfx3DMatrix transform;
michael@0 368 transform.Translate(gfxPoint3D(-aOffset.x, -aOffset.y, 0));
michael@0 369 void* raw = &const_cast<gfx3DMatrix&>(transform)._11;
michael@0 370 effect()->GetVariableByName("mLayerTransform")->SetRawValue(raw, 0, 64);
michael@0 371
michael@0 372 ID3D10EffectTechnique *technique =
michael@0 373 effect()->GetTechniqueByName("PrepareAlphaExtractionTextures");
michael@0 374
michael@0 375 nsIntRegionRectIterator iter(aRegion);
michael@0 376
michael@0 377 const nsIntRect *iterRect;
michael@0 378 while ((iterRect = iter.Next())) {
michael@0 379 effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
michael@0 380 ShaderConstantRectD3D10(
michael@0 381 (float)iterRect->x,
michael@0 382 (float)iterRect->y,
michael@0 383 (float)iterRect->width,
michael@0 384 (float)iterRect->height)
michael@0 385 );
michael@0 386
michael@0 387 technique->GetPassByIndex(0)->Apply(0);
michael@0 388 device()->Draw(4, 0);
michael@0 389 }
michael@0 390
michael@0 391 views[0] = oldRT;
michael@0 392 device()->OMSetRenderTargets(1, views, nullptr);
michael@0 393 mD3DManager->SetViewport(oldVP);
michael@0 394 device()->RSSetScissorRects(1, &oldScissor);
michael@0 395 }
michael@0 396 }
michael@0 397
michael@0 398 void
michael@0 399 ThebesLayerD3D10::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode)
michael@0 400 {
michael@0 401 nsIntRect visibleRect = mVisibleRegion.GetBounds();
michael@0 402
michael@0 403 if (!mD2DSurface && !mDrawTarget) {
michael@0 404 return;
michael@0 405 }
michael@0 406
michael@0 407 aRegion.SimplifyOutwardByArea(100 * 100);
michael@0 408
michael@0 409 nsRefPtr<gfxASurface> destinationSurface;
michael@0 410
michael@0 411 if (aMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) {
michael@0 412 FillTexturesBlackWhite(aRegion, visibleRect.TopLeft());
michael@0 413 } else {
michael@0 414 destinationSurface = mD2DSurface;
michael@0 415 }
michael@0 416
michael@0 417 MOZ_ASSERT(mDrawTarget);
michael@0 418 nsRefPtr<gfxContext> context = new gfxContext(mDrawTarget);
michael@0 419
michael@0 420 context->Translate(gfxPoint(-visibleRect.x, -visibleRect.y));
michael@0 421 if (aMode == SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA) {
michael@0 422 nsIntRegionRectIterator iter(aRegion);
michael@0 423 const nsIntRect *iterRect;
michael@0 424 while ((iterRect = iter.Next())) {
michael@0 425 mDrawTarget->ClearRect(Rect(iterRect->x, iterRect->y, iterRect->width, iterRect->height));
michael@0 426 }
michael@0 427 }
michael@0 428
michael@0 429 mDrawTarget->SetPermitSubpixelAA(!(mContentFlags & CONTENT_COMPONENT_ALPHA));
michael@0 430
michael@0 431 LayerManagerD3D10::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
michael@0 432 cbInfo.Callback(this, context, aRegion, DrawRegionClip::DRAW, nsIntRegion(), cbInfo.CallbackData);
michael@0 433 }
michael@0 434
michael@0 435 void
michael@0 436 ThebesLayerD3D10::CreateNewTextures(const gfx::IntSize &aSize, SurfaceMode aMode)
michael@0 437 {
michael@0 438 if (aSize.width == 0 || aSize.height == 0) {
michael@0 439 // Nothing to do.
michael@0 440 return;
michael@0 441 }
michael@0 442
michael@0 443 CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1);
michael@0 444 desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
michael@0 445 desc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
michael@0 446 HRESULT hr;
michael@0 447
michael@0 448 if (!mTexture) {
michael@0 449 hr = device()->CreateTexture2D(&desc, nullptr, getter_AddRefs(mTexture));
michael@0 450
michael@0 451 if (FAILED(hr)) {
michael@0 452 NS_WARNING("Failed to create new texture for ThebesLayerD3D10!");
michael@0 453 return;
michael@0 454 }
michael@0 455
michael@0 456 hr = device()->CreateShaderResourceView(mTexture, nullptr, getter_AddRefs(mSRView));
michael@0 457
michael@0 458 if (FAILED(hr)) {
michael@0 459 NS_WARNING("Failed to create shader resource view for ThebesLayerD3D10.");
michael@0 460 }
michael@0 461
michael@0 462 mDrawTarget = nullptr;
michael@0 463 }
michael@0 464
michael@0 465 if (aMode == SurfaceMode::SURFACE_COMPONENT_ALPHA && !mTextureOnWhite) {
michael@0 466 hr = device()->CreateTexture2D(&desc, nullptr, getter_AddRefs(mTextureOnWhite));
michael@0 467
michael@0 468 if (FAILED(hr)) {
michael@0 469 NS_WARNING("Failed to create new texture for ThebesLayerD3D10!");
michael@0 470 return;
michael@0 471 }
michael@0 472
michael@0 473 hr = device()->CreateShaderResourceView(mTextureOnWhite, nullptr, getter_AddRefs(mSRViewOnWhite));
michael@0 474
michael@0 475 if (FAILED(hr)) {
michael@0 476 NS_WARNING("Failed to create shader resource view for ThebesLayerD3D10.");
michael@0 477 }
michael@0 478
michael@0 479 mDrawTarget = nullptr;
michael@0 480 }
michael@0 481
michael@0 482 if (!mDrawTarget) {
michael@0 483 if (aMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) {
michael@0 484 mDrawTarget = Factory::CreateDualDrawTargetForD3D10Textures(mTexture, mTextureOnWhite, SurfaceFormat::B8G8R8X8);
michael@0 485 } else {
michael@0 486 mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, aMode != SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA ?
michael@0 487 SurfaceFormat::B8G8R8X8 : SurfaceFormat::B8G8R8A8);
michael@0 488 }
michael@0 489
michael@0 490 if (!mDrawTarget) {
michael@0 491 NS_WARNING("Failed to create DrawTarget for ThebesLayerD3D10.");
michael@0 492 mDrawTarget = nullptr;
michael@0 493 return;
michael@0 494 }
michael@0 495 }
michael@0 496 }
michael@0 497
michael@0 498 } /* namespace layers */
michael@0 499 } /* namespace mozilla */

mercurial