summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-06 06:28:14 +0000
committerreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-06 06:28:14 +0000
commit9693753d30fd8b0b4d5fcf2caa9ca148d67b3f8d (patch)
treec29e616bcc175c5f58136e2b4376342519f70e36 /skia
parent1a3d726c4ca20def7a0571a508aa5dac896aa2d6 (diff)
downloadchromium_src-9693753d30fd8b0b4d5fcf2caa9ca148d67b3f8d.zip
chromium_src-9693753d30fd8b0b4d5fcf2caa9ca148d67b3f8d.tar.gz
chromium_src-9693753d30fd8b0b4d5fcf2caa9ca148d67b3f8d.tar.bz2
skia: Remove gather pixel refs from AnalysisCanvas.
The compositor is no longer using this so it's just adding unnecessary overhead to the analysis. BUG=237514 Review URL: https://chromiumcodereview.appspot.com/14652015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198390 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/analysis_canvas.cc68
-rw-r--r--skia/ext/analysis_canvas.h18
-rw-r--r--skia/ext/analysis_canvas_unittest.cc144
3 files changed, 0 insertions, 230 deletions
diff --git a/skia/ext/analysis_canvas.cc b/skia/ext/analysis_canvas.cc
index 196d1d0..467f62c 100644
--- a/skia/ext/analysis_canvas.cc
+++ b/skia/ext/analysis_canvas.cc
@@ -13,10 +13,6 @@
namespace {
-// URI label for a lazily decoded SkPixelRef.
-const char kLabelLazyDecoded[] = "lazy";
-const int kLabelLazyDecodedLength = 4;
-
bool isSolidColorPaint(const SkPaint& paint) {
SkXfermode::Mode xferMode;
@@ -112,52 +108,6 @@ 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<IdSet::iterator, bool> insertionResult =
- existingPixelRefIDs_.insert(genID);
- if (!insertionResult.second)
- return;
-
- if (pixelRef->getURI() &&
- !strncmp(pixelRef->getURI(),
- kLabelLazyDecoded,
- kLabelLazyDecodedLength)) {
- 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(LazyPixelRefList* pixelRefs) {
- DCHECK(pixelRefs);
- DCHECK(pixelRefs->empty());
- lazyPixelRefs_.swap(*pixelRefs);
- existingPixelRefIDs_.clear();
-}
-
void AnalysisDevice::clear(SkColor color) {
isTransparent_ = (!isForcedNotTransparent_ && SkColorGetA(color) == 0);
hasText_ = false;
@@ -172,7 +122,6 @@ void AnalysisDevice::clear(SkColor color) {
}
void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
- addBitmapFromPaint(paint);
isSolidColor_ =
(isSolidColor_ && isSolidColorPaint(paint) && paint.getColor() == color_);
isTransparent_ = false;
@@ -181,15 +130,12 @@ void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
void AnalysisDevice::drawPoints(const SkDraw&, SkCanvas::PointMode mode,
size_t count, const SkPoint[],
const SkPaint& paint) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
void AnalysisDevice::drawRect(const SkDraw& draw, const SkRect& rect,
const SkPaint& paint) {
- addBitmapFromPaint(paint);
-
bool doesCoverCanvas = isFullQuad(draw,
SkRect::MakeWH(width(), height()),
rect);
@@ -239,7 +185,6 @@ void AnalysisDevice::drawRect(const SkDraw& draw, const SkRect& rect,
void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval,
const SkPaint& paint) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
@@ -248,7 +193,6 @@ void AnalysisDevice::drawPath(const SkDraw&, const SkPath& path,
const SkPaint& paint,
const SkMatrix* prePathMatrix,
bool pathIsMutable ) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
@@ -258,14 +202,12 @@ void AnalysisDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
const SkMatrix& matrix, const SkPaint& paint) {
isSolidColor_ = false;
isTransparent_ = false;
- addBitmap(bitmap);
}
void AnalysisDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
int x, int y, const SkPaint& paint) {
isSolidColor_ = false;
isTransparent_ = false;
- addBitmap(bitmap);
}
void AnalysisDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
@@ -275,13 +217,11 @@ void AnalysisDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
// but reset solid color to false.
drawRect(draw, dst, paint);
isSolidColor_ = false;
- addBitmap(bitmap);
}
void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -291,7 +231,6 @@ void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text,
size_t len,
const SkScalar pos[], SkScalar constY,
int scalarsPerPos, const SkPaint& paint) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -301,7 +240,6 @@ void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text,
size_t len,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -312,7 +250,6 @@ void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text,
size_t len,
const SkPoint pos[], const SkPaint& paint,
const SkPath& path, const SkMatrix* matrix) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
hasText_ = true;
@@ -325,7 +262,6 @@ void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode,
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
- addBitmapFromPaint(paint);
isSolidColor_ = false;
isTransparent_ = false;
}
@@ -358,10 +294,6 @@ bool AnalysisCanvas::hasText() const {
return (static_cast<AnalysisDevice*>(getDevice()))->hasText();
}
-void AnalysisCanvas::consumeLazyPixelRefs(LazyPixelRefList* pixelRefs) {
- static_cast<AnalysisDevice*>(getDevice())->consumeLazyPixelRefs(pixelRefs);
-}
-
bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op,
bool doAA) {
return INHERITED::clipRect(rect, op, doAA);
diff --git a/skia/ext/analysis_canvas.h b/skia/ext/analysis_canvas.h
index 3b6c15c..67151d3 100644
--- a/skia/ext/analysis_canvas.h
+++ b/skia/ext/analysis_canvas.h
@@ -5,11 +5,6 @@
#ifndef SKIA_EXT_ANALYSIS_CANVAS_H_
#define SKIA_EXT_ANALYSIS_CANVAS_H_
-#include <list>
-#include <set>
-
-#include "base/hash_tables.h"
-#include "skia/ext/lazy_pixel_ref.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkDevice.h"
@@ -25,15 +20,12 @@ class AnalysisDevice;
// Play a picture into the canvas, and then check result.
class SK_API AnalysisCanvas : public SkCanvas {
public:
- typedef std::list<skia::LazyPixelRef*> LazyPixelRefList;
-
AnalysisCanvas(AnalysisDevice*);
virtual ~AnalysisCanvas();
// Returns true when a SkColor can be used to represent result.
bool getColorIfSolid(SkColor* color) const;
bool hasText() const;
- void consumeLazyPixelRefs(LazyPixelRefList* pixelRefs);
virtual bool clipRect(const SkRect& rect,
SkRegion::Op op = SkRegion::kIntersect_Op,
@@ -62,15 +54,11 @@ class SK_API AnalysisCanvas : public SkCanvas {
class SK_API AnalysisDevice : public SkDevice {
public:
- typedef std::list<skia::LazyPixelRef*> LazyPixelRefList;
- typedef base::hash_set<uint32_t> IdSet;
-
AnalysisDevice(const SkBitmap& bm);
virtual ~AnalysisDevice();
bool getColorIfSolid(SkColor* color) const;
bool hasText() const;
- void consumeLazyPixelRefs(LazyPixelRefList* pixelRefs);
void setForceNotSolid(bool flag);
void setForceNotTransparent(bool flag);
@@ -127,18 +115,12 @@ class SK_API AnalysisDevice : public SkDevice {
typedef SkDevice INHERITED;
- void addPixelRefIfLazy(SkPixelRef* pixelRef);
- void addBitmap(const SkBitmap& bitmap);
- void addBitmapFromPaint(const SkPaint& paint);
-
bool isForcedNotSolid_;
bool isForcedNotTransparent_;
bool isSolidColor_;
SkColor color_;
bool isTransparent_;
bool hasText_;
- IdSet existingPixelRefIDs_;
- LazyPixelRefList lazyPixelRefs_;
};
} // namespace skia
diff --git a/skia/ext/analysis_canvas_unittest.cc b/skia/ext/analysis_canvas_unittest.cc
index aa69259..4c54dd5 100644
--- a/skia/ext/analysis_canvas_unittest.cc
+++ b/skia/ext/analysis_canvas_unittest.cc
@@ -20,50 +20,6 @@ void transparentFill(skia::AnalysisCanvas& canvas) {
} // namespace
namespace skia {
-class TestPixelRef : public SkPixelRef {
- public:
- // Pure virtual implementation.
- virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; }
- virtual void* onLockPixels(SkColorTable**) OVERRIDE { return NULL; }
- virtual void onUnlockPixels() OVERRIDE {}
-};
-
-class TestLazyPixelRef : public LazyPixelRef {
- public:
- // Pure virtual implementation.
- virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; }
- virtual void* onLockPixels(SkColorTable**) OVERRIDE { return NULL; }
- virtual void onUnlockPixels() OVERRIDE {}
- virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE {
- return true;
- }
- virtual void Decode() OVERRIDE {}
-};
-
-class TestShader : public SkShader {
- public:
- TestShader(SkBitmap* bitmap)
- : bitmap_(bitmap) {
- }
-
- virtual SkShader::BitmapType asABitmap(
- SkBitmap* bitmap,
- SkMatrix*,
- TileMode xy[2]) const OVERRIDE {
- if (bitmap)
- *bitmap = *bitmap_;
- return SkShader::kDefault_BitmapType;
- }
-
- // Pure virtual implementation.
- virtual void shadeSpan(int x, int y, SkPMColor[], int count) OVERRIDE {}
- virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; }
-
- private:
-
- SkBitmap* bitmap_;
-};
-
TEST(AnalysisCanvasTest, EmptyCanvas) {
SkBitmap emptyBitmap;
emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
@@ -329,106 +285,6 @@ TEST(AnalysisCanvasTest, SaveLayerRestore) {
EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
}
-TEST(AnalysisCanvasTest, LazyPixelRefs) {
- // Set up two lazy and two non-lazy pixel refs and the corresponding bitmaps.
- TestLazyPixelRef firstLazyPixelRef;
- firstLazyPixelRef.setURI("lazy");
- TestLazyPixelRef secondLazyPixelRef;
- secondLazyPixelRef.setURI("lazy");
-
- TestPixelRef firstNonLazyPixelRef;
- TestPixelRef secondNonLazyPixelRef;
- secondNonLazyPixelRef.setURI("notsolazy");
-
- SkBitmap firstLazyBitmap;
- firstLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- firstLazyBitmap.setPixelRef(&firstLazyPixelRef);
- SkBitmap secondLazyBitmap;
- secondLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- secondLazyBitmap.setPixelRef(&secondLazyPixelRef);
-
- SkBitmap firstNonLazyBitmap;
- firstNonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- SkBitmap secondNonLazyBitmap;
- secondNonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- secondNonLazyBitmap.setPixelRef(&secondNonLazyPixelRef);
-
- // The testcase starts here.
- SkBitmap emptyBitmap;
- emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- skia::AnalysisDevice device(emptyBitmap);
- skia::AnalysisCanvas canvas(&device);
-
- // This should be the first ref.
- canvas.drawBitmap(firstLazyBitmap, 0, 0);
- // The following will be ignored (non-lazy).
- canvas.drawBitmap(firstNonLazyBitmap, 0, 0);
- canvas.drawBitmap(firstNonLazyBitmap, 0, 0);
- canvas.drawBitmap(secondNonLazyBitmap, 0, 0);
- canvas.drawBitmap(secondNonLazyBitmap, 0, 0);
- // This one will be ignored (already exists).
- canvas.drawBitmap(firstLazyBitmap, 0, 0);
- // This should be the second ref.
- canvas.drawBitmap(secondLazyBitmap, 0, 0);
-
- std::list<skia::LazyPixelRef*> pixelRefs;
- canvas.consumeLazyPixelRefs(&pixelRefs);
-
- // We expect to get only lazy pixel refs and only unique results.
- EXPECT_EQ(pixelRefs.size(), 2u);
- if (!pixelRefs.empty()) {
- EXPECT_EQ(pixelRefs.front(),
- static_cast<LazyPixelRef*>(&firstLazyPixelRef));
- EXPECT_EQ(pixelRefs.back(),
- static_cast<LazyPixelRef*>(&secondLazyPixelRef));
- }
-}
-
-TEST(AnalysisCanvasTest, PixelRefsFromPaint) {
- TestLazyPixelRef lazyPixelRef;
- lazyPixelRef.setURI("lazy");
-
- TestPixelRef nonLazyPixelRef;
- nonLazyPixelRef.setURI("notsolazy");
-
- SkBitmap lazyBitmap;
- lazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- lazyBitmap.setPixelRef(&lazyPixelRef);
-
- SkBitmap nonLazyBitmap;
- nonLazyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- nonLazyBitmap.setPixelRef(&nonLazyPixelRef);
-
- TestShader lazyShader(&lazyBitmap);
- TestShader nonLazyShader(&nonLazyBitmap);
-
- SkPaint lazyPaint;
- lazyPaint.setShader(&lazyShader);
- SkPaint nonLazyPaint;
- nonLazyPaint.setShader(&nonLazyShader);
-
- SkBitmap emptyBitmap;
- emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255);
- skia::AnalysisDevice device(emptyBitmap);
- skia::AnalysisCanvas canvas(&device);
-
- canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
- canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
- canvas.drawRect(SkRect::MakeWH(255, 255), lazyPaint);
- canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
- canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
- canvas.drawRect(SkRect::MakeWH(255, 255), nonLazyPaint);
-
- std::list<skia::LazyPixelRef*> pixelRefs;
- canvas.consumeLazyPixelRefs(&pixelRefs);
-
- // We expect to get only lazy pixel refs and only unique results.
- EXPECT_EQ(pixelRefs.size(), 1u);
- if (!pixelRefs.empty()) {
- EXPECT_EQ(pixelRefs.front(), static_cast<LazyPixelRef*>(&lazyPixelRef));
- }
-}
-
TEST(AnalysisCanvasTest, HasText) {
int width = 200;
int height = 100;