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

Unified Diff: tests/RecordingXfermodeTest.cpp

Issue 617953002: Strip old backend recording down to essentials (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: debug-only Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/PictureStateTreeTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RecordingXfermodeTest.cpp
diff --git a/tests/RecordingXfermodeTest.cpp b/tests/RecordingXfermodeTest.cpp
index 8da81b3680482adf8e6a987ab3a538a23f5020e6..aa6bf687a1c1ead581ba0b5e6a40582573c73e26 100644
--- a/tests/RecordingXfermodeTest.cpp
+++ b/tests/RecordingXfermodeTest.cpp
@@ -20,20 +20,17 @@
// This arose from http://crbug.com/401593 which has
// https://code.google.com/p/skia/issues/detail?id=1291 as its root cause.
-
namespace {
class Drawer {
public:
- explicit Drawer()
- : fImageInfo(SkImageInfo::MakeN32Premul(200,100))
- {
- fCircleBM.allocPixels( SkImageInfo::MakeN32Premul(100,100) );
+ explicit Drawer() : fImageInfo(SkImageInfo::MakeN32Premul(200, 100)) {
+ fCircleBM.allocPixels(SkImageInfo::MakeN32Premul(100, 100));
SkCanvas canvas(fCircleBM);
canvas.clear(0xffffffff);
SkPaint circlePaint;
circlePaint.setColor(0xff000000);
- canvas.drawCircle(50,50,50,circlePaint);
+ canvas.drawCircle(50, 50, 50, circlePaint);
}
const SkImageInfo& imageInfo() const { return fImageInfo; }
@@ -48,15 +45,16 @@ class Drawer {
SkPaint layerPaint;
layerPaint.setColor(0xff000000);
layerPaint.setXfermodeMode(mode);
- SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fImageInfo.width()),SkIntToScalar(fImageInfo.height())));
+ SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fImageInfo.width()),
+ SkIntToScalar(fImageInfo.height())));
canvas->clipRect(clipRect);
canvas->clear(0xff000000);
- canvas->saveLayer(NULL,&blackPaint);
- canvas->drawRect(canvasRect,greenPaint);
- canvas->saveLayer(NULL,&layerPaint);
- canvas->drawBitmapRect(fCircleBM,SkRect::MakeXYWH(20,20,60,60),&blackPaint);
+ canvas->saveLayer(NULL, &blackPaint);
+ canvas->drawRect(canvasRect, greenPaint);
+ canvas->saveLayer(NULL, &layerPaint);
+ canvas->drawBitmapRect(fCircleBM, SkRect::MakeXYWH(20,20,60,60), &blackPaint);
canvas->restore();
canvas->restore();
}
@@ -69,7 +67,6 @@ class Drawer {
class RecordingStrategy {
public:
virtual ~RecordingStrategy() {}
- virtual void init(const SkImageInfo&) = 0;
virtual const SkBitmap& recordAndReplay(const Drawer& drawer,
const SkRect& intoClip,
SkXfermode::Mode) = 0;
@@ -78,9 +75,7 @@ class RecordingStrategy {
class BitmapBackedCanvasStrategy : public RecordingStrategy {
// This version just draws into a bitmap-backed canvas.
public:
- BitmapBackedCanvasStrategy() {}
-
- virtual void init(const SkImageInfo& imageInfo) {
+ BitmapBackedCanvasStrategy(const SkImageInfo& imageInfo) {
fBitmap.allocPixels(imageInfo);
}
@@ -99,57 +94,15 @@ class BitmapBackedCanvasStrategy : public RecordingStrategy {
SkBitmap fBitmap;
};
-class DeprecatedRecorderStrategy : public RecordingStrategy {
- // This version draws the entire scene into an SkPictureRecorder,
- // using the deprecated recording backend.
- // Then it then replays the scene through a clip rectangle.
- // This backend proved to be buggy.
- public:
- DeprecatedRecorderStrategy() {}
-
- virtual void init(const SkImageInfo& imageInfo) {
- fBitmap.allocPixels(imageInfo);
- fWidth = imageInfo.width();
- fHeight= imageInfo.height();
- }
-
- virtual const SkBitmap& recordAndReplay(const Drawer& drawer,
- const SkRect& intoClip,
- SkXfermode::Mode mode) {
- SkTileGridFactory::TileGridInfo tileGridInfo = { {100,100}, {0,0}, {0,0} };
- SkTileGridFactory factory(tileGridInfo);
- SkPictureRecorder recorder;
- SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fWidth),SkIntToScalar(fHeight)));
- SkCanvas* canvas = recorder.DEPRECATED_beginRecording( SkIntToScalar(fWidth), SkIntToScalar(fHeight), &factory);
- drawer.draw(canvas, canvasRect, mode);
- SkAutoTDelete<SkPicture> picture(recorder.endRecording());
-
- SkCanvas replayCanvas(fBitmap);
- replayCanvas.clear(0xffffffff);
- replayCanvas.clipRect(intoClip);
- picture->playback(&replayCanvas);
-
- return fBitmap;
- }
-
- private:
- SkBitmap fBitmap;
- int fWidth;
- int fHeight;
-};
-
-class NewRecordingStrategy : public RecordingStrategy {
- // This version draws the entire scene into an SkPictureRecorder,
- // using the new recording backend.
+class PictureStrategy : public RecordingStrategy {
+ // This version draws the entire scene into an SkPictureRecorder.
// Then it then replays the scene through a clip rectangle.
// This backend proved to be buggy.
public:
- NewRecordingStrategy() {}
-
- virtual void init(const SkImageInfo& imageInfo) {
+ PictureStrategy(const SkImageInfo& imageInfo) {
fBitmap.allocPixels(imageInfo);
- fWidth = imageInfo.width();
- fHeight= imageInfo.height();
+ fWidth = imageInfo.width();
+ fHeight = imageInfo.height();
}
virtual const SkBitmap& recordAndReplay(const Drawer& drawer,
@@ -159,8 +112,9 @@ class NewRecordingStrategy : public RecordingStrategy {
SkTileGridFactory factory(tileGridInfo);
SkPictureRecorder recorder;
SkRect canvasRect(SkRect::MakeWH(SkIntToScalar(fWidth),SkIntToScalar(fHeight)));
- SkCanvas* canvas = recorder.EXPERIMENTAL_beginRecording( SkIntToScalar(fWidth), SkIntToScalar(fHeight), &factory);
-
+ SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(fWidth),
+ SkIntToScalar(fHeight),
+ &factory);
drawer.draw(canvas, canvasRect, mode);
SkAutoTDelete<SkPicture> picture(recorder.endRecording());
@@ -177,64 +131,45 @@ class NewRecordingStrategy : public RecordingStrategy {
int fHeight;
};
-}
-
+} // namespace
DEF_TEST(SkRecordingAccuracyXfermode, reporter) {
#define FINEGRAIN 0
-
const Drawer drawer;
- BitmapBackedCanvasStrategy golden; // This is the expected result.
- DeprecatedRecorderStrategy deprecatedRecording;
- NewRecordingStrategy newRecording;
-
- golden.init(drawer.imageInfo());
- deprecatedRecording.init(drawer.imageInfo());
- newRecording.init(drawer.imageInfo());
+ BitmapBackedCanvasStrategy golden(drawer.imageInfo());
+ PictureStrategy picture(drawer.imageInfo());
#if !FINEGRAIN
unsigned numErrors = 0;
SkString errors;
#endif
- for (int iMode = 0; iMode < int(SkXfermode::kLastMode) ; iMode++ ) {
- const SkRect& clip = SkRect::MakeXYWH(100,0,100,100);
+ for (int iMode = 0; iMode < int(SkXfermode::kLastMode); iMode++) {
+ const SkRect& clip = SkRect::MakeXYWH(100, 0, 100, 100);
SkXfermode::Mode mode = SkXfermode::Mode(iMode);
const SkBitmap& goldenBM = golden.recordAndReplay(drawer, clip, mode);
- const SkBitmap& deprecatedBM = deprecatedRecording.recordAndReplay(drawer, clip, mode);
- const SkBitmap& newRecordingBM = newRecording.recordAndReplay(drawer, clip, mode);
+ const SkBitmap& pictureBM = picture.recordAndReplay(drawer, clip, mode);
size_t pixelsSize = goldenBM.getSize();
- REPORTER_ASSERT( reporter, pixelsSize == deprecatedBM.getSize() );
- REPORTER_ASSERT( reporter, pixelsSize == newRecordingBM.getSize() );
+ REPORTER_ASSERT(reporter, pixelsSize == pictureBM.getSize());
// The pixel arrays should match.
#if FINEGRAIN
- REPORTER_ASSERT_MESSAGE( reporter,
- 0==memcmp( goldenBM.getPixels(), deprecatedBM.getPixels(), pixelsSize ),
- "Tiled bitmap is wrong");
- REPORTER_ASSERT_MESSAGE( reporter,
- 0==memcmp( goldenBM.getPixels(), recordingBM.getPixels(), pixelsSize ),
- "SkRecorder bitmap is wrong");
+ REPORTER_ASSERT(reporter,
+ 0 == memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize));
#else
- if ( memcmp( goldenBM.getPixels(), deprecatedBM.getPixels(), pixelsSize ) ) {
+ if (memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize)) {
numErrors++;
- SkString str;
- str.printf("For SkXfermode %d %s: Deprecated recorder bitmap is wrong\n", iMode, SkXfermode::ModeName(mode));
- errors.append(str);
- }
- if ( memcmp( goldenBM.getPixels(), newRecordingBM.getPixels(), pixelsSize ) ) {
- numErrors++;
- SkString str;
- str.printf("For SkXfermode %d %s: SkPictureRecorder bitmap is wrong\n", iMode, SkXfermode::ModeName(mode));
- errors.append(str);
+ errors.appendf("For SkXfermode %d %s: SkPictureRecorder bitmap is wrong\n",
+ iMode, SkXfermode::ModeName(mode));
}
#endif
}
+
#if !FINEGRAIN
- REPORTER_ASSERT_MESSAGE( reporter, 0==numErrors, errors.c_str() );
+ REPORTER_ASSERT_MESSAGE(reporter, 0 == numErrors, errors.c_str());
#endif
}
« no previous file with comments | « tests/PictureStateTreeTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698