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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | src/core/SkRecordOpts.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkCanvas.h"
10 #include "SkPath.h"
11 #include "SkPictureRecorder.h"
12
13 /** A call pattern that should be optimized to a single draw call. */
14 static void draw_save_layer_draw_restore(SkCanvas* canvas, int layerAlpha, int d rawAlpha) {
15 SkPaint layerPaint;
16 layerPaint.setColor(SkColorSetARGB(layerAlpha, 0x0, 0x00, 0x0));
17 canvas->saveLayer(NULL, &layerPaint);
18 SkPaint drawPaint;
19 drawPaint.setColor(SkColorSetARGB(drawAlpha, 100, 255, 70));
20 SkRect target(SkRect::MakeWH(SK_Scalar1, SK_Scalar1));
21 canvas->drawRect(target, drawPaint);
22 canvas->restore();
23 }
24
25 /**
26 Tests record optimizations. Draws shapes using a call patterns that get
27 optimized in SkRecord. Used to ensure that the optimization does not change t he
28 pixels (too drasticly).
29 */
30
31 class RecordOptsGM : public skiagm::GM {
32 public:
33 RecordOptsGM() {
34 }
35
36 protected:
37 virtual SkString onShortName() SK_OVERRIDE {
38 return SkString("recordopts");
39 }
40
41 virtual SkISize onISize() SK_OVERRIDE {
42 return SkISize::Make(256, 256);
43 }
44
45 virtual void onOnceBeforeDraw() SK_OVERRIDE {
46 SkPictureRecorder recorder;
47 SkCanvas* pictureCanvas = recorder.beginRecording(256, 256);
48 for (int layerAlpha = 0; layerAlpha < 256; ++layerAlpha) {
49 pictureCanvas->save();
50 for (int drawAlpha = 0; drawAlpha < 256; ++drawAlpha) {
51 draw_save_layer_draw_restore(pictureCanvas, layerAlpha, drawAlph a);
52 pictureCanvas->translate(SK_Scalar1, 0);
53 }
54 pictureCanvas->restore();
55 pictureCanvas->translate(0, SK_Scalar1);
56 }
57 fPicture.reset(recorder.endRecordingAsPicture());
58 }
59
60 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
61 canvas->clear(SK_ColorTRANSPARENT);
62 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.
63 }
64
65 private:
66 typedef skiagm::GM INHERITED;
67 SkAutoTUnref<SkPicture> fPicture;
68 };
69
70 DEF_GM( return SkNEW(RecordOptsGM); )
71
OLDNEW
« 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