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

Side by Side Diff: gm/arithmode.cpp

Issue 16115007: Revert "Provide a GPU implementation of SkArithmeticMode, using a custom GrEffect exposed via asNew… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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
57 static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar k[]) { 69 static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar k[]) {
58 SkPaint paint; 70 SkPaint paint;
59 paint.setTextSize(SkIntToScalar(24)); 71 paint.setTextSize(SkIntToScalar(24));
60 paint.setAntiAlias(true); 72 paint.setAntiAlias(true);
61 for (int i = 0; i < 4; ++i) { 73 for (int i = 0; i < 4; ++i) {
62 SkString str; 74 SkString str;
63 str.appendScalar(k[i]); 75 str.appendScalar(k[i]);
64 SkScalar width = paint.measureText(str.c_str(), str.size()); 76 SkScalar width = paint.measureText(str.c_str(), str.size());
65 canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize(), pa int); 77 canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize(), pa int);
66 x += width + SkIntToScalar(10); 78 x += width + SkIntToScalar(10);
(...skipping 30 matching lines...) Expand all
97 one/4, one/2, one/2, 0, 109 one/4, one/2, one/2, 0,
98 -one/4, one/2, one/2, 0, 110 -one/4, one/2, one/2, 0,
99 }; 111 };
100 112
101 const SkScalar* k = K; 113 const SkScalar* k = K;
102 const SkScalar* stop = k + SK_ARRAY_COUNT(K); 114 const SkScalar* stop = k + SK_ARRAY_COUNT(K);
103 SkScalar y = 0; 115 SkScalar y = 0;
104 SkScalar gap = SkIntToScalar(src.width() + 20); 116 SkScalar gap = SkIntToScalar(src.width() + 20);
105 while (k < stop) { 117 while (k < stop) {
106 SkScalar x = 0; 118 SkScalar x = 0;
119 SkBitmap res = make_arith(src, dst, k);
107 canvas->drawBitmap(src, x, y, NULL); 120 canvas->drawBitmap(src, x, y, NULL);
108 x += gap; 121 x += gap;
109 canvas->drawBitmap(dst, x, y, NULL); 122 canvas->drawBitmap(dst, x, y, NULL);
110 x += gap; 123 x += gap;
111 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala r(HH)); 124 canvas->drawBitmap(res, x, y, NULL);
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();
119 x += gap; 125 x += gap;
120 show_k_text(canvas, x, y, k); 126 show_k_text(canvas, x, y, k);
121 k += 4; 127 k += 4;
122 y += SkIntToScalar(src.height() + 12); 128 y += SkIntToScalar(src.height() + 12);
123 } 129 }
124 } 130 }
125 131
126 private: 132 private:
127 typedef GM INHERITED; 133 typedef GM INHERITED;
128 }; 134 };
129 135
130 /////////////////////////////////////////////////////////////////////////////// 136 ///////////////////////////////////////////////////////////////////////////////
131 137
132 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; } 138 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; }
133 static skiagm::GMRegistry reg(MyFactory); 139 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