Bug 1066280 - Fixes for SurfaceStream removal. - r=kamidphish,mattwoodrow
authorjdashg <jdashg+github@gmail.com>
Tue, 07 Oct 2014 21:16:14 -0700
changeset 209893 49531b0af9b802c859cda9bd4241b611ed025c38
parent 209892 72ce4c2ccdcb6f0dd58f55422a52c5dce1caba71
child 209894 a3bc505ee94570005f01b41bed8082369bdbe7e6
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerskamidphish, mattwoodrow
bugs1066280
milestone35.0a1
Bug 1066280 - Fixes for SurfaceStream removal. - r=kamidphish,mattwoodrow
dom/canvas/CanvasRenderingContext2D.cpp
dom/canvas/WebGLContext.cpp
gfx/2d/DrawTargetSkia.cpp
gfx/gl/SharedSurfaceGralloc.cpp
gfx/layers/CopyableCanvasLayer.cpp
gfx/layers/CopyableCanvasLayer.h
gfx/layers/client/CanvasClient.cpp
gfx/layers/client/ClientCanvasLayer.cpp
gfx/layers/client/ClientCanvasLayer.h
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -4848,19 +4848,22 @@ CanvasRenderingContext2D::GetCanvasLayer
   mTarget->Flush();
 
   if (!mResetLayer && aOldLayer) {
     CanvasRenderingContext2DUserData* userData =
       static_cast<CanvasRenderingContext2DUserData*>(
         aOldLayer->GetUserData(&g2DContextLayerUserData));
 
     CanvasLayer::Data data;
+
     SkiaGLGlue* glue = gfxPlatform::GetPlatform()->GetSkiaGLGlue();
-    if (glue) {
+    GLuint skiaGLTex = (GLuint)(uintptr_t)mTarget->GetNativeSurface(NativeSurfaceType::OPENGL_TEXTURE);
+    if (glue && skiaGLTex) {
       data.mGLContext = glue->GetGLContext();
+      data.mFrontbufferGLTex = skiaGLTex;
     } else {
       data.mDrawTarget = mTarget;
     }
 
     if (userData && userData->IsForContext(this) && aOldLayer->IsDataValid(data)) {
       nsRefPtr<CanvasLayer> ret = aOldLayer;
       return ret.forget();
     }
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -660,16 +660,19 @@ CreateOffscreen(GLContext* gl,
     baseCaps.color = true;
     baseCaps.alpha = options.alpha;
     baseCaps.antialias = options.antialias;
     baseCaps.depth = options.depth;
     baseCaps.premultAlpha = options.premultipliedAlpha;
     baseCaps.preserve = options.preserveDrawingBuffer;
     baseCaps.stencil = options.stencil;
 
+    if (!baseCaps.alpha)
+        baseCaps.premultAlpha = true;
+
     // we should really have this behind a
     // |gfxPlatform::GetPlatform()->GetScreenDepth() == 16| check, but
     // for now it's just behind a pref for testing/evaluation.
     baseCaps.bpp16 = Preferences::GetBool("webgl.prefer-16bpp", false);
 
 #ifdef MOZ_WIDGET_GONK
     baseCaps.surfaceAllocator = surfAllocator;
 #endif
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -159,20 +159,20 @@ SetPaintPattern(SkPaint& aPaint, const P
       GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
       SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
 
       if (stops->mCount >= 2) {
         SkPoint points[2];
         points[0] = SkPoint::Make(SkFloatToScalar(pat.mBegin.x), SkFloatToScalar(pat.mBegin.y));
         points[1] = SkPoint::Make(SkFloatToScalar(pat.mEnd.x), SkFloatToScalar(pat.mEnd.y));
 
-        SkShader* shader = SkGradientShader::CreateLinear(points, 
-                                                          &stops->mColors.front(), 
-                                                          &stops->mPositions.front(), 
-                                                          stops->mCount, 
+        SkShader* shader = SkGradientShader::CreateLinear(points,
+                                                          &stops->mColors.front(),
+                                                          &stops->mPositions.front(),
+                                                          stops->mCount,
                                                           mode);
 
         if (shader) {
             SkMatrix mat;
             GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
             SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
             SkSafeUnref(shader);
             SkSafeUnref(aPaint.setShader(matrixShader));
@@ -188,23 +188,23 @@ SetPaintPattern(SkPaint& aPaint, const P
       GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
       SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
 
       if (stops->mCount >= 2) {
         SkPoint points[2];
         points[0] = SkPoint::Make(SkFloatToScalar(pat.mCenter1.x), SkFloatToScalar(pat.mCenter1.y));
         points[1] = SkPoint::Make(SkFloatToScalar(pat.mCenter2.x), SkFloatToScalar(pat.mCenter2.y));
 
-        SkShader* shader = SkGradientShader::CreateTwoPointConical(points[0], 
+        SkShader* shader = SkGradientShader::CreateTwoPointConical(points[0],
                                                                    SkFloatToScalar(pat.mRadius1),
-                                                                   points[1], 
+                                                                   points[1],
                                                                    SkFloatToScalar(pat.mRadius2),
-                                                                   &stops->mColors.front(), 
-                                                                   &stops->mPositions.front(), 
-                                                                   stops->mCount, 
+                                                                   &stops->mColors.front(),
+                                                                   &stops->mPositions.front(),
+                                                                   stops->mCount,
                                                                    mode);
         if (shader) {
             SkMatrix mat;
             GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
             SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
             SkSafeUnref(shader);
             SkSafeUnref(aPaint.setShader(matrixShader));
         }
@@ -341,17 +341,17 @@ DrawTargetSkia::DrawSurface(SourceSurfac
   }
 
   MarkChanged();
 
   SkRect destRect = RectToSkRect(aDest);
   SkRect sourceRect = RectToSkRect(aSource);
 
   TempBitmap bitmap = GetBitmapForSurface(aSurface);
- 
+
   AutoPaintSetup paint(mCanvas.get(), aOptions, &aDest);
   if (aSurfOptions.mFilter == Filter::POINT) {
     paint.mPaint.setFilterLevel(SkPaint::kNone_FilterLevel);
   }
 
   mCanvas->drawBitmapRectToRect(bitmap.mBitmap, &sourceRect, destRect, &paint.mPaint);
 }
 
@@ -453,31 +453,31 @@ DrawTargetSkia::StrokeRect(const Rect &a
   AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
   if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
     return;
   }
 
   mCanvas->drawRect(RectToSkRect(aRect), paint.mPaint);
 }
 
-void 
+void
 DrawTargetSkia::StrokeLine(const Point &aStart,
                            const Point &aEnd,
                            const Pattern &aPattern,
                            const StrokeOptions &aStrokeOptions,
                            const DrawOptions &aOptions)
 {
   MarkChanged();
   AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
   if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
     return;
   }
 
-  mCanvas->drawLine(SkFloatToScalar(aStart.x), SkFloatToScalar(aStart.y), 
-                    SkFloatToScalar(aEnd.x), SkFloatToScalar(aEnd.y), 
+  mCanvas->drawLine(SkFloatToScalar(aStart.x), SkFloatToScalar(aStart.y),
+                    SkFloatToScalar(aEnd.x), SkFloatToScalar(aEnd.y),
                     paint.mPaint);
 }
 
 void
 DrawTargetSkia::Fill(const Path *aPath,
                     const Pattern &aPattern,
                     const DrawOptions &aOptions)
 {
@@ -558,17 +558,17 @@ DrawTargetSkia::Mask(const Pattern &aSou
                      const DrawOptions &aOptions)
 {
   MarkChanged();
   AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
 
   SkPaint maskPaint;
   TempBitmap tmpBitmap;
   SetPaintPattern(maskPaint, aMask, tmpBitmap);
-  
+
   SkLayerRasterizer::Builder builder;
   builder.addLayer(maskPaint);
   SkAutoTUnref<SkRasterizer> raster(builder.detachRasterizer());
   paint.mPaint.setRasterizer(raster.get());
 
   mCanvas->drawRect(SkRectCoveringWholeSurface(), paint.mPaint);
 }
 
@@ -612,17 +612,17 @@ DrawTargetSkia::CreateSourceSurfaceFromD
                                             SurfaceFormat aFormat) const
 {
   RefPtr<SourceSurfaceSkia> newSurf = new SourceSurfaceSkia();
 
   if (!newSurf->InitFromData(aData, aSize, aStride, aFormat)) {
     gfxDebug() << *this << ": Failure to create source surface from data. Size: " << aSize;
     return nullptr;
   }
-    
+
   return newSurf.forget();
 }
 
 TemporaryRef<DrawTarget>
 DrawTargetSkia::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
 {
   RefPtr<DrawTargetSkia> target = new DrawTargetSkia();
   if (!target->Init(aSize, aFormat)) {
@@ -700,33 +700,33 @@ DrawTargetSkia::CopySurface(SourceSurfac
   }
 
   MarkChanged();
 
   TempBitmap bitmap = GetBitmapForSurface(aSurface);
 
   // This is a fast path that is disabled for now to mimimize risk
   if (false && !bitmap.mBitmap.getTexture() && mCanvas->imageInfo() == bitmap.mBitmap.info()) {
-	SkBitmap bm(bitmap.mBitmap);
-	bm.lockPixels();
-	if (bm.getPixels()) {
-	  SkImageInfo info = bm.info();
-	  info.fWidth = aSourceRect.width;
-	  info.fHeight = aSourceRect.height;
-	  uint8_t* pixels = static_cast<uint8_t*>(bm.getPixels());
-	  // adjust pixels for the source offset
-	  pixels += aSourceRect.x + aSourceRect.y*bm.rowBytes();
-	  mCanvas->writePixels(info, pixels, bm.rowBytes(), aDestination.x, aDestination.y);
-	  return;
-	}
+  SkBitmap bm(bitmap.mBitmap);
+  bm.lockPixels();
+  if (bm.getPixels()) {
+    SkImageInfo info = bm.info();
+    info.fWidth = aSourceRect.width;
+    info.fHeight = aSourceRect.height;
+    uint8_t* pixels = static_cast<uint8_t*>(bm.getPixels());
+    // adjust pixels for the source offset
+    pixels += aSourceRect.x + aSourceRect.y*bm.rowBytes();
+    mCanvas->writePixels(info, pixels, bm.rowBytes(), aDestination.x, aDestination.y);
+    return;
+  }
   }
 
   mCanvas->save();
   mCanvas->resetMatrix();
-  SkRect dest = IntRectToSkRect(IntRect(aDestination.x, aDestination.y, aSourceRect.width, aSourceRect.height)); 
+  SkRect dest = IntRectToSkRect(IntRect(aDestination.x, aDestination.y, aSourceRect.width, aSourceRect.height));
   SkIRect source = IntRectToSkIRect(aSourceRect);
   mCanvas->clipRect(dest, SkRegion::kReplace_Op);
   SkPaint paint;
 
   if (mCanvas->imageInfo().colorType() == kRGB_565_SkColorType) {
     // Set the xfermode to SOURCE_OVER to workaround
     // http://code.google.com/p/skia/issues/detail?id=628
     // RGB565 is opaque so they're equivalent anyway
@@ -847,21 +847,21 @@ DrawTargetSkia::SetTransform(const Matri
 
 void*
 DrawTargetSkia::GetNativeSurface(NativeSurfaceType aType)
 {
   if (aType == NativeSurfaceType::OPENGL_TEXTURE) {
     return (void*)((uintptr_t)mTexture);
   }
 
-  return nullptr;  
+  return nullptr;
 }
 
 
-TemporaryRef<PathBuilder> 
+TemporaryRef<PathBuilder>
 DrawTargetSkia::CreatePathBuilder(FillRule aFillRule) const
 {
   return new PathBuilderSkia(aFillRule);
 }
 
 void
 DrawTargetSkia::ClearRect(const Rect &aRect)
 {
@@ -906,17 +906,17 @@ TemporaryRef<GradientStops>
 DrawTargetSkia::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode) const
 {
   std::vector<GradientStop> stops;
   stops.resize(aNumStops);
   for (uint32_t i = 0; i < aNumStops; i++) {
     stops[i] = aStops[i];
   }
   std::stable_sort(stops.begin(), stops.end());
-  
+
   return new GradientStopsSkia(stops, aNumStops, aExtendMode);
 }
 
 TemporaryRef<FilterNode>
 DrawTargetSkia::CreateFilter(FilterType aType)
 {
   return FilterNodeSoftware::Create(aType);
 }
--- a/gfx/gl/SharedSurfaceGralloc.cpp
+++ b/gfx/gl/SharedSurfaceGralloc.cpp
@@ -62,28 +62,27 @@ SharedSurface_Gralloc::Create(GLContext*
     DEBUG_PRINT("SharedSurface_Gralloc::Create -------\n");
 
     if (!HasExtensions(egl, prodGL))
         return Move(ret);
 
     gfxContentType type = hasAlpha ? gfxContentType::COLOR_ALPHA
                                    : gfxContentType::COLOR;
 
-    gfxImageFormat format
-      = gfxPlatform::GetPlatform()->OptimalFormatForContent(type);
+    auto platform = gfxPlatform::GetPlatform();
+    gfxImageFormat format = platform->OptimalFormatForContent(type);
 
-    RefPtr<GrallocTextureClientOGL> grallocTC =
-      new GrallocTextureClientOGL(
-          allocator,
-          gfx::ImageFormatToSurfaceFormat(format),
-          gfx::BackendType::NONE, // we don't need to use it with a DrawTarget
-          flags);
+    typedef GrallocTextureClientOGL ptrT;
+    RefPtr<ptrT> grallocTC = new ptrT(allocator,
+                                      gfx::ImageFormatToSurfaceFormat(format),
+                                      gfx::BackendType::NONE, // we don't need to use it with a DrawTarget
+                                      flags);
 
     if (!grallocTC->AllocateForGLRendering(size)) {
-      return Move(ret);
+        return Move(ret);
     }
 
     sp<GraphicBuffer> buffer = grallocTC->GetGraphicBuffer();
 
     EGLDisplay display = egl->Display();
     EGLClientBuffer clientBuffer = buffer->getNativeBuffer();
     EGLint attrs[] = {
         LOCAL_EGL_NONE, LOCAL_EGL_NONE
--- a/gfx/layers/CopyableCanvasLayer.cpp
+++ b/gfx/layers/CopyableCanvasLayer.cpp
@@ -75,38 +75,35 @@ bool
 CopyableCanvasLayer::IsDataValid(const Data& aData)
 {
   return mGLContext == aData.mGLContext;
 }
 
 void
 CopyableCanvasLayer::UpdateTarget(DrawTarget* aDestTarget)
 {
-  if (!IsDirty())
-    return;
-  Painted();
-
   if (mDrawTarget) {
     mDrawTarget->Flush();
     mSurface = mDrawTarget->Snapshot();
   }
 
   if (!mGLContext && aDestTarget) {
     NS_ASSERTION(mSurface, "Must have surface to draw!");
     if (mSurface) {
       aDestTarget->CopySurface(mSurface,
                                IntRect(0, 0, mBounds.width, mBounds.height),
                                IntPoint(0, 0));
       mSurface = nullptr;
     }
     return;
   }
 
-  if (mDrawTarget)
+  if (mDrawTarget) {
     return;
+  }
 
   MOZ_ASSERT(mGLContext);
 
   SharedSurface* frontbuffer = nullptr;
   if (mGLFrontbuffer) {
     frontbuffer = mGLFrontbuffer.get();
   } else {
     auto screen = mGLContext->Screen();
--- a/gfx/layers/CopyableCanvasLayer.h
+++ b/gfx/layers/CopyableCanvasLayer.h
@@ -33,19 +33,19 @@ class CopyableCanvasLayer : public Canva
 {
 public:
   CopyableCanvasLayer(LayerManager* aLayerManager, void *aImplData);
 
 protected:
   virtual ~CopyableCanvasLayer();
 
 public:
-  virtual void Initialize(const Data& aData);
+  virtual void Initialize(const Data& aData) MOZ_OVERRIDE;
 
-  virtual bool IsDataValid(const Data& aData);
+  virtual bool IsDataValid(const Data& aData) MOZ_OVERRIDE;
 
   bool IsGLLayer() { return !!mGLContext; }
 
 protected:
   void UpdateTarget(gfx::DrawTarget* aDestTarget = nullptr);
 
   RefPtr<gfx::SourceSurface> mSurface;
   nsRefPtr<gl::GLContext> mGLContext;
--- a/gfx/layers/client/CanvasClient.cpp
+++ b/gfx/layers/client/CanvasClient.cpp
@@ -475,14 +475,12 @@ CanvasClientSharedSurface::Update(gfx::I
     mFrontTex = nullptr;
   }
 
   // Use the new TexClient.
   mFrontTex = newTex;
 
   forwarder->UpdatedTexture(this, mFrontTex, nullptr);
   forwarder->UseTexture(this, mFrontTex);
-
-  aLayer->Painted();
 }
 
 }
 }
--- a/gfx/layers/client/ClientCanvasLayer.cpp
+++ b/gfx/layers/client/ClientCanvasLayer.cpp
@@ -143,16 +143,17 @@ ClientCanvasLayer::RenderLayer()
 
   if (GetMaskLayer()) {
     ToClientLayer(GetMaskLayer())->RenderLayer();
   }
 
   if (!IsDirty()) {
     return;
   }
+  Painted();
 
   if (!mCanvasClient) {
     TextureFlags flags = TextureFlags::IMMEDIATE_UPLOAD;
     if (mNeedsYFlip) {
       flags |= TextureFlags::NEEDS_Y_FLIP;
     }
 
     if (!mGLContext) {
--- a/gfx/layers/client/ClientCanvasLayer.h
+++ b/gfx/layers/client/ClientCanvasLayer.h
@@ -41,43 +41,43 @@ public:
   {
     MOZ_COUNT_CTOR(ClientCanvasLayer);
   }
 
 protected:
   virtual ~ClientCanvasLayer();
 
 public:
-  virtual void SetVisibleRegion(const nsIntRegion& aRegion)
+  virtual void SetVisibleRegion(const nsIntRegion& aRegion) MOZ_OVERRIDE
   {
     NS_ASSERTION(ClientManager()->InConstruction(),
                  "Can only set properties in construction phase");
     CanvasLayer::SetVisibleRegion(aRegion);
   }
 
-  virtual void Initialize(const Data& aData);
+  virtual void Initialize(const Data& aData) MOZ_OVERRIDE;
 
-  virtual void RenderLayer();
+  virtual void RenderLayer() MOZ_OVERRIDE;
 
-  virtual void ClearCachedResources()
+  virtual void ClearCachedResources() MOZ_OVERRIDE
   {
     if (mCanvasClient) {
       mCanvasClient->Clear();
     }
   }
 
-  virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
+  virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) MOZ_OVERRIDE
   {
     aAttrs = CanvasLayerAttributes(mFilter, mBounds);
   }
 
-  virtual Layer* AsLayer() { return this; }
-  virtual ShadowableLayer* AsShadowableLayer() { return this; }
+  virtual Layer* AsLayer()  MOZ_OVERRIDE { return this; }
+  virtual ShadowableLayer* AsShadowableLayer()  MOZ_OVERRIDE { return this; }
 
-  virtual void Disconnect()
+  virtual void Disconnect() MOZ_OVERRIDE
   {
     mCanvasClient = nullptr;
     ClientLayer::Disconnect();
   }
 
   virtual CompositableClient* GetCompositableClient() MOZ_OVERRIDE
   {
     return mCanvasClient;