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

Side by Side Diff: tests/DeferredCanvasTest.cpp

Issue 12879005: Fixing deferred canvas bug caused by SkTwoPointConicalGradient declaring itself as opaque. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | « src/effects/gradients/SkTwoPointConicalGradient.cpp ('k') | no next file » | 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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkBitmapProcShader.h" 10 #include "SkBitmapProcShader.h"
11 #include "SkDeferredCanvas.h" 11 #include "SkDeferredCanvas.h"
12 #include "SkDevice.h" 12 #include "SkDevice.h"
13 #include "SkGradientShader.h"
13 #include "SkShader.h" 14 #include "SkShader.h"
14 15
15 static const int gWidth = 2; 16 static const int gWidth = 2;
16 static const int gHeight = 2; 17 static const int gHeight = 2;
17 18
18 static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) { 19 static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
19 bm->setConfig(config, gWidth, gHeight); 20 bm->setConfig(config, gWidth, gHeight);
20 bm->allocPixels(); 21 bm->allocPixels();
21 bm->eraseColor(color); 22 bm->eraseColor(color);
22 } 23 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 canvas.save(SkCanvas::kMatrixClip_SaveFlag); 91 canvas.save(SkCanvas::kMatrixClip_SaveFlag);
91 canvas.clipRect(partialRect, SkRegion::kIntersect_Op, false); 92 canvas.clipRect(partialRect, SkRegion::kIntersect_Op, false);
92 canvas.clear(0x00000000); 93 canvas.clear(0x00000000);
93 canvas.restore(); 94 canvas.restore();
94 REPORTER_ASSERT(reporter, canvas.isFreshFrame()); 95 REPORTER_ASSERT(reporter, canvas.isFreshFrame());
95 96
96 // Verify that full frame rects with different forms of opaque paint 97 // Verify that full frame rects with different forms of opaque paint
97 // trigger frames to be marked as fresh 98 // trigger frames to be marked as fresh
98 { 99 {
99 SkPaint paint; 100 SkPaint paint;
100 paint.setStyle( SkPaint::kFill_Style ); 101 paint.setStyle(SkPaint::kFill_Style);
101 paint.setAlpha( 255 ); 102 paint.setAlpha(255);
102 canvas.drawRect(fullRect, paint); 103 canvas.drawRect(fullRect, paint);
103 REPORTER_ASSERT(reporter, canvas.isFreshFrame()); 104 REPORTER_ASSERT(reporter, canvas.isFreshFrame());
104 } 105 }
105 { 106 {
106 SkPaint paint; 107 SkPaint paint;
107 paint.setStyle( SkPaint::kFill_Style ); 108 paint.setStyle(SkPaint::kFill_Style);
108 paint.setAlpha( 255 ); 109 paint.setAlpha(255);
109 paint.setXfermodeMode(SkXfermode::kSrcIn_Mode); 110 paint.setXfermodeMode(SkXfermode::kSrcIn_Mode);
110 canvas.drawRect(fullRect, paint); 111 canvas.drawRect(fullRect, paint);
111 REPORTER_ASSERT(reporter, !canvas.isFreshFrame()); 112 REPORTER_ASSERT(reporter, !canvas.isFreshFrame());
112 } 113 }
113 { 114 {
114 SkPaint paint; 115 SkPaint paint;
115 paint.setStyle( SkPaint::kFill_Style ); 116 paint.setStyle(SkPaint::kFill_Style);
116 SkBitmap bmp; 117 SkBitmap bmp;
117 create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); 118 create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
118 bmp.setIsOpaque(true); 119 bmp.setIsOpaque(true);
119 SkShader* shader = SkShader::CreateBitmapShader(bmp, 120 SkShader* shader = SkShader::CreateBitmapShader(bmp,
120 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 121 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
121 paint.setShader(shader)->unref(); 122 paint.setShader(shader)->unref();
122 canvas.drawRect(fullRect, paint); 123 canvas.drawRect(fullRect, paint);
123 REPORTER_ASSERT(reporter, canvas.isFreshFrame()); 124 REPORTER_ASSERT(reporter, canvas.isFreshFrame());
124 } 125 }
125 126
126 // Verify that full frame rects with different forms of non-opaque paint 127 // Verify that full frame rects with different forms of non-opaque paint
127 // do not trigger frames to be marked as fresh 128 // do not trigger frames to be marked as fresh
128 { 129 {
129 SkPaint paint; 130 SkPaint paint;
130 paint.setStyle( SkPaint::kFill_Style ); 131 paint.setStyle(SkPaint::kFill_Style);
131 paint.setAlpha( 254 ); 132 paint.setAlpha(254);
132 canvas.drawRect(fullRect, paint); 133 canvas.drawRect(fullRect, paint);
133 REPORTER_ASSERT(reporter, !canvas.isFreshFrame()); 134 REPORTER_ASSERT(reporter, !canvas.isFreshFrame());
134 } 135 }
135 { 136 {
136 SkPaint paint; 137 SkPaint paint;
137 paint.setStyle( SkPaint::kFill_Style ); 138 paint.setStyle(SkPaint::kFill_Style);
139 // Defining a cone that partially overlaps the canvas
140 const SkPoint pt1 = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
141 const SkScalar r1 = SkIntToScalar(1);
142 const SkPoint pt2 = SkPoint::Make(SkIntToScalar(10), SkIntToScalar(0));
143 const SkScalar r2 = SkIntToScalar(5);
144 const SkColor colors[2] = {SK_ColorWHITE, SK_ColorWHITE};
145 const SkScalar pos[2] = {0, SK_Scalar1};
146 SkShader* shader = SkGradientShader::CreateTwoPointConical(
147 pt1, r1, pt2, r2, colors, pos, 2, SkShader::kClamp_TileMode, NULL);
148 paint.setShader(shader)->unref();
149 canvas.drawRect(fullRect, paint);
150 REPORTER_ASSERT(reporter, !canvas.isFreshFrame());
151 }
152 {
153 SkPaint paint;
154 paint.setStyle(SkPaint::kFill_Style);
138 SkBitmap bmp; 155 SkBitmap bmp;
139 create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); 156 create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
140 bmp.setIsOpaque(false); 157 bmp.setIsOpaque(false);
141 SkShader* shader = SkShader::CreateBitmapShader(bmp, 158 SkShader* shader = SkShader::CreateBitmapShader(bmp,
142 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); 159 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
143 paint.setShader(shader)->unref(); 160 paint.setShader(shader)->unref();
144 canvas.drawRect(fullRect, paint); 161 canvas.drawRect(fullRect, paint);
145 REPORTER_ASSERT(reporter, !canvas.isFreshFrame()); 162 REPORTER_ASSERT(reporter, !canvas.isFreshFrame());
146 } 163 }
147 164
(...skipping 14 matching lines...) Expand all
162 SkPaint paint; 179 SkPaint paint;
163 paint.setStyle(SkPaint::kFill_Style); 180 paint.setStyle(SkPaint::kFill_Style);
164 paint.setAlpha(255); 181 paint.setAlpha(255);
165 canvas.drawRect(fullRect, paint); 182 canvas.drawRect(fullRect, paint);
166 canvas.restore(); 183 canvas.restore();
167 REPORTER_ASSERT(reporter, !canvas.isFreshFrame()); 184 REPORTER_ASSERT(reporter, !canvas.isFreshFrame());
168 } 185 }
169 { 186 {
170 canvas.save(SkCanvas::kMatrixClip_SaveFlag); 187 canvas.save(SkCanvas::kMatrixClip_SaveFlag);
171 SkPaint paint; 188 SkPaint paint;
172 paint.setStyle( SkPaint::kFill_Style ); 189 paint.setStyle(SkPaint::kFill_Style);
173 paint.setAlpha( 255 ); 190 paint.setAlpha(255);
174 SkPath path; 191 SkPath path;
175 path.addCircle(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(2)); 192 path.addCircle(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(2));
176 canvas.clipPath(path, SkRegion::kIntersect_Op, false); 193 canvas.clipPath(path, SkRegion::kIntersect_Op, false);
177 canvas.drawRect(fullRect, paint); 194 canvas.drawRect(fullRect, paint);
178 canvas.restore(); 195 canvas.restore();
179 REPORTER_ASSERT(reporter, !canvas.isFreshFrame()); 196 REPORTER_ASSERT(reporter, !canvas.isFreshFrame());
180 } 197 }
181 198
182 // Verify that stroked rect does not trigger a fresh frame 199 // Verify that stroked rect does not trigger a fresh frame
183 { 200 {
184 SkPaint paint; 201 SkPaint paint;
185 paint.setStyle( SkPaint::kStroke_Style ); 202 paint.setStyle(SkPaint::kStroke_Style);
186 paint.setAlpha( 255 ); 203 paint.setAlpha(255);
187 canvas.drawRect(fullRect, paint); 204 canvas.drawRect(fullRect, paint);
188 REPORTER_ASSERT(reporter, !canvas.isFreshFrame()); 205 REPORTER_ASSERT(reporter, !canvas.isFreshFrame());
189 } 206 }
190 207
191 // Verify kSrcMode triggers a fresh frame even with transparent color 208 // Verify kSrcMode triggers a fresh frame even with transparent color
192 { 209 {
193 SkPaint paint; 210 SkPaint paint;
194 paint.setStyle( SkPaint::kFill_Style ); 211 paint.setStyle(SkPaint::kFill_Style);
195 paint.setAlpha( 100 ); 212 paint.setAlpha(100);
196 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 213 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
197 canvas.drawRect(fullRect, paint); 214 canvas.drawRect(fullRect, paint);
198 REPORTER_ASSERT(reporter, canvas.isFreshFrame()); 215 REPORTER_ASSERT(reporter, canvas.isFreshFrame());
199 } 216 }
200 } 217 }
201 218
202 class MockDevice : public SkDevice { 219 class MockDevice : public SkDevice {
203 public: 220 public:
204 MockDevice(const SkBitmap& bm) : SkDevice(bm) { 221 MockDevice(const SkBitmap& bm) : SkDevice(bm) {
205 fDrawBitmapCallCount = 0; 222 fDrawBitmapCallCount = 0;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 TestDeferredCanvasFreshFrame(reporter); 471 TestDeferredCanvasFreshFrame(reporter);
455 TestDeferredCanvasMemoryLimit(reporter); 472 TestDeferredCanvasMemoryLimit(reporter);
456 TestDeferredCanvasBitmapCaching(reporter); 473 TestDeferredCanvasBitmapCaching(reporter);
457 TestDeferredCanvasSkip(reporter); 474 TestDeferredCanvasSkip(reporter);
458 TestDeferredCanvasBitmapShaderNoLeak(reporter); 475 TestDeferredCanvasBitmapShaderNoLeak(reporter);
459 TestDeferredCanvasBitmapSizeThreshold(reporter); 476 TestDeferredCanvasBitmapSizeThreshold(reporter);
460 } 477 }
461 478
462 #include "TestClassDef.h" 479 #include "TestClassDef.h"
463 DEFINE_TESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanvas) 480 DEFINE_TESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanvas)
OLDNEW
« no previous file with comments | « src/effects/gradients/SkTwoPointConicalGradient.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698