OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 class ArithmodeGM : public skiagm::GM { | 71 class ArithmodeGM : public skiagm::GM { |
72 public: | 72 public: |
73 ArithmodeGM () {} | 73 ArithmodeGM () {} |
74 | 74 |
75 protected: | 75 protected: |
76 | 76 |
77 virtual SkString onShortName() { | 77 virtual SkString onShortName() { |
78 return SkString("arithmode"); | 78 return SkString("arithmode"); |
79 } | 79 } |
80 | 80 |
81 virtual SkISize onISize() { return SkISize::Make(640, 480); } | 81 virtual SkISize onISize() { return SkISize::Make(640, 572); } |
82 | 82 |
83 virtual void onDraw(SkCanvas* canvas) { | 83 virtual void onDraw(SkCanvas* canvas) { |
84 SkBitmap src = make_src(); | 84 SkBitmap src = make_src(); |
85 SkBitmap dst = make_dst(); | 85 SkBitmap dst = make_dst(); |
86 | 86 |
87 const SkScalar one = SK_Scalar1; | 87 const SkScalar one = SK_Scalar1; |
88 static const SkScalar K[] = { | 88 static const SkScalar K[] = { |
89 0, 0, 0, 0, | 89 0, 0, 0, 0, |
90 0, 0, 0, one, | 90 0, 0, 0, one, |
91 0, one, 0, 0, | 91 0, one, 0, 0, |
(...skipping 23 matching lines...) Expand all Loading... |
115 SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]); | 115 SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]); |
116 SkPaint paint; | 116 SkPaint paint; |
117 paint.setXfermode(xfer)->unref(); | 117 paint.setXfermode(xfer)->unref(); |
118 canvas->drawBitmap(src, x, y, &paint); | 118 canvas->drawBitmap(src, x, y, &paint); |
119 canvas->restore(); | 119 canvas->restore(); |
120 x += gap; | 120 x += gap; |
121 show_k_text(canvas, x, y, k); | 121 show_k_text(canvas, x, y, k); |
122 k += 4; | 122 k += 4; |
123 y += SkIntToScalar(src.height() + 12); | 123 y += SkIntToScalar(src.height() + 12); |
124 } | 124 } |
| 125 |
| 126 // Draw two special cases to test enforcePMColor. In these cases, we |
| 127 // draw the dst bitmap twice, the first time it is halved and inverted, |
| 128 // leading to invalid premultiplied colors. If we enforcePMColor, these |
| 129 // invalid values should be clamped, and will not contribute to the |
| 130 // second draw. |
| 131 for (int i = 0; i < 2; i++) { |
| 132 const bool enforcePMColor = (i == 0); |
| 133 SkScalar x = gap; |
| 134 canvas->drawBitmap(dst, x, y, nullptr); |
| 135 x += gap; |
| 136 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala
r(HH)); |
| 137 canvas->saveLayer(&rect, nullptr); |
| 138 SkXfermode* xfer1 = SkArithmeticMode::Create(0, -one / 2, 0, 1, enfo
rcePMColor); |
| 139 SkPaint paint1; |
| 140 paint1.setXfermode(xfer1)->unref(); |
| 141 canvas->drawBitmap(dst, x, y, &paint1); |
| 142 SkXfermode* xfer2 = SkArithmeticMode::Create(0, one / 2, -one, 1); |
| 143 SkPaint paint2; |
| 144 paint2.setXfermode(xfer2)->unref(); |
| 145 canvas->drawBitmap(dst, x, y, &paint2); |
| 146 canvas->restore(); |
| 147 x += gap; |
| 148 |
| 149 // Label |
| 150 SkPaint paint; |
| 151 paint.setTextSize(SkIntToScalar(24)); |
| 152 paint.setAntiAlias(true); |
| 153 sk_tool_utils::set_portable_typeface(&paint); |
| 154 SkString str(enforcePMColor ? "enforcePM" : "no enforcePM"); |
| 155 canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize()
, paint); |
| 156 |
| 157 y += SkIntToScalar(src.height() + 12); |
| 158 } |
125 } | 159 } |
126 | 160 |
127 private: | 161 private: |
128 typedef GM INHERITED; | 162 typedef GM INHERITED; |
129 }; | 163 }; |
130 | 164 |
131 /////////////////////////////////////////////////////////////////////////////// | 165 /////////////////////////////////////////////////////////////////////////////// |
132 | 166 |
133 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; } | 167 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; } |
134 static skiagm::GMRegistry reg(MyFactory); | 168 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |