aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RecordingXfermodeTest.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-09-30 14:47:10 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-30 14:47:10 -0700
commit46616af01b412ea984a516fda1ed8ec08e689f29 (patch)
treeb9662789028445ee0a3dffec8019965ebc7b7473 /tests/RecordingXfermodeTest.cpp
parentafbf2d6273cd22c683f20a7e5773843876af3085 (diff)
Strip old backend recording down to essentials
Feature-wise, this removes: 1) BBH support; 2) peephole optimizations; 3) record-time text op specializations; 4) the guarantee that SkPaints are flattened. This deletes the optimizations GM, which only exists to test the peepholes of the old backend. SkRecord optimizations are unit tested, and if that ever fails we can think about adding another GM like this, but they're different enough we'd want to start from scratch anyway. We need to keep the code that plays back the specialized text ops around for a while for compatibility with existing .SKPs that have those ops recorded. BUG=skia: CQ_EXTRA_TRYBOTS=tryserver.skia:Canary-Chrome-Ubuntu13.10-Ninja-x86_64-ToT-Trybot R=robertphillips@google.com, reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/617953002
Diffstat (limited to 'tests/RecordingXfermodeTest.cpp')
-rw-r--r--tests/RecordingXfermodeTest.cpp129
1 files changed, 32 insertions, 97 deletions
diff --git a/tests/RecordingXfermodeTest.cpp b/tests/RecordingXfermodeTest.cpp
index 8da81b3680..aa6bf687a1 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
}