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

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: junov's review 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
Index: skia/ext/analysis_canvas.cc
diff --git a/skia/ext/analysis_canvas.cc b/skia/ext/analysis_canvas.cc
index 2a2c7f3e32aed9ab9437e1c195a6d900988efc7d..d529a186b3615b2411ae35bcb3f5d95266f313d2 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";
Sami 2013/03/18 12:14:33 const char kLabelLazyDecoded[] = ...
+
static bool isSolidColorPaint(const SkPaint& paint) {
SkXfermode::Mode xferMode;
@@ -111,6 +115,49 @@ void AnalysisDevice::setForceNotTransparent(bool flag) {
isTransparent_ = false;
}
+void AnalysisDevice::addPixelRefIfLazy(SkPixelRef* pixelRef) {
+ if (!pixelRef)
+ return;
+
+ uint32_t genID = pixelRef->getGenerationID();
+
+ // If this ID exists (whether it is lazy pixel ref or not),
+ // we can return early.
+ std::pair<base::hash_set<uint32_t>::iterator, bool> insertionResult =
+ existingPixelRefIDs_.insert(genID);
+ if (!insertionResult.second)
+ return;
+
+ if (pixelRef->getURI() &&
+ !strncmp(pixelRef->getURI(), labelLazyDecoded, 4)) {
Sami 2013/03/18 12:14:33 Use a named constant instead of 4.
+ lazyPixelRefs_.push_back(static_cast<skia::LazyPixelRef*>(pixelRef));
+ }
+}
+
+void AnalysisDevice::addBitmap(const SkBitmap& bitmap) {
+ 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) &&
+ SkShader::kNone_BitmapType != shader->asABitmap(&bitmap, NULL, NULL)) {
+ addPixelRefIfLazy(bitmap.pixelRef());
+ }
+ }
+}
+
+void AnalysisDevice::consumeLazyPixelRefs(std::list<LazyPixelRef*>& pixelRefs) {
+ DCHECK(pixelRefs.empty());
+ lazyPixelRefs_.swap(pixelRefs);
+ existingPixelRefIDs_.clear();
+}
+
void AnalysisDevice::clear(SkColor color) {
++estimatedCost_;
@@ -129,6 +176,7 @@ void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
Tom Hudson 2013/03/18 11:52:39 Hmm, idiomatically this isn't how I expected drawP
}
void AnalysisDevice::drawPoints(const SkDraw&, SkCanvas::PointMode mode,
@@ -137,6 +185,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 +196,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 +244,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 +260,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 +269,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 +277,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 +289,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 +298,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 +309,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 +318,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 +329,7 @@ void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text,
++estimatedCost_;
isSolidColor_ = false;
isTransparent_ = false;
+ addBitmapFromPaint(paint);
}
#endif
@@ -284,6 +342,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 +382,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);

Powered by Google App Engine
This is Rietveld 408576698