Bug 615316 - Part 3: Support any container in ImageLayerD3D10. r=jrmuizel a=blocking-betan
authorBas Schouten <bschouten@mozilla.com>
Wed, 15 Dec 2010 21:37:15 +0100
changeset 59258 965edccda61cb9e53bb7b6bb942e49a61569fd36
parent 59257 97bbced8ab7148239a1b20aeea9e99e43db0502a
child 59259 6246b6c7fff6ea667181ae7cc79981f0631418ca
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjrmuizel, blocking-betan
bugs615316
milestone2.0b9pre
Bug 615316 - Part 3: Support any container in ImageLayerD3D10. r=jrmuizel a=blocking-betan
gfx/layers/d3d10/ImageLayerD3D10.cpp
--- a/gfx/layers/d3d10/ImageLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ImageLayerD3D10.cpp
@@ -176,17 +176,20 @@ ImageContainerD3D10::GetCurrentSize()
   }
 
   return gfxIntSize(0,0);
 }
 
 PRBool
 ImageContainerD3D10::SetLayerManager(LayerManager *aManager)
 {
-  // we can't do anything here for now
+  if (aManager->GetBackendType() == LayerManager::LAYERS_D3D10) {
+    mManager = aManager;
+    return PR_TRUE;
+  }
   return PR_FALSE;
 }
 
 Layer*
 ImageLayerD3D10::GetLayer()
 {
   return this;
 }
@@ -199,17 +202,70 @@ ImageLayerD3D10::RenderLayer()
   }
 
   nsRefPtr<Image> image = GetContainer()->GetCurrentImage();
 
   SetEffectTransformAndOpacity();
 
   ID3D10EffectTechnique *technique;
 
-  if (image->GetFormat() == Image::PLANAR_YCBCR) {
+  if (GetContainer()->Manager() != Manager()) {
+    GetContainer()->SetLayerManager(Manager());
+  }
+
+  if (GetContainer()->Manager() != Manager() ||
+      image->GetFormat() == Image::CAIRO_SURFACE)
+  {
+    gfxIntSize size;
+    bool hasAlpha;
+    nsRefPtr<ID3D10ShaderResourceView> srView;
+
+    if (GetContainer()->Manager() != Manager()) {
+      nsRefPtr<gfxASurface> surf = GetContainer()->GetCurrentAsSurface(&size);
+      
+      nsRefPtr<ID3D10Texture2D> texture = SurfaceToTexture(device(), surf, size);
+      
+      hasAlpha = surf->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA;
+      
+      device()->CreateShaderResourceView(texture, NULL, getter_AddRefs(srView));
+    } else {
+      // image->GetFormat() == Image::CAIRO_SURFACE
+      CairoImageD3D10 *cairoImage =
+        static_cast<CairoImageD3D10*>(image.get());
+      srView = cairoImage->mSRView;
+      hasAlpha = cairoImage->mHasAlpha;
+      size = cairoImage->mSize;
+    }
+
+    if (hasAlpha) {
+      if (mFilter == gfxPattern::FILTER_NEAREST) {
+        technique = effect()->GetTechniqueByName("RenderRGBALayerPremulPoint");
+      } else {
+        technique = effect()->GetTechniqueByName("RenderRGBALayerPremul");
+      }
+    } else {
+      if (mFilter == gfxPattern::FILTER_NEAREST) {
+        technique = effect()->GetTechniqueByName("RenderRGBLayerPremulPoint");
+      } else {
+        technique = effect()->GetTechniqueByName("RenderRGBLayerPremul");
+      }
+    }
+
+    if (srView) {
+      effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(srView);
+    }
+
+    effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
+      ShaderConstantRectD3D10(
+        (float)0,
+        (float)0,
+        (float)size.width,
+        (float)size.height)
+      );
+  } else if (image->GetFormat() == Image::PLANAR_YCBCR) {
     PlanarYCbCrImageD3D10 *yuvImage =
       static_cast<PlanarYCbCrImageD3D10*>(image.get());
 
     if (!yuvImage->HasData()) {
       return;
     }
 
     // TODO: At some point we should try to deal with mFilter here, you don't
@@ -225,45 +281,16 @@ ImageLayerD3D10::RenderLayer()
 
     effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
       ShaderConstantRectD3D10(
         (float)0,
         (float)0,
         (float)yuvImage->mSize.width,
         (float)yuvImage->mSize.height)
       );
-  } else if (image->GetFormat() == Image::CAIRO_SURFACE) {
-    CairoImageD3D10 *cairoImage =
-      static_cast<CairoImageD3D10*>(image.get());
-
-    if (cairoImage->mHasAlpha) {
-      if (mFilter == gfxPattern::FILTER_NEAREST) {
-        technique = effect()->GetTechniqueByName("RenderRGBALayerPremulPoint");
-      } else {
-        technique = effect()->GetTechniqueByName("RenderRGBALayerPremul");
-      }
-    } else {
-      if (mFilter == gfxPattern::FILTER_NEAREST) {
-        technique = effect()->GetTechniqueByName("RenderRGBLayerPremulPoint");
-      } else {
-        technique = effect()->GetTechniqueByName("RenderRGBLayerPremul");
-      }
-    }
-
-    if (cairoImage->mSRView) {
-      effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(cairoImage->mSRView);
-    }
-
-    effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
-      ShaderConstantRectD3D10(
-        (float)0,
-        (float)0,
-        (float)cairoImage->mSize.width,
-        (float)cairoImage->mSize.height)
-      );
   }
 
   technique->GetPassByIndex(0)->Apply(0);
   device()->Draw(4, 0);
 }
 
 PlanarYCbCrImageD3D10::PlanarYCbCrImageD3D10(ID3D10Device1 *aDevice)
   : PlanarYCbCrImage(static_cast<ImageD3D10*>(this))