Bug 1036859 - Make gfxContext code assume there is always a DrawTarget. r=mstange
authorJonathan Watt <jwatt@jwatt.org>
Fri, 11 Jul 2014 08:06:38 +0100
changeset 214341 50dba12b10c28711b2619263e5f6ff02527c4d0c
parent 214340 477bf7013118359c7efc91c90f7ab2949a7ddb03
child 214342 343acb32cd03367d481c7c84d1376cc8de2ac840
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1036859
milestone33.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 1036859 - Make gfxContext code assume there is always a DrawTarget. r=mstange
gfx/thebes/gfxContext.cpp
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -84,16 +84,18 @@ gfxContext::gfxContext(DrawTarget *aTarg
   : mPathIsRect(false)
   , mTransformChanged(false)
   , mRefCairo(nullptr)
   , mSurface(nullptr)
   , mFlags(0)
   , mDT(aTarget)
   , mOriginalDT(aTarget)
 {
+  MOZ_ASSERT(aTarget, "Don't create a gfxContext without a DrawTarget");
+
   MOZ_COUNT_CTOR(gfxContext);
 
   mStateStack.SetLength(1);
   CurrentState().drawTarget = mDT;
   CurrentState().deviceOffset = aDeviceOffset;
   mDT->SetTransform(Matrix());
 }
 
@@ -106,28 +108,26 @@ gfxContext::ContextForDrawTarget(DrawTar
   return result.forget();
 }
 
 gfxContext::~gfxContext()
 {
   if (mRefCairo) {
     cairo_destroy(mRefCairo);
   }
-  if (mDT) {
-    for (int i = mStateStack.Length() - 1; i >= 0; i--) {
-      for (unsigned int c = 0; c < mStateStack[i].pushedClips.Length(); c++) {
-        mDT->PopClip();
-      }
+  for (int i = mStateStack.Length() - 1; i >= 0; i--) {
+    for (unsigned int c = 0; c < mStateStack[i].pushedClips.Length(); c++) {
+      mDT->PopClip();
+    }
 
-      if (mStateStack[i].clipWasReset) {
-        break;
-      }
+    if (mStateStack[i].clipWasReset) {
+      break;
     }
-    mDT->Flush();
   }
+  mDT->Flush();
   MOZ_COUNT_DTOR(gfxContext);
 }
 
 gfxASurface *
 gfxContext::OriginalSurface()
 {
     if (mSurface) {
         return mSurface;
@@ -1022,19 +1022,16 @@ gfxContext::Mask(gfxASurface *surface, c
   gfxPoint pt = surface->GetDeviceOffset();
 
   Mask(sourceSurf, Point(offset.x - pt.x, offset.y - pt.y));
 }
 
 void
 gfxContext::Mask(SourceSurface *surface, const Point& offset)
 {
-  MOZ_ASSERT(mDT);
-
-
   // We clip here to bind to the mask surface bounds, see above.
   mDT->MaskSurface(GeneralPattern(this),
             surface,
             offset,
             DrawOptions(1.0f, CurrentState().op, CurrentState().aaMode));
 }
 
 void
@@ -1309,41 +1306,29 @@ gfxContext::RoundedRectangle(const gfxRe
                    ToSize(corners[NS_CORNER_BOTTOM_LEFT]) };
   AppendRoundedRectToPath(mPathBuilder, ToRect(rect), radii, draw_clockwise);
 }
 
 #ifdef MOZ_DUMP_PAINTING
 void
 gfxContext::WriteAsPNG(const char* aFile)
 {
-  if (mDT) {
-    gfxUtils::WriteAsPNG(mDT, aFile);
-  } else {
-    NS_WARNING("No DrawTarget found!");
-  }
+  gfxUtils::WriteAsPNG(mDT, aFile);
 }
 
 void 
 gfxContext::DumpAsDataURI()
 {
-  if (mDT) {
-    gfxUtils::DumpAsDataURI(mDT);
-  } else {
-    NS_WARNING("No DrawTarget found!");
-  }
+  gfxUtils::DumpAsDataURI(mDT);
 }
 
 void 
 gfxContext::CopyAsDataURI()
 {
-  if (mDT) {
-    gfxUtils::CopyAsDataURI(mDT);
-  } else {
-    NS_WARNING("No DrawTarget found!");
-  }
+  gfxUtils::CopyAsDataURI(mDT);
 }
 #endif
 
 void
 gfxContext::EnsurePath()
 {
   if (mPathBuilder) {
     mPath = mPathBuilder->Finish();