Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: gm/arithmode.cpp

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 SkScalar gap = SkIntToScalar(src.width() + 20); 103 SkScalar gap = SkIntToScalar(src.width() + 20);
104 while (k < stop) { 104 while (k < stop) {
105 SkScalar x = 0; 105 SkScalar x = 0;
106 canvas->drawBitmap(src, x, y, nullptr); 106 canvas->drawBitmap(src, x, y, nullptr);
107 x += gap; 107 x += gap;
108 canvas->drawBitmap(dst, x, y, nullptr); 108 canvas->drawBitmap(dst, x, y, nullptr);
109 x += gap; 109 x += gap;
110 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala r(HH)); 110 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala r(HH));
111 canvas->saveLayer(&rect, nullptr); 111 canvas->saveLayer(&rect, nullptr);
112 canvas->drawBitmap(dst, x, y, nullptr); 112 canvas->drawBitmap(dst, x, y, nullptr);
113 SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]);
114 SkPaint paint; 113 SkPaint paint;
115 paint.setXfermode(xfer)->unref(); 114 paint.setXfermode(SkArithmeticMode::Make(k[0], k[1], k[2], k[3]));
116 canvas->drawBitmap(src, x, y, &paint); 115 canvas->drawBitmap(src, x, y, &paint);
117 canvas->restore(); 116 canvas->restore();
118 x += gap; 117 x += gap;
119 show_k_text(canvas, x, y, k); 118 show_k_text(canvas, x, y, k);
120 k += 4; 119 k += 4;
121 y += SkIntToScalar(src.height() + 12); 120 y += SkIntToScalar(src.height() + 12);
122 } 121 }
123 122
124 // Draw two special cases to test enforcePMColor. In these cases, we 123 // Draw two special cases to test enforcePMColor. In these cases, we
125 // draw the dst bitmap twice, the first time it is halved and inverted, 124 // draw the dst bitmap twice, the first time it is halved and inverted,
126 // leading to invalid premultiplied colors. If we enforcePMColor, these 125 // leading to invalid premultiplied colors. If we enforcePMColor, these
127 // invalid values should be clamped, and will not contribute to the 126 // invalid values should be clamped, and will not contribute to the
128 // second draw. 127 // second draw.
129 for (int i = 0; i < 2; i++) { 128 for (int i = 0; i < 2; i++) {
130 const bool enforcePMColor = (i == 0); 129 const bool enforcePMColor = (i == 0);
131 SkScalar x = gap; 130 SkScalar x = gap;
132 canvas->drawBitmap(dst, x, y, nullptr); 131 canvas->drawBitmap(dst, x, y, nullptr);
133 x += gap; 132 x += gap;
134 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala r(HH)); 133 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala r(HH));
135 canvas->saveLayer(&rect, nullptr); 134 canvas->saveLayer(&rect, nullptr);
136 SkXfermode* xfer1 = SkArithmeticMode::Create(0, -one / 2, 0, 1, enfo rcePMColor);
137 SkPaint paint1; 135 SkPaint paint1;
138 paint1.setXfermode(xfer1)->unref(); 136 paint1.setXfermode(SkArithmeticMode::Make(0, -one / 2, 0, 1, enforce PMColor));
139 canvas->drawBitmap(dst, x, y, &paint1); 137 canvas->drawBitmap(dst, x, y, &paint1);
140 SkXfermode* xfer2 = SkArithmeticMode::Create(0, one / 2, -one, 1);
141 SkPaint paint2; 138 SkPaint paint2;
142 paint2.setXfermode(xfer2)->unref(); 139 paint2.setXfermode(SkArithmeticMode::Make(0, one / 2, -one, 1));
143 canvas->drawBitmap(dst, x, y, &paint2); 140 canvas->drawBitmap(dst, x, y, &paint2);
144 canvas->restore(); 141 canvas->restore();
145 x += gap; 142 x += gap;
146 143
147 // Label 144 // Label
148 SkPaint paint; 145 SkPaint paint;
149 paint.setTextSize(SkIntToScalar(24)); 146 paint.setTextSize(SkIntToScalar(24));
150 paint.setAntiAlias(true); 147 paint.setAntiAlias(true);
151 sk_tool_utils::set_portable_typeface(&paint); 148 sk_tool_utils::set_portable_typeface(&paint);
152 SkString str(enforcePMColor ? "enforcePM" : "no enforcePM"); 149 SkString str(enforcePMColor ? "enforcePM" : "no enforcePM");
153 canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize() , paint); 150 canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize() , paint);
154 151
155 y += SkIntToScalar(src.height() + 12); 152 y += SkIntToScalar(src.height() + 12);
156 } 153 }
157 } 154 }
158 155
159 private: 156 private:
160 typedef GM INHERITED; 157 typedef GM INHERITED;
161 }; 158 };
162 159
163 /////////////////////////////////////////////////////////////////////////////// 160 ///////////////////////////////////////////////////////////////////////////////
164 161
165 DEF_GM( return new ArithmodeGM; ) 162 DEF_GM( return new ArithmodeGM; )
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698