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

Unified Diff: tests/PictureTest.cpp

Issue 252873005: add replay entry point to SkPictureRecorder for Android (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 8 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
« src/core/SkPictureRecorder.cpp ('K') | « src/core/SkPictureRecorder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PictureTest.cpp
===================================================================
--- tests/PictureTest.cpp (revision 14396)
+++ tests/PictureTest.cpp (working copy)
@@ -774,6 +774,128 @@
canvas->save();
}
+#ifdef SK_BUILD_FOR_ANDROID
+/**
+ * A canvas that records the number of saves, saveLayers and restores.
+ */
+class SaveCountingCanvas : public SkCanvas {
+public:
+ explicit SaveCountingCanvas(int width, int height)
mtklein 2014/04/30 20:20:11 I guess it's fine, but you don't need explicit her
robertphillips 2014/05/27 14:10:08 Done.
+ : INHERITED(width, height)
+ , fSaveCount(0)
+ , fSaveLayerCount(0)
+ , fRestoreCount(0){
+ }
+
+ virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
mtklein 2014/04/30 20:20:11 If you'd like to save space, virtual is not needed
robertphillips 2014/05/27 14:10:08 We seem to pull through the virtual keyword whenev
+ SaveFlags flags) SK_OVERRIDE {
+ ++fSaveLayerCount;
+ return this->INHERITED::willSaveLayer(bounds, paint, flags);
+ }
+
+ virtual void willSave(SaveFlags flags) SK_OVERRIDE {
+ ++fSaveCount;
+ this->INHERITED::willSave(flags);
+ }
+
+ virtual void willRestore() SK_OVERRIDE {
+ ++fRestoreCount;
+ this->INHERITED::willRestore();
+ }
+
+ unsigned int getSaveCount() const { return fSaveCount; }
mtklein 2014/04/30 20:20:11 I think we tend to just write "unsigned"
+ unsigned int getSaveLayerCount() const { return fSaveLayerCount; }
+ unsigned int getRestoreCount() const { return fRestoreCount; }
+
+private:
+ unsigned int fSaveCount;
+ unsigned int fSaveLayerCount;
+ unsigned int fRestoreCount;
+
+ typedef SkCanvas INHERITED;
+};
+
+void check_save_state(skiatest::Reporter* reporter, SkPicture* picture,
+ int numSaves, int numSaveLayers, int numRestores) {
+ SaveCountingCanvas canvas(picture->width(), picture->height());
+
+ picture->draw(&canvas);
+
+ REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount());
+ REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount());
+ REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount());
+}
+
+class SkPictureRecorderReplayTester {
+public:
+ static SkPicture* Copy(SkPictureRecorder* recorder) {
mtklein 2014/04/30 20:20:11 Can you add a note that the class is here so it ca
mtklein 2014/04/30 20:20:11 Is Android also going to be using this for copying
robertphillips 2014/05/27 14:10:08 Done.
robertphillips 2014/05/27 14:10:08 I proposed a "snapshot" version of this in https:/
+ SkPictureRecorder recorder2;
+
+ SkCanvas* canvas = recorder2.beginRecording(10, 10, NULL, 0);
+
+ recorder->replay(canvas);
+
robertphillips 2014/04/28 17:35:21 This is where the save/saveLayer balancing occurs
+ return recorder2.endRecording();
+ }
+};
+
+// Test out SkPictureRecorder::replay
+static void test_replay(skiatest::Reporter* reporter) {
mtklein 2014/04/30 20:20:11 DEF_TEST(PictureRecorder_replay, reporter) { ...
robertphillips 2014/05/27 14:10:08 Done.
+
+ // check save/saveLayer state
+ {
+ SkPictureRecorder recorder;
+
+ SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0);
+
+ canvas->saveLayer(NULL, NULL);
+
+ SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
+
robertphillips 2014/04/28 17:35:21 The extra save and restore comes from the Copy pro
mtklein 2014/04/30 20:20:11 Tack this on as a comment here?
robertphillips 2014/05/27 14:10:08 Done.
+ check_save_state(reporter, copy, 2, 1, 3);
+
+ canvas->saveLayer(NULL, NULL);
+
+ SkAutoTUnref<SkPicture> final(recorder.endRecording());
+
+ check_save_state(reporter, final, 1, 2, 3);
+
+ // The copy shouldn't pick up any operations added after it was made
+ check_save_state(reporter, copy, 2, 1, 3);
+ }
+
+ // (partially) check leakage of draw ops
mtklein 2014/04/30 20:20:11 Might as well split this into a separate DEF_TEST
robertphillips 2014/05/27 14:10:08 I would prefer to keep these together since they a
+ {
+ SkPictureRecorder recorder;
+
+ SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0);
+
+ SkRect r = SkRect::MakeWH(5, 5);
+ SkPaint p;
+
+ canvas->drawRect(r, p);
+
+ SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder));
+
+ REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps());
+
+ SkBitmap bm;
+ make_bm(&bm, 10, 10, SK_ColorRED, true);
+
+ r.offset(5.0f, 5.0f);
+ canvas->drawBitmapRectToRect(bm, NULL, r);
+
+ SkAutoTUnref<SkPicture> final(recorder.endRecording());
+ REPORTER_ASSERT(reporter, final->willPlayBackBitmaps());
+
+ REPORTER_ASSERT(reporter, copy->uniqueID() != final->uniqueID());
+
+ // The snapshot shouldn't pick up any operations added after it was made
+ REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps());
+ }
+}
+#endif
+
static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
SkCanvas testCanvas(100, 100);
set_canvas_to_save_count_4(&testCanvas);
@@ -1268,6 +1390,9 @@
#else
test_bad_bitmap();
#endif
+#ifdef SK_BUILD_FOR_ANDROID
+ test_replay(reporter);
+#endif
test_unbalanced_save_restores(reporter);
test_peephole();
#if SK_SUPPORT_GPU
« src/core/SkPictureRecorder.cpp ('K') | « src/core/SkPictureRecorder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698