Bug 603488 part 3: Modified DrawTargetSkia to accept non-skia sourcesurfaces. r=nrc
authorJames Kolb <jck1089@gmail.com>
Mon, 13 Jan 2014 13:29:48 +1300
changeset 163085 a956cec79aadb296926c3264cc301405dec75c73
parent 163084 c92ffdf59f17587c945f1849c141316218c36454
child 163086 c305df97cbc6494a517ce5299b0f90074e9f62dc
push id25979
push usercbook@mozilla.com
push dateMon, 13 Jan 2014 11:46:02 +0000
treeherdermozilla-central@ea6657f1d682 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnrc
bugs603488
milestone29.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 603488 part 3: Modified DrawTargetSkia to accept non-skia sourcesurfaces. r=nrc
dom/xbl/XBLChildrenElement.cpp
dom/xbl/XBLChildrenElement.h
dom/xbl/builtin/android/jar.mn
dom/xbl/builtin/android/moz.build
dom/xbl/builtin/android/platformHTMLBindings.xml
dom/xbl/builtin/browser-base.inc
dom/xbl/builtin/editor-base.inc
dom/xbl/builtin/emacs/jar.mn
dom/xbl/builtin/emacs/moz.build
dom/xbl/builtin/emacs/platformHTMLBindings.xml
dom/xbl/builtin/input-fields-base.inc
dom/xbl/builtin/mac/jar.mn
dom/xbl/builtin/mac/moz.build
dom/xbl/builtin/mac/platformHTMLBindings.xml
dom/xbl/builtin/moz.build
dom/xbl/builtin/textareas-base.inc
dom/xbl/builtin/unix/jar.mn
dom/xbl/builtin/unix/moz.build
dom/xbl/builtin/unix/platformHTMLBindings.xml
dom/xbl/builtin/win/jar.mn
dom/xbl/builtin/win/moz.build
dom/xbl/builtin/win/platformHTMLBindings.xml
dom/xbl/crashtests/205735-1.xhtml
dom/xbl/crashtests/223799-1.xul
dom/xbl/crashtests/226744-1.xhtml
dom/xbl/crashtests/232095-1.xul
dom/xbl/crashtests/277523-1.xhtml
dom/xbl/crashtests/277950-1.xhtml
dom/xbl/crashtests/336744-1-inner.html
dom/xbl/crashtests/336744-1.html
dom/xbl/crashtests/336960-1-inner.xhtml
dom/xbl/crashtests/336960-1.html
dom/xbl/crashtests/342954-1.xhtml
dom/xbl/crashtests/342954-2-xbl.xml
dom/xbl/crashtests/342954-2.xhtml
dom/xbl/crashtests/368276-1.xhtml
dom/xbl/crashtests/368641-1.xhtml
dom/xbl/crashtests/378521-1.xhtml
dom/xbl/crashtests/382376-1.xhtml
dom/xbl/crashtests/382376-2.xhtml
dom/xbl/crashtests/397596-1.xhtml
dom/xbl/crashtests/404125-1.xhtml
dom/xbl/crashtests/406900-1.xul
dom/xbl/crashtests/406904-1.xhtml
dom/xbl/crashtests/406904-2.xhtml
dom/xbl/crashtests/415192-1.xul
dom/xbl/crashtests/415301-1.xul
dom/xbl/crashtests/418133-1.xhtml
dom/xbl/crashtests/420233-1.xhtml
dom/xbl/crashtests/421997-1.xhtml
dom/xbl/crashtests/432813-1-xbl.xml
dom/xbl/crashtests/432813-1.xhtml
dom/xbl/crashtests/454820-1.html
dom/xbl/crashtests/460665-1.xhtml
dom/xbl/crashtests/463511-1.xhtml
dom/xbl/crashtests/464863-1.xhtml
dom/xbl/crashtests/472260-1.xhtml
dom/xbl/crashtests/477878-1.html
dom/xbl/crashtests/492978-1.xul
dom/xbl/crashtests/493123-1.xhtml
dom/xbl/crashtests/495354-1.xhtml
dom/xbl/crashtests/507628-1.xhtml
dom/xbl/crashtests/507991-1.xhtml
dom/xbl/crashtests/830614-1.xul
dom/xbl/crashtests/895805-1.xhtml
dom/xbl/crashtests/crashtests.list
dom/xbl/crashtests/set-field-bad-this.xhtml
dom/xbl/moz.build
dom/xbl/nsBindingManager.cpp
dom/xbl/nsBindingManager.h
dom/xbl/nsXBLBinding.cpp
dom/xbl/nsXBLBinding.h
dom/xbl/nsXBLContentSink.cpp
dom/xbl/nsXBLContentSink.h
dom/xbl/nsXBLDocumentInfo.cpp
dom/xbl/nsXBLDocumentInfo.h
dom/xbl/nsXBLEventHandler.cpp
dom/xbl/nsXBLEventHandler.h
dom/xbl/nsXBLMaybeCompiled.h
dom/xbl/nsXBLProtoImpl.cpp
dom/xbl/nsXBLProtoImpl.h
dom/xbl/nsXBLProtoImplField.cpp
dom/xbl/nsXBLProtoImplField.h
dom/xbl/nsXBLProtoImplMember.h
dom/xbl/nsXBLProtoImplMethod.cpp
dom/xbl/nsXBLProtoImplMethod.h
dom/xbl/nsXBLProtoImplProperty.cpp
dom/xbl/nsXBLProtoImplProperty.h
dom/xbl/nsXBLPrototypeBinding.cpp
dom/xbl/nsXBLPrototypeBinding.h
dom/xbl/nsXBLPrototypeHandler.cpp
dom/xbl/nsXBLPrototypeHandler.h
dom/xbl/nsXBLPrototypeResources.cpp
dom/xbl/nsXBLPrototypeResources.h
dom/xbl/nsXBLResourceLoader.cpp
dom/xbl/nsXBLResourceLoader.h
dom/xbl/nsXBLSerialize.cpp
dom/xbl/nsXBLSerialize.h
dom/xbl/nsXBLService.cpp
dom/xbl/nsXBLService.h
dom/xbl/nsXBLWindowKeyHandler.cpp
dom/xbl/nsXBLWindowKeyHandler.h
dom/xbl/test/bug310107-resource.xhtml
dom/xbl/test/chrome.ini
dom/xbl/test/file_bug372769.xhtml
dom/xbl/test/file_bug379959_cross.html
dom/xbl/test/file_bug379959_data.html
dom/xbl/test/file_bug379959_xbl.xml
dom/xbl/test/file_bug397934.xhtml
dom/xbl/test/file_bug481558.xbl
dom/xbl/test/file_bug481558css.sjs
dom/xbl/test/file_bug591198_inner.html
dom/xbl/test/file_bug591198_xbl.xml
dom/xbl/test/file_bug821850.xhtml
dom/xbl/test/file_bug844783.xhtml
dom/xbl/test/file_bug944407.html
dom/xbl/test/file_bug944407.xml
dom/xbl/test/file_bug950909.html
dom/xbl/test/file_bug950909.xml
dom/xbl/test/mochitest.ini
dom/xbl/test/moz.build
dom/xbl/test/test_bug310107.html
dom/xbl/test/test_bug366770.html
dom/xbl/test/test_bug371724.xhtml
dom/xbl/test/test_bug372769.html
dom/xbl/test/test_bug378518.xul
dom/xbl/test/test_bug378866.xhtml
dom/xbl/test/test_bug379959.html
dom/xbl/test/test_bug389322.xhtml
dom/xbl/test/test_bug397934.html
dom/xbl/test/test_bug398135.xul
dom/xbl/test/test_bug398492.xul
dom/xbl/test/test_bug400705.xhtml
dom/xbl/test/test_bug401907.xhtml
dom/xbl/test/test_bug403162.xhtml
dom/xbl/test/test_bug468210.xhtml
dom/xbl/test/test_bug481558.html
dom/xbl/test/test_bug526178.xhtml
dom/xbl/test/test_bug542406.xhtml
dom/xbl/test/test_bug591198.html
dom/xbl/test/test_bug639338.xhtml
dom/xbl/test/test_bug721452.xul
dom/xbl/test/test_bug723676.xul
dom/xbl/test/test_bug772966.xul
dom/xbl/test/test_bug790265.xhtml
dom/xbl/test/test_bug821850.html
dom/xbl/test/test_bug844783.html
dom/xbl/test/test_bug944407.xul
dom/xbl/test/test_bug950909.xul
gfx/2d/DrawTargetSkia.cpp
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -146,34 +146,49 @@ DrawTargetSkia::PurgeAllCaches()
   uint32_t targetCount = targets.size();
   for (uint32_t i = 0; i < targetCount; i++) {
     targets[i]->PurgeCaches();
   }
 }
 
 #endif
 
-static SkBitmap
-GetBitmapForSurface(SourceSurface *aSurface)
+/**
+ * When constructing a temporary SkBitmap via GetBitmapForSurface, we may also
+ * have to construct a temporary DataSourceSurface, which must live as long as
+ * the SkBitmap. So we return a pair of the SkBitmap and the (optional)
+ * temporary surface.
+ */
+struct TempBitmap
 {
-  switch (aSurface->GetType()) {
-  case SurfaceType::SKIA:
-    return static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
-  case SurfaceType::DATA:
-    {
-      DataSourceSurface* surf = static_cast<DataSourceSurface*>(aSurface);
-      SkBitmap tmp;
-      tmp.setConfig(GfxFormatToSkiaConfig(surf->GetFormat()),
-                    surf->GetSize().width, surf->GetSize().height, surf->Stride());
-      tmp.setPixels(surf->GetData());
-      return tmp;
-    }
-  default:
+  SkBitmap mBitmap;
+  RefPtr<SourceSurface> mTmpSurface;
+};
+
+static TempBitmap
+GetBitmapForSurface(SourceSurface* aSurface)
+{
+  TempBitmap result;
+
+  if (aSurface->GetType() == SurfaceType::SKIA) {
+    result.mBitmap = static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
+    return result;
+  }
+
+  RefPtr<DataSourceSurface> surf = aSurface->GetDataSurface();
+  if (!surf) {
     MOZ_CRASH("Non-skia SourceSurfaces need to be DataSourceSurfaces");
   }
+
+  result.mBitmap.setConfig(GfxFormatToSkiaConfig(surf->GetFormat()),
+                                 surf->GetSize().width, surf->GetSize().height,
+                                 surf->Stride());
+  result.mBitmap.setPixels(surf->GetData());
+  result.mTmpSurface = surf.forget();
+  return result;
 }
 
 DrawTargetSkia::DrawTargetSkia()
   : mSnapshot(nullptr)
 {
 }
 
 DrawTargetSkia::~DrawTargetSkia()
@@ -192,17 +207,19 @@ DrawTargetSkia::Snapshot()
     mSnapshot = snapshot;
     if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat, this))
       return nullptr;
   }
 
   return snapshot;
 }
 
-void SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, Float aAlpha = 1.0)
+static void
+SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, TempBitmap& aTmpBitmap,
+                Float aAlpha = 1.0)
 {
   switch (aPattern.GetType()) {
     case PatternType::COLOR: {
       Color color = static_cast<const ColorPattern&>(aPattern).mColor;
       aPaint.setColor(ColorToSkColor(color, aAlpha));
       break;
     }
     case PatternType::LINEAR_GRADIENT: {
@@ -260,17 +277,18 @@ void SetPaintPattern(SkPaint& aPaint, co
 
       } else {
         aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
       }
       break;
     }
     case PatternType::SURFACE: {
       const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
-      const SkBitmap& bitmap = GetBitmapForSurface(pat.mSurface);
+      aTmpBitmap = GetBitmapForSurface(pat.mSurface);
+      const SkBitmap& bitmap = aTmpBitmap.mBitmap;
 
       SkShader::TileMode mode = ExtendModeToTileMode(pat.mExtendMode);
       SkShader* shader = SkShader::CreateBitmapShader(bitmap, mode, mode);
       SkMatrix mat;
       GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
       shader->setLocalMatrix(mat);
       SkSafeUnref(aPaint.setShader(shader));
       if (pat.mFilter == Filter::POINT) {
@@ -281,17 +299,17 @@ void SetPaintPattern(SkPaint& aPaint, co
   }
 }
 
 struct AutoPaintSetup {
   AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Pattern& aPattern)
     : mNeedsRestore(false), mAlpha(1.0)
   {
     Init(aCanvas, aOptions);
-    SetPaintPattern(mPaint, aPattern, mAlpha);
+    SetPaintPattern(mPaint, aPattern, mTmpBitmap, mAlpha);
   }
 
   AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions)
     : mNeedsRestore(false), mAlpha(1.0)
   {
     Init(aCanvas, aOptions);
   }
 
@@ -329,16 +347,17 @@ struct AutoPaintSetup {
       mPaint.setAlpha(U8CPU(aOptions.mAlpha*255.0));
       mAlpha = aOptions.mAlpha;
     }
     mPaint.setFilterBitmap(true);
   }
 
   // TODO: Maybe add an operator overload to access this easier?
   SkPaint mPaint;
+  TempBitmap mTmpBitmap;
   bool mNeedsRestore;
   SkCanvas* mCanvas;
   Float mAlpha;
 };
 
 void
 DrawTargetSkia::Flush()
 {
@@ -369,17 +388,17 @@ DrawTargetSkia::DrawSurface(SourceSurfac
   SkRect sourceRect = RectToSkRect(aSource);
 
   Rect boundingSource = aSource;
   boundingSource.RoundOut();
 
   SkRect sourceBoundingRect = RectToSkRect(boundingSource);
   SkIRect sourceBoundingIRect = RectToSkIRect(boundingSource);
 
-  const SkBitmap& bitmap = GetBitmapForSurface(aSurface);
+  TempBitmap bitmap = GetBitmapForSurface(aSurface);
  
   AutoPaintSetup paint(mCanvas.get(), aOptions);
   if (aSurfOptions.mFilter == Filter::POINT) {
     paint.mPaint.setFilterBitmap(false);
   }
 
   if (!integerAligned) {
     // We need to inflate our destRect by the same amount we inflated sourceRect
@@ -389,17 +408,17 @@ DrawTargetSkia::DrawSurface(SourceSurfac
     mCanvas->save();
     mCanvas->clipRect(destRect);
 
     SkMatrix rectTransform;
     rectTransform.setRectToRect(sourceRect, sourceBoundingRect, SkMatrix::kFill_ScaleToFit);
     rectTransform.mapRect(&destRect);
   }
 
-  mCanvas->drawBitmapRect(bitmap, &sourceBoundingIRect, destRect, &paint.mPaint);
+  mCanvas->drawBitmapRect(bitmap.mBitmap, &sourceBoundingIRect, destRect, &paint.mPaint);
 
   if (!integerAligned) {
     mCanvas->restore();
   }
 }
 
 void
 DrawTargetSkia::DrawFilter(FilterNode *aNode,
@@ -420,18 +439,19 @@ DrawTargetSkia::DrawSurfaceWithShadow(So
                                       CompositionOp aOperator)
 {
   MarkChanged();
   mCanvas->save(SkCanvas::kMatrix_SaveFlag);
   mCanvas->resetMatrix();
 
   uint32_t blurFlags = SkBlurMaskFilter::kHighQuality_BlurFlag |
                        SkBlurMaskFilter::kIgnoreTransform_BlurFlag;
-  const SkBitmap& bitmap = GetBitmapForSurface(aSurface);
-  SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
+  TempBitmap bitmap = GetBitmapForSurface(aSurface);
+  SkShader* shader = SkShader::CreateBitmapShader(bitmap.mBitmap,
+    SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
   SkMatrix matrix;
   matrix.reset();
   matrix.setTranslateX(SkFloatToScalar(aDest.x));
   matrix.setTranslateY(SkFloatToScalar(aDest.y));
   shader->setLocalMatrix(matrix);
   SkLayerDrawLooper* dl = new SkLayerDrawLooper;
   SkLayerDrawLooper::LayerInfo info;
   info.fPaintBits |= SkLayerDrawLooper::kShader_Bit;
@@ -465,17 +485,17 @@ DrawTargetSkia::DrawSurfaceWithShadow(So
   
   SkPaint paint;
   paint.setAntiAlias(true);
   SkSafeUnref(paint.setRasterizer(raster));
   paint.setXfermodeMode(GfxOpToSkiaOp(aOperator));
   SkSafeUnref(paint.setLooper(dl));
 
   SkRect rect = RectToSkRect(Rect(Float(aDest.x), Float(aDest.y),
-                                  Float(bitmap.width()), Float(bitmap.height())));
+                                  Float(bitmap.mBitmap.width()), Float(bitmap.mBitmap.height())));
   mCanvas->drawRect(rect, paint);
   mCanvas->restore();
 }
 
 void
 DrawTargetSkia::FillRect(const Rect &aRect,
                          const Pattern &aPattern,
                          const DrawOptions &aOptions)
@@ -623,17 +643,18 @@ void
 DrawTargetSkia::Mask(const Pattern &aSource,
                      const Pattern &aMask,
                      const DrawOptions &aOptions)
 {
   MarkChanged();
   AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
 
   SkPaint maskPaint;
-  SetPaintPattern(maskPaint, aMask);
+  TempBitmap tmpBitmap;
+  SetPaintPattern(maskPaint, aMask, tmpBitmap);
   
   SkLayerRasterizer *raster = new SkLayerRasterizer();
   raster->addLayer(maskPaint);
   SkSafeUnref(paint.mPaint.setRasterizer(raster));
 
   mCanvas->drawRect(SkRectCoveringWholeSurface(), paint.mPaint);
 }
 
@@ -642,17 +663,18 @@ DrawTargetSkia::MaskSurface(const Patter
                             SourceSurface *aMask,
                             Point aOffset,
                             const DrawOptions &aOptions)
 {
   MarkChanged();
   AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
 
   SkPaint maskPaint;
-  SetPaintPattern(maskPaint, SurfacePattern(aMask, ExtendMode::CLAMP));
+  TempBitmap tmpBitmap;
+  SetPaintPattern(maskPaint, SurfacePattern(aMask, ExtendMode::CLAMP), tmpBitmap);
 
   SkMatrix transform = maskPaint.getShader()->getLocalMatrix();
   transform.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
   maskPaint.getShader()->setLocalMatrix(transform);
 
   SkLayerRasterizer *raster = new SkLayerRasterizer();
   raster->addLayer(maskPaint);
   SkSafeUnref(paint.mPaint.setRasterizer(raster));
@@ -721,17 +743,17 @@ DrawTargetSkia::CopySurface(SourceSurfac
   //TODO: We could just use writePixels() here if the sourceRect is the entire source
 
   if (aSurface->GetType() != SurfaceType::SKIA) {
     return;
   }
 
   MarkChanged();
 
-  const SkBitmap& bitmap = GetBitmapForSurface(aSurface);
+  TempBitmap bitmap = GetBitmapForSurface(aSurface);
 
   mCanvas->save();
   mCanvas->resetMatrix();
   SkRect dest = IntRectToSkRect(IntRect(aDestination.x, aDestination.y, aSourceRect.width, aSourceRect.height)); 
   SkIRect source = IntRectToSkIRect(aSourceRect);
   mCanvas->clipRect(dest, SkRegion::kReplace_Op);
   SkPaint paint;
 
@@ -739,17 +761,17 @@ DrawTargetSkia::CopySurface(SourceSurfac
     // 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
     paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
   } else {
     paint.setXfermodeMode(SkXfermode::kSrc_Mode);
   }
 
-  mCanvas->drawBitmapRect(bitmap, &source, dest, &paint);
+  mCanvas->drawBitmapRect(bitmap.mBitmap, &source, dest, &paint);
   mCanvas->restore();
 }
 
 bool
 DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
 {
   SkAutoTUnref<SkDevice> device(new SkDevice(GfxFormatToSkiaConfig(aFormat),
                                              aSize.width, aSize.height,