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

Side by Side Diff: tests/RecordingXfermodeTest.cpp

Issue 2396953002: Revert[8] "replace SkXfermode obj with SkBlendMode enum in paints" (Closed)
Patch Set: add tmp virtual to unroll legacy arithmodes Created 4 years, 2 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
« no previous file with comments | « tests/RecordOptsTest.cpp ('k') | tests/SerializationTest.cpp » ('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 2014 Google Inc. 2 * Copyright 2014 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 "Test.h" 8 #include "Test.h"
9 9
10 #include "../include/core/SkCanvas.h" 10 #include "../include/core/SkCanvas.h"
(...skipping 16 matching lines...) Expand all
27 fCircleBM.allocPixels(SkImageInfo::MakeN32Premul(100, 100)); 27 fCircleBM.allocPixels(SkImageInfo::MakeN32Premul(100, 100));
28 SkCanvas canvas(fCircleBM); 28 SkCanvas canvas(fCircleBM);
29 canvas.clear(0xffffffff); 29 canvas.clear(0xffffffff);
30 SkPaint circlePaint; 30 SkPaint circlePaint;
31 circlePaint.setColor(0xff000000); 31 circlePaint.setColor(0xff000000);
32 canvas.drawCircle(50, 50, 50, circlePaint); 32 canvas.drawCircle(50, 50, 50, circlePaint);
33 } 33 }
34 34
35 const SkImageInfo& imageInfo() const { return fImageInfo; } 35 const SkImageInfo& imageInfo() const { return fImageInfo; }
36 36
37 void draw(SkCanvas* canvas, const SkRect& clipRect, SkXfermode::Mode mode) c onst { 37 void draw(SkCanvas* canvas, const SkRect& clipRect, SkBlendMode mode) const {
38 SkPaint greenPaint; 38 SkPaint greenPaint;
39 greenPaint.setColor(0xff008000); 39 greenPaint.setColor(0xff008000);
40 SkPaint blackPaint; 40 SkPaint blackPaint;
41 blackPaint.setColor(0xff000000); 41 blackPaint.setColor(0xff000000);
42 SkPaint whitePaint; 42 SkPaint whitePaint;
43 whitePaint.setColor(0xffffffff); 43 whitePaint.setColor(0xffffffff);
44 SkPaint layerPaint; 44 SkPaint layerPaint;
45 layerPaint.setColor(0xff000000); 45 layerPaint.setColor(0xff000000);
46 layerPaint.setXfermodeMode(mode); 46 layerPaint.setBlendMode(mode);
47 SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fImageInfo.width()), 47 SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fImageInfo.width()),
48 SkIntToScalar(fImageInfo.height()))); 48 SkIntToScalar(fImageInfo.height())));
49 49
50 canvas->clipRect(clipRect); 50 canvas->clipRect(clipRect);
51 canvas->clear(0xff000000); 51 canvas->clear(0xff000000);
52 52
53 canvas->saveLayer(nullptr, &blackPaint); 53 canvas->saveLayer(nullptr, &blackPaint);
54 canvas->drawRect(canvasRect, greenPaint); 54 canvas->drawRect(canvasRect, greenPaint);
55 canvas->saveLayer(nullptr, &layerPaint); 55 canvas->saveLayer(nullptr, &layerPaint);
56 canvas->drawBitmapRect(fCircleBM, SkRect::MakeXYWH(20,20,60,60), &blackPaint); 56 canvas->drawBitmapRect(fCircleBM, SkRect::MakeXYWH(20,20,60,60), &blackPaint);
57 canvas->restore(); 57 canvas->restore();
58 canvas->restore(); 58 canvas->restore();
59 } 59 }
60 60
61 private: 61 private:
62 const SkImageInfo fImageInfo; 62 const SkImageInfo fImageInfo;
63 SkBitmap fCircleBM; 63 SkBitmap fCircleBM;
64 }; 64 };
65 65
66 class RecordingStrategy { 66 class RecordingStrategy {
67 public: 67 public:
68 virtual ~RecordingStrategy() {} 68 virtual ~RecordingStrategy() {}
69 virtual const SkBitmap& recordAndReplay(const Drawer& drawer, 69 virtual const SkBitmap& recordAndReplay(const Drawer& drawer,
70 const SkRect& intoClip, 70 const SkRect& intoClip,
71 SkXfermode::Mode) = 0; 71 SkBlendMode) = 0;
72 }; 72 };
73 73
74 class BitmapBackedCanvasStrategy : public RecordingStrategy { 74 class BitmapBackedCanvasStrategy : public RecordingStrategy {
75 // This version just draws into a bitmap-backed canvas. 75 // This version just draws into a bitmap-backed canvas.
76 public: 76 public:
77 BitmapBackedCanvasStrategy(const SkImageInfo& imageInfo) { 77 BitmapBackedCanvasStrategy(const SkImageInfo& imageInfo) {
78 fBitmap.allocPixels(imageInfo); 78 fBitmap.allocPixels(imageInfo);
79 } 79 }
80 80
81 virtual const SkBitmap& recordAndReplay(const Drawer& drawer, 81 const SkBitmap& recordAndReplay(const Drawer& drawer, const SkRect& intoClip ,
82 const SkRect& intoClip, 82 SkBlendMode mode) override {
83 SkXfermode::Mode mode) {
84 SkCanvas canvas(fBitmap); 83 SkCanvas canvas(fBitmap);
85 canvas.clear(0xffffffff); 84 canvas.clear(0xffffffff);
86 // Note that the scene is drawn just into the clipped region! 85 // Note that the scene is drawn just into the clipped region!
87 canvas.clipRect(intoClip); 86 canvas.clipRect(intoClip);
88 drawer.draw(&canvas, intoClip, mode); // Shouild be canvas-wide... 87 drawer.draw(&canvas, intoClip, mode); // Shouild be canvas-wide...
89 return fBitmap; 88 return fBitmap;
90 } 89 }
91 90
92 private: 91 private:
93 SkBitmap fBitmap; 92 SkBitmap fBitmap;
94 }; 93 };
95 94
96 class PictureStrategy : public RecordingStrategy { 95 class PictureStrategy : public RecordingStrategy {
97 // This version draws the entire scene into an SkPictureRecorder. 96 // This version draws the entire scene into an SkPictureRecorder.
98 // Then it then replays the scene through a clip rectangle. 97 // Then it then replays the scene through a clip rectangle.
99 // This backend proved to be buggy. 98 // This backend proved to be buggy.
100 public: 99 public:
101 PictureStrategy(const SkImageInfo& imageInfo) { 100 PictureStrategy(const SkImageInfo& imageInfo) {
102 fBitmap.allocPixels(imageInfo); 101 fBitmap.allocPixels(imageInfo);
103 fWidth = imageInfo.width(); 102 fWidth = imageInfo.width();
104 fHeight = imageInfo.height(); 103 fHeight = imageInfo.height();
105 } 104 }
106 105
107 virtual const SkBitmap& recordAndReplay(const Drawer& drawer, 106 const SkBitmap& recordAndReplay(const Drawer& drawer, const SkRect& intoClip ,
108 const SkRect& intoClip, 107 SkBlendMode mode) override {
109 SkXfermode::Mode mode) {
110 SkRTreeFactory factory; 108 SkRTreeFactory factory;
111 SkPictureRecorder recorder; 109 SkPictureRecorder recorder;
112 SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fWidth),SkIntToScalar(fHe ight))); 110 SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fWidth),SkIntToScalar(fHe ight)));
113 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(fWidth), 111 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(fWidth),
114 SkIntToScalar(fHeight), 112 SkIntToScalar(fHeight),
115 &factory); 113 &factory);
116 drawer.draw(canvas, canvasRect, mode); 114 drawer.draw(canvas, canvasRect, mode);
117 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); 115 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
118 116
119 SkCanvas replayCanvas(fBitmap); 117 SkCanvas replayCanvas(fBitmap);
(...skipping 17 matching lines...) Expand all
137 const Drawer drawer; 135 const Drawer drawer;
138 136
139 BitmapBackedCanvasStrategy golden(drawer.imageInfo()); 137 BitmapBackedCanvasStrategy golden(drawer.imageInfo());
140 PictureStrategy picture(drawer.imageInfo()); 138 PictureStrategy picture(drawer.imageInfo());
141 139
142 #if !FINEGRAIN 140 #if !FINEGRAIN
143 unsigned numErrors = 0; 141 unsigned numErrors = 0;
144 SkString errors; 142 SkString errors;
145 #endif 143 #endif
146 144
147 for (int iMode = 0; iMode < int(SkXfermode::kLastMode); iMode++) { 145 for (int iMode = 0; iMode < int(SkBlendMode::kLastMode); iMode++) {
148 const SkRect& clip = SkRect::MakeXYWH(100, 0, 100, 100); 146 const SkRect& clip = SkRect::MakeXYWH(100, 0, 100, 100);
149 SkXfermode::Mode mode = SkXfermode::Mode(iMode); 147 SkBlendMode mode = SkBlendMode(iMode);
150 148
151 const SkBitmap& goldenBM = golden.recordAndReplay(drawer, clip, mode); 149 const SkBitmap& goldenBM = golden.recordAndReplay(drawer, clip, mode);
152 const SkBitmap& pictureBM = picture.recordAndReplay(drawer, clip, mode); 150 const SkBitmap& pictureBM = picture.recordAndReplay(drawer, clip, mode);
153 151
154 size_t pixelsSize = goldenBM.getSize(); 152 size_t pixelsSize = goldenBM.getSize();
155 REPORTER_ASSERT(reporter, pixelsSize == pictureBM.getSize()); 153 REPORTER_ASSERT(reporter, pixelsSize == pictureBM.getSize());
156 154
157 // The pixel arrays should match. 155 // The pixel arrays should match.
158 #if FINEGRAIN 156 #if FINEGRAIN
159 REPORTER_ASSERT(reporter, 157 REPORTER_ASSERT(reporter,
160 0 == memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize)); 158 0 == memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize));
161 #else 159 #else
162 if (memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize)) { 160 if (memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize)) {
163 numErrors++; 161 numErrors++;
164 errors.appendf("For SkXfermode %d %s: SkPictureRecorder bitmap is wrong\n", 162 errors.appendf("For SkXfermode %d %s: SkPictureRecorder bitmap is wrong\n",
165 iMode, SkXfermode::ModeName(mode)); 163 iMode, SkXfermode::ModeName(mode));
166 } 164 }
167 #endif 165 #endif
168 } 166 }
169 167
170 #if !FINEGRAIN 168 #if !FINEGRAIN
171 REPORTER_ASSERT_MESSAGE(reporter, 0 == numErrors, errors.c_str()); 169 REPORTER_ASSERT_MESSAGE(reporter, 0 == numErrors, errors.c_str());
172 #endif 170 #endif
173 } 171 }
OLDNEW
« no previous file with comments | « tests/RecordOptsTest.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698