Index: skia/ext/analysis_canvas.cc |
diff --git a/skia/ext/analysis_canvas.cc b/skia/ext/analysis_canvas.cc |
index 9db42f17ab67093694b1998ffa801ecfc3ea886f..644103e57cb8c5257f3f0629ded36a50855131c0 100644 |
--- a/skia/ext/analysis_canvas.cc |
+++ b/skia/ext/analysis_canvas.cc |
@@ -11,6 +11,7 @@ |
#include "third_party/skia/include/core/SkShader.h" |
#include "third_party/skia/src/core/SkRasterClip.h" |
#include "ui/gfx/rect_conversions.h" |
+#include "ui/gfx/skia_util.h" |
namespace { |
@@ -70,8 +71,9 @@ bool IsFullQuad(const SkDraw& draw, |
namespace skia { |
-AnalysisDevice::AnalysisDevice(const SkBitmap& bitmap) |
+AnalysisDevice::AnalysisDevice(const SkBitmap& bitmap, gfx::Rect analysis_rect) |
: INHERITED(bitmap), |
+ analysis_rect_(analysis_rect), |
is_forced_not_solid_(false), |
is_forced_not_transparent_(false), |
is_solid_color_(true), |
@@ -121,6 +123,7 @@ void AnalysisDevice::clear(SkColor color) { |
} |
void AnalysisDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
+ INHERITED::drawPaint(draw, paint); |
vangelis
2013/11/07 01:35:03
Do we see this method getting called for common we
enne (OOO)
2013/11/07 22:13:50
No. This is not called from Blink.
|
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -130,6 +133,7 @@ void AnalysisDevice::drawPoints(const SkDraw& draw, |
size_t count, |
const SkPoint points[], |
const SkPaint& paint) { |
+ INHERITED::drawPoints(draw, mode, count, points, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -137,47 +141,14 @@ void AnalysisDevice::drawPoints(const SkDraw& draw, |
void AnalysisDevice::drawRect(const SkDraw& draw, |
const SkRect& rect, |
const SkPaint& paint) { |
- bool does_cover_canvas = |
- IsFullQuad(draw, SkRect::MakeWH(width(), height()), rect); |
- |
- SkXfermode::Mode xfermode; |
- SkXfermode::AsMode(paint.getXfermode(), &xfermode); |
- |
- // This canvas will become transparent if the following holds: |
- // - The quad is a full tile quad |
- // - We're not in "forced not transparent" mode |
- // - Transfer mode is clear (0 color, 0 alpha) |
- // |
- // If the paint alpha is not 0, or if the transfrer mode is |
- // not src, then this canvas will not be transparent. |
- // |
- // In all other cases, we keep the current transparent value |
- if (does_cover_canvas && |
- !is_forced_not_transparent_ && |
- xfermode == SkXfermode::kClear_Mode) { |
- is_transparent_ = true; |
- has_text_ = false; |
- } else if (paint.getAlpha() != 0 || xfermode != SkXfermode::kSrc_Mode) { |
- is_transparent_ = false; |
- } |
- |
- // This bitmap is solid if and only if the following holds. |
- // Note that this might be overly conservative: |
- // - We're not in "forced not solid" mode |
- // - Paint is solid color |
- // - The quad is a full tile quad |
- if (!is_forced_not_solid_ && IsSolidColorPaint(paint) && does_cover_canvas) { |
- is_solid_color_ = true; |
- color_ = paint.getColor(); |
- has_text_ = false; |
- } else { |
- is_solid_color_ = false; |
- } |
+ INHERITED::drawRect(draw, rect, paint); |
+ AnalyzeDrawRect(draw, rect, paint); |
} |
void AnalysisDevice::drawOval(const SkDraw& draw, |
const SkRect& oval, |
const SkPaint& paint) { |
+ INHERITED::drawOval(draw, oval, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -187,6 +158,7 @@ void AnalysisDevice::drawPath(const SkDraw& draw, |
const SkPaint& paint, |
const SkMatrix* pre_path_matrix, |
bool path_is_mutable) { |
+ INHERITED::drawPath(draw, path, paint, pre_path_matrix, path_is_mutable); |
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -195,6 +167,7 @@ void AnalysisDevice::drawBitmap(const SkDraw& draw, |
const SkBitmap& bitmap, |
const SkMatrix& matrix, |
const SkPaint& paint) { |
+ INHERITED::drawBitmap(draw, bitmap, matrix, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -204,6 +177,7 @@ void AnalysisDevice::drawSprite(const SkDraw& draw, |
int x, |
int y, |
const SkPaint& paint) { |
+ INHERITED::drawSprite(draw, bitmap, x, y, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -211,12 +185,14 @@ void AnalysisDevice::drawSprite(const SkDraw& draw, |
void AnalysisDevice::drawBitmapRect(const SkDraw& draw, |
const SkBitmap& bitmap, |
const SkRect* src_or_null, |
- const SkRect& dst, |
+ const SkRect& rect, |
const SkPaint& paint, |
SkCanvas::DrawBitmapRectFlags flags) { |
- // Call drawRect to determine transparency, |
+ INHERITED::drawBitmapRect(draw, bitmap, src_or_null, rect, paint, flags); |
+ |
+ // Call AnalyzeDrawRect to determine transparency, |
// but reset solid color to false. |
- drawRect(draw, dst, paint); |
+ AnalyzeDrawRect(draw, rect, paint); |
is_solid_color_ = false; |
} |
@@ -226,6 +202,7 @@ void AnalysisDevice::drawText(const SkDraw& draw, |
SkScalar x, |
SkScalar y, |
const SkPaint& paint) { |
+ INHERITED::drawText(draw, text, len, x, y, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
has_text_ = true; |
@@ -238,6 +215,7 @@ void AnalysisDevice::drawPosText(const SkDraw& draw, |
SkScalar const_y, |
int scalars_per_pos, |
const SkPaint& paint) { |
+ INHERITED::drawPosText(draw, text, len, pos, const_y, scalars_per_pos, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
has_text_ = true; |
@@ -249,6 +227,7 @@ void AnalysisDevice::drawTextOnPath(const SkDraw& draw, |
const SkPath& path, |
const SkMatrix* matrix, |
const SkPaint& paint) { |
+ INHERITED::drawTextOnPath(draw, text, len, path, matrix, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
has_text_ = true; |
@@ -262,6 +241,7 @@ void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, |
const SkPaint& paint, |
const SkPath& path, |
const SkMatrix* matrix) { |
+ INHERITED::drawPosTextOnPath(draw, text, len, pos, paint, path, matrix); |
is_solid_color_ = false; |
is_transparent_ = false; |
has_text_ = true; |
@@ -269,7 +249,7 @@ void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, |
#endif |
void AnalysisDevice::drawVertices(const SkDraw& draw, |
- SkCanvas::VertexMode, |
+ SkCanvas::VertexMode mode, |
int vertex_count, |
const SkPoint verts[], |
const SkPoint texs[], |
@@ -278,6 +258,16 @@ void AnalysisDevice::drawVertices(const SkDraw& draw, |
const uint16_t indices[], |
int index_count, |
const SkPaint& paint) { |
+ INHERITED::drawVertices(draw, |
+ mode, |
+ vertex_count, |
+ verts, |
+ texs, |
+ colors, |
+ xmode, |
+ indices, |
+ index_count, |
+ paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -287,6 +277,7 @@ void AnalysisDevice::drawDevice(const SkDraw& draw, |
int x, |
int y, |
const SkPaint& paint) { |
+ INHERITED::drawDevice(draw, device, x, y, paint); |
is_solid_color_ = false; |
is_transparent_ = false; |
} |
@@ -307,11 +298,6 @@ bool AnalysisCanvas::HasText() const { |
return (static_cast<AnalysisDevice*>(getDevice()))->HasText(); |
} |
-bool AnalysisCanvas::abortDrawing() { |
- // Early out as soon as we have detected that the tile has text. |
- return HasText(); |
-} |
- |
bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool do_aa) { |
return INHERITED::clipRect(rect, op, do_aa); |
} |
@@ -329,7 +315,7 @@ bool AnalysisCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool do_aa) { |
(static_cast<AnalysisDevice*>(getDevice()))->SetForceNotTransparent(true); |
} |
- return INHERITED::clipRect(path.getBounds(), op, do_aa); |
+ return INHERITED::clipPath(path, op, do_aa); |
} |
bool AnalysisCanvas::clipRRect(const SkRRect& rrect, |
@@ -347,7 +333,7 @@ bool AnalysisCanvas::clipRRect(const SkRRect& rrect, |
(static_cast<AnalysisDevice*>(getDevice()))->SetForceNotTransparent(true); |
} |
- return INHERITED::clipRect(rrect.getBounds(), op, do_aa); |
+ return INHERITED::clipRRect(rrect, op, do_aa); |
} |
int AnalysisCanvas::save(SkCanvas::SaveFlags flags) { |
@@ -363,9 +349,10 @@ int AnalysisCanvas::saveLayer(const SkRect* bounds, |
// If after we draw to the saved layer, we have to blend with the current |
// layer, then we can conservatively say that the canvas will not be of |
// solid color. |
+ gfx::Rect analysis_rect = |
+ static_cast<AnalysisDevice*>(getDevice())->AnalysisRect(); |
if ((paint && !IsSolidColorPaint(*paint)) || |
- (bounds && !bounds->contains(SkRect::MakeWH(getDevice()->width(), |
- getDevice()->height())))) { |
+ (bounds && !bounds->contains(RectToSkRect(analysis_rect)))) { |
if (force_not_solid_stack_level_ == kNoLayer) { |
force_not_solid_stack_level_ = saved_stack_size_; |
(static_cast<AnalysisDevice*>(getDevice()))->SetForceNotSolid(true); |
@@ -385,13 +372,7 @@ int AnalysisCanvas::saveLayer(const SkRect* bounds, |
} |
} |
- // Actually saving a layer here could cause a new bitmap to be created |
- // and real rendering to occur. |
- int count = INHERITED::save(flags); |
- if (bounds) { |
- INHERITED::clipRectBounds(bounds, flags, NULL); |
- } |
- return count; |
+ return INHERITED::saveLayer(bounds, paint, flags); |
} |
void AnalysisCanvas::restore() { |
@@ -412,6 +393,45 @@ void AnalysisCanvas::restore() { |
} |
} |
-} // namespace skia |
+void AnalysisDevice::AnalyzeDrawRect(const SkDraw& draw, |
+ const SkRect& rect, |
+ const SkPaint& paint) { |
+ bool does_cover_canvas = |
+ IsFullQuad(draw, RectToSkRect(analysis_rect_), rect); |
+ |
+ SkXfermode::Mode xfermode; |
+ SkXfermode::AsMode(paint.getXfermode(), &xfermode); |
+ |
+ // This canvas will become transparent if the following holds: |
+ // - The quad is a full tile quad |
+ // - We're not in "forced not transparent" mode |
+ // - Transfer mode is clear (0 color, 0 alpha) |
Stephen White
2013/11/07 18:14:22
Nit: also not new to this patch, but is it possibl
enne (OOO)
2013/11/07 22:36:10
Such a helper function from the Skia side would be
|
+ // |
+ // If the paint alpha is not 0, or if the transfrer mode is |
+ // not src, then this canvas will not be transparent. |
+ // |
+ // In all other cases, we keep the current transparent value |
+ if (does_cover_canvas && |
+ !is_forced_not_transparent_ && |
+ xfermode == SkXfermode::kClear_Mode) { |
+ is_transparent_ = true; |
+ has_text_ = false; |
+ } else if (paint.getAlpha() != 0 || xfermode != SkXfermode::kSrc_Mode) { |
+ is_transparent_ = false; |
+ } |
+ // This bitmap is solid if and only if the following holds. |
+ // Note that this might be overly conservative: |
+ // - We're not in "forced not solid" mode |
+ // - Paint is solid color |
+ // - The quad is a full tile quad |
+ if (!is_forced_not_solid_ && IsSolidColorPaint(paint) && does_cover_canvas) { |
+ is_solid_color_ = true; |
+ color_ = paint.getColor(); |
+ has_text_ = false; |
+ } else { |
+ is_solid_color_ = false; |
+ } |
+} |
+} // namespace skia |