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

Unified Diff: gm/recordopts.cpp

Issue 840483005: Fold alpha to the draw in savelayer-draw-restore patterns with non-opaque draw (Closed) Base URL: https://skia.googlesource.com/skia.git@unique-id-unflatten
Patch Set: Created 5 years, 11 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 | « no previous file | gyp/gmslides.gypi » ('j') | src/core/SkRecordOpts.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/recordopts.cpp
diff --git a/gm/recordopts.cpp b/gm/recordopts.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8c40757e8084cbe23de13716934916ece66b4715
--- /dev/null
+++ b/gm/recordopts.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkPath.h"
+#include "SkPictureRecorder.h"
+
+/** A call pattern that should be optimized to a single draw call. */
+static void draw_save_layer_draw_restore(SkCanvas* canvas, int layerAlpha, int drawAlpha) {
+ SkPaint layerPaint;
+ layerPaint.setColor(SkColorSetARGB(layerAlpha, 0x0, 0x00, 0x0));
+ canvas->saveLayer(NULL, &layerPaint);
+ SkPaint drawPaint;
+ drawPaint.setColor(SkColorSetARGB(drawAlpha, 100, 255, 70));
+ SkRect target(SkRect::MakeWH(SK_Scalar1, SK_Scalar1));
+ canvas->drawRect(target, drawPaint);
+ canvas->restore();
+}
+
+/**
+ Tests record optimizations. Draws shapes using a call patterns that get
+ optimized in SkRecord. Used to ensure that the optimization does not change the
+ pixels (too drasticly).
+*/
+
+class RecordOptsGM : public skiagm::GM {
+public:
+ RecordOptsGM() {
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("recordopts");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(256, 256);
+ }
+
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+ SkPictureRecorder recorder;
+ SkCanvas* pictureCanvas = recorder.beginRecording(256, 256);
+ for (int layerAlpha = 0; layerAlpha < 256; ++layerAlpha) {
+ pictureCanvas->save();
+ for (int drawAlpha = 0; drawAlpha < 256; ++drawAlpha) {
+ draw_save_layer_draw_restore(pictureCanvas, layerAlpha, drawAlpha);
+ pictureCanvas->translate(SK_Scalar1, 0);
+ }
+ pictureCanvas->restore();
+ pictureCanvas->translate(0, SK_Scalar1);
+ }
+ fPicture.reset(recorder.endRecordingAsPicture());
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->clear(SK_ColorTRANSPARENT);
+ fPicture->playback(canvas);
mtklein 2015/01/13 18:48:20 Seems like we might also want a reference image th
mtklein 2015/01/13 18:50:58 Or even better, we can draw a diff between the non
Kimmo Kinnunen 2015/01/14 13:07:51 Done.
Kimmo Kinnunen 2015/01/14 13:07:51 Done.
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+ SkAutoTUnref<SkPicture> fPicture;
+};
+
+DEF_GM( return SkNEW(RecordOptsGM); )
+
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | src/core/SkRecordOpts.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698