Bug 1066138: Disable using TextureClientD3D11 for A8 surfaces and fix various TextureClientD3D11 A8 bugs. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Sun, 14 Sep 2014 23:51:31 +0200
changeset 205249 d9619b1c61c8cb145048cafdf98e9a9a098b0144
parent 205248 551bc6fcaadf4b87a122b21d3335a568a7e53c51
child 205250 cab3c0ac23b00dc6de1e4f625a807684e0c3f32a
push id49118
push userbschouten@mozilla.com
push dateSun, 14 Sep 2014 21:53:14 +0000
treeherdermozilla-inbound@8e28464849fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1066138
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1066138: Disable using TextureClientD3D11 for A8 surfaces and fix various TextureClientD3D11 A8 bugs. r=jrmuizel
gfx/2d/DrawTargetD2D1.cpp
gfx/layers/d3d11/TextureD3D11.cpp
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -279,27 +279,49 @@ DrawTargetD2D1::MaskSurface(const Patter
 
 void
 DrawTargetD2D1::CopySurface(SourceSurface *aSurface,
                             const IntRect &aSourceRect,
                             const IntPoint &aDestination)
 {
   MarkChanged();
 
+  PopAllClips();
+
   mDC->SetTransform(D2D1::IdentityMatrix());
   mTransformDirty = true;
 
   Matrix mat;
   RefPtr<ID2D1Image> image = GetImageForSurface(aSurface, mat, ExtendMode::CLAMP);
 
   if (!mat.IsIdentity()) {
     gfxDebug() << *this << ": At this point complex partial uploads are not supported for CopySurface.";
     return;
   }
 
+  if (mFormat == SurfaceFormat::A8) {
+    RefPtr<ID2D1Bitmap> bitmap;
+    image->QueryInterface((ID2D1Bitmap**)byRef(bitmap));
+
+    mDC->PushAxisAlignedClip(D2D1::RectF(aDestination.x, aDestination.y,
+                                         aDestination.x + aSourceRect.width,
+                                         aDestination.y + aSourceRect.height),
+                             D2D1_ANTIALIAS_MODE_ALIASED);
+    mDC->Clear();
+    mDC->PopAxisAlignedClip();
+
+    RefPtr<ID2D1SolidColorBrush> brush;
+    mDC->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White),
+                               D2D1::BrushProperties(), byRef(brush));
+    mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+    mDC->FillOpacityMask(bitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS);
+    mDC->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
+    return;
+  }
+
   mDC->DrawImage(image, D2D1::Point2F(Float(aDestination.x), Float(aDestination.y)),
                  D2D1::RectF(Float(aSourceRect.x), Float(aSourceRect.y), 
                              Float(aSourceRect.XMost()), Float(aSourceRect.YMost())),
                  D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
 }
 
 void
 DrawTargetD2D1::FillRect(const Rect &aRect,
@@ -686,20 +708,20 @@ DrawTargetD2D1::Init(ID3D11Texture2D* aT
   }
 
   D2D1_BITMAP_PROPERTIES1 props;
   props.dpiX = 96;
   props.dpiY = 96;
   props.pixelFormat = D2DPixelFormat(aFormat);
   props.colorContext = nullptr;
   props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
-  mDC->CreateBitmapFromDxgiSurface(dxgiSurface, props, (ID2D1Bitmap1**)byRef(mBitmap));
+  hr = mDC->CreateBitmapFromDxgiSurface(dxgiSurface, props, (ID2D1Bitmap1**)byRef(mBitmap));
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << ": Error " << hr << " failed to create new CommandList.";
+    gfxWarning() << *this << ": Error " << hr << " failed to create new bitmap.";
     return false;
   }
 
   mFormat = aFormat;
   D3D11_TEXTURE2D_DESC desc;
   aTexture->GetDesc(&desc);
   mSize.width = desc.Width;
   mSize.height = desc.Height;
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -331,22 +331,28 @@ TextureClientD3D11::BorrowDrawTarget()
   return mDrawTarget;
 }
 
 bool
 TextureClientD3D11::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags)
 {
   mSize = aSize;
   HRESULT hr;
+
+  if (mFormat == SurfaceFormat::A8) {
+    // Currently TextureClientD3D11 does not support A8 surfaces. Fallback.
+    return false;
+  }
+
 #ifdef USE_D2D1_1
   ID3D11Device* d3d11device = gfxWindowsPlatform::GetPlatform()->GetD3D11ContentDevice();
 
   if (gfxPrefs::Direct2DUse1_1() && d3d11device) {
 
-    CD3D11_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM,
+    CD3D11_TEXTURE2D_DESC newDesc(mFormat == SurfaceFormat::A8 ? DXGI_FORMAT_A8_UNORM : DXGI_FORMAT_B8G8R8A8_UNORM,
                                   aSize.width, aSize.height, 1, 1,
                                   D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
 
     newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
 
     hr = d3d11device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture));
   } else
 #endif