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

Side by Side Diff: gm/aaclip.cpp

Issue 2296703003: test dont-clip-layer (Closed)
Patch Set: update gm bounds 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 | src/core/SkCanvas.cpp » ('j') | 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"
11 11
12 static void do_draw(SkCanvas* canvas, const SkRect& r) {
13 SkPaint paint;
14 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
15 paint.setColor(0x800000FF);
16 canvas->drawRect(r, paint);
17 }
18
19 /**
20 * Exercise kDontClipToLayer_Legacy_SaveLayerFlag flag, which does not limit th e clip to the
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.
23 *
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.
26 *
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
29 * has no paint, so it gets the default xfermode during restore).
30 *
31 * 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.
33 * The portion in the layer, will end up SRC_OVERing the 0x80 layer pixels onto the canvas, so
34 * they will appear lighter (since the canvas was erased to white initially).
35 *
36 * Thus the expected result is the upper half to be light-blue w/ 0xFF for its alpha, and
37 * the lower half to be darker blue with 0x80 for its alpha.
38 */
39 DEF_SIMPLE_GM(dont_clip_to_layer, canvas, 120, 120) {
40 SkRect r { 10, 10, 110, 110 };
41 SkRect r0 = SkRect::MakeXYWH(r.left(), r.top(), r.width(), r.height()/2);
42
43 SkCanvas::SaveLayerRec rec;
44 rec.fPaint = nullptr;
45 rec.fBounds = &r0;
46 rec.fBackdrop = nullptr;
47 rec.fSaveLayerFlags = 1 << 31;//SkCanvas::kDontClipToLayer_Legacy_SaveLayerF lag;
48 canvas->saveLayer(rec);
49 do_draw(canvas, r);
50 canvas->restore();
51 }
52
12 /** Draw a 2px border around the target, then red behind the target; 53 /** Draw a 2px border around the target, then red behind the target;
13 set the clip to match the target, then draw >> the target in blue. 54 set the clip to match the target, then draw >> the target in blue.
14 */ 55 */
15 56
16 static void draw(SkCanvas* canvas, SkRect& target, int x, int y) { 57 static void draw(SkCanvas* canvas, SkRect& target, int x, int y) {
17 SkPaint borderPaint; 58 SkPaint borderPaint;
18 borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0)); 59 borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0));
19 borderPaint.setAntiAlias(true); 60 borderPaint.setAntiAlias(true);
20 SkPaint backgroundPaint; 61 SkPaint backgroundPaint;
21 backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0)); 62 backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0));
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 canvas->translate(80, 10); 295 canvas->translate(80, 10);
255 this->drawAndClip(canvas, fVPath, 200, 0); 296 this->drawAndClip(canvas, fVPath, 200, 0);
256 canvas->translate(0, 200); 297 canvas->translate(0, 200);
257 this->drawAndClip(canvas, fHPath, 200, 0); 298 this->drawAndClip(canvas, fHPath, 200, 0);
258 } 299 }
259 300
260 private: 301 private:
261 typedef skiagm::GM INHERITED; 302 typedef skiagm::GM INHERITED;
262 }; 303 };
263 DEF_GM(return new ClipCubicGM;) 304 DEF_GM(return new ClipCubicGM;)
OLDNEW
« no previous file with comments | « no previous file | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698