Bug 1315212 - Allow for failed call to wrapped DrawTarget in DrawTargetRecording::CreateSimilarDrawTarget. r=bas, a=gchang
authorBob Owen <bobowencode@gmail.com>
Tue, 15 Nov 2016 11:10:02 +0000
changeset 352505 3bba008880c83696cf0012992e84942d1157e953
parent 352504 adf273962957d0063068a8e17295770a045ba80b
child 352506 a6fb57388eec0de915ec385805eb1c81c7d97261
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, gchang
bugs1315212
milestone52.0a2
Bug 1315212 - Allow for failed call to wrapped DrawTarget in DrawTargetRecording::CreateSimilarDrawTarget. r=bas, a=gchang MozReview-Commit-ID: 4SMixY4Nook
gfx/2d/DrawTargetRecording.cpp
gfx/2d/DrawTargetRecording.h
--- a/gfx/2d/DrawTargetRecording.cpp
+++ b/gfx/2d/DrawTargetRecording.cpp
@@ -294,22 +294,23 @@ DrawTargetRecording::DrawTargetRecording
                                                     mFinalDT->GetBackendType(),
                                                     mFinalDT->GetSize(),
                                                     mFinalDT->GetFormat(),
                                                     aHasData, snapshot));
   mFormat = mFinalDT->GetFormat();
 }
 
 DrawTargetRecording::DrawTargetRecording(const DrawTargetRecording *aDT,
-                                         const IntSize &aSize,
-                                         SurfaceFormat aFormat)
+                                         DrawTarget *aSimilarDT)
   : mRecorder(aDT->mRecorder)
-  , mFinalDT(aDT->mFinalDT->CreateSimilarDrawTarget(aSize, aFormat))
+  , mFinalDT(aSimilarDT)
 {
-  mRecorder->RecordEvent(RecordedCreateSimilarDrawTarget(this, aSize, aFormat));
+  mRecorder->RecordEvent(RecordedCreateSimilarDrawTarget(this,
+                                                         mFinalDT->GetSize(),
+                                                         mFinalDT->GetFormat()));
   mFormat = mFinalDT->GetFormat();
 }
 
 DrawTargetRecording::~DrawTargetRecording()
 {
   mRecorder->RecordEvent(RecordedDrawTargetDestruction(this));
 }
 
@@ -635,17 +636,24 @@ DrawTargetRecording::CreateSourceSurface
   StoreSourceSurface(mRecorder, retSurf, dataSurf, "CreateSourceSurfaceFromNativeSurface");
 
   return retSurf.forget();
 }
 
 already_AddRefed<DrawTarget>
 DrawTargetRecording::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
 {
-  return MakeAndAddRef<DrawTargetRecording>(this, aSize, aFormat);
+  RefPtr<DrawTarget> similarDT =
+    mFinalDT->CreateSimilarDrawTarget(aSize, aFormat);
+  if (!similarDT) {
+    return nullptr;
+  }
+
+  similarDT = new DrawTargetRecording(this, similarDT);
+  return similarDT.forget();
 }
 
 already_AddRefed<PathBuilder>
 DrawTargetRecording::CreatePathBuilder(FillRule aFillRule) const
 {
   RefPtr<PathBuilder> builder = mFinalDT->CreatePathBuilder(aFillRule);
   return MakeAndAddRef<PathBuilderRecording>(builder, aFillRule);
 }
--- a/gfx/2d/DrawTargetRecording.h
+++ b/gfx/2d/DrawTargetRecording.h
@@ -14,26 +14,16 @@ namespace mozilla {
 namespace gfx {
 
 class DrawTargetRecording : public DrawTarget
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording, override)
   DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false);
 
-  /**
-   * Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call.
-   *
-   * @param aDT DrawTargetRecording on which CreateSimilarDrawTarget  was called
-   * @param aSize size for the similar DrawTarget
-   * @param aFormat format for the similar DrawTarget
-   */
-  DrawTargetRecording(const DrawTargetRecording *aDT, const IntSize &aSize,
-                      SurfaceFormat aFormat);
-
   ~DrawTargetRecording();
 
   virtual DrawTargetType GetType() const override { return mFinalDT->GetType(); }
   virtual BackendType GetBackendType() const override { return mFinalDT->GetBackendType(); }
   virtual bool IsRecording() const override { return true; }
 
   virtual already_AddRefed<SourceSurface> Snapshot() override;
 
@@ -317,16 +307,27 @@ public:
    */
   virtual void *GetNativeSurface(NativeSurfaceType aType) override { return mFinalDT->GetNativeSurface(aType); }
 
   virtual bool IsCurrentGroupOpaque() override {
     return mFinalDT->IsCurrentGroupOpaque();
   }
 
 private:
+  /**
+   * Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call.
+   * We have to call CreateSimilarDrawTarget on mFinalDT up front and pass it in
+   * as it can fail.
+   *
+   * @param aDT DrawTargetRecording on which CreateSimilarDrawTarget was called
+   * @param aSimilarDT Similar DrawTarget created from aDT.mFinalDT.
+   */
+  DrawTargetRecording(const DrawTargetRecording *aDT,
+                      DrawTarget *aSimilarDT);
+
   Path *GetPathForPathRecording(const Path *aPath) const;
   already_AddRefed<PathRecording> EnsurePathStored(const Path *aPath);
   void EnsurePatternDependenciesStored(const Pattern &aPattern);
 
   RefPtr<DrawEventRecorderPrivate> mRecorder;
   RefPtr<DrawTarget> mFinalDT;
 };