summaryrefslogtreecommitdiffstats
path: root/skia/ext
diff options
context:
space:
mode:
authorreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-29 19:15:31 +0000
committerreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-29 19:15:31 +0000
commit670075650836296e023acf7bd77383fefc08e493 (patch)
tree138a3874c26c56e295054d2942514136a60bdb39 /skia/ext
parent7060d65997d7b88b05137c70b1b509fbcafb0850 (diff)
downloadchromium_src-670075650836296e023acf7bd77383fefc08e493.zip
chromium_src-670075650836296e023acf7bd77383fefc08e493.tar.gz
chromium_src-670075650836296e023acf7bd77383fefc08e493.tar.bz2
cc: Remove cheapness estimator from AnalysisCanvas.
BUG=235995 Review URL: https://chromiumcodereview.appspot.com/13901018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197101 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r--skia/ext/analysis_canvas.cc124
-rw-r--r--skia/ext/analysis_canvas.h11
-rw-r--r--skia/ext/analysis_canvas_unittest.cc17
3 files changed, 11 insertions, 141 deletions
diff --git a/skia/ext/analysis_canvas.cc b/skia/ext/analysis_canvas.cc
index 0af76f2..74a7c23 100644
--- a/skia/ext/analysis_canvas.cc
+++ b/skia/ext/analysis_canvas.cc
@@ -13,23 +13,10 @@
namespace {
-// FIXME: Arbitrary numbers. Requires tuning & experimentation.
-// Probably requires per-platform tuning; N10 average draw call takes
-// 25x as long as Z620.
-const int gPictureCostThreshold = 1000;
-const int kUnknownExpensiveCost = 500;
-const int kUnknownBitmapCost = 1000;
-
// URI label for a lazily decoded SkPixelRef.
const char kLabelLazyDecoded[] = "lazy";
const int kLabelLazyDecodedLength = 4;
-// Estimate of rasterization performance on mid-low-range hardware,
-// drawing rectangles with simple paints.
-const int kSimpleRectPixelsPerUS = 1000;
-const int kComplexRectPixelsPerUS = 100;
-const int kSimpleTextCharPerUS = 2;
-
bool isSolidColorPaint(const SkPaint& paint) {
SkXfermode::Mode xferMode;
@@ -80,19 +67,12 @@ bool isFullQuad(const SkDraw& draw,
drawBitmapRect.contains(canvasRect);
}
-bool hasBitmap(const SkPaint& paint) {
- SkShader* shader = paint.getShader();
- return shader &&
- (SkShader::kNone_BitmapType != shader->asABitmap(NULL, NULL, NULL));
-}
-
} // namespace
namespace skia {
AnalysisDevice::AnalysisDevice(const SkBitmap& bm)
: INHERITED(bm)
- , estimatedCost_(0)
, isForcedNotSolid_(false)
, isForcedNotTransparent_(false)
, isSolidColor_(false)
@@ -104,10 +84,6 @@ AnalysisDevice::~AnalysisDevice() {
}
-int AnalysisDevice::getEstimatedCost() const {
- return estimatedCost_;
-}
-
bool AnalysisDevice::getColorIfSolid(SkColor* color) const {
if (isSolidColor_)
*color = color_;
@@ -181,9 +157,6 @@ void AnalysisDevice::consumeLazyPixelRefs(LazyPixelRefList* pixelRefs) {
}
void AnalysisDevice::clear(SkColor color) {
- // FIXME: cost here should be simple rect of device size
- estimatedCost_ += kUnknownExpensiveCost;
-
isTransparent_ = (!isForcedNotTransparent_ && SkColorGetA(color) == 0);
hasText_ = false;
@@ -197,11 +170,7 @@ void AnalysisDevice::clear(SkColor color) {
}
void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
- estimatedCost_ += kUnknownExpensiveCost;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
@@ -209,27 +178,14 @@ void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
void AnalysisDevice::drawPoints(const SkDraw&, SkCanvas::PointMode mode,
size_t count, const SkPoint[],
const SkPaint& paint) {
- estimatedCost_ += kUnknownExpensiveCost;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
void AnalysisDevice::drawRect(const SkDraw& draw, const SkRect& rect,
const SkPaint& paint) {
-
- // FIXME: if there's a pending image decode & resize, more expensive
- estimatedCost_ += 1 + rect.width() * rect.height() / kSimpleRectPixelsPerUS;
- if (paint.getMaskFilter()) {
- estimatedCost_ += kUnknownExpensiveCost;
- }
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
bool doesCoverCanvas = isFullQuad(draw,
SkRect::MakeWH(width(), height()),
@@ -277,11 +233,7 @@ void AnalysisDevice::drawRect(const SkDraw& draw, const SkRect& rect,
void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval,
const SkPaint& paint) {
- estimatedCost_ += kUnknownExpensiveCost;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
@@ -290,19 +242,7 @@ void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
const SkPaint& paint,
const SkMatrix* prePathMatrix,
bool pathIsMutable ) {
- // On Z620, every antialiased path costs us about 300us.
- // We've only seen this in practice on filled paths, but
- // we expect it to apply to all path stroking modes.
- if (paint.getMaskFilter()) {
- estimatedCost_ += 300;
- }
- // FIXME: horrible overestimate if the path is stroked instead of filled
- estimatedCost_ += 1 + path.getBounds().width() *
- path.getBounds().height() / kSimpleRectPixelsPerUS;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
@@ -310,9 +250,6 @@ void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
const SkIRect* srcRectOrNull,
const SkMatrix& matrix, const SkPaint& paint) {
- estimatedCost_ += kUnknownExpensiveCost;
- //DCHECK(hasBitmap(paint));
- estimatedCost_ += kUnknownBitmapCost;
isSolidColor_ = false;
isTransparent_ = false;
addBitmap(bitmap);
@@ -320,9 +257,6 @@ void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
int x, int y, const SkPaint& paint) {
- estimatedCost_ += kUnknownExpensiveCost;
- //DCHECK(hasBitmap(paint));
- estimatedCost_ += kUnknownBitmapCost;
isSolidColor_ = false;
isTransparent_ = false;
addBitmap(bitmap);
@@ -331,11 +265,6 @@ void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
void AnalysisDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
const SkRect* srcOrNull, const SkRect& dst,
const SkPaint& paint) {
- // FIXME: we also accumulate cost from drawRect()
- estimatedCost_ += 1 + dst.width() * dst.height() / kComplexRectPixelsPerUS;
- //DCHECK(hasBitmap(paint));
- estimatedCost_ += kUnknownBitmapCost;
-
// Call drawRect to determine transparency,
// but reset solid color to false.
drawRect(draw, dst, paint);
@@ -346,11 +275,7 @@ void AnalysisDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) {
- estimatedCost_ += 1 + len / kSimpleTextCharPerUS;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -360,13 +285,7 @@ void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text,
size_t len,
const SkScalar pos[], SkScalar constY,
int scalarsPerPos, const SkPaint& paint) {
- // FIXME: On Z620, every glyph cache miss costs us about 10us.
- // We don't have a good mechanism for predicting glyph cache misses.
- estimatedCost_ += 1 + len / kSimpleTextCharPerUS;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -376,11 +295,7 @@ void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text,
size_t len,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) {
- estimatedCost_ += 1 + len / kSimpleTextCharPerUS;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -391,11 +306,7 @@ void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text,
size_t len,
const SkPoint pos[], const SkPaint& paint,
const SkPath& path, const SkMatrix* matrix) {
- estimatedCost_ += 1 + len / kSimpleTextCharPerUS;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -408,20 +319,13 @@ void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
- estimatedCost_ += kUnknownExpensiveCost;
- if (hasBitmap(paint)) {
- estimatedCost_ += kUnknownBitmapCost;
- addBitmapFromPaint(paint);
- }
+ addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
void AnalysisDevice::drawDevice(const SkDraw&, SkDevice*, int x, int y,
const SkPaint& paint) {
- estimatedCost_ += kUnknownExpensiveCost;
- if (hasBitmap(paint))
- estimatedCost_ += kUnknownBitmapCost;
isSolidColor_ = false;
isTransparent_ = false;
}
@@ -440,10 +344,6 @@ AnalysisCanvas::~AnalysisCanvas() {
}
-bool AnalysisCanvas::isCheap() const {
- return getEstimatedCost() < gPictureCostThreshold;
-}
-
bool AnalysisCanvas::getColorIfSolid(SkColor* color) const {
return (static_cast<AnalysisDevice*>(getDevice()))->getColorIfSolid(color);
}
@@ -456,10 +356,6 @@ bool AnalysisCanvas::hasText() const {
return (static_cast<AnalysisDevice*>(getDevice()))->hasText();
}
-int AnalysisCanvas::getEstimatedCost() const {
- return (static_cast<AnalysisDevice*>(getDevice()))->getEstimatedCost();
-}
-
void AnalysisCanvas::consumeLazyPixelRefs(LazyPixelRefList* pixelRefs) {
static_cast<AnalysisDevice*>(getDevice())->consumeLazyPixelRefs(pixelRefs);
}
diff --git a/skia/ext/analysis_canvas.h b/skia/ext/analysis_canvas.h
index 4ebf793..2d80ea0 100644
--- a/skia/ext/analysis_canvas.h
+++ b/skia/ext/analysis_canvas.h
@@ -22,7 +22,7 @@ class AnalysisDevice;
// played back through it.
// To use: create a SkBitmap with kNo_Config, create an AnalysisDevice
// using that bitmap, and create an AnalysisCanvas using the device.
-// Play a picture into the canvas, and then check isCheap().
+// Play a picture into the canvas, and then check result.
class SK_API AnalysisCanvas : public SkCanvas {
public:
typedef std::list<skia::LazyPixelRef*> LazyPixelRefList;
@@ -30,17 +30,11 @@ class SK_API AnalysisCanvas : public SkCanvas {
AnalysisCanvas(AnalysisDevice*);
virtual ~AnalysisCanvas();
- // Returns true if the estimated cost of drawing is below an
- // arbitrary threshold.
- bool isCheap() const;
bool getColorIfSolid(SkColor* color) const;
bool isTransparent() const;
bool hasText() const;
void consumeLazyPixelRefs(LazyPixelRefList* pixelRefs);
- // Returns the estimated cost of drawing, in arbitrary units.
- int getEstimatedCost() const;
-
virtual bool clipRect(const SkRect& rect,
SkRegion::Op op = SkRegion::kIntersect_Op,
bool doAntiAlias = false) OVERRIDE;
@@ -74,7 +68,6 @@ class SK_API AnalysisDevice : public SkDevice {
AnalysisDevice(const SkBitmap& bm);
virtual ~AnalysisDevice();
- int getEstimatedCost() const;
bool getColorIfSolid(SkColor* color) const;
bool isTransparent() const;
bool hasText() const;
@@ -131,8 +124,6 @@ class SK_API AnalysisDevice : public SkDevice {
virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
const SkPaint&) OVERRIDE;
- int estimatedCost_;
-
private:
typedef SkDevice INHERITED;
diff --git a/skia/ext/analysis_canvas_unittest.cc b/skia/ext/analysis_canvas_unittest.cc
index a8a9d0d..b2fa978 100644
--- a/skia/ext/analysis_canvas_unittest.cc
+++ b/skia/ext/analysis_canvas_unittest.cc
@@ -73,7 +73,6 @@ TEST(AnalysisCanvasTest, EmptyCanvas) {
SkColor color;
EXPECT_FALSE(canvas.getColorIfSolid(&color));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
}
TEST(AnalysisCanvasTest, ClearCanvas) {
@@ -89,7 +88,6 @@ TEST(AnalysisCanvasTest, ClearCanvas) {
SkColor outputColor;
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_TRUE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
// Solid color
color = SkColorSetARGB(255, 65, 43, 21);
@@ -97,7 +95,6 @@ TEST(AnalysisCanvasTest, ClearCanvas) {
EXPECT_TRUE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_FALSE(canvas.isCheap());
EXPECT_EQ(outputColor, color);
// Translucent color
@@ -106,7 +103,6 @@ TEST(AnalysisCanvasTest, ClearCanvas) {
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_FALSE(canvas.isCheap());
// Test helper methods
solidColorFill(canvas);
@@ -135,7 +131,6 @@ TEST(AnalysisCanvasTest, ComplexActions) {
//TODO(vmpstr): This should return true. (crbug.com/180597)
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
// Draw points test.
SkPoint points[4] = {
@@ -150,7 +145,6 @@ TEST(AnalysisCanvasTest, ComplexActions) {
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_FALSE(canvas.isCheap());
// Draw oval test.
solidColorFill(canvas);
@@ -158,7 +152,6 @@ TEST(AnalysisCanvasTest, ComplexActions) {
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_FALSE(canvas.isCheap());
// Draw bitmap test.
solidColorFill(canvas);
@@ -168,7 +161,6 @@ TEST(AnalysisCanvasTest, ComplexActions) {
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_FALSE(canvas.isCheap());
}
TEST(AnalysisCanvasTest, SimpleDrawRect) {
@@ -186,7 +178,6 @@ TEST(AnalysisCanvasTest, SimpleDrawRect) {
SkColor outputColor;
EXPECT_TRUE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
EXPECT_EQ(color, outputColor);
color = SkColorSetARGB(255, 22, 33, 44);
@@ -196,7 +187,6 @@ TEST(AnalysisCanvasTest, SimpleDrawRect) {
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
color = SkColorSetARGB(255, 33, 44, 55);
paint.setColor(color);
@@ -204,7 +194,6 @@ TEST(AnalysisCanvasTest, SimpleDrawRect) {
EXPECT_TRUE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
EXPECT_EQ(color, outputColor);
color = SkColorSetARGB(0, 0, 0, 0);
@@ -213,7 +202,6 @@ TEST(AnalysisCanvasTest, SimpleDrawRect) {
EXPECT_TRUE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
EXPECT_EQ(outputColor, SkColorSetARGB(255, 33, 44, 55));
color = SkColorSetARGB(128, 128, 128, 128);
@@ -222,20 +210,17 @@ TEST(AnalysisCanvasTest, SimpleDrawRect) {
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
paint.setXfermodeMode(SkXfermode::kClear_Mode);
canvas.drawRect(SkRect::MakeWH(382, 382), paint);
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
canvas.drawRect(SkRect::MakeWH(383, 383), paint);
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_TRUE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
canvas.translate(128, 128);
color = SkColorSetARGB(255, 11, 22, 33);
@@ -245,7 +230,6 @@ TEST(AnalysisCanvasTest, SimpleDrawRect) {
EXPECT_TRUE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
EXPECT_EQ(color, outputColor);
canvas.rotate(50);
@@ -253,7 +237,6 @@ TEST(AnalysisCanvasTest, SimpleDrawRect) {
EXPECT_FALSE(canvas.getColorIfSolid(&outputColor));
EXPECT_FALSE(canvas.isTransparent());
- EXPECT_TRUE(canvas.isCheap());
}
TEST(AnalysisCanvasTest, ClipPath) {