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

Unified Diff: skia/ext/analysis_canvas.cc

Issue 12184010: skia::AnalysisCanvas: implementation for IsCheapInRect(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to reviewer comments Created 7 years, 10 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
« no previous file with comments | « skia/ext/analysis_canvas.h ('k') | skia/skia.gyp » ('j') | 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
new file mode 100644
index 0000000000000000000000000000000000000000..12ed69ec262c6b4493cb84b054e31e0fb2bba366
--- /dev/null
+++ b/skia/ext/analysis_canvas.cc
@@ -0,0 +1,198 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/debug/trace_event.h"
+#include "skia/ext/analysis_canvas.h"
+
+namespace {
+
+// FIXME: Arbitrary number. Requires tuning & experimentation.
+// Probably requires per-platform tuning; N10 average draw call takes
+// 25x as long as Z620.
+int gPictureCostThreshold = 100;
+
+}
+
+namespace skia {
+
+AnalysisDevice::AnalysisDevice(const SkBitmap& bm) : SkDevice(bm) { }
+
+AnalysisCanvas::AnalysisCanvas(SkDevice* device, SkRect clip)
+ : SkCanvas(device)
+ , estimatedCost_(0)
+ , clip_(clip) {
+ SkIRect ir;
+ clip.roundOut(&ir);
+ this->setClipRegion(SkRegion(ir));
+}
+
+AnalysisCanvas::~AnalysisCanvas() {
+
+}
+
+
+int AnalysisCanvas::save(SkCanvas::SaveFlags) {
+ ++estimatedCost_;
+}
+
+int AnalysisCanvas::saveLayer(const SkRect*, const SkPaint*,
+ SkCanvas::SaveFlags) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::restore() {
+ ++estimatedCost_;
+}
+
+bool AnalysisCanvas::clipRect(const SkRect&, SkRegion::Op, bool) {
+ ++estimatedCost_;
+}
+
+bool AnalysisCanvas::clipRRect(const SkRRect&, SkRegion::Op, bool) {
+ ++estimatedCost_;
+}
+
+bool AnalysisCanvas::clipPath(const SkPath&, SkRegion::Op, bool) {
+ ++estimatedCost_;
+}
+
+bool AnalysisCanvas::clipRegion(const SkRegion&, SkRegion::Op) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::clear(SkColor) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawPaint(const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawPoints(PointMode, size_t, const SkPoint [],
+ const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawRect(const SkRect&, const SkPaint&) {
+// FIXME: if there's a pending image decode & resize, more expensive
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawOval(const SkRect&, const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawRRect(const SkRRect&, const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
+char tmpbuf [256];
+sprintf(tmpbuf, "AnalysisCanvas::drawPath effect %s fill %s", paint.getPathEffect() ? "true" : "false", paint.getStyle() == SkPaint::kFill_Style ? "true" : "false");
+TRACE_EVENT0("skia", strdup(tmpbuf));
+ // if the path is filled, and there's a mask filter, more expensive
+ // FIXME: this isn't correctly detecting yet; no paths are taking
+ // the branch. See SkDraw::drawPath() for the code we're attempting
+ // to reproduce.
+ bool doFill = true;
+ if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) {
+TRACE_EVENT0("skia", "Checking fill path...");
+ SkPath tmpPath;
+ doFill = paint.getFillPath(path, &tmpPath, &clip_);
+ }
+ if (doFill && paint.getMaskFilter()) {
+TRACE_EVENT0("skia", "Found filled masked path; ouch!");
+ estimatedCost_ += 100;
+ }
+ if (!paint.getMaskFilter()) {
+TRACE_EVENT0("skia", "No mask filter.");
+ }
+ ++estimatedCost_;
+
+}
+
+void AnalysisCanvas::drawBitmap(const SkBitmap&, SkScalar, SkScalar,
+ const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawBitmapRectToRect(const SkBitmap&, const SkRect*,
+ const SkRect&, const SkPaint*) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
+ const SkPaint*) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawBitmapNine(const SkBitmap&, const SkIRect&,
+ const SkRect&, const SkPaint*) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawSprite(const SkBitmap&, int left, int top,
+ const SkPaint*) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawText(const void*, size_t, SkScalar, SkScalar,
+ const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawPosText(const void*, size_t, const SkPoint [],
+ const SkPaint&) {
+// FIXME: sometimes very expensive
+// NOT proportional to length: we see ~40B inputs taking 10-500 us
+// The difference seems to be cache misses; every miss adds 10-30 us,
+// and we might see 8 misses in 52B and spend >200us drawing a string
+// immediately after drawing a 48B string in 2us (!) with no misses.
+// https://code.google.com/p/skia/issues/detail?id=1102
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawPosTextH(const void*, size_t, const SkScalar [],
+ SkScalar, const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawTextOnPath(const void*, size_t, const SkPath&,
+ const SkMatrix*, const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawVertices(VertexMode, int, const SkPoint [],
+ const SkPoint [], const SkColor [],
+ SkXfermode*,
+ const uint16_t [], int, const SkPaint&) {
+ ++estimatedCost_;
+}
+
+void AnalysisCanvas::drawData(const void*, size_t) {
+ ++estimatedCost_;
+}
+
+bool AnalysisCanvas::isCheap() const {
+ return estimatedCost_ < gPictureCostThreshold;
+}
+
+int AnalysisCanvas::getEstimatedCost() const {
+ return estimatedCost_;
+}
+
+
+void AnalysisCanvas::reset(SkRect clip) {
+ estimatedCost_ = 0;
+ clip_ = clip;
+ SkIRect ir;
+ clip.roundOut(&ir);
+ this->setClipRegion(SkRegion(ir));
+}
+
+
+
+} // namespace skia
+
+
« no previous file with comments | « skia/ext/analysis_canvas.h ('k') | skia/skia.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698