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

Unified Diff: tests/RecordOptsTest.cpp

Issue 269813010: Add SaveLayer-Draw-Restore optimization. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: notes Created 6 years, 7 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 | « src/record/SkRecordOpts.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RecordOptsTest.cpp
diff --git a/tests/RecordOptsTest.cpp b/tests/RecordOptsTest.cpp
index 260b97b3e8535a48c4c517e88c66ec10a9edf46c..90347eda1f5836a64b7cfa6d21bb9f2fe5e2c3df 100644
--- a/tests/RecordOptsTest.cpp
+++ b/tests/RecordOptsTest.cpp
@@ -12,6 +12,8 @@
#include "SkRecorder.h"
#include "SkRecords.h"
+#include "SkXfermode.h"
+
static const int W = 1920, H = 1080;
// If the command we're reading is a U, set ptr to it, otherwise set it to NULL.
@@ -151,3 +153,76 @@ DEF_TEST(RecordOpts_NoopSaveRestores, r) {
assert_type<SkRecords::DrawRect>(r, record, 9);
assert_type<SkRecords::Restore>(r, record, 10);
}
+
+static void assert_savelayer_restore(skiatest::Reporter* r,
+ SkRecord* record,
+ unsigned i,
+ bool shouldBeNoOped) {
+ SkRecordNoopSaveLayerDrawRestores(record);
+ if (shouldBeNoOped) {
+ assert_type<SkRecords::NoOp>(r, *record, i);
+ assert_type<SkRecords::NoOp>(r, *record, i+2);
+ } else {
+ assert_type<SkRecords::SaveLayer>(r, *record, i);
+ assert_type<SkRecords::Restore>(r, *record, i+2);
+ }
+}
+
+DEF_TEST(RecordOpts_NoopSaveLayerDrawRestore, r) {
+ SkRecord record;
+ SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, W, H);
+
+ SkRect bounds = SkRect::MakeWH(100, 200);
+ SkRect draw = SkRect::MakeWH(50, 60);
+
+ SkPaint goodLayerPaint, badLayerPaint, worseLayerPaint;
+ goodLayerPaint.setColor(0x03000000); // Only alpha.
+ badLayerPaint.setColor( 0x03040506); // Not only alpha.
+ worseLayerPaint.setXfermodeMode(SkXfermode::kDstIn_Mode); // Any effect will do.
+
+ SkPaint goodDrawPaint, badDrawPaint;
+ goodDrawPaint.setColor(0xFF020202); // Opaque.
+ badDrawPaint.setColor( 0x0F020202); // Not opaque.
+
+ // No change: optimization can't handle bounds.
+ recorder.saveLayer(&bounds, NULL);
+ recorder.drawRect(draw, goodDrawPaint);
+ recorder.restore();
+ assert_savelayer_restore(r, &record, 0, false);
+
+ // SaveLayer/Restore removed: no bounds + no paint = no point.
+ recorder.saveLayer(NULL, NULL);
+ recorder.drawRect(draw, goodDrawPaint);
+ recorder.restore();
+ assert_savelayer_restore(r, &record, 3, true);
+
+ // TODO(mtklein): test case with null draw paint
+
+ // No change: layer paint isn't alpha-only.
+ recorder.saveLayer(NULL, &badLayerPaint);
+ recorder.drawRect(draw, goodDrawPaint);
+ recorder.restore();
+ assert_savelayer_restore(r, &record, 6, false);
+
+ // No change: layer paint has an effect.
+ recorder.saveLayer(NULL, &worseLayerPaint);
+ recorder.drawRect(draw, goodDrawPaint);
+ recorder.restore();
+ assert_savelayer_restore(r, &record, 9, false);
+
+ // No change: draw paint isn't opaque.
+ recorder.saveLayer(NULL, &goodLayerPaint);
+ recorder.drawRect(draw, badDrawPaint);
+ recorder.restore();
+ assert_savelayer_restore(r, &record, 12, false);
+
+ // SaveLayer/Restore removed: we can fold in the alpha!
+ recorder.saveLayer(NULL, &goodLayerPaint);
+ recorder.drawRect(draw, goodDrawPaint);
+ recorder.restore();
+ assert_savelayer_restore(r, &record, 15, true);
+
+ const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, record, 16);
+ REPORTER_ASSERT(r, drawRect != NULL);
+ REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
+}
« no previous file with comments | « src/record/SkRecordOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698