Skip to content

Commit

Permalink
AnalysisCanvas is missing an override for virtual void onClipRegion
Browse files Browse the repository at this point in the history
BUG=405364

Review URL: https://codereview.chromium.org/492943002

Cr-Commit-Position: refs/heads/master@{#291548}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291548 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hendrikw@chromium.org committed Aug 22, 2014
1 parent cf2b255 commit 59b165d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
46 changes: 25 additions & 21 deletions skia/ext/analysis_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,8 @@ bool AnalysisCanvas::abortDrawing() {
return false;
}

void AnalysisCanvas::onClipRect(const SkRect& rect, SkRegion::Op op,
ClipEdgeStyle edge_style) {

INHERITED::onClipRect(rect, op, edge_style);
}

void AnalysisCanvas::onClipPath(const SkPath& path, SkRegion::Op op,
ClipEdgeStyle edge_style) {
// clipPaths can make our calls to IsFullQuad invalid (ie have false
void AnalysisCanvas::OnComplexClip() {
// complex clips can make our calls to IsFullQuad invalid (ie have false
// positives). As a precaution, force the setting to be non-solid
// and non-transparent until we pop this
if (force_not_solid_stack_level_ == kNoLayer) {
Expand All @@ -350,28 +343,39 @@ void AnalysisCanvas::onClipPath(const SkPath& path, SkRegion::Op op,
force_not_transparent_stack_level_ = saved_stack_size_;
SetForceNotTransparent(true);
}
}

void AnalysisCanvas::onClipRect(const SkRect& rect,
SkRegion::Op op,
ClipEdgeStyle edge_style) {
INHERITED::onClipRect(rect, op, edge_style);
}

void AnalysisCanvas::onClipPath(const SkPath& path,
SkRegion::Op op,
ClipEdgeStyle edge_style) {
OnComplexClip();
INHERITED::onClipRect(path.getBounds(), op, edge_style);
}

void AnalysisCanvas::onClipRRect(const SkRRect& rrect,
SkRegion::Op op,
ClipEdgeStyle edge_style) {
// clipRRect can make our calls to IsFullQuad invalid (ie have false
// positives). As a precaution, force the setting to be non-solid
// and non-transparent until we pop this
if (force_not_solid_stack_level_ == kNoLayer) {
force_not_solid_stack_level_ = saved_stack_size_;
SetForceNotSolid(true);
}
if (force_not_transparent_stack_level_ == kNoLayer) {
force_not_transparent_stack_level_ = saved_stack_size_;
SetForceNotTransparent(true);
}

OnComplexClip();
INHERITED::onClipRect(rrect.getBounds(), op, edge_style);
}

void AnalysisCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
const ClipEdgeStyle edge_style = kHard_ClipEdgeStyle;
if (deviceRgn.isRect()) {
onClipRect(SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style);
return;
}
OnComplexClip();
INHERITED::onClipRect(
SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style);
}

void AnalysisCanvas::willSave() {
++saved_stack_size_;
INHERITED::willSave();
Expand Down
6 changes: 5 additions & 1 deletion skia/ext/analysis_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class SK_API AnalysisCanvas : public SkCanvas, public SkDrawPictureCallback {
virtual void onClipPath(const SkPath& path,
SkRegion::Op op,
ClipEdgeStyle edge_style) OVERRIDE;
virtual void onClipRegion(const SkRegion& deviceRgn,
SkRegion::Op op) OVERRIDE;

virtual void onDrawText(const void* text,
size_t byteLength,
Expand All @@ -108,7 +110,9 @@ class SK_API AnalysisCanvas : public SkCanvas, public SkDrawPictureCallback {
const SkRRect& inner,
const SkPaint&) OVERRIDE;

private:
void OnComplexClip();

private:
typedef SkCanvas INHERITED;

int saved_stack_size_;
Expand Down
31 changes: 31 additions & 0 deletions skia/ext/analysis_canvas_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,35 @@ TEST(AnalysisCanvasTest, EarlyOutNotSolid) {

}

TEST(AnalysisCanvasTest, ClipComplexRegion) {
skia::AnalysisCanvas canvas(255, 255);

SkPath path;
path.moveTo(0, 0);
path.lineTo(128, 50);
path.lineTo(255, 0);
path.lineTo(255, 255);
path.lineTo(0, 255);
SkIRect pathBounds = path.getBounds().round();
SkRegion region;
region.setPath(path, SkRegion(pathBounds));

SkColor outputColor;
SolidColorFill(canvas);
canvas.clipRegion(region);
EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));

canvas.save();
EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));

canvas.clipRegion(region);
EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));

canvas.restore();
EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));

SolidColorFill(canvas);
EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
}

} // namespace skia

0 comments on commit 59b165d

Please sign in to comment.