| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkArithmeticMode.h" | 9 #include "SkArithmeticMode.h" |
| 10 #include "SkShader.h" | 10 #include "SkShader.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Verifies AA works properly on all Xfermodes, including arithmetic, with both
opaque and unknown | 44 * Verifies AA works properly on all Xfermodes, including arithmetic, with both
opaque and unknown |
| 45 * src colors. | 45 * src colors. |
| 46 */ | 46 */ |
| 47 class AAXfermodesGM : public GM { | 47 class AAXfermodesGM : public GM { |
| 48 public: | 48 public: |
| 49 AAXfermodesGM() {} | 49 AAXfermodesGM() {} |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 enum DrawingPass { |
| 53 kCheckerboard_Pass, |
| 54 kBackground_Pass, |
| 55 kShape_Pass |
| 56 }; |
| 57 |
| 52 SkString onShortName() override { | 58 SkString onShortName() override { |
| 53 return SkString("aaxfermodes"); | 59 return SkString("aaxfermodes"); |
| 54 } | 60 } |
| 55 | 61 |
| 56 SkISize onISize() override { | 62 SkISize onISize() override { |
| 57 return SkISize::Make(2 * kMargin + 2 * kXfermodeTypeSpacing - | 63 return SkISize::Make(2 * kMargin + 2 * kXfermodeTypeSpacing - |
| 58 (kXfermodeTypeSpacing - (kLabelSpacing + 2 * kPaint
Spacing)), | 64 (kXfermodeTypeSpacing - (kLabelSpacing + 2 * kPaint
Spacing)), |
| 59 2 * kMargin + kTitleSpacing + kSubtitleSpacing + | 65 2 * kMargin + kTitleSpacing + kSubtitleSpacing + |
| 60 (1 + SkXfermode::kLastCoeffMode) * kShapeSpacing); | 66 (1 + SkXfermode::kLastCoeffMode) * kShapeSpacing); |
| 61 } | 67 } |
| 62 | 68 |
| 63 void onOnceBeforeDraw() override { | 69 void onOnceBeforeDraw() override { |
| 70 #if 0 |
| 64 fLabelPaint.setAntiAlias(true); | 71 fLabelPaint.setAntiAlias(true); |
| 65 sk_tool_utils::set_portable_typeface(&fLabelPaint); | 72 #endif |
| 73 sk_tool_utils::set_portable_typeface_always(&fLabelPaint); |
| 66 fLabelPaint.setTextSize(5 * kShapeSize/8); | 74 fLabelPaint.setTextSize(5 * kShapeSize/8); |
| 67 fLabelPaint.setSubpixelText(true); | 75 fLabelPaint.setSubpixelText(true); |
| 68 | 76 |
| 69 static const SkScalar radius = -1.4f * kShapeSize/2; | 77 static const SkScalar radius = -1.4f * kShapeSize/2; |
| 70 SkPoint pts[4] = { | 78 SkPoint pts[4] = { |
| 71 {-radius, 0}, | 79 {-radius, 0}, |
| 72 {0, -1.33f * radius}, | 80 {0, -1.33f * radius}, |
| 73 {radius, 0}, | 81 {radius, 0}, |
| 74 {0, 1.33f * radius} | 82 {0, 1.33f * radius} |
| 75 }; | 83 }; |
| 76 fPath.moveTo(pts[0]); | 84 fPath.moveTo(pts[0]); |
| 77 fPath.quadTo(pts[1], pts[2]); | 85 fPath.quadTo(pts[1], pts[2]); |
| 78 fPath.quadTo(pts[3], pts[0]); | 86 fPath.quadTo(pts[3], pts[0]); |
| 79 } | 87 } |
| 80 | 88 |
| 81 void onDraw(SkCanvas* canvas) override { | 89 void draw_pass(SkCanvas* canvas, DrawingPass drawingPass) { |
| 82 sk_tool_utils::draw_checkerboard(canvas, 0xffffffff, 0xffc0c0c0, 10); | 90 SkRect clipRect = |
| 91 { -kShapeSize*11/16, -kShapeSize*11/16, kShapeSize*11/16, kShape
Size*11/16 }; |
| 83 | 92 |
| 84 canvas->saveLayer(NULL, NULL); | 93 canvas->save(); |
| 85 canvas->drawColor(kBGColor, SkXfermode::kSrc_Mode); | 94 if (kCheckerboard_Pass == drawingPass) { |
| 86 | 95 canvas->translate(kMargin, kMargin); |
| 87 canvas->translate(kMargin, kMargin); | 96 } |
| 88 | |
| 89 SkPaint titlePaint(fLabelPaint); | |
| 90 titlePaint.setTextSize(9 * titlePaint.getTextSize() / 8); | |
| 91 titlePaint.setFakeBoldText(true); | |
| 92 titlePaint.setTextAlign(SkPaint::kCenter_Align); | |
| 93 canvas->drawText("Porter Duff", sizeof("Porter Duff") - 1, | |
| 94 kLabelSpacing + 3 * kShapeTypeSpacing, | |
| 95 kTitleSpacing / 2 + titlePaint.getTextSize() / 3, title
Paint); | |
| 96 canvas->drawText("Advanced", sizeof("Advanced") - 1, | |
| 97 kXfermodeTypeSpacing + kLabelSpacing + 3 * kShapeTypeSp
acing, | |
| 98 kTitleSpacing / 2 + titlePaint.getTextSize() / 3, title
Paint); | |
| 99 | |
| 100 canvas->translate(0, kTitleSpacing); | 97 canvas->translate(0, kTitleSpacing); |
| 101 | 98 |
| 102 for (size_t xfermodeSet = 0; xfermodeSet < 2; xfermodeSet++) { | 99 for (size_t xfermodeSet = 0; xfermodeSet < 2; xfermodeSet++) { |
| 103 size_t firstMode = (SkXfermode::kLastCoeffMode + 1) * xfermodeSet; | 100 size_t firstMode = (SkXfermode::kLastCoeffMode + 1) * xfermodeSet; |
| 104 canvas->save(); | 101 canvas->save(); |
| 105 | 102 |
| 106 fLabelPaint.setTextAlign(SkPaint::kCenter_Align); | 103 if (kShape_Pass == drawingPass) { |
| 107 canvas->drawText("Src Unknown", sizeof("Src Unknown") - 1, | 104 fLabelPaint.setTextAlign(SkPaint::kCenter_Align); |
| 108 kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpaci
ng, | 105 canvas->drawText("Src Unknown", sizeof("Src Unknown") - 1, |
| 109 kSubtitleSpacing / 2 + fLabelPaint.getTextSize() /
3, fLabelPaint); | 106 kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpacing, |
| 110 canvas->drawText("Src Opaque", sizeof("Src Opaque") - 1, | 107 kSubtitleSpacing / 2 + fLabelPaint.getTextSize() / 3, fL
abelPaint); |
| 111 kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpaci
ng + kPaintSpacing, | 108 canvas->drawText("Src Opaque", sizeof("Src Opaque") - 1, |
| 112 kSubtitleSpacing / 2 + fLabelPaint.getTextSize() /
3, fLabelPaint); | 109 kLabelSpacing + kShapeSpacing / 2 + kShapeTypeSpacing +
kPaintSpacing, |
| 110 kSubtitleSpacing / 2 + fLabelPaint.getTextSize() / 3, fL
abelPaint); |
| 111 } |
| 113 | 112 |
| 114 canvas->translate(0, kSubtitleSpacing + kShapeSpacing/2); | 113 canvas->translate(0, kSubtitleSpacing + kShapeSpacing/2); |
| 115 | 114 |
| 116 for (size_t m = 0; m <= SkXfermode::kLastCoeffMode; m++) { | 115 for (size_t m = 0; m <= SkXfermode::kLastCoeffMode; m++) { |
| 117 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(firstMode
+ m); | 116 SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(firstMode
+ m); |
| 118 canvas->save(); | 117 canvas->save(); |
| 119 | 118 |
| 120 this->drawModeName(canvas, mode); | 119 if (kShape_Pass == drawingPass) { |
| 120 this->drawModeName(canvas, mode); |
| 121 } |
| 121 canvas->translate(kLabelSpacing + kShapeSpacing/2, 0); | 122 canvas->translate(kLabelSpacing + kShapeSpacing/2, 0); |
| 122 | 123 |
| 123 for (size_t colorIdx = 0; colorIdx < SK_ARRAY_COUNT(kShapeColors
); colorIdx++) { | 124 for (size_t colorIdx = 0; colorIdx < SK_ARRAY_COUNT(kShapeColors
); colorIdx++) { |
| 124 SkPaint paint; | 125 SkPaint paint; |
| 125 this->setupShapePaint(canvas, kShapeColors[colorIdx], mode,
&paint); | 126 this->setupShapePaint(canvas, kShapeColors[colorIdx], mode,
&paint); |
| 126 SkASSERT(colorIdx == 0 || 255 == paint.getAlpha()); | 127 SkASSERT(colorIdx == 0 || 255 == paint.getAlpha()); |
| 127 canvas->save(); | 128 canvas->save(); |
| 128 | 129 |
| 129 for (size_t shapeIdx = 0; shapeIdx <= kLast_Shape; shapeIdx+
+) { | 130 for (size_t shapeIdx = 0; shapeIdx <= kLast_Shape; shapeIdx+
+) { |
| 130 this->drawShape(canvas, static_cast<Shape>(shapeIdx), pa
int, mode); | 131 if (kShape_Pass != drawingPass) { |
| 132 canvas->save(); |
| 133 canvas->clipRect(clipRect); |
| 134 if (kCheckerboard_Pass == drawingPass) { |
| 135 sk_tool_utils::draw_checkerboard(canvas, 0xfffff
fff, 0xffc6c3c6, |
| 136 10); |
| 137 } else { |
| 138 SkASSERT(kBackground_Pass == drawingPass); |
| 139 canvas->drawColor(kBGColor, SkXfermode::kSrc_Mod
e); |
| 140 } |
| 141 canvas->restore(); |
| 142 } else { |
| 143 this->drawShape(canvas, static_cast<Shape>(shapeIdx)
, paint, mode); |
| 144 } |
| 131 canvas->translate(kShapeTypeSpacing, 0); | 145 canvas->translate(kShapeTypeSpacing, 0); |
| 132 } | 146 } |
| 133 | 147 |
| 134 canvas->restore(); | 148 canvas->restore(); |
| 135 canvas->translate(kPaintSpacing, 0); | 149 canvas->translate(kPaintSpacing, 0); |
| 136 } | 150 } |
| 137 | 151 |
| 138 canvas->restore(); | 152 canvas->restore(); |
| 139 canvas->translate(0, kShapeSpacing); | 153 canvas->translate(0, kShapeSpacing); |
| 140 } | 154 } |
| 141 | 155 |
| 142 canvas->restore(); | 156 canvas->restore(); |
| 143 canvas->translate(kXfermodeTypeSpacing, 0); | 157 canvas->translate(kXfermodeTypeSpacing, 0); |
| 144 } | 158 } |
| 145 | 159 |
| 146 canvas->restore(); | 160 canvas->restore(); |
| 147 } | 161 } |
| 148 | 162 |
| 163 void onDraw(SkCanvas* canvas) override { |
| 164 draw_pass(canvas, kCheckerboard_Pass); |
| 165 canvas->saveLayer(NULL, NULL); |
| 166 |
| 167 canvas->translate(kMargin, kMargin); |
| 168 draw_pass(canvas, kBackground_Pass); |
| 169 |
| 170 SkPaint titlePaint(fLabelPaint); |
| 171 titlePaint.setTextSize(9 * titlePaint.getTextSize() / 8); |
| 172 titlePaint.setFakeBoldText(true); |
| 173 titlePaint.setTextAlign(SkPaint::kCenter_Align); |
| 174 canvas->drawText("Porter Duff", sizeof("Porter Duff") - 1, |
| 175 kLabelSpacing + 3 * kShapeTypeSpacing, |
| 176 kTitleSpacing / 2 + titlePaint.getTextSize() / 3, title
Paint); |
| 177 canvas->drawText("Advanced", sizeof("Advanced") - 1, |
| 178 kXfermodeTypeSpacing + kLabelSpacing + 3 * kShapeTypeSp
acing, |
| 179 kTitleSpacing / 2 + titlePaint.getTextSize() / 3, title
Paint); |
| 180 |
| 181 draw_pass(canvas, kShape_Pass); |
| 182 canvas->restore(); |
| 183 } |
| 184 |
| 149 void drawModeName(SkCanvas* canvas, SkXfermode::Mode mode) { | 185 void drawModeName(SkCanvas* canvas, SkXfermode::Mode mode) { |
| 150 const char* modeName = mode <= SkXfermode::kLastMode ? SkXfermode::ModeN
ame(mode) | 186 const char* modeName = mode <= SkXfermode::kLastMode ? SkXfermode::ModeN
ame(mode) |
| 151 : "Arithmetic"; | 187 : "Arithmetic"; |
| 152 fLabelPaint.setTextAlign(SkPaint::kRight_Align); | 188 fLabelPaint.setTextAlign(SkPaint::kRight_Align); |
| 153 canvas->drawText(modeName, strlen(modeName), kLabelSpacing - kShapeSize
/ 4, | 189 canvas->drawText(modeName, strlen(modeName), kLabelSpacing - kShapeSize
/ 4, |
| 154 fLabelPaint.getTextSize() / 3, fLabelPaint); | 190 fLabelPaint.getTextSize() / 3, fLabelPaint); |
| 155 } | 191 } |
| 156 | 192 |
| 157 void setupShapePaint(SkCanvas* canvas, GrColor color, SkXfermode::Mode mode,
SkPaint* paint) { | 193 void setupShapePaint(SkCanvas* canvas, GrColor color, SkXfermode::Mode mode,
SkPaint* paint) { |
| 158 paint->setColor(color); | 194 paint->setColor(color); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 263 |
| 228 typedef GM INHERITED; | 264 typedef GM INHERITED; |
| 229 }; | 265 }; |
| 230 | 266 |
| 231 ////////////////////////////////////////////////////////////////////////////// | 267 ////////////////////////////////////////////////////////////////////////////// |
| 232 | 268 |
| 233 static GM* MyFactory(void*) { return new AAXfermodesGM; } | 269 static GM* MyFactory(void*) { return new AAXfermodesGM; } |
| 234 static GMRegistry reg(MyFactory); | 270 static GMRegistry reg(MyFactory); |
| 235 | 271 |
| 236 } | 272 } |
| OLD | NEW |