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

Side by Side Diff: gm/arithmode.cpp

Issue 16064002: Provide a GPU implementation of SkArithmeticMode (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Don't attempt to write to inputColor. Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | include/effects/SkArithmeticMode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 SkColor colors[] = { 47 SkColor colors[] = {
48 SK_ColorBLUE, SK_ColorYELLOW, SK_ColorBLACK, SK_ColorGREEN, SK_ColorGRAY 48 SK_ColorBLUE, SK_ColorYELLOW, SK_ColorBLACK, SK_ColorGREEN, SK_ColorGRAY
49 }; 49 };
50 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COU NT(colors), 50 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COU NT(colors),
51 SkShader::kClamp_TileMode); 51 SkShader::kClamp_TileMode);
52 paint.setShader(s)->unref(); 52 paint.setShader(s)->unref();
53 canvas.drawPaint(paint); 53 canvas.drawPaint(paint);
54 return bm; 54 return bm;
55 } 55 }
56 56
57 static SkBitmap make_arith(const SkBitmap& src, const SkBitmap& dst,
58 const SkScalar k[]) {
59 SkBitmap bm = make_bm();
60 SkCanvas canvas(bm);
61 SkPaint paint;
62 canvas.drawBitmap(dst, 0, 0, NULL);
63 SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]);
64 paint.setXfermode(xfer)->unref();
65 canvas.drawBitmap(src, 0, 0, &paint);
66 return bm;
67 }
68
69 static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar k[]) { 57 static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar k[]) {
70 SkPaint paint; 58 SkPaint paint;
71 paint.setTextSize(SkIntToScalar(24)); 59 paint.setTextSize(SkIntToScalar(24));
72 paint.setAntiAlias(true); 60 paint.setAntiAlias(true);
73 for (int i = 0; i < 4; ++i) { 61 for (int i = 0; i < 4; ++i) {
74 SkString str; 62 SkString str;
75 str.appendScalar(k[i]); 63 str.appendScalar(k[i]);
76 SkScalar width = paint.measureText(str.c_str(), str.size()); 64 SkScalar width = paint.measureText(str.c_str(), str.size());
77 canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize(), pa int); 65 canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize(), pa int);
78 x += width + SkIntToScalar(10); 66 x += width + SkIntToScalar(10);
(...skipping 30 matching lines...) Expand all
109 one/4, one/2, one/2, 0, 97 one/4, one/2, one/2, 0,
110 -one/4, one/2, one/2, 0, 98 -one/4, one/2, one/2, 0,
111 }; 99 };
112 100
113 const SkScalar* k = K; 101 const SkScalar* k = K;
114 const SkScalar* stop = k + SK_ARRAY_COUNT(K); 102 const SkScalar* stop = k + SK_ARRAY_COUNT(K);
115 SkScalar y = 0; 103 SkScalar y = 0;
116 SkScalar gap = SkIntToScalar(src.width() + 20); 104 SkScalar gap = SkIntToScalar(src.width() + 20);
117 while (k < stop) { 105 while (k < stop) {
118 SkScalar x = 0; 106 SkScalar x = 0;
119 SkBitmap res = make_arith(src, dst, k);
120 canvas->drawBitmap(src, x, y, NULL); 107 canvas->drawBitmap(src, x, y, NULL);
121 x += gap; 108 x += gap;
122 canvas->drawBitmap(dst, x, y, NULL); 109 canvas->drawBitmap(dst, x, y, NULL);
123 x += gap; 110 x += gap;
124 canvas->drawBitmap(res, x, y, NULL); 111 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala r(HH));
112 canvas->saveLayer(&rect, NULL);
113 canvas->drawBitmap(dst, x, y, NULL);
114 SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]);
115 SkPaint paint;
116 paint.setXfermode(xfer)->unref();
117 canvas->drawBitmap(src, x, y, &paint);
118 canvas->restore();
125 x += gap; 119 x += gap;
126 show_k_text(canvas, x, y, k); 120 show_k_text(canvas, x, y, k);
127 k += 4; 121 k += 4;
128 y += SkIntToScalar(src.height() + 12); 122 y += SkIntToScalar(src.height() + 12);
129 } 123 }
130 } 124 }
131 125
132 private: 126 private:
133 typedef GM INHERITED; 127 typedef GM INHERITED;
134 }; 128 };
135 129
136 /////////////////////////////////////////////////////////////////////////////// 130 ///////////////////////////////////////////////////////////////////////////////
137 131
138 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; } 132 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; }
139 static skiagm::GMRegistry reg(MyFactory); 133 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | include/effects/SkArithmeticMode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698