xref: /aosp_15_r20/external/skia/docs/examples/Canvas_getLocalClipBounds.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Canvas_getLocalClipBounds, 256, 256, true, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     SkCanvas local(256, 256);
7     canvas = &local;
8     SkRect bounds = canvas->getLocalClipBounds();
9     SkDebugf("left:%g  top:%g  right:%g  bottom:%g\n",
10             bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
11     SkPoint clipPoints[]  = {{30, 130}, {120, 130}, {120, 230} };
12     SkPath clipPath;
13     clipPath.addPoly(clipPoints, std::size(clipPoints), true);
14     canvas->clipPath(clipPath);
15     bounds = canvas->getLocalClipBounds();
16     SkDebugf("left:%g  top:%g  right:%g  bottom:%g\n",
17             bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
18     canvas->scale(2, 2);
19     bounds = canvas->getLocalClipBounds();
20     SkDebugf("left:%g  top:%g  right:%g  bottom:%g\n",
21             bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
22 }
23 }  // END FIDDLE
24