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

Side by Side Diff: gm/aaclip.cpp

Issue 2313653005: reconfigure dont-clip-to-layer gm to not have transparent pixels in its final output (Closed)
Patch Set: Created 4 years, 3 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
(...skipping 10 matching lines...) Expand all
21 * layer's bounds. Thus when a draw occurs, it can (depending on "where" it is) draw into the layer 21 * layer's bounds. Thus when a draw occurs, it can (depending on "where" it is) draw into the layer
22 * and/or draw onto the surrounding portions of the canvas, or both. 22 * and/or draw onto the surrounding portions of the canvas, or both.
23 * 23 *
24 * This GM has a 100x100 rectangle (r), which its going to draw. However first it creates a layer 24 * This GM has a 100x100 rectangle (r), which its going to draw. However first it creates a layer
25 * with this flag covering 1/2 of the rectangle (upper half). Then it draws the rect in SRC mode. 25 * with this flag covering 1/2 of the rectangle (upper half). Then it draws the rect in SRC mode.
26 * 26 *
27 * The portion of the draw that intersects the layer should see the SRC draw, a pply it to the layer 27 * The portion of the draw that intersects the layer should see the SRC draw, a pply it to the layer
28 * and then during restore, it will SRC_OVER that layer onto the canvas (SRC_OV ER since the layer 28 * and then during restore, it will SRC_OVER that layer onto the canvas (SRC_OV ER since the layer
29 * has no paint, so it gets the default xfermode during restore). 29 * has no paint, so it gets the default xfermode during restore).
30 * 30 *
31 * Note: when we talk about drawing directly into the "canvas", in fact we are drawing into an
32 * "outer" layer we created (filled with red). This is a testing detail, so that our final
33 * output image is itself opaque, otherwise we make it harder to view the GM as a PNG.
34 *
31 * The portion of the draw below the layer draws directly into the canvas. Sinc e it is in SRC mode, 35 * The portion of the draw below the layer draws directly into the canvas. Sinc e it is in SRC mode,
32 * it will wrote 0x80 to the canvas' alpha, making it appear darker when shown in the window. 36 * it will write 0x80 to the canvas' alpha, overwriting the "red", which then g ets blended with
33 * The portion in the layer, will end up SRC_OVERing the 0x80 layer pixels onto the canvas, so 37 * the GM's white background.
34 * they will appear lighter (since the canvas was erased to white initially).
35 * 38 *
36 * Thus the expected result is the upper half to be light-blue w/ 0xFF for its alpha, and 39 * The portion in the layer, will end up SRC_OVERing the 0x80 layer pixels onto the canvas' red
37 * the lower half to be darker blue with 0x80 for its alpha. 40 * pixels, making magenta.
41 *
42 * Thus the expected result is the upper half to be magenta 0xFF7F0080, and the lower half to be
43 * light blue 0xFF7F7FFF.
38 */ 44 */
39 DEF_SIMPLE_GM(dont_clip_to_layer, canvas, 120, 120) { 45 DEF_SIMPLE_GM(dont_clip_to_layer, canvas, 120, 120) {
40 SkRect r { 10, 10, 110, 110 }; 46 const SkRect r { 10, 10, 110, 110 };
47
48 // Wrap the entire test inside a red layer, so we don't punch the actual gm' s alpha with
49 // kSrc_Mode, which makes it hard to view (we like our GMs to have opaque pi xels).
50 canvas->saveLayer(&r, nullptr);
51 canvas->drawColor(SK_ColorRED);
52
41 SkRect r0 = SkRect::MakeXYWH(r.left(), r.top(), r.width(), r.height()/2); 53 SkRect r0 = SkRect::MakeXYWH(r.left(), r.top(), r.width(), r.height()/2);
42 54
43 SkCanvas::SaveLayerRec rec; 55 SkCanvas::SaveLayerRec rec;
44 rec.fPaint = nullptr; 56 rec.fPaint = nullptr;
45 rec.fBounds = &r0; 57 rec.fBounds = &r0;
46 rec.fBackdrop = nullptr; 58 rec.fBackdrop = nullptr;
47 rec.fSaveLayerFlags = 1 << 31;//SkCanvas::kDontClipToLayer_Legacy_SaveLayerF lag; 59 rec.fSaveLayerFlags = 1 << 31;//SkCanvas::kDontClipToLayer_Legacy_SaveLayerF lag;
48 canvas->saveLayer(rec); 60 canvas->saveLayer(rec);
49 do_draw(canvas, r); 61 do_draw(canvas, r);
50 canvas->restore(); 62 canvas->restore();
63
64 canvas->restore(); // red-layer
51 } 65 }
52 66
53 /** Draw a 2px border around the target, then red behind the target; 67 /** Draw a 2px border around the target, then red behind the target;
54 set the clip to match the target, then draw >> the target in blue. 68 set the clip to match the target, then draw >> the target in blue.
55 */ 69 */
56 70
57 static void draw(SkCanvas* canvas, SkRect& target, int x, int y) { 71 static void draw(SkCanvas* canvas, SkRect& target, int x, int y) {
58 SkPaint borderPaint; 72 SkPaint borderPaint;
59 borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0)); 73 borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0));
60 borderPaint.setAntiAlias(true); 74 borderPaint.setAntiAlias(true);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 canvas->translate(80, 10); 309 canvas->translate(80, 10);
296 this->drawAndClip(canvas, fVPath, 200, 0); 310 this->drawAndClip(canvas, fVPath, 200, 0);
297 canvas->translate(0, 200); 311 canvas->translate(0, 200);
298 this->drawAndClip(canvas, fHPath, 200, 0); 312 this->drawAndClip(canvas, fHPath, 200, 0);
299 } 313 }
300 314
301 private: 315 private:
302 typedef skiagm::GM INHERITED; 316 typedef skiagm::GM INHERITED;
303 }; 317 };
304 DEF_GM(return new ClipCubicGM;) 318 DEF_GM(return new ClipCubicGM;)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698