Add fixes & test for isConfigTexturable and isConfigRenderable
[platform/upstream/libSkiaSharp.git] / gm / simpleaaclip.cpp
index c6e8ba9..5e4067f 100644 (file)
@@ -5,10 +5,11 @@
  * found in the LICENSE file.
  */
 
-
 #include "gm.h"
-#include "SkCanvas.h"
+#include "sk_tool_utils.h"
 #include "SkAAClip.h"
+#include "SkCanvas.h"
+#include "SkPath.h"
 
 namespace skiagm {
 
@@ -21,14 +22,12 @@ static void paint_rgn(SkCanvas* canvas, const SkAAClip& clip,
 
     SkAutoMaskFreeImage amfi(mask.fImage);
 
-    bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(),
-                 mask.fBounds.height(), mask.fRowBytes);
-    bm.setPixels(mask.fImage);
+    bm.installMaskPixels(mask);
 
     // need to copy for deferred drawing test to work
     SkBitmap bm2;
 
-    bm.deepCopyTo(&bm2, SkBitmap::kA8_Config);
+    sk_tool_utils::copy_to(&bm2, bm.colorType(), bm);
 
     canvas->drawBitmap(bm2,
                        SK_Scalar1 * mask.fBounds.fLeft,
@@ -51,28 +50,30 @@ public:
 
     SimpleClipGM(SkGeomTypes geomType)
     : fGeomType(geomType) {
+    }
 
+protected:
+    void onOnceBeforeDraw() override {
         // offset the rects a bit so we get anti-aliasing in the rect case
-        fBase.set(SkFloatToScalar(100.65f),
-                  SkFloatToScalar(100.65f),
-                  SkFloatToScalar(150.65f),
-                  SkFloatToScalar(150.65f));
+        fBase.set(100.65f,
+                  100.65f,
+                  150.65f,
+                  150.65f);
         fRect = fBase;
         fRect.inset(5, 5);
         fRect.offset(25, 25);
 
         fBasePath.addRoundRect(fBase, SkIntToScalar(5), SkIntToScalar(5));
         fRectPath.addRoundRect(fRect, SkIntToScalar(5), SkIntToScalar(5));
-        INHERITED::setBGColor(0xFFDDDDDD);
+        INHERITED::setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
     }
 
-protected:
-    void buildRgn(SkAAClip* clip, SkRegion::Op op) {
-        clip->setPath(fBasePath, NULL, true);
+    void buildRgn(SkAAClip* clip, SkClipOp op) {
+        clip->setPath(fBasePath, nullptr, true);
 
         SkAAClip clip2;
-        clip2.setPath(fRectPath, NULL, true);
-        clip->op(clip2, op);
+        clip2.setPath(fRectPath, nullptr, true);
+        clip->op(clip2, (SkRegion::Op)op);
     }
 
     void drawOrig(SkCanvas* canvas) {
@@ -85,7 +86,7 @@ protected:
         canvas->drawRect(fRect, paint);
     }
 
-    void drawRgnOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) {
+    void drawRgnOped(SkCanvas* canvas, SkClipOp op, SkColor color) {
 
         SkAAClip clip;
 
@@ -97,7 +98,7 @@ protected:
         paint_rgn(canvas, clip, paint);
     }
 
-    void drawPathsOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) {
+    void drawPathsOped(SkCanvas* canvas, SkClipOp op, SkColor color) {
 
         this->drawOrig(canvas);
 
@@ -106,11 +107,11 @@ protected:
         // create the clip mask with the supplied boolean op
         if (kPath_GeomType == fGeomType) {
             // path-based case
-            canvas->clipPath(fBasePath, SkRegion::kReplace_Op, true);
+            canvas->clipPath(fBasePath, true);
             canvas->clipPath(fRectPath, op, true);
         } else {
             // rect-based case
-            canvas->clipRect(fBase, SkRegion::kReplace_Op, true);
+            canvas->clipRect(fBase, true);
             canvas->clipRect(fRect, op, true);
         }
 
@@ -126,7 +127,7 @@ protected:
         canvas->restore();
     }
 
-    virtual SkString onShortName() {
+    SkString onShortName() override {
         SkString str;
         str.printf("simpleaaclip_%s",
                     kRect_GeomType == fGeomType ? "rect" :
@@ -135,32 +136,33 @@ protected:
         return str;
     }
 
-    virtual SkISize onISize() {
-        return make_isize(640, 480);
+    SkISize onISize() override {
+        return SkISize::Make(640, 480);
     }
 
-    virtual void onDraw(SkCanvas* canvas) {
+    void onDraw(SkCanvas* canvas) override {
 
-        static const struct {
+        const struct {
             SkColor         fColor;
             const char*     fName;
-            SkRegion::Op    fOp;
+            SkClipOp        fOp;
         } gOps[] = {
-            { SK_ColorBLACK,    "Difference", SkRegion::kDifference_Op    },
-            { SK_ColorRED,      "Intersect",  SkRegion::kIntersect_Op     },
-            { 0xFF008800,       "Union",      SkRegion::kUnion_Op         },
-            { SK_ColorGREEN,    "Rev Diff",   SkRegion::kReverseDifference_Op },
-            { SK_ColorYELLOW,   "Replace",    SkRegion::kReplace_Op       },
-            { SK_ColorBLUE,     "XOR",        SkRegion::kXOR_Op           },
+            { SK_ColorBLACK,    "Difference", kDifference_SkClipOp    },
+            { SK_ColorRED,      "Intersect",  kIntersect_SkClipOp     },
+            { sk_tool_utils::color_to_565(0xFF008800), "Union", kUnion_SkClipOp },
+            { SK_ColorGREEN,    "Rev Diff",   kReverseDifference_SkClipOp },
+            { SK_ColorYELLOW,   "Replace",    kReplace_SkClipOp       },
+            { SK_ColorBLUE,     "XOR",        kXOR_SkClipOp           },
         };
 
         SkPaint textPaint;
         textPaint.setAntiAlias(true);
+        sk_tool_utils::set_portable_typeface(&textPaint);
         textPaint.setTextSize(SK_Scalar1*24);
         int xOff = 0;
 
         for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); op++) {
-            canvas->drawText(gOps[op].fName, strlen(gOps[op].fName),
+            canvas->drawString(gOps[op].fName,
                              SkIntToScalar(75), SkIntToScalar(50),
                              textPaint);
 
@@ -195,18 +197,8 @@ private:
 //////////////////////////////////////////////////////////////////////////////
 
 // rects
-static GM* MyFactory(void*) { return new SimpleClipGM(
-                                            SimpleClipGM::kRect_GeomType); }
-static GMRegistry reg(MyFactory);
-
-// paths
-static GM* MyFactory2(void*) { return new SimpleClipGM(
-                                            SimpleClipGM::kPath_GeomType); }
-static GMRegistry reg2(MyFactory2);
-
-// aa clip
-static GM* MyFactory3(void*) { return new SimpleClipGM(
-                                            SimpleClipGM::kAAClip_GeomType); }
-static GMRegistry reg3(MyFactory3);
+DEF_GM( return new SimpleClipGM(SimpleClipGM::kRect_GeomType); )
+DEF_GM( return new SimpleClipGM(SimpleClipGM::kPath_GeomType); )
+DEF_GM( return new SimpleClipGM(SimpleClipGM::kAAClip_GeomType); )
 
 }