aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-01-12 11:28:01 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-12 17:05:15 +0000
commit108f55ed5d0b63baf653e4e443cc469df887c811 (patch)
tree73edce21add4da89f2be1e008b85d7b01ba1f098 /samplecode
parent693fdbd6b81a860657612e7604430dd55d6e721b (diff)
fix clipping in rasterhandleallocator
BUG=skia: Change-Id: Ia24c5ae191fd823095cd0c75993cfd0208c98869 Reviewed-on: https://skia-review.googlesource.com/6952 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleBigGradient.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/samplecode/SampleBigGradient.cpp b/samplecode/SampleBigGradient.cpp
index 8bc1f59d05..becb1cea54 100644
--- a/samplecode/SampleBigGradient.cpp
+++ b/samplecode/SampleBigGradient.cpp
@@ -67,6 +67,7 @@ public:
void translate(float x, float y) { fCanvas->translate(x, y); }
void scale(float s) { fCanvas->scale(s, s); }
+ void clip(const SkRect& r) { fCanvas->clipRect(r); }
void drawOval(const SkRect& r, SkColor c) {
SkPaint p;
@@ -79,6 +80,8 @@ public:
p.setColor(c);
fCanvas->drawRect(r, p);
}
+
+ SkCanvas* peekCanvas() const { return fCanvas; }
};
#ifdef SK_BUILD_FOR_MAC
@@ -139,7 +142,7 @@ public:
CGContextRestoreGState(cg);
CGContextSaveGState(cg);
- CGContextClearRect(cg, CGRectMake(clip.x(), clip.y(), clip.width(), clip.height()));
+ CGContextClipToRect(cg, CGRectMake(clip.x(), clip.y(), clip.width(), clip.height()));
CGContextConcatCTM(cg, matrix_to_transform(cg, ctm));
}
};
@@ -269,6 +272,8 @@ protected:
}
void doDraw(GraphicsPort* port) {
+ SkAutoCanvasRestore acr(port->peekCanvas(), true);
+
port->drawRect({0, 0, 256, 256}, SK_ColorRED);
port->save();
port->translate(30, 30);
@@ -279,6 +284,9 @@ protected:
port->saveLayer({50, 50, 100, 100}, 0x80);
port->drawRect({55, 55, 95, 95}, SK_ColorGREEN);
port->restore();
+
+ port->clip({150, 50, 200, 200});
+ port->drawRect({0, 0, 256, 256}, 0xFFCCCCCC);
}
void onDrawContent(SkCanvas* canvas) override {