Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Unified Diff: skia/ext/analysis_canvas.cc

Issue 12388095: cc: Merge GatherPixelRefs and AnalyzeInRect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« skia/ext/analysis_canvas.h ('K') | « skia/ext/analysis_canvas.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/analysis_canvas.cc
diff --git a/skia/ext/analysis_canvas.cc b/skia/ext/analysis_canvas.cc
index 2a2c7f3e32aed9ab9437e1c195a6d900988efc7d..ec25006f29ad634c57b4116f325b9d6ed564f2ad 100644
--- a/skia/ext/analysis_canvas.cc
+++ b/skia/ext/analysis_canvas.cc
@@ -7,6 +7,7 @@
#include "third_party/skia/include/core/SkDevice.h"
#include "third_party/skia/include/core/SkDraw.h"
#include "third_party/skia/include/core/SkRRect.h"
+#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/src/core/SkRasterClip.h"
#include "ui/gfx/rect_conversions.h"
@@ -17,6 +18,9 @@ namespace {
// 25x as long as Z620.
const int gPictureCostThreshold = 1000;
+// URI label for a lazily decoded SkPixelRef.
+const char labelLazyDecoded[] = "lazy";
Justin Novosad 2013/03/11 15:26:11 This string constant should only be defined in one
+
static bool isSolidColorPaint(const SkPaint& paint) {
SkXfermode::Mode xferMode;
@@ -111,6 +115,45 @@ void AnalysisDevice::setForceNotTransparent(bool flag) {
isTransparent_ = false;
}
+void AnalysisDevice::addPixelRefIfLazy(SkPixelRef* pixelRef) {
+ uint32_t genID = pixelRef->getGenerationID();
+
+ // If this ID exists (whether it is lazy pixel ref or not),
+ // we can return early.
+ std::pair<std::set<uint32_t>::iterator, bool> result =
Justin Novosad 2013/03/11 15:26:11 "result" is a bad name for a variable that is not
+ existingPixelRefIDs_.insert(genID);
+ if (!result.second)
+ return;
+
+ if (pixelRef->getURI() &&
+ !strncmp(pixelRef->getURI(), labelLazyDecoded, 4)) {
+ lazyPixelRefs_.push_back(static_cast<skia::LazyPixelRef*>(pixelRef));
+ }
+}
+
+void AnalysisDevice::addBitmap(const SkBitmap& bitmap) {
Justin Novosad 2013/03/11 15:26:11 Needs unit testing. Test should verify: a) lazy vs
+ addPixelRefIfLazy(bitmap.pixelRef());
+}
+
+void AnalysisDevice::addBitmapFromPaint(const SkPaint& paint) {
+ SkShader* shader = paint.getShader();
+ if (shader) {
+ SkBitmap bitmap;
+ // Check whether the shader is a gradient in order to short-circuit
+ // call to asABitmap to prevent generation of bitmaps from
+ // gradient shaders, which implement asABitmap.
+ if (SkShader::kNone_GradientType == shader->asAGradient(NULL) &&
+ shader->asABitmap(&bitmap, NULL, NULL)) {
+ addPixelRefIfLazy(bitmap.pixelRef());
+ }
+ }
+}
+
+void AnalysisDevice::consumeLazyPixelRefs(std::list<LazyPixelRef*>& pixelRefs) {
+ DCHECK(pixelRefs.empty());
+ lazyPixelRefs_.swap(pixelRefs);
+}
+
void AnalysisDevice::clear(SkColor color) {
++estimatedCost_;
@@ -129,6 +172,7 @@ void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
void AnalysisDevice::drawPoints(const SkDraw&, SkCanvas::PointMode mode,
@@ -137,6 +181,7 @@ void AnalysisDevice::drawPoints(const SkDraw&, SkCanvas::PointMode mode,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
void AnalysisDevice::drawRect(const SkDraw& draw, const SkRect& rect,
@@ -147,7 +192,7 @@ void AnalysisDevice::drawRect(const SkDraw& draw, const SkRect& rect,
estimatedCost_ += 300;
}
++estimatedCost_;
-
+ addBitmapFromPaint(paint);
bool doesCoverCanvas = isFullQuad(draw,
SkRect::MakeWH(width(), height()),
rect);
@@ -195,6 +240,7 @@ void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
@@ -210,6 +256,7 @@ void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
@@ -218,6 +265,7 @@ void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmap(bitmap);
}
void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
@@ -225,9 +273,10 @@ void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmap(bitmap);
}
-void AnalysisDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap&,
+void AnalysisDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
const SkRect* srcOrNull, const SkRect& dst,
const SkPaint& paint) {
++estimatedCost_;
@@ -236,6 +285,7 @@ void AnalysisDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap&,
// but reset solid color to false.
drawRect(draw, dst, paint);
isSolidColor_ = false;
+ addBitmap(bitmap);
}
@@ -244,6 +294,7 @@ void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
@@ -254,6 +305,7 @@ void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, size_t le
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len,
@@ -262,6 +314,7 @@ void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
#ifdef SK_BUILD_FOR_ANDROID
@@ -272,6 +325,7 @@ void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
#endif
@@ -284,6 +338,7 @@ void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
void AnalysisDevice::drawDevice(const SkDraw&, SkDevice*, int x, int y,
@@ -323,6 +378,10 @@ int AnalysisCanvas::getEstimatedCost() const {
return (static_cast<AnalysisDevice*>(getDevice()))->getEstimatedCost();
}
+void AnalysisCanvas::consumeLazyPixelRefs(std::list<LazyPixelRef*>& pixelRefs) {
+ static_cast<AnalysisDevice*>(getDevice())->consumeLazyPixelRefs(pixelRefs);
+}
+
bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op,
bool doAA) {
return INHERITED::clipRect(rect, op, doAA);
« skia/ext/analysis_canvas.h ('K') | « skia/ext/analysis_canvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698