diff options
-rw-r--r-- | samplecode/SampleBigGradient.cpp | 10 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 2 |
2 files changed, 10 insertions, 2 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 { diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 8bcc421432..067ccdc4ef 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -3423,7 +3423,7 @@ SkRasterHandleAllocator::Handle SkCanvas::accessTopRasterHandle() const { SkIRect clip = fMCRec->fRasterClip.getBounds(); clip.offset(-origin.x(), -origin.y()); - if (clip.intersect(0, 0, dev->width(), dev->height())) { + if (!clip.intersect(0, 0, dev->width(), dev->height())) { clip.setEmpty(); } |