Revert of Make SkGraphics::Term a no-op, stop calling it. (patchset #2 id:20001 of...
authormtklein <mtklein@google.com>
Wed, 9 Sep 2015 14:22:09 +0000 (07:22 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 9 Sep 2015 14:22:09 +0000 (07:22 -0700)
Reason for revert:
SK_ATTR_DEPRECATED is meaningful to Android.  Don't use it.

Original issue's description:
> Make SkGraphics::Term a no-op, stop calling it.
>
> I'd remove it entirely but Android is calling it explicitly.
>
> BUG=skia:4259
>
> Committed: https://skia.googlesource.com/skia/+/925979f733fe8e70d84627147dee04d030423349

TBR=reed@google.com,scroggo@google.com,mtklein@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:4259

Review URL: https://codereview.chromium.org/1314483006

15 files changed:
debugger/debuggermain.cpp
example/HelloWorld.cpp
experimental/SimpleCocoaApp/SimpleApp.mm
experimental/SimpleiOSApp/SimpleApp.mm
experimental/SkV8Example/SkV8Example.cpp
include/core/SkGraphics.h
include/core/SkPaint.h
include/views/SkEvent.h
samplecode/SampleApp.cpp
src/core/SkGraphics.cpp
src/core/SkPaint.cpp
tests/PathOpsSkpClipTest.cpp
tools/VisualBench/VisualBench.cpp
tools/filtermain.cpp
tools/iOSShell.cpp

index eebcd5f..0aec02b 100644 (file)
@@ -67,5 +67,6 @@ int main(int argc, char *argv[]) {
 
     w.show();
     int result = a.exec();
+    SkGraphics::Term();
     return result;
 }
index 0d12d0f..495d2af 100644 (file)
@@ -23,6 +23,7 @@ void application_init() {
 
 void application_term() {
     SkEvent::Term();
+    SkGraphics::Term();
 }
 
 HelloWorldWindow::HelloWorldWindow(void* hwnd)
index 95684c1..6f9958f 100644 (file)
@@ -69,7 +69,7 @@ protected:
      //   SkRect r = {50, 50, 80, 80};
         p.setColor(0xAA11EEAA);
    //     canvas->drawRect(r, p);
-
+        
         SkRect result;
         SkPath path;
         path.moveTo(0, 0);
@@ -77,7 +77,7 @@ protected:
         path.lineTo(1, 8);
         path.lineTo(0, 9);
         SkASSERT(path.hasRectangularInterior(&result));
-
+        
         path.reset();
         path.addRect(10, 10, 100, 100, SkPath::kCW_Direction);
         path.addRect(20, 20, 50, 50, SkPath::kCW_Direction);
@@ -94,7 +94,7 @@ protected:
 
     }
 private:
-    typedef SkView INHERITED;
+    typedef SkView INHERITED; 
 };
 
 void application_init();
@@ -194,12 +194,12 @@ class PathCanvas : public SkCanvas {
         path.hasRectangularInterior(&copy);
         SkDebugf("</div>\n\n");
     }
-
+    
     virtual void drawPosTextH(const void* text, size_t byteLength,
                               const SkScalar xpos[], SkScalar constY,
                               const SkPaint& paint) {
     }
-
+    
 public:
     void divName(const SkString& str, bool only) {
         filename = str;
@@ -211,14 +211,14 @@ public:
         count = 0;
         nameonly = only;
     }
-
+    
     void init() {
         pointsMin = verbsMin = SK_MaxS32;
         pointsMax = verbsMax = SK_MinS32;
         rectPointsMin = rectVerbsMin = SK_MaxS32;
         rectPointsMax = rectVerbsMax = SK_MinS32;
     }
-
+    
     SkString filename;
     int count;
     bool nameonly;
@@ -279,6 +279,7 @@ void application_init() {
 }
 
 void application_term() {
+    SkGraphics::Term();
     SkEvent::Term();
 }
 
index 123449f..040472c 100644 (file)
@@ -1,10 +1,3 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
 #include "SkApplication.h"
 #import "SkCanvas.h"
 #import "SkPaint.h"
@@ -33,7 +26,7 @@ protected:
         canvas->drawRect(r, p);
     }
 private:
-    typedef SkView INHERITED;
+    typedef SkView INHERITED; 
 };
 
 void application_init() {
@@ -42,6 +35,7 @@ void application_init() {
 }
 
 void application_term() {
+    SkGraphics::Term();
     SkEvent::Term();
 }
 
index 03a8826..d537fd4 100644 (file)
@@ -40,6 +40,7 @@ void application_init() {
 
 void application_term() {
     SkEvent::Term();
+    SkGraphics::Term();
 }
 
 SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context)
index e9c5af5..8e8bd77 100644 (file)
@@ -23,8 +23,10 @@ public:
      */
     static void Init();
 
-    SK_ATTR_DEPRECATED("SkGraphics::Term() is a no-op.  We're in the middle of cleaning it up.")
-    static void Term() {}
+    /**
+     *  Call this to release any memory held privately, such as the font cache.
+     */
+    static void Term();
 
     /**
      *  Return the version numbers for the library. If the parameter is not
@@ -167,6 +169,9 @@ public:
     SkAutoGraphics() {
         SkGraphics::Init();
     }
+    ~SkAutoGraphics() {
+        SkGraphics::Term();
+    }
 };
 
 #endif
index 2090ed2..0c071ad 100644 (file)
@@ -289,7 +289,7 @@ public:
     SkFilterQuality getFilterQuality() const {
         return (SkFilterQuality)fBitfields.fFilterQuality;
     }
-
+    
     /**
      *  Set the filter quality. This affects the quality (and performance) of
      *  drawing scaled images.
@@ -1046,6 +1046,8 @@ private:
      */
     SkColor computeLuminanceColor() const;
 
+    static void Term();
+
     enum {
         /*  This is the size we use when we ask for a glyph's path. We then
          *  post-transform it as we draw to match the request.
@@ -1088,6 +1090,7 @@ private:
     friend class SkAutoGlyphCacheNoGamma;
     friend class SkCanvas;
     friend class SkDraw;
+    friend class SkGraphics; // So Term() can be called.
     friend class SkPDFDevice;
     friend class GrBitmapTextContext;
     friend class GrAtlasTextContext;
index 0af76fe..f4df448 100644 (file)
@@ -223,7 +223,7 @@ public:
     */
     static void Init();
     /** Global cleanup function for the SkEvent system. Should be called exactly once after
-        all event methods have been called.
+        all event methods have been called, and should be called before calling SkGraphics::Term().
     */
     static void Term();
 
index 02c5e03..22e8b8a 100644 (file)
@@ -2397,4 +2397,5 @@ void application_init() {
 
 void application_term() {
     SkEvent::Term();
+    SkGraphics::Term();
 }
index 5290ea1..e9dcadc 100644 (file)
@@ -58,6 +58,12 @@ void SkGraphics::Init() {
 #endif
 }
 
+void SkGraphics::Term() {
+    PurgeFontCache();
+    PurgeResourceCache();
+    SkPaint::Term();
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkGraphics::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
index e15c1a7..c109720 100644 (file)
@@ -1525,6 +1525,18 @@ static const SkMaskGamma& cachedMaskGamma(SkScalar contrast, SkScalar paintGamma
     return *gMaskGamma;
 }
 
+/*static*/ void SkPaint::Term() {
+    SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
+
+    SkSafeUnref(gLinearMaskGamma);
+    gLinearMaskGamma = nullptr;
+    SkSafeUnref(gMaskGamma);
+    gMaskGamma = nullptr;
+    SkDEBUGCODE(gContrast = SK_ScalarMin;)
+    SkDEBUGCODE(gPaintGamma = SK_ScalarMin;)
+    SkDEBUGCODE(gDeviceGamma = SK_ScalarMin;)
+}
+
 /**
  *  We ensure that the rec is self-consistent and efficient (where possible)
  */
index 7b63c1c..edc79d1 100644 (file)
@@ -1102,6 +1102,7 @@ int tool_main(int argc, char** argv) {
             test->run();
         }
     }
+    SkGraphics::Term();
     return 0;
 }
 
index 3c41204..7b90266 100644 (file)
@@ -114,6 +114,7 @@ void application_init() {
 
 void application_term() {
     SkEvent::Term();
+    SkGraphics::Term();
 }
 
 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
index 24f0c78..1ed9797 100644 (file)
@@ -794,6 +794,7 @@ int tool_main(int argc, char** argv) {
         SkDebugf("opt %d: %d\n", opt, gOptTable[opt].fNumTimesApplied);
     }
 
+    SkGraphics::Term();
     return 0;
 }
 
index 02884c8..1f5f2da 100644 (file)
@@ -96,4 +96,5 @@ void application_init() {
 void application_term();
 void application_term() {
     SkEvent::Term();
+    SkGraphics::Term();
 }