Bug 1011865 - Create optimized source surfaces when skia-gl is enabled since we want to cache the GPU texture. r=gw280
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 23 May 2014 17:09:34 +1200
changeset 184596 bb71ae94a9fd15e2c7c0484a5dbe6cdb955a1324
parent 184595 c4a259f05a180a2a505a2b2d89c2d506fa665ff8
child 184597 67652107c498f017ff1878b6b80cd7df0470670e
push id26826
push usercbook@mozilla.com
push dateFri, 23 May 2014 13:41:49 +0000
treeherdermozilla-central@e3d39ffacb5e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw280
bugs1011865
milestone32.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 1011865 - Create optimized source surfaces when skia-gl is enabled since we want to cache the GPU texture. r=gw280
gfx/2d/DrawTargetSkia.cpp
gfx/2d/DrawTargetSkia.h
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -595,24 +595,55 @@ DrawTargetSkia::CreateSimilarDrawTarget(
 {
   RefPtr<DrawTargetSkia> target = new DrawTargetSkia();
   if (!target->Init(aSize, aFormat)) {
     return nullptr;
   }
   return target;
 }
 
+bool
+DrawTargetSkia::UsingSkiaGPU() const
+{
+#ifdef USE_SKIA_GPU
+  return !!mTexture;
+#else
+  return false;
+#endif
+}
+
 TemporaryRef<SourceSurface>
 DrawTargetSkia::OptimizeSourceSurface(SourceSurface *aSurface) const
 {
   if (aSurface->GetType() == SurfaceType::SKIA) {
     return aSurface;
   }
 
-  return aSurface->GetDataSurface();
+  if (!UsingSkiaGPU()) {
+    // If we're not using skia-gl then drawing doesn't require any
+    // uploading, so any data surface is fine. Call GetDataSurface
+    // to trigger any required readback so that it only happens
+    // once.
+    return aSurface->GetDataSurface();
+  }
+
+  // If we are using skia-gl then we want to copy into a surface that
+  // will cache the uploaded gl texture.
+  RefPtr<DataSourceSurface> dataSurf = aSurface->GetDataSurface();
+  DataSourceSurface::MappedSurface map;
+  if (!dataSurf->Map(DataSourceSurface::READ, &map)) {
+    return nullptr;
+  }
+
+  RefPtr<SourceSurface> result = CreateSourceSurfaceFromData(map.mData,
+                                                             dataSurf->GetSize(),
+                                                             map.mStride,
+                                                             dataSurf->GetFormat());
+  dataSurf->Unmap();
+  return result;
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetSkia::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const
 {
   return nullptr;
 }
 
--- a/gfx/2d/DrawTargetSkia.h
+++ b/gfx/2d/DrawTargetSkia.h
@@ -121,16 +121,18 @@ public:
 private:
   friend class SourceSurfaceSkia;
   void SnapshotDestroyed();
 
   void MarkChanged();
 
   SkRect SkRectCoveringWholeSurface() const;
 
+  bool UsingSkiaGPU() const;
+
 #ifdef USE_SKIA_GPU
   SkRefPtr<GrContext> mGrContext;
   uint32_t mTexture;
 #endif
 
   IntSize mSize;
   SkRefPtr<SkCanvas> mCanvas;
   SourceSurfaceSkia* mSnapshot;