diff options
author | Zeno Albisser <zeno.albisser@theqtcompany.com> | 2014-12-05 15:04:29 +0100 |
---|---|---|
committer | Andras Becsi <andras.becsi@theqtcompany.com> | 2014-12-09 10:49:28 +0100 |
commit | af6588f8d723931a298c995fa97259bb7f7deb55 (patch) | |
tree | 060ca707847ba1735f01af2372e0d5e494dc0366 /chromium/skia/ext | |
parent | 2fff84d821cc7b1c785f6404e0f8091333283e74 (diff) | |
download | qtwebengine-chromium-af6588f8d723931a298c995fa97259bb7f7deb55.tar.gz |
BASELINE: Update chromium to 40.0.2214.28 and ninja to 1.5.3.
Change-Id: I759465284fd64d59ad120219cbe257f7402c4181
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'chromium/skia/ext')
34 files changed, 660 insertions, 683 deletions
diff --git a/chromium/skia/ext/SkDiscardableMemory_chrome.h b/chromium/skia/ext/SkDiscardableMemory_chrome.h index b251dc452db..50946e64918 100644 --- a/chromium/skia/ext/SkDiscardableMemory_chrome.h +++ b/chromium/skia/ext/SkDiscardableMemory_chrome.h @@ -13,12 +13,12 @@ // base::DiscardableMemory. class SK_API SkDiscardableMemoryChrome : public SkDiscardableMemory { public: - virtual ~SkDiscardableMemoryChrome(); + ~SkDiscardableMemoryChrome() override; // SkDiscardableMemory: - virtual bool lock() OVERRIDE; - virtual void* data() OVERRIDE; - virtual void unlock() OVERRIDE; + bool lock() override; + void* data() override; + void unlock() override; private: friend class SkDiscardableMemory; diff --git a/chromium/skia/ext/analysis_canvas.cc b/chromium/skia/ext/analysis_canvas.cc index 16a7ffa4567..ca19170339f 100644 --- a/chromium/skia/ext/analysis_canvas.cc +++ b/chromium/skia/ext/analysis_canvas.cc @@ -80,7 +80,6 @@ void AnalysisCanvas::SetForceNotTransparent(bool flag) { void AnalysisCanvas::clear(SkColor color) { is_transparent_ = (!is_forced_not_transparent_ && SkColorGetA(color) == 0); - has_text_ = false; if (!is_forced_not_solid_ && SkColorGetA(color) == 255) { is_solid_color_ = true; @@ -98,6 +97,7 @@ void AnalysisCanvas::drawPaint(const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawPoints(SkCanvas::PointMode mode, @@ -106,11 +106,18 @@ void AnalysisCanvas::drawPoints(SkCanvas::PointMode mode, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { - // This recreates the early-exit logic in SkCanvas.cpp, which aborts early - // if the paint will "draw nothing". + // This recreates the early-exit logic in SkCanvas.cpp. + SkRect scratch; + if (paint.canComputeFastBounds() && + quickReject(paint.computeFastBounds(rect, &scratch))) { + return; + } + + // An extra no-op check SkCanvas.cpp doesn't do. if (paint.nothingToDraw()) return; @@ -132,7 +139,6 @@ void AnalysisCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { !is_forced_not_transparent_ && xfermode == SkXfermode::kClear_Mode) { is_transparent_ = true; - has_text_ = false; } else if (paint.getAlpha() != 0 || xfermode != SkXfermode::kSrc_Mode) { is_transparent_ = false; } @@ -145,15 +151,16 @@ void AnalysisCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { if (!is_forced_not_solid_ && IsSolidColorPaint(paint) && does_cover_canvas) { is_solid_color_ = true; color_ = paint.getColor(); - has_text_ = false; } else { is_solid_color_ = false; } + ++draw_op_count_; } void AnalysisCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawRRect(const SkRRect& rr, const SkPaint& paint) { @@ -162,11 +169,13 @@ void AnalysisCanvas::drawRRect(const SkRRect& rr, const SkPaint& paint) { // do the same work here. is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawPath(const SkPath& path, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawBitmap(const SkBitmap& bitmap, @@ -175,6 +184,7 @@ void AnalysisCanvas::drawBitmap(const SkBitmap& bitmap, const SkPaint*) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawBitmapRectToRect(const SkBitmap&, @@ -189,6 +199,7 @@ void AnalysisCanvas::drawBitmapRectToRect(const SkBitmap&, paint = &tmpPaint; drawRect(dst, *paint); is_solid_color_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawBitmapMatrix(const SkBitmap& bitmap, @@ -196,6 +207,7 @@ void AnalysisCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkPaint* paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawBitmapNine(const SkBitmap& bitmap, @@ -204,6 +216,7 @@ void AnalysisCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkPaint* paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawSprite(const SkBitmap& bitmap, @@ -212,6 +225,7 @@ void AnalysisCanvas::drawSprite(const SkBitmap& bitmap, const SkPaint* paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::onDrawText(const void* text, @@ -221,7 +235,7 @@ void AnalysisCanvas::onDrawText(const void* text, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; - has_text_ = true; + ++draw_op_count_; } void AnalysisCanvas::onDrawPosText(const void* text, @@ -230,7 +244,7 @@ void AnalysisCanvas::onDrawPosText(const void* text, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; - has_text_ = true; + ++draw_op_count_; } void AnalysisCanvas::onDrawPosTextH(const void* text, @@ -240,7 +254,7 @@ void AnalysisCanvas::onDrawPosTextH(const void* text, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; - has_text_ = true; + ++draw_op_count_; } void AnalysisCanvas::onDrawTextOnPath(const void* text, @@ -250,7 +264,16 @@ void AnalysisCanvas::onDrawTextOnPath(const void* text, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; - has_text_ = true; + ++draw_op_count_; +} + +void AnalysisCanvas::onDrawTextBlob(const SkTextBlob* blob, + SkScalar x, + SkScalar y, + const SkPaint &paint) { + is_solid_color_ = false; + is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::onDrawDRRect(const SkRRect& outer, @@ -258,6 +281,7 @@ void AnalysisCanvas::onDrawDRRect(const SkRRect& outer, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } void AnalysisCanvas::drawVertices(SkCanvas::VertexMode, @@ -271,6 +295,7 @@ void AnalysisCanvas::drawVertices(SkCanvas::VertexMode, const SkPaint& paint) { is_solid_color_ = false; is_transparent_ = false; + ++draw_op_count_; } // Needed for now, since SkCanvas requires a bitmap, even if it is not backed @@ -289,8 +314,10 @@ AnalysisCanvas::AnalysisCanvas(int width, int height) is_forced_not_solid_(false), is_forced_not_transparent_(false), is_solid_color_(true), + color_(SK_ColorTRANSPARENT), is_transparent_(true), - has_text_(false) {} + draw_op_count_(0) { +} AnalysisCanvas::~AnalysisCanvas() {} @@ -306,22 +333,23 @@ bool AnalysisCanvas::GetColorIfSolid(SkColor* color) const { return false; } -bool AnalysisCanvas::HasText() const { return has_text_; } - bool AnalysisCanvas::abortDrawing() { - // Early out as soon as we have detected that the tile has text. - return HasText(); -} - -void AnalysisCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, - ClipEdgeStyle edge_style) { - - INHERITED::onClipRect(rect, op, edge_style); + // Early out as soon as we have more than one draw op. + // TODO(vmpstr): Investigate if 1 is the correct metric here. We need to + // balance the amount of time we spend analyzing vs how many tiles would be + // solid if the number was higher. + if (draw_op_count_ > 1) { + // We have to reset solid/transparent state to false since we don't + // know whether consequent operations will make this false. + is_solid_color_ = false; + is_transparent_ = false; + return true; + } + return false; } -void AnalysisCanvas::onClipPath(const SkPath& path, SkRegion::Op op, - ClipEdgeStyle edge_style) { - // clipPaths can make our calls to IsFullQuad invalid (ie have false +void AnalysisCanvas::OnComplexClip() { + // complex clips can make our calls to IsFullQuad invalid (ie have false // positives). As a precaution, force the setting to be non-solid // and non-transparent until we pop this if (force_not_solid_stack_level_ == kNoLayer) { @@ -332,28 +360,39 @@ void AnalysisCanvas::onClipPath(const SkPath& path, SkRegion::Op op, force_not_transparent_stack_level_ = saved_stack_size_; SetForceNotTransparent(true); } +} +void AnalysisCanvas::onClipRect(const SkRect& rect, + SkRegion::Op op, + ClipEdgeStyle edge_style) { + INHERITED::onClipRect(rect, op, edge_style); +} + +void AnalysisCanvas::onClipPath(const SkPath& path, + SkRegion::Op op, + ClipEdgeStyle edge_style) { + OnComplexClip(); INHERITED::onClipRect(path.getBounds(), op, edge_style); } void AnalysisCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edge_style) { - // clipRRect can make our calls to IsFullQuad invalid (ie have false - // positives). As a precaution, force the setting to be non-solid - // and non-transparent until we pop this - if (force_not_solid_stack_level_ == kNoLayer) { - force_not_solid_stack_level_ = saved_stack_size_; - SetForceNotSolid(true); - } - if (force_not_transparent_stack_level_ == kNoLayer) { - force_not_transparent_stack_level_ = saved_stack_size_; - SetForceNotTransparent(true); - } - + OnComplexClip(); INHERITED::onClipRect(rrect.getBounds(), op, edge_style); } +void AnalysisCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { + const ClipEdgeStyle edge_style = kHard_ClipEdgeStyle; + if (deviceRgn.isRect()) { + onClipRect(SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style); + return; + } + OnComplexClip(); + INHERITED::onClipRect( + SkRect::MakeFromIRect(deviceRgn.getBounds()), op, edge_style); +} + void AnalysisCanvas::willSave() { ++saved_stack_size_; INHERITED::willSave(); diff --git a/chromium/skia/ext/analysis_canvas.h b/chromium/skia/ext/analysis_canvas.h index b3e5275c043..abedcaf0e52 100644 --- a/chromium/skia/ext/analysis_canvas.h +++ b/chromium/skia/ext/analysis_canvas.h @@ -18,98 +18,106 @@ namespace skia { class SK_API AnalysisCanvas : public SkCanvas, public SkDrawPictureCallback { public: AnalysisCanvas(int width, int height); - virtual ~AnalysisCanvas(); + ~AnalysisCanvas() override; // Returns true when a SkColor can be used to represent result. bool GetColorIfSolid(SkColor* color) const; - bool HasText() const; void SetForceNotSolid(bool flag); void SetForceNotTransparent(bool flag); // SkDrawPictureCallback override. - virtual bool abortDrawing() OVERRIDE; + bool abortDrawing() override; // SkCanvas overrides. - virtual void clear(SkColor) OVERRIDE; - virtual void drawPaint(const SkPaint& paint) OVERRIDE; - virtual void drawPoints(PointMode, - size_t count, - const SkPoint pts[], - const SkPaint&) OVERRIDE; - virtual void drawOval(const SkRect&, const SkPaint&) OVERRIDE; - virtual void drawRect(const SkRect&, const SkPaint&) OVERRIDE; - virtual void drawRRect(const SkRRect&, const SkPaint&) OVERRIDE; - virtual void drawPath(const SkPath& path, const SkPaint&) OVERRIDE; - virtual void drawBitmap(const SkBitmap&, - SkScalar left, - SkScalar top, - const SkPaint* paint = NULL) OVERRIDE; - virtual void drawBitmapRectToRect(const SkBitmap&, - const SkRect* src, - const SkRect& dst, - const SkPaint* paint, - DrawBitmapRectFlags flags) OVERRIDE; - virtual void drawBitmapMatrix(const SkBitmap&, - const SkMatrix&, - const SkPaint* paint = NULL) OVERRIDE; - virtual void drawBitmapNine(const SkBitmap& bitmap, - const SkIRect& center, - const SkRect& dst, - const SkPaint* paint = NULL) OVERRIDE; - virtual void drawSprite(const SkBitmap&, int left, int top, - const SkPaint* paint = NULL) OVERRIDE; - virtual void drawVertices(VertexMode, - int vertexCount, - const SkPoint vertices[], - const SkPoint texs[], - const SkColor colors[], - SkXfermode*, - const uint16_t indices[], - int indexCount, - const SkPaint&) OVERRIDE; + void clear(SkColor) override; + void drawPaint(const SkPaint& paint) override; + void drawPoints(PointMode, + size_t count, + const SkPoint pts[], + const SkPaint&) override; + void drawOval(const SkRect&, const SkPaint&) override; + void drawRect(const SkRect&, const SkPaint&) override; + void drawRRect(const SkRRect&, const SkPaint&) override; + void drawPath(const SkPath& path, const SkPaint&) override; + void drawBitmap(const SkBitmap&, + SkScalar left, + SkScalar top, + const SkPaint* paint = NULL) override; + void drawBitmapRectToRect(const SkBitmap&, + const SkRect* src, + const SkRect& dst, + const SkPaint* paint, + DrawBitmapRectFlags flags) override; + void drawBitmapMatrix(const SkBitmap&, + const SkMatrix&, + const SkPaint* paint = NULL) override; + void drawBitmapNine(const SkBitmap& bitmap, + const SkIRect& center, + const SkRect& dst, + const SkPaint* paint = NULL) override; + void drawSprite(const SkBitmap&, + int left, + int top, + const SkPaint* paint = NULL) override; + void drawVertices(VertexMode, + int vertexCount, + const SkPoint vertices[], + const SkPoint texs[], + const SkColor colors[], + SkXfermode*, + const uint16_t indices[], + int indexCount, + const SkPaint&) override; protected: - virtual void willSave() OVERRIDE; - virtual SaveLayerStrategy willSaveLayer(const SkRect*, - const SkPaint*, - SaveFlags) OVERRIDE; - virtual void willRestore() OVERRIDE; - - virtual void onClipRect(const SkRect& rect, - SkRegion::Op op, - ClipEdgeStyle edge_style) OVERRIDE; - virtual void onClipRRect(const SkRRect& rrect, - SkRegion::Op op, - ClipEdgeStyle edge_style) OVERRIDE; - virtual void onClipPath(const SkPath& path, - SkRegion::Op op, - ClipEdgeStyle edge_style) OVERRIDE; - - virtual void onDrawText(const void* text, - size_t byteLength, - SkScalar x, - SkScalar y, - const SkPaint&) OVERRIDE; - virtual void onDrawPosText(const void* text, - size_t byteLength, - const SkPoint pos[], - const SkPaint&) OVERRIDE; - virtual void onDrawPosTextH(const void* text, - size_t byteLength, - const SkScalar xpos[], - SkScalar constY, - const SkPaint&) OVERRIDE; - virtual void onDrawTextOnPath(const void* text, - size_t byteLength, - const SkPath& path, - const SkMatrix* matrix, - const SkPaint&) OVERRIDE; - virtual void onDrawDRRect(const SkRRect& outer, - const SkRRect& inner, - const SkPaint&) OVERRIDE; - -private: + void willSave() override; + SaveLayerStrategy willSaveLayer(const SkRect*, + const SkPaint*, + SaveFlags) override; + void willRestore() override; + + void onClipRect(const SkRect& rect, + SkRegion::Op op, + ClipEdgeStyle edge_style) override; + void onClipRRect(const SkRRect& rrect, + SkRegion::Op op, + ClipEdgeStyle edge_style) override; + void onClipPath(const SkPath& path, + SkRegion::Op op, + ClipEdgeStyle edge_style) override; + void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override; + + void onDrawText(const void* text, + size_t byteLength, + SkScalar x, + SkScalar y, + const SkPaint&) override; + void onDrawPosText(const void* text, + size_t byteLength, + const SkPoint pos[], + const SkPaint&) override; + void onDrawPosTextH(const void* text, + size_t byteLength, + const SkScalar xpos[], + SkScalar constY, + const SkPaint&) override; + void onDrawTextOnPath(const void* text, + size_t byteLength, + const SkPath& path, + const SkMatrix* matrix, + const SkPaint&) override; + void onDrawTextBlob(const SkTextBlob* blob, + SkScalar x, + SkScalar y, + const SkPaint& paint) override; + void onDrawDRRect(const SkRRect& outer, + const SkRRect& inner, + const SkPaint&) override; + + void OnComplexClip(); + + private: typedef SkCanvas INHERITED; int saved_stack_size_; @@ -121,7 +129,7 @@ private: bool is_solid_color_; SkColor color_; bool is_transparent_; - bool has_text_; + int draw_op_count_; }; } // namespace skia diff --git a/chromium/skia/ext/analysis_canvas_unittest.cc b/chromium/skia/ext/analysis_canvas_unittest.cc index 91d9692fb0a..378d27d6569 100644 --- a/chromium/skia/ext/analysis_canvas_unittest.cc +++ b/chromium/skia/ext/analysis_canvas_unittest.cc @@ -6,6 +6,8 @@ #include "skia/ext/analysis_canvas.h" #include "skia/ext/refptr.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkPicture.h" +#include "third_party/skia/include/core/SkPictureRecorder.h" #include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/effects/SkOffsetImageFilter.h" @@ -280,114 +282,75 @@ TEST(AnalysisCanvasTest, SaveLayerRestore) { EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); } -TEST(AnalysisCanvasTest, HasText) { - int width = 200; - int height = 100; +TEST(AnalysisCanvasTest, EarlyOutNotSolid) { + SkTileGridFactory::TileGridInfo tile_grid_info; + tile_grid_info.fTileInterval.set(256, 256); + tile_grid_info.fOffset.setZero(); + tile_grid_info.fMargin.setEmpty(); + SkTileGridFactory factory(tile_grid_info); + SkPictureRecorder recorder; - const char* text = "A"; - size_t byteLength = 1; + // Create a picture with 3 commands, last of which is non-solid. + skia::RefPtr<SkCanvas> record_canvas = + skia::SharePtr(recorder.beginRecording(256, 256, &factory)); + std::string text = "text"; SkPoint point = SkPoint::Make(SkIntToScalar(25), SkIntToScalar(25)); - SkPath path; - path.moveTo(point); - path.lineTo(SkIntToScalar(75), SkIntToScalar(75)); SkPaint paint; - paint.setColor(SK_ColorGRAY); - paint.setTextSize(SkIntToScalar(10)); - - { - skia::AnalysisCanvas canvas(width, height); - // Test after initialization. - EXPECT_FALSE(canvas.HasText()); - // Test drawing anything other than text. - canvas.drawRect(SkRect::MakeWH(width/2, height), paint); - EXPECT_FALSE(canvas.HasText()); - } - { - // Test SkCanvas::drawText. - skia::AnalysisCanvas canvas(width, height); - canvas.drawText(text, byteLength, point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - } - { - // Test SkCanvas::drawPosText. - skia::AnalysisCanvas canvas(width, height); - canvas.drawPosText(text, byteLength, &point, paint); - EXPECT_TRUE(canvas.HasText()); - } - { - // Test SkCanvas::drawPosTextH. - skia::AnalysisCanvas canvas(width, height); - canvas.drawPosTextH(text, byteLength, &point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - } - { - // Test SkCanvas::drawTextOnPathHV. - skia::AnalysisCanvas canvas(width, height); - canvas.drawTextOnPathHV(text, byteLength, path, point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - } - { - // Test SkCanvas::drawTextOnPath. - skia::AnalysisCanvas canvas(width, height); - canvas.drawTextOnPath(text, byteLength, path, NULL, paint); - EXPECT_TRUE(canvas.HasText()); - } - { - // Text under opaque rect. - skia::AnalysisCanvas canvas(width, height); - canvas.drawText(text, byteLength, point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - canvas.drawRect(SkRect::MakeWH(width, height), paint); - EXPECT_FALSE(canvas.HasText()); - } - { - // Text under translucent rect. - skia::AnalysisCanvas canvas(width, height); - canvas.drawText(text, byteLength, point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - SkPaint translucentPaint; - translucentPaint.setColor(0x88FFFFFF); - canvas.drawRect(SkRect::MakeWH(width, height), translucentPaint); - EXPECT_TRUE(canvas.HasText()); - } - { - // Text under rect in clear mode. - skia::AnalysisCanvas canvas(width, height); - canvas.drawText(text, byteLength, point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - SkPaint clearModePaint; - clearModePaint.setXfermodeMode(SkXfermode::kClear_Mode); - canvas.drawRect(SkRect::MakeWH(width, height), clearModePaint); - EXPECT_FALSE(canvas.HasText()); - } - { - // Clear. - skia::AnalysisCanvas canvas(width, height); - canvas.drawText(text, byteLength, point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - canvas.clear(SK_ColorGRAY); - EXPECT_FALSE(canvas.HasText()); - } - { - // Text inside clip region. - skia::AnalysisCanvas canvas(width, height); - canvas.clipRect(SkRect::MakeWH(100, 100)); - canvas.drawText(text, byteLength, point.fX, point.fY, paint); - EXPECT_TRUE(canvas.HasText()); - } - { - // Text outside clip region. - skia::AnalysisCanvas canvas(width, height); - canvas.clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); - canvas.drawText(text, byteLength, point.fX, point.fY, paint); - // Analysis device does not do any clipping. - // So even when text is outside the clip region, - // it is marked as having the text. - // TODO(alokp): We may be able to do some trivial rejection. - EXPECT_TRUE(canvas.HasText()); - } + paint.setColor(SkColorSetARGB(255, 255, 255, 255)); + paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); + + record_canvas->drawRect(SkRect::MakeWH(256, 256), paint); + record_canvas->drawRect(SkRect::MakeWH(256, 256), paint); + record_canvas->drawText( + text.c_str(), text.length(), point.fX, point.fY, paint); + + skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); + + // Draw the picture into the analysis canvas, using the canvas as a callback + // as well. + skia::AnalysisCanvas canvas(256, 256); + picture->draw(&canvas, &canvas); + + // Ensure that canvas is not solid. + SkColor output_color; + EXPECT_FALSE(canvas.GetColorIfSolid(&output_color)); + + // Verify that we aborted drawing. + EXPECT_TRUE(canvas.abortDrawing()); + +} + +TEST(AnalysisCanvasTest, ClipComplexRegion) { + skia::AnalysisCanvas canvas(255, 255); + + SkPath path; + path.moveTo(0, 0); + path.lineTo(128, 50); + path.lineTo(255, 0); + path.lineTo(255, 255); + path.lineTo(0, 255); + SkIRect pathBounds = path.getBounds().round(); + SkRegion region; + region.setPath(path, SkRegion(pathBounds)); + + SkColor outputColor; + SolidColorFill(canvas); + canvas.clipRegion(region); + EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); + + canvas.save(); + EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); + + canvas.clipRegion(region); + EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); + + canvas.restore(); + EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); + + SolidColorFill(canvas); + EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor)); } } // namespace skia diff --git a/chromium/skia/ext/benchmarking_canvas.cc b/chromium/skia/ext/benchmarking_canvas.cc index b0a3082c5ed..64d3f6c4369 100644 --- a/chromium/skia/ext/benchmarking_canvas.cc +++ b/chromium/skia/ext/benchmarking_canvas.cc @@ -29,8 +29,7 @@ public: setProxy(canvas_.get()); } - virtual ~TimingCanvas() { - } + ~TimingCanvas() override {} double GetTime(size_t index) { TimingsMap::const_iterator timing_info = timings_map_.find(index); @@ -40,150 +39,174 @@ public: } // SkCanvas overrides. - virtual void willSave() OVERRIDE { + void willSave() override { AutoStamper stamper(this); SkProxyCanvas::willSave(); } - virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, - const SkPaint* paint, - SaveFlags flags) OVERRIDE { + SaveLayerStrategy willSaveLayer(const SkRect* bounds, + const SkPaint* paint, + SaveFlags flags) override { AutoStamper stamper(this); return SkProxyCanvas::willSaveLayer(bounds, paint, flags); } - virtual void willRestore() OVERRIDE { + void willRestore() override { AutoStamper stamper(this); SkProxyCanvas::willRestore(); } - virtual void drawPaint(const SkPaint& paint) OVERRIDE { + void drawPaint(const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::drawPaint(paint); } - virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], - const SkPaint& paint) OVERRIDE { + void drawPoints(PointMode mode, + size_t count, + const SkPoint pts[], + const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::drawPoints(mode, count, pts, paint); } - virtual void drawOval(const SkRect& rect, const SkPaint& paint) OVERRIDE { + void drawOval(const SkRect& rect, const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::drawOval(rect, paint); } - virtual void drawRect(const SkRect& rect, const SkPaint& paint) OVERRIDE { + void drawRect(const SkRect& rect, const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::drawRect(rect, paint); } - virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) OVERRIDE { + void drawRRect(const SkRRect& rrect, const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::drawRRect(rrect, paint); } - virtual void drawPath(const SkPath& path, const SkPaint& paint) OVERRIDE { + void drawPath(const SkPath& path, const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::drawPath(path, paint); } - virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, - const SkPaint* paint = NULL) OVERRIDE { + void drawBitmap(const SkBitmap& bitmap, + SkScalar left, + SkScalar top, + const SkPaint* paint = NULL) override { AutoStamper stamper(this); SkProxyCanvas::drawBitmap(bitmap, left, top, paint); } - virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, - const SkRect& dst, - const SkPaint* paint, - DrawBitmapRectFlags flags) OVERRIDE { + void drawBitmapRectToRect(const SkBitmap& bitmap, + const SkRect* src, + const SkRect& dst, + const SkPaint* paint, + DrawBitmapRectFlags flags) override { AutoStamper stamper(this); SkProxyCanvas::drawBitmapRectToRect(bitmap, src, dst, paint, flags); } - virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, - const SkPaint* paint = NULL) OVERRIDE { + void drawBitmapMatrix(const SkBitmap& bitmap, + const SkMatrix& m, + const SkPaint* paint = NULL) override { AutoStamper stamper(this); SkProxyCanvas::drawBitmapMatrix(bitmap, m, paint); } - virtual void drawSprite(const SkBitmap& bitmap, int left, int top, - const SkPaint* paint = NULL) OVERRIDE { + void drawSprite(const SkBitmap& bitmap, + int left, + int top, + const SkPaint* paint = NULL) override { AutoStamper stamper(this); SkProxyCanvas::drawSprite(bitmap, left, top, paint); } - virtual void drawVertices(VertexMode vmode, int vertexCount, - const SkPoint vertices[], const SkPoint texs[], - const SkColor colors[], SkXfermode* xmode, - const uint16_t indices[], int indexCount, - const SkPaint& paint) OVERRIDE { + void drawVertices(VertexMode vmode, + int vertexCount, + const SkPoint vertices[], + const SkPoint texs[], + const SkColor colors[], + SkXfermode* xmode, + const uint16_t indices[], + int indexCount, + const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::drawVertices(vmode, vertexCount, vertices, texs, colors, xmode, indices, indexCount, paint); } - virtual void drawData(const void* data, size_t length) OVERRIDE { + void drawData(const void* data, size_t length) override { AutoStamper stamper(this); SkProxyCanvas::drawData(data, length); } protected: - virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, - SkScalar y, const SkPaint& paint) OVERRIDE { + void onDrawText(const void* text, + size_t byteLength, + SkScalar x, + SkScalar y, + const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::onDrawText(text, byteLength, x, y, paint); } - virtual void onDrawPosText(const void* text, size_t byteLength, - const SkPoint pos[], - const SkPaint& paint) OVERRIDE { + void onDrawPosText(const void* text, + size_t byteLength, + const SkPoint pos[], + const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::onDrawPosText(text, byteLength, pos, paint); } - virtual void onDrawPosTextH(const void* text, size_t byteLength, - const SkScalar xpos[], SkScalar constY, - const SkPaint& paint) OVERRIDE { + void onDrawPosTextH(const void* text, + size_t byteLength, + const SkScalar xpos[], + SkScalar constY, + const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::onDrawPosTextH(text, byteLength, xpos, constY, paint); } - virtual void onDrawTextOnPath(const void* text, size_t byteLength, - const SkPath& path, const SkMatrix* matrix, - const SkPaint& paint) OVERRIDE { + void onDrawTextOnPath(const void* text, + size_t byteLength, + const SkPath& path, + const SkMatrix* matrix, + const SkPaint& paint) override { AutoStamper stamper(this); SkProxyCanvas::onDrawTextOnPath(text, byteLength, path, matrix, paint); } - virtual void onClipRect(const SkRect& rect, SkRegion::Op op, - ClipEdgeStyle edge_style) OVERRIDE { + void onClipRect(const SkRect& rect, + SkRegion::Op op, + ClipEdgeStyle edge_style) override { AutoStamper stamper(this); SkProxyCanvas::onClipRect(rect, op, edge_style); } - virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, - ClipEdgeStyle edge_style) OVERRIDE { + void onClipRRect(const SkRRect& rrect, + SkRegion::Op op, + ClipEdgeStyle edge_style) override { AutoStamper stamper(this); SkProxyCanvas::onClipRRect(rrect, op, edge_style); } - virtual void onClipPath(const SkPath& path, SkRegion::Op op, - ClipEdgeStyle edge_style) OVERRIDE { + void onClipPath(const SkPath& path, + SkRegion::Op op, + ClipEdgeStyle edge_style) override { AutoStamper stamper(this); SkProxyCanvas::onClipPath(path, op, edge_style); } - virtual void onClipRegion(const SkRegion& region, - SkRegion::Op op) OVERRIDE { + void onClipRegion(const SkRegion& region, SkRegion::Op op) override { AutoStamper stamper(this); SkProxyCanvas::onClipRegion(region, op); } - virtual void onDrawPicture(const SkPicture* picture) OVERRIDE { + void onDrawPicture(const SkPicture* picture, + const SkMatrix* matrix, + const SkPaint* paint) override { AutoStamper stamper(this); - SkProxyCanvas::onDrawPicture(picture); + SkProxyCanvas::onDrawPicture(picture, matrix, paint); } private: diff --git a/chromium/skia/ext/benchmarking_canvas.h b/chromium/skia/ext/benchmarking_canvas.h index 7ef82049b2c..50289a5746b 100644 --- a/chromium/skia/ext/benchmarking_canvas.h +++ b/chromium/skia/ext/benchmarking_canvas.h @@ -17,7 +17,7 @@ class TimingCanvas; class SK_API BenchmarkingCanvas : public SkNWayCanvas { public: BenchmarkingCanvas(int width, int height); - virtual ~BenchmarkingCanvas(); + ~BenchmarkingCanvas() override; // Returns the number of draw commands executed on this canvas. size_t CommandCount() const; diff --git a/chromium/skia/ext/bitmap_platform_device_cairo.cc b/chromium/skia/ext/bitmap_platform_device_cairo.cc index f6858306e63..6d5d77c01e7 100644 --- a/chromium/skia/ext/bitmap_platform_device_cairo.cc +++ b/chromium/skia/ext/bitmap_platform_device_cairo.cc @@ -169,7 +169,7 @@ BitmapPlatformDevice::~BitmapPlatformDevice() { SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const SkImageInfo& info, Usage /*usage*/) { - SkASSERT(info.colorType() == kPMColor_SkColorType); + SkASSERT(info.colorType() == kN32_SkColorType); return BitmapPlatformDevice::Create(info.width(), info.height(), info.isOpaque()); } diff --git a/chromium/skia/ext/bitmap_platform_device_cairo.h b/chromium/skia/ext/bitmap_platform_device_cairo.h index 6952e9a6bf4..29321110b84 100644 --- a/chromium/skia/ext/bitmap_platform_device_cairo.h +++ b/chromium/skia/ext/bitmap_platform_device_cairo.h @@ -85,16 +85,16 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { // Overridden from SkBaseDevice: virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, - const SkClipStack&) OVERRIDE; + const SkClipStack&) override; // Overridden from PlatformDevice: - virtual cairo_t* BeginPlatformPaint() OVERRIDE; + virtual cairo_t* BeginPlatformPaint() override; virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, - const PlatformRect* src_rect) OVERRIDE; + const PlatformRect* src_rect) override; protected: virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, - Usage usage) OVERRIDE; + Usage usage) override; private: static BitmapPlatformDevice* Create(int width, int height, bool is_opaque, diff --git a/chromium/skia/ext/bitmap_platform_device_mac.cc b/chromium/skia/ext/bitmap_platform_device_mac.cc index f30a405a268..5204468bce9 100644 --- a/chromium/skia/ext/bitmap_platform_device_mac.cc +++ b/chromium/skia/ext/bitmap_platform_device_mac.cc @@ -110,7 +110,7 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context, data = CGBitmapContextGetData(context); bitmap.setPixels(data); } else { - if (!bitmap.allocPixels()) + if (!bitmap.tryAllocPixels()) return NULL; data = bitmap.getPixels(); } @@ -239,7 +239,7 @@ void BitmapPlatformDevice::DrawToNativeContext(CGContextRef context, int x, SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const SkImageInfo& info, Usage /*usage*/) { - SkASSERT(info.colorType() == kPMColor_SkColorType); + SkASSERT(info.colorType() == kN32_SkColorType); return BitmapPlatformDevice::CreateAndClear(info.width(), info.height(), info.isOpaque()); } @@ -271,7 +271,7 @@ bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { if (RasterDeviceTooBigToAllocate(width, height)) return false; - if (!bitmap_.allocN32Pixels(width, height, is_opaque)) + if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque)) return false; if (!is_opaque) diff --git a/chromium/skia/ext/bitmap_platform_device_mac.h b/chromium/skia/ext/bitmap_platform_device_mac.h index 665356f7a34..dc78562ebef 100644 --- a/chromium/skia/ext/bitmap_platform_device_mac.h +++ b/chromium/skia/ext/bitmap_platform_device_mac.h @@ -48,23 +48,25 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice int width, int height, bool is_opaque); - virtual ~BitmapPlatformDevice(); + ~BitmapPlatformDevice() override; // PlatformDevice overrides - virtual CGContextRef GetBitmapContext() OVERRIDE; - virtual void DrawToNativeContext(CGContextRef context, int x, int y, - const CGRect* src_rect) OVERRIDE; + CGContextRef GetBitmapContext() override; + void DrawToNativeContext(CGContextRef context, + int x, + int y, + const CGRect* src_rect) override; // SkBaseDevice overrides - virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, - const SkClipStack&) OVERRIDE; + void setMatrixClip(const SkMatrix& transform, + const SkRegion& region, + const SkClipStack&) override; protected: BitmapPlatformDevice(CGContextRef context, const SkBitmap& bitmap); - virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, - Usage usage) OVERRIDE; + SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) override; private: void ReleaseBitmapContext(); diff --git a/chromium/skia/ext/bitmap_platform_device_skia.cc b/chromium/skia/ext/bitmap_platform_device_skia.cc index a105c77496d..ee44e26af82 100644 --- a/chromium/skia/ext/bitmap_platform_device_skia.cc +++ b/chromium/skia/ext/bitmap_platform_device_skia.cc @@ -10,7 +10,7 @@ namespace skia { BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, bool is_opaque) { SkBitmap bitmap; - if (bitmap.allocN32Pixels(width, height, is_opaque)) { + if (bitmap.tryAllocN32Pixels(width, height, is_opaque)) { // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it // is not opaque. if (!is_opaque) @@ -37,7 +37,7 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); if (data) bitmap.setPixels(data); - else if (!bitmap.allocPixels()) + else if (!bitmap.tryAllocPixels()) return NULL; return new BitmapPlatformDevice(bitmap); @@ -53,7 +53,7 @@ BitmapPlatformDevice::~BitmapPlatformDevice() { SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const SkImageInfo& info, Usage /*usage*/) { - SkASSERT(info.colorType() == kPMColor_SkColorType); + SkASSERT(info.colorType() == kN32_SkColorType); return BitmapPlatformDevice::Create(info.width(), info.height(), info.isOpaque()); } @@ -85,7 +85,7 @@ PlatformBitmap::~PlatformBitmap() { } bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { - if (!bitmap_.allocN32Pixels(width, height, is_opaque)) + if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque)) return false; surface_ = bitmap_.getPixels(); diff --git a/chromium/skia/ext/bitmap_platform_device_skia.h b/chromium/skia/ext/bitmap_platform_device_skia.h index f1bb375c88f..f670dea2d11 100644 --- a/chromium/skia/ext/bitmap_platform_device_skia.h +++ b/chromium/skia/ext/bitmap_platform_device_skia.h @@ -42,13 +42,13 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { explicit BitmapPlatformDevice(const SkBitmap& other); virtual ~BitmapPlatformDevice(); - virtual PlatformSurface BeginPlatformPaint() OVERRIDE; + virtual PlatformSurface BeginPlatformPaint() override; virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, - const PlatformRect* src_rect) OVERRIDE; + const PlatformRect* src_rect) override; protected: virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, - Usage usage) OVERRIDE; + Usage usage) override; private: DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); diff --git a/chromium/skia/ext/bitmap_platform_device_win.cc b/chromium/skia/ext/bitmap_platform_device_win.cc index f526488cba2..e10a6de3bcd 100644 --- a/chromium/skia/ext/bitmap_platform_device_win.cc +++ b/chromium/skia/ext/bitmap_platform_device_win.cc @@ -272,7 +272,7 @@ const SkBitmap& BitmapPlatformDevice::onAccessBitmap() { SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const SkImageInfo& info, Usage /*usage*/) { - SkASSERT(info.colorType() == kPMColor_SkColorType); + SkASSERT(info.colorType() == kN32_SkColorType); return BitmapPlatformDevice::CreateAndClear(info.width(), info.height(), info.isOpaque()); } diff --git a/chromium/skia/ext/bitmap_platform_device_win.h b/chromium/skia/ext/bitmap_platform_device_win.h index 78f801e794f..a8b7d8394ae 100644 --- a/chromium/skia/ext/bitmap_platform_device_win.h +++ b/chromium/skia/ext/bitmap_platform_device_win.h @@ -51,25 +51,25 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice // PlatformDevice overrides // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The // bitmap DC is lazy created. - virtual PlatformSurface BeginPlatformPaint() OVERRIDE; - virtual void EndPlatformPaint() OVERRIDE; + virtual PlatformSurface BeginPlatformPaint() override; + virtual void EndPlatformPaint() override; virtual void DrawToNativeContext(HDC dc, int x, int y, - const RECT* src_rect) OVERRIDE; + const RECT* src_rect) override; // Loads the given transform and clipping region into the HDC. This is // overridden from SkBaseDevice. virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, - const SkClipStack&) OVERRIDE; + const SkClipStack&) override; protected: // Flushes the Windows device context so that the pixel data can be accessed // directly by Skia. Overridden from SkBaseDevice, this is called when Skia // starts accessing pixel data. - virtual const SkBitmap& onAccessBitmap() OVERRIDE; + virtual const SkBitmap& onAccessBitmap() override; virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, - Usage usage) OVERRIDE; + Usage usage) override; private: // Private constructor. diff --git a/chromium/skia/ext/convolver.cc b/chromium/skia/ext/convolver.cc index 4b40ffd2cea..092fefaa9b6 100644 --- a/chromium/skia/ext/convolver.cc +++ b/chromium/skia/ext/convolver.cc @@ -362,13 +362,10 @@ struct ConvolveProcs { void SetupSIMD(ConvolveProcs *procs) { #ifdef SIMD_SSE2 - base::CPU cpu; - if (cpu.has_sse2()) { - procs->extra_horizontal_reads = 3; - procs->convolve_vertically = &ConvolveVertically_SSE2; - procs->convolve_4rows_horizontally = &Convolve4RowsHorizontally_SSE2; - procs->convolve_horizontally = &ConvolveHorizontally_SSE2; - } + procs->extra_horizontal_reads = 3; + procs->convolve_vertically = &ConvolveVertically_SSE2; + procs->convolve_4rows_horizontally = &Convolve4RowsHorizontally_SSE2; + procs->convolve_horizontally = &ConvolveHorizontally_SSE2; #elif defined SIMD_MIPS_DSPR2 procs->extra_horizontal_reads = 3; procs->convolve_vertically = &ConvolveVertically_mips_dspr2; diff --git a/chromium/skia/ext/convolver.h b/chromium/skia/ext/convolver.h index dd99a7272f9..ace8c217b3e 100644 --- a/chromium/skia/ext/convolver.h +++ b/chromium/skia/ext/convolver.h @@ -9,7 +9,6 @@ #include <vector> #include "base/basictypes.h" -#include "base/cpu.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkTypes.h" diff --git a/chromium/skia/ext/event_tracer_impl.cc b/chromium/skia/ext/event_tracer_impl.cc index 4974b0064af..53ddf2b8c3f 100644 --- a/chromium/skia/ext/event_tracer_impl.cc +++ b/chromium/skia/ext/event_tracer_impl.cc @@ -9,23 +9,20 @@ namespace skia { class SkChromiumEventTracer: public SkEventTracer { - virtual const uint8_t* getCategoryGroupEnabled(const char* name) OVERRIDE; - virtual const char* getCategoryGroupName( - const uint8_t* categoryEnabledFlag) OVERRIDE; - virtual SkEventTracer::Handle - addTraceEvent(char phase, - const uint8_t* categoryEnabledFlag, - const char* name, - uint64_t id, - int32_t numArgs, - const char** argNames, - const uint8_t* argTypes, - const uint64_t* argValues, - uint8_t flags) OVERRIDE; - virtual void - updateTraceEventDuration(const uint8_t* categoryEnabledFlag, - const char *name, - SkEventTracer::Handle handle) OVERRIDE; + const uint8_t* getCategoryGroupEnabled(const char* name) override; + const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override; + SkEventTracer::Handle addTraceEvent(char phase, + const uint8_t* categoryEnabledFlag, + const char* name, + uint64_t id, + int32_t numArgs, + const char** argNames, + const uint8_t* argTypes, + const uint64_t* argValues, + uint8_t flags) override; + void updateTraceEventDuration(const uint8_t* categoryEnabledFlag, + const char* name, + SkEventTracer::Handle handle) override; }; const uint8_t* diff --git a/chromium/skia/ext/image_operations.cc b/chromium/skia/ext/image_operations.cc index bcf01dd0355..bf063d7719b 100644 --- a/chromium/skia/ext/image_operations.cc +++ b/chromium/skia/ext/image_operations.cc @@ -495,7 +495,7 @@ SkBitmap ImageOperations::ResizeBasic(const SkBitmap& source, (method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD)); SkAutoLockPixels locker(source); - if (!source.readyToDraw() || source.config() != SkBitmap::kARGB_8888_Config) + if (!source.readyToDraw() || source.colorType() != kN32_SkColorType) return SkBitmap(); ResizeFilter filter(method, source.width(), source.height(), diff --git a/chromium/skia/ext/image_operations_unittest.cc b/chromium/skia/ext/image_operations_unittest.cc index 9a3dcffb22d..61527310c38 100644 --- a/chromium/skia/ext/image_operations_unittest.cc +++ b/chromium/skia/ext/image_operations_unittest.cc @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/file_util.h" +#include "base/files/file_util.h" #include "base/strings/string_util.h" #include "skia/ext/image_operations.h" #include "testing/gtest/include/gtest/gtest.h" @@ -535,7 +535,7 @@ TEST(ImageOperations, ResizeShouldAverageColors) { // For each method, downscale by 16 in each dimension, // and check each tested pixel against the expected average color. - bool all_methods_ok ALLOW_UNUSED = true; + bool all_methods_ok = true; for (size_t method_index = 0; method_index < arraysize(tested_methods); @@ -550,11 +550,11 @@ TEST(ImageOperations, ResizeShouldAverageColors) { } } -#if DEBUG_BITMAP_GENERATION if (!all_methods_ok) { +#if DEBUG_BITMAP_GENERATION SaveBitmapToPNG(src, "/tmp/ResizeShouldAverageColors_src.png"); - } #endif // #if DEBUG_BITMAP_GENERATION + } } diff --git a/chromium/skia/ext/lazy_pixel_ref.h b/chromium/skia/ext/lazy_pixel_ref.h index b3f704d2f19..2335fdfb39e 100644 --- a/chromium/skia/ext/lazy_pixel_ref.h +++ b/chromium/skia/ext/lazy_pixel_ref.h @@ -15,7 +15,7 @@ namespace skia { class SK_API LazyPixelRef : public SkPixelRef { public: explicit LazyPixelRef(const SkImageInfo& info); - virtual ~LazyPixelRef(); + ~LazyPixelRef() override; struct PrepareParams { // Clipping rect for this pixel ref. diff --git a/chromium/skia/ext/opacity_draw_filter.h b/chromium/skia/ext/opacity_draw_filter.h index a2a686cad8d..7d11d689e16 100644 --- a/chromium/skia/ext/opacity_draw_filter.h +++ b/chromium/skia/ext/opacity_draw_filter.h @@ -19,8 +19,8 @@ namespace skia { class SK_API OpacityDrawFilter : public SkDrawFilter { public: OpacityDrawFilter(float opacity, bool disable_image_filtering); - virtual ~OpacityDrawFilter(); - virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE; + ~OpacityDrawFilter() override; + bool filter(SkPaint* paint, SkDrawFilter::Type type) override; private: int alpha_; diff --git a/chromium/skia/ext/paint_simplifier.cc b/chromium/skia/ext/paint_simplifier.cc deleted file mode 100644 index 683f92ec00a..00000000000 --- a/chromium/skia/ext/paint_simplifier.cc +++ /dev/null @@ -1,58 +0,0 @@ -// 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 "skia/ext/paint_simplifier.h" -#include "third_party/skia/include/core/SkPaint.h" -#include "third_party/skia/include/core/SkShader.h" - -namespace skia { -namespace { - -bool PaintHasBitmap(const SkPaint &paint) { - SkShader* shader = paint.getShader(); - if (!shader) - return false; - - if (shader->asAGradient(NULL) == SkShader::kNone_GradientType) - return false; - - return shader->asABitmap(NULL, NULL, NULL) != SkShader::kNone_BitmapType; -} - -} // namespace - -PaintSimplifier::PaintSimplifier() - : INHERITED() { - -} - -PaintSimplifier::~PaintSimplifier() { - -} - -bool PaintSimplifier::filter(SkPaint* paint, Type type) { - // Bitmaps are expensive. Skip draw if type has a bitmap. - if (type == kBitmap_Type || PaintHasBitmap(*paint)) - return false; - - // Preserve a modicum of text quality; black & white text is - // just too blocky, even during a fling. - if (type != kText_Type) { - paint->setAntiAlias(false); - } - paint->setSubpixelText(false); - paint->setLCDRenderText(false); - - paint->setMaskFilter(NULL); - - // Uncomment this line to shade simplified tiles pink during debugging. - //paint->setColor(SkColorSetRGB(255, 127, 127)); - - return true; -} - - -} // namespace skia - - diff --git a/chromium/skia/ext/paint_simplifier.h b/chromium/skia/ext/paint_simplifier.h deleted file mode 100644 index 0eff833727d..00000000000 --- a/chromium/skia/ext/paint_simplifier.h +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -#ifndef SKIA_EXT_PAINT_SIMPLIFIER_H -#define SKIA_EXT_PAINT_SIMPLIFIER_H - -#include "base/values.h" -#include "third_party/skia/include/core/SkDrawFilter.h" - -class SkPaint; - -namespace skia { - -/* - When installed on a SkCanvas, reduces the quality of all draws - to that canvas. This improves rasterization speed during flings. - We turn off blurs, filters, and antialiasing *except for* text. -*/ -class SK_API PaintSimplifier : public SkDrawFilter { - public: - PaintSimplifier(); - virtual ~PaintSimplifier(); - virtual bool filter(SkPaint*, Type) OVERRIDE; - - private: - typedef SkDrawFilter INHERITED; -}; - -} // namespace skia - -#endif // SKIA_EXT_PAINT_SIMPLIFIER_H - diff --git a/chromium/skia/ext/pixel_ref_utils.cc b/chromium/skia/ext/pixel_ref_utils.cc index 85a4e4896ab..4e85f7ad331 100644 --- a/chromium/skia/ext/pixel_ref_utils.cc +++ b/chromium/skia/ext/pixel_ref_utils.cc @@ -51,8 +51,8 @@ class GatherPixelRefDevice : public SkBitmapDevice { DiscardablePixelRefSet* pixel_ref_set) : SkBitmapDevice(bm), pixel_ref_set_(pixel_ref_set) {} - virtual void clear(SkColor color) SK_OVERRIDE {} - virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) SK_OVERRIDE { + void clear(SkColor color) override {} + void drawPaint(const SkDraw& draw, const SkPaint& paint) override { SkBitmap bitmap; if (GetBitmapFromPaint(paint, &bitmap)) { SkRect clip_rect = SkRect::Make(draw.fRC->getBounds()); @@ -60,11 +60,11 @@ class GatherPixelRefDevice : public SkBitmapDevice { } } - virtual void drawPoints(const SkDraw& draw, - SkCanvas::PointMode mode, - size_t count, - const SkPoint points[], - const SkPaint& paint) SK_OVERRIDE { + void drawPoints(const SkDraw& draw, + SkCanvas::PointMode mode, + size_t count, + const SkPoint points[], + const SkPaint& paint) override { SkBitmap bitmap; if (!GetBitmapFromPaint(paint, &bitmap)) return; @@ -87,9 +87,9 @@ class GatherPixelRefDevice : public SkBitmapDevice { GatherPixelRefDevice::drawRect(draw, bounds, paint); } - virtual void drawRect(const SkDraw& draw, - const SkRect& rect, - const SkPaint& paint) SK_OVERRIDE { + void drawRect(const SkDraw& draw, + const SkRect& rect, + const SkPaint& paint) override { SkBitmap bitmap; if (GetBitmapFromPaint(paint, &bitmap)) { SkRect mapped_rect; @@ -98,21 +98,21 @@ class GatherPixelRefDevice : public SkBitmapDevice { AddBitmap(bitmap, mapped_rect); } } - virtual void drawOval(const SkDraw& draw, - const SkRect& rect, - const SkPaint& paint) SK_OVERRIDE { + void drawOval(const SkDraw& draw, + const SkRect& rect, + const SkPaint& paint) override { GatherPixelRefDevice::drawRect(draw, rect, paint); } - virtual void drawRRect(const SkDraw& draw, - const SkRRect& rect, - const SkPaint& paint) SK_OVERRIDE { + void drawRRect(const SkDraw& draw, + const SkRRect& rect, + const SkPaint& paint) override { GatherPixelRefDevice::drawRect(draw, rect.rect(), paint); } - virtual void drawPath(const SkDraw& draw, - const SkPath& path, - const SkPaint& paint, - const SkMatrix* pre_path_matrix, - bool path_is_mutable) SK_OVERRIDE { + void drawPath(const SkDraw& draw, + const SkPath& path, + const SkPaint& paint, + const SkMatrix* pre_path_matrix, + bool path_is_mutable) override { SkBitmap bitmap; if (!GetBitmapFromPaint(paint, &bitmap)) return; @@ -126,10 +126,10 @@ class GatherPixelRefDevice : public SkBitmapDevice { GatherPixelRefDevice::drawRect(draw, final_rect, paint); } - virtual void drawBitmap(const SkDraw& draw, - const SkBitmap& bitmap, - const SkMatrix& matrix, - const SkPaint& paint) SK_OVERRIDE { + void drawBitmap(const SkDraw& draw, + const SkBitmap& bitmap, + const SkMatrix& matrix, + const SkPaint& paint) override { SkMatrix total_matrix; total_matrix.setConcat(*draw.fMatrix, matrix); @@ -142,22 +142,22 @@ class GatherPixelRefDevice : public SkBitmapDevice { if (GetBitmapFromPaint(paint, &paint_bitmap)) AddBitmap(paint_bitmap, mapped_rect); } - virtual void drawBitmapRect(const SkDraw& draw, - const SkBitmap& bitmap, - const SkRect* src_or_null, - const SkRect& dst, - const SkPaint& paint, - SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE { + void drawBitmapRect(const SkDraw& draw, + const SkBitmap& bitmap, + const SkRect* src_or_null, + const SkRect& dst, + const SkPaint& paint, + SkCanvas::DrawBitmapRectFlags flags) override { SkRect bitmap_rect = SkRect::MakeWH(bitmap.width(), bitmap.height()); SkMatrix matrix; matrix.setRectToRect(bitmap_rect, dst, SkMatrix::kFill_ScaleToFit); GatherPixelRefDevice::drawBitmap(draw, bitmap, matrix, paint); } - virtual void drawSprite(const SkDraw& draw, - const SkBitmap& bitmap, - int x, - int y, - const SkPaint& paint) SK_OVERRIDE { + void drawSprite(const SkDraw& draw, + const SkBitmap& bitmap, + int x, + int y, + const SkPaint& paint) override { // Sprites aren't affected by current matrix, so we can't reuse drawRect. SkMatrix matrix; matrix.setTranslate(x, y); @@ -171,12 +171,12 @@ class GatherPixelRefDevice : public SkBitmapDevice { if (GetBitmapFromPaint(paint, &paint_bitmap)) AddBitmap(paint_bitmap, mapped_rect); } - virtual void drawText(const SkDraw& draw, - const void* text, - size_t len, - SkScalar x, - SkScalar y, - const SkPaint& paint) SK_OVERRIDE { + void drawText(const SkDraw& draw, + const void* text, + size_t len, + SkScalar x, + SkScalar y, + const SkPaint& paint) override { SkBitmap bitmap; if (!GetBitmapFromPaint(paint, &bitmap)) return; @@ -218,13 +218,13 @@ class GatherPixelRefDevice : public SkBitmapDevice { GatherPixelRefDevice::drawRect(draw, bounds, paint); } - virtual void drawPosText(const SkDraw& draw, - const void* text, - size_t len, - const SkScalar pos[], - SkScalar const_y, - int scalars_per_pos, - const SkPaint& paint) SK_OVERRIDE { + void drawPosText(const SkDraw& draw, + const void* text, + size_t len, + const SkScalar pos[], + int scalars_per_pos, + const SkPoint& offset, + const SkPaint& paint) override { SkBitmap bitmap; if (!GetBitmapFromPaint(paint, &bitmap)) return; @@ -235,21 +235,13 @@ class GatherPixelRefDevice : public SkBitmapDevice { // Similar to SkDraw asserts. SkASSERT(scalars_per_pos == 1 || scalars_per_pos == 2); - SkPoint min_point; - SkPoint max_point; - if (scalars_per_pos == 1) { - min_point.set(pos[0], const_y); - max_point.set(pos[0], const_y); - } else if (scalars_per_pos == 2) { - min_point.set(pos[0], const_y + pos[1]); - max_point.set(pos[0], const_y + pos[1]); - } + SkPoint min_point = SkPoint::Make(offset.x() + pos[0], + offset.y() + (2 == scalars_per_pos ? pos[1] : 0)); + SkPoint max_point = min_point; for (size_t i = 0; i < len; ++i) { - SkScalar x = pos[i * scalars_per_pos]; - SkScalar y = const_y; - if (scalars_per_pos == 2) - y += pos[i * scalars_per_pos + 1]; + SkScalar x = offset.x() + pos[i * scalars_per_pos]; + SkScalar y = offset.y() + (2 == scalars_per_pos ? pos[i * scalars_per_pos + 1] : 0); min_point.set(std::min(x, min_point.x()), std::min(y, min_point.y())); max_point.set(std::max(x, max_point.x()), std::max(y, max_point.y())); @@ -271,12 +263,12 @@ class GatherPixelRefDevice : public SkBitmapDevice { GatherPixelRefDevice::drawRect(draw, bounds, paint); } - virtual void drawTextOnPath(const SkDraw& draw, - const void* text, - size_t len, - const SkPath& path, - const SkMatrix* matrix, - const SkPaint& paint) SK_OVERRIDE { + void drawTextOnPath(const SkDraw& draw, + const void* text, + size_t len, + const SkPath& path, + const SkMatrix* matrix, + const SkPaint& paint) override { SkBitmap bitmap; if (!GetBitmapFromPaint(paint, &bitmap)) return; @@ -294,39 +286,39 @@ class GatherPixelRefDevice : public SkBitmapDevice { GatherPixelRefDevice::drawRect(draw, bounds, paint); } - virtual void drawVertices(const SkDraw& draw, - SkCanvas::VertexMode, - int vertex_count, - const SkPoint verts[], - const SkPoint texs[], - const SkColor colors[], - SkXfermode* xmode, - const uint16_t indices[], - int index_count, - const SkPaint& paint) SK_OVERRIDE { + void drawVertices(const SkDraw& draw, + SkCanvas::VertexMode, + int vertex_count, + const SkPoint verts[], + const SkPoint texs[], + const SkColor colors[], + SkXfermode* xmode, + const uint16_t indices[], + int index_count, + const SkPaint& paint) override { GatherPixelRefDevice::drawPoints( draw, SkCanvas::kPolygon_PointMode, vertex_count, verts, paint); } - virtual void drawDevice(const SkDraw&, - SkBaseDevice*, - int x, - int y, - const SkPaint&) SK_OVERRIDE {} + void drawDevice(const SkDraw&, + SkBaseDevice*, + int x, + int y, + const SkPaint&) override {} protected: - virtual bool onReadPixels(const SkImageInfo& info, - void* pixels, - size_t rowBytes, - int x, - int y) SK_OVERRIDE { + bool onReadPixels(const SkImageInfo& info, + void* pixels, + size_t rowBytes, + int x, + int y) override { return false; } - virtual bool onWritePixels(const SkImageInfo& info, - const void* pixels, - size_t rowBytes, - int x, - int y) SK_OVERRIDE { + bool onWritePixels(const SkImageInfo& info, + const void* pixels, + size_t rowBytes, + int x, + int y) override { return false; } diff --git a/chromium/skia/ext/pixel_ref_utils_unittest.cc b/chromium/skia/ext/pixel_ref_utils_unittest.cc index 1a0ff96ee06..656ef5ce892 100644 --- a/chromium/skia/ext/pixel_ref_utils_unittest.cc +++ b/chromium/skia/ext/pixel_ref_utils_unittest.cc @@ -10,7 +10,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkFlattenableBuffers.h" #include "third_party/skia/include/core/SkPictureRecorder.h" #include "third_party/skia/include/core/SkPixelRef.h" #include "third_party/skia/include/core/SkPoint.h" @@ -31,30 +30,22 @@ class TestDiscardableShader : public SkShader { CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_); } - TestDiscardableShader(SkFlattenableReadBuffer& flattenable_buffer) { - SkOrderedReadBuffer& buffer = - static_cast<SkOrderedReadBuffer&>(flattenable_buffer); - SkReader32* reader = buffer.getReader32(); - - reader->skip(-4); - uint32_t toSkip = reader->readU32(); - reader->skip(toSkip); - + TestDiscardableShader(SkReadBuffer& buffer) { CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_); } - virtual SkShader::BitmapType asABitmap(SkBitmap* bitmap, - SkMatrix* matrix, - TileMode xy[2]) const OVERRIDE { + SkShader::BitmapType asABitmap(SkBitmap* bitmap, + SkMatrix* matrix, + TileMode xy[2]) const override { if (bitmap) *bitmap = bitmap_; return SkShader::kDefault_BitmapType; } // not indended to return an actual context. Just need to supply this. - virtual size_t contextSize() const OVERRIDE { - return sizeof(SkShader::Context); - } + size_t contextSize() const override { return sizeof(SkShader::Context); } + + void flatten(SkWriteBuffer&) const override {} SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(TestDiscardableShader); @@ -62,12 +53,14 @@ class TestDiscardableShader : public SkShader { SkBitmap bitmap_; }; -void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { - const SkImageInfo info = { - size.width(), size.height(), kPMColor_SkColorType, kPremul_SkAlphaType - }; +#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING +SkFlattenable* TestDiscardableShader::CreateProc(SkReadBuffer&) { + return new TestDiscardableShader; +} +#endif - bitmap->allocPixels(info); +void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { + bitmap->allocN32Pixels(size.width(), size.height()); bitmap->pixelRef()->setImmutable(); bitmap->pixelRef()->setURI(uri); } diff --git a/chromium/skia/ext/platform_canvas_unittest.cc b/chromium/skia/ext/platform_canvas_unittest.cc index a9ae148af4f..3d8ef00fe63 100644 --- a/chromium/skia/ext/platform_canvas_unittest.cc +++ b/chromium/skia/ext/platform_canvas_unittest.cc @@ -20,12 +20,20 @@ #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/core/SkColorPriv.h" #include "third_party/skia/include/core/SkPixelRef.h" namespace skia { namespace { +bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { + // For masking out the alpha values. + static uint32_t alpha_mask = + static_cast<uint32_t>(SK_A32_MASK) << SK_A32_SHIFT; + return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); +} + // Return true if the canvas is filled to canvas_color, and contains a single // rectangle filled to rect_color. This function ignores the alpha channel, // since Windows will sometimes clear the alpha channel when drawing, and we @@ -37,21 +45,16 @@ bool VerifyRect(const PlatformCanvas& canvas, const SkBitmap& bitmap = device->accessBitmap(false); SkAutoLockPixels lock(bitmap); - // For masking out the alpha values. - uint32_t alpha_mask = 0xFF << SK_A32_SHIFT; - for (int cur_y = 0; cur_y < bitmap.height(); cur_y++) { for (int cur_x = 0; cur_x < bitmap.width(); cur_x++) { if (cur_x >= x && cur_x < x + w && cur_y >= y && cur_y < y + h) { // Inside the square should be rect_color - if ((*bitmap.getAddr32(cur_x, cur_y) | alpha_mask) != - (rect_color | alpha_mask)) + if (!IsOfColor(bitmap, cur_x, cur_y, rect_color)) return false; } else { // Outside the square should be canvas_color - if ((*bitmap.getAddr32(cur_x, cur_y) | alpha_mask) != - (canvas_color | alpha_mask)) + if (!IsOfColor(bitmap, cur_x, cur_y, canvas_color)) return false; } } @@ -60,12 +63,6 @@ bool VerifyRect(const PlatformCanvas& canvas, } #if !defined(OS_MACOSX) -bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { - // For masking out the alpha values. - static uint32_t alpha_mask = 0xFF << SK_A32_SHIFT; - return (*bitmap.getAddr32(x, y) | alpha_mask) == (color | alpha_mask); -} - // Return true if canvas has something that passes for a rounded-corner // rectangle. Basically, we're just checking to make sure that the pixels in the // middle are of rect_color and pixels in the corners are of canvas_color. @@ -413,8 +410,8 @@ TEST(PlatformBitmapTest, PlatformBitmap) { EXPECT_EQ(kHeight, platform_bitmap->GetBitmap().height()); EXPECT_LE(static_cast<size_t>(platform_bitmap->GetBitmap().width()*4), platform_bitmap->GetBitmap().rowBytes()); - EXPECT_EQ(SkBitmap::kARGB_8888_Config, // Same for all platforms. - platform_bitmap->GetBitmap().config()); + EXPECT_EQ(kN32_SkColorType, // Same for all platforms. + platform_bitmap->GetBitmap().colorType()); EXPECT_TRUE(platform_bitmap->GetBitmap().lockPixelsAreWritable()); EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->isLocked()); EXPECT_EQ(1, platform_bitmap->GetBitmap().pixelRef()->getRefCnt()); diff --git a/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc b/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc index 3f00bac68b0..9fe386b7c56 100644 --- a/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc +++ b/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc @@ -7,8 +7,8 @@ #include <vector> #include "base/basictypes.h" -#include "base/file_util.h" #include "base/files/file_path.h" +#include "base/files/file_util.h" #include "base/logging.h" #include "base/time/time.h" #include "skia/ext/convolver.h" diff --git a/chromium/skia/ext/skia_utils_ios.mm b/chromium/skia/ext/skia_utils_ios.mm index 6f4814a2dd3..3ae962cd59e 100644 --- a/chromium/skia/ext/skia_utils_ios.mm +++ b/chromium/skia/ext/skia_utils_ios.mm @@ -18,13 +18,7 @@ SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) { if (!image) return bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, - size.width, - size.height, - 0, - is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); - - if (!bitmap.allocPixels()) + if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque)) return bitmap; void* data = bitmap.getPixels(); diff --git a/chromium/skia/ext/skia_utils_mac.h b/chromium/skia/ext/skia_utils_mac.h index 6a0efdebfab..b60f9e8ad53 100644 --- a/chromium/skia/ext/skia_utils_mac.h +++ b/chromium/skia/ext/skia_utils_mac.h @@ -108,17 +108,41 @@ SK_API NSImage* SkBitmapToNSImage(const SkBitmap& icon); // Converts a SkCanvas temporarily to a CGContext class SK_API SkiaBitLocker { public: + // TODO(ccameron): delete this constructor explicit SkiaBitLocker(SkCanvas* canvas); + SkiaBitLocker(SkCanvas* canvas, + const SkIRect& userClipRect, + SkScalar bitmapScaleFactor = 1); ~SkiaBitLocker(); CGContextRef cgContext(); + bool hasEmptyClipRegion() const; private: void releaseIfNeeded(); + SkIRect computeDirtyRect(); + SkCanvas* canvas_; + + // If the user specified a clip rect it would draw into then the locker may + // skip the step of searching for a rect bounding the pixels that the user + // has drawn into. + bool userClipRectSpecified_; + CGContextRef cgContext_; SkBitmap bitmap_; SkIPoint bitmapOffset_; + SkScalar bitmapScaleFactor_; + + // True if we are drawing to |canvas_|'s SkBaseDevice's bits directly through + // |bitmap_|. Otherwise, the bits in |bitmap_| are our allocation and need to + // be copied over to |canvas_|. bool useDeviceBits_; + + // True if |bitmap_| is a dummy 1x1 bitmap allocated for the sake of creating + // a non-NULL CGContext (it is invalid to use a NULL CGContext), and will not + // be copied to |canvas_|. This will happen if |canvas_|'s clip region is + // empty. + bool bitmapIsDummy_; }; diff --git a/chromium/skia/ext/skia_utils_mac.mm b/chromium/skia/ext/skia_utils_mac.mm index 4f7ddd98f2d..dd8f560e1d9 100644 --- a/chromium/skia/ext/skia_utils_mac.mm +++ b/chromium/skia/ext/skia_utils_mac.mm @@ -27,7 +27,7 @@ SkBitmap NSImageOrNSImageRepToSkBitmapWithColorSpace( DCHECK((image != 0) ^ (image_rep != 0)); SkBitmap bitmap; - if (!bitmap.allocN32Pixels(size.width, size.height, is_opaque)) + if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque)) return bitmap; // Return |bitmap| which should respond true to isNull(). @@ -267,81 +267,111 @@ NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { SkiaBitLocker::SkiaBitLocker(SkCanvas* canvas) : canvas_(canvas), - cgContext_(0) { + userClipRectSpecified_(false), + cgContext_(0), + bitmapScaleFactor_(1), + useDeviceBits_(false), + bitmapIsDummy_(false) { +} + +SkiaBitLocker::SkiaBitLocker(SkCanvas* canvas, + const SkIRect& userClipRect, + SkScalar bitmapScaleFactor) + : canvas_(canvas), + userClipRectSpecified_(true), + cgContext_(0), + bitmapScaleFactor_(bitmapScaleFactor), + useDeviceBits_(false), + bitmapIsDummy_(false) { + canvas_->save(); + canvas_->clipRect(SkRect::MakeFromIRect(userClipRect)); } SkiaBitLocker::~SkiaBitLocker() { releaseIfNeeded(); + if (userClipRectSpecified_) + canvas_->restore(); } -// This must be called to balance calls to cgContext -void SkiaBitLocker::releaseIfNeeded() { - if (!cgContext_) - return; - if (useDeviceBits_) { - bitmap_.unlockPixels(); - } else { - // Find the bits that were drawn to. - SkAutoLockPixels lockedPixels(bitmap_); - const uint32_t* pixelBase - = reinterpret_cast<uint32_t*>(bitmap_.getPixels()); - int rowPixels = bitmap_.rowBytesAsPixels(); - int width = bitmap_.width(); - int height = bitmap_.height(); - SkIRect bounds; - bounds.fTop = 0; - int x; - int y = -1; - const uint32_t* pixels = pixelBase; - while (++y < height) { - for (x = 0; x < width; ++x) { - if (pixels[x]) { - bounds.fTop = y; - goto foundTop; - } +SkIRect SkiaBitLocker::computeDirtyRect() { + // If the user specified a clip region, assume that it was tight and that the + // dirty rect is approximately the whole bitmap. + if (userClipRectSpecified_) + return SkIRect::MakeWH(bitmap_.width(), bitmap_.height()); + + // Find the bits that were drawn to. + SkAutoLockPixels lockedPixels(bitmap_); + const uint32_t* pixelBase + = reinterpret_cast<uint32_t*>(bitmap_.getPixels()); + int rowPixels = bitmap_.rowBytesAsPixels(); + int width = bitmap_.width(); + int height = bitmap_.height(); + SkIRect bounds; + bounds.fTop = 0; + int x; + int y = -1; + const uint32_t* pixels = pixelBase; + while (++y < height) { + for (x = 0; x < width; ++x) { + if (pixels[x]) { + bounds.fTop = y; + goto foundTop; } - pixels += rowPixels; } + pixels += rowPixels; + } foundTop: - bounds.fBottom = height; - y = height; - pixels = pixelBase + rowPixels * (y - 1); - while (--y > bounds.fTop) { - for (x = 0; x < width; ++x) { - if (pixels[x]) { - bounds.fBottom = y + 1; - goto foundBottom; - } + bounds.fBottom = height; + y = height; + pixels = pixelBase + rowPixels * (y - 1); + while (--y > bounds.fTop) { + for (x = 0; x < width; ++x) { + if (pixels[x]) { + bounds.fBottom = y + 1; + goto foundBottom; } - pixels -= rowPixels; } + pixels -= rowPixels; + } foundBottom: - bounds.fLeft = 0; - x = -1; - while (++x < width) { - pixels = pixelBase + rowPixels * bounds.fTop; - for (y = bounds.fTop; y < bounds.fBottom; ++y) { - if (pixels[x]) { - bounds.fLeft = x; - goto foundLeft; - } - pixels += rowPixels; + bounds.fLeft = 0; + x = -1; + while (++x < width) { + pixels = pixelBase + rowPixels * bounds.fTop; + for (y = bounds.fTop; y < bounds.fBottom; ++y) { + if (pixels[x]) { + bounds.fLeft = x; + goto foundLeft; } + pixels += rowPixels; } + } foundLeft: - bounds.fRight = width; - x = width; - while (--x > bounds.fLeft) { - pixels = pixelBase + rowPixels * bounds.fTop; - for (y = bounds.fTop; y < bounds.fBottom; ++y) { - if (pixels[x]) { - bounds.fRight = x + 1; - goto foundRight; - } - pixels += rowPixels; + bounds.fRight = width; + x = width; + while (--x > bounds.fLeft) { + pixels = pixelBase + rowPixels * bounds.fTop; + for (y = bounds.fTop; y < bounds.fBottom; ++y) { + if (pixels[x]) { + bounds.fRight = x + 1; + goto foundRight; } + pixels += rowPixels; } + } foundRight: + return bounds; +} + +// This must be called to balance calls to cgContext +void SkiaBitLocker::releaseIfNeeded() { + if (!cgContext_) + return; + if (useDeviceBits_) { + bitmap_.unlockPixels(); + } else if (!bitmapIsDummy_) { + // Find the bits that were drawn to. + SkIRect bounds = computeDirtyRect(); SkBitmap subset; if (!bitmap_.extractSubset(&subset, bounds)) { return; @@ -356,18 +386,27 @@ foundRight: return; canvas_->save(); canvas_->concat(inverse); - canvas_->drawBitmap(subset, bounds.x() + bitmapOffset_.x(), - bounds.y() + bitmapOffset_.y()); + canvas_->translate(bounds.x() + bitmapOffset_.x(), + bounds.y() + bitmapOffset_.y()); + canvas_->scale(1.f / bitmapScaleFactor_, 1.f / bitmapScaleFactor_); + canvas_->drawBitmap(subset, 0, 0); canvas_->restore(); } CGContextRelease(cgContext_); cgContext_ = 0; + useDeviceBits_ = false; + bitmapIsDummy_ = false; } CGContextRef SkiaBitLocker::cgContext() { SkIRect clip_bounds; - if (!canvas_->getClipDeviceBounds(&clip_bounds)) - return 0; // the clip is empty, nothing to draw + if (!canvas_->getClipDeviceBounds(&clip_bounds)) { + // If the clip is empty, then there is nothing to draw. The caller may + // attempt to draw (to-be-clipped) results, so ensure there is a dummy + // non-NULL CGContext to use. + bitmapIsDummy_ = true; + clip_bounds = SkIRect::MakeXYWH(0, 0, 1, 1); + } SkBaseDevice* device = canvas_->getTopDevice(); DCHECK(device); @@ -387,13 +426,21 @@ CGContextRef SkiaBitLocker::cgContext() { // Only draw directly if we have pixels, and we're only rect-clipped. // If not, we allocate an offscreen and draw into that, relying on the // compositing step to apply skia's clip. - useDeviceBits_ = deviceBits.getPixels() && canvas_->isClipRect(); + useDeviceBits_ = deviceBits.getPixels() && + canvas_->isClipRect() && + !bitmapIsDummy_; if (useDeviceBits_) { - if (!deviceBits.extractSubset(&bitmap_, clip_bounds)) + bool result = deviceBits.extractSubset(&bitmap_, clip_bounds); + DCHECK(result); + if (!result) return 0; bitmap_.lockPixels(); } else { - if (!bitmap_.allocN32Pixels(clip_bounds.width(), clip_bounds.height())) + bool result = bitmap_.tryAllocN32Pixels( + SkScalarCeilToInt(bitmapScaleFactor_ * clip_bounds.width()), + SkScalarCeilToInt(bitmapScaleFactor_ * clip_bounds.height())); + DCHECK(result); + if (!result) return 0; bitmap_.eraseColor(0); } @@ -402,11 +449,12 @@ CGContextRef SkiaBitLocker::cgContext() { cgContext_ = CGBitmapContextCreate(bitmap_.getPixels(), bitmap_.width(), bitmap_.height(), 8, bitmap_.rowBytes(), colorSpace, kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst); + DCHECK(cgContext_); SkMatrix matrix = canvas_->getTotalMatrix(); matrix.postTranslate(-SkIntToScalar(bitmapOffset_.x()), -SkIntToScalar(bitmapOffset_.y())); - matrix.postScale(1, -1); + matrix.postScale(bitmapScaleFactor_, -bitmapScaleFactor_); matrix.postTranslate(0, SkIntToScalar(bitmap_.height())); CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix)); @@ -414,4 +462,8 @@ CGContextRef SkiaBitLocker::cgContext() { return cgContext_; } +bool SkiaBitLocker::hasEmptyClipRegion() const { + return canvas_->isClipEmpty(); +} + } // namespace gfx diff --git a/chromium/skia/ext/vector_canvas_unittest.cc b/chromium/skia/ext/vector_canvas_unittest.cc index bd394d6b45f..8785cb4af45 100644 --- a/chromium/skia/ext/vector_canvas_unittest.cc +++ b/chromium/skia/ext/vector_canvas_unittest.cc @@ -9,7 +9,7 @@ #endif #include "base/command_line.h" -#include "base/file_util.h" +#include "base/files/file_util.h" #include "base/path_service.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" diff --git a/chromium/skia/ext/vector_platform_device_emf_win.cc b/chromium/skia/ext/vector_platform_device_emf_win.cc index 31059aff7bd..19e30668d95 100644 --- a/chromium/skia/ext/vector_platform_device_emf_win.cc +++ b/chromium/skia/ext/vector_platform_device_emf_win.cc @@ -510,8 +510,8 @@ void VectorPlatformDeviceEmf::drawPosText(const SkDraw& draw, const void* text, size_t len, const SkScalar pos[], - SkScalar constY, int scalarsPerPos, + const SkPoint& offset, const SkPaint& paint) { SkGDIFontSetup setup; bool useDrawText = true; @@ -519,8 +519,8 @@ void VectorPlatformDeviceEmf::drawPosText(const SkDraw& draw, if (scalarsPerPos == 2 && len >= 2 && SkPaint::kUTF8_TextEncoding != paint.getTextEncoding() && setup.useGDI(hdc_, paint)) { - int startX = SkScalarRoundToInt(pos[0]); - int startY = SkScalarRoundToInt(pos[1] + getAscent(paint)); + int startX = SkScalarRoundToInt(pos[0] + offset.x()); + int startY = SkScalarRoundToInt(pos[1] + offset.y() + getAscent(paint)); const int count = len >> 1; SkAutoSTMalloc<64, INT> storage(count); INT* advances = storage.get(); @@ -552,9 +552,11 @@ void VectorPlatformDeviceEmf::drawPosText(const SkDraw& draw, const char* curr = reinterpret_cast<const char*>(text); const char* stop = curr + len; while (curr < stop) { - SkScalar y = (1 == scalarsPerPos) ? constY : pos[1]; + SkScalar x = offset.x() + pos[0]; + SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[1] : 0); + size_t bytes = bytesPerCodePoint(curr); - drawText(draw, curr, bytes, pos[0], y, paint); + drawText(draw, curr, bytes, x, y, paint); curr += bytes; pos += scalarsPerPos; } @@ -693,18 +695,9 @@ void VectorPlatformDeviceEmf::LoadClipRegion() { LoadClippingRegionToDC(hdc_, clip_region_, t); } -#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG -SkBaseDevice* VectorPlatformDeviceEmf::onCreateCompatibleDevice( - SkBitmap::Config config, int width, int height, bool isOpaque, - Usage /*usage*/) { - SkASSERT(config == SkBitmap::kARGB_8888_Config); - return VectorPlatformDeviceEmf::CreateDevice(width, height, isOpaque, NULL); -} -#endif - SkBaseDevice* VectorPlatformDeviceEmf::onCreateDevice(const SkImageInfo& info, Usage /*usage*/) { - SkASSERT(info.colorType() == kPMColor_SkColorType); + SkASSERT(info.colorType() == kN32_SkColorType); return VectorPlatformDeviceEmf::CreateDevice( info.width(), info.height(), info.isOpaque(), NULL); } @@ -904,7 +897,7 @@ void VectorPlatformDeviceEmf::InternalDrawBitmap(const SkBitmap& bitmap, bitmap_header.bV4AlphaMask = 0xff000000; SkAutoLockPixels lock(bitmap); - SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); + SkASSERT(bitmap.colorType() == kN32_SkColorType); const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels()); if (pixels == NULL) { SkASSERT(false); diff --git a/chromium/skia/ext/vector_platform_device_emf_win.h b/chromium/skia/ext/vector_platform_device_emf_win.h index 844624fc52b..f65390fd9a2 100644 --- a/chromium/skia/ext/vector_platform_device_emf_win.h +++ b/chromium/skia/ext/vector_platform_device_emf_win.h @@ -31,61 +31,56 @@ class VectorPlatformDeviceEmf : public SkBitmapDevice, public PlatformDevice { virtual ~VectorPlatformDeviceEmf(); // PlatformDevice methods - virtual PlatformSurface BeginPlatformPaint() OVERRIDE; + virtual PlatformSurface BeginPlatformPaint() override; virtual void DrawToNativeContext(HDC dc, int x, int y, - const RECT* src_rect) OVERRIDE; + const RECT* src_rect) override; // SkBaseDevice methods. - virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) OVERRIDE; + virtual void drawPaint(const SkDraw& draw, const SkPaint& paint) override; virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count, const SkPoint[], - const SkPaint& paint) OVERRIDE; + const SkPaint& paint) override; virtual void drawRect(const SkDraw& draw, const SkRect& r, - const SkPaint& paint) OVERRIDE; + const SkPaint& paint) override; virtual void drawRRect(const SkDraw&, const SkRRect& rr, - const SkPaint& paint) OVERRIDE; + const SkPaint& paint) override; virtual void drawPath(const SkDraw& draw, const SkPath& path, const SkPaint& paint, const SkMatrix* prePathMatrix = NULL, - bool pathIsMutable = false) OVERRIDE; + bool pathIsMutable = false) override; virtual void drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, const SkPaint& paint, - SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE; + SkCanvas::DrawBitmapRectFlags flags) override; virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, const SkMatrix& matrix, - const SkPaint& paint) OVERRIDE; + const SkPaint& paint) override; virtual void drawSprite(const SkDraw& draw, const SkBitmap& bitmap, - int x, int y, const SkPaint& paint) OVERRIDE; + int x, int y, const SkPaint& paint) override; virtual void drawText(const SkDraw& draw, const void* text, size_t len, - SkScalar x, SkScalar y, const SkPaint& paint) OVERRIDE; + SkScalar x, SkScalar y, const SkPaint& paint) override; virtual void drawPosText(const SkDraw& draw, const void* text, size_t len, - const SkScalar pos[], SkScalar constY, - int scalarsPerPos, const SkPaint& paint) OVERRIDE; + const SkScalar pos[], int scalarsPerPos, + const SkPoint& offset, const SkPaint& paint) override; virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len, const SkPath& path, const SkMatrix* matrix, - const SkPaint& paint) OVERRIDE; + const SkPaint& paint) override; virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, int vertexCount, const SkPoint verts[], const SkPoint texs[], const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, - const SkPaint& paint) OVERRIDE; + const SkPaint& paint) override; virtual void drawDevice(const SkDraw& draw, SkBaseDevice*, int x, int y, - const SkPaint&) OVERRIDE; + const SkPaint&) override; virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, - const SkClipStack&) OVERRIDE; + const SkClipStack&) override; void LoadClipRegion(); protected: -#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG - virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, - int height, bool isOpaque, - Usage usage) OVERRIDE; -#endif virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, - Usage usage) OVERRIDE; + Usage usage) override; private: // Applies the SkPaint's painting properties in the current GDI context, if diff --git a/chromium/skia/ext/vector_platform_device_skia.h b/chromium/skia/ext/vector_platform_device_skia.h index cf392c05da3..528eac9814e 100644 --- a/chromium/skia/ext/vector_platform_device_skia.h +++ b/chromium/skia/ext/vector_platform_device_skia.h @@ -23,29 +23,29 @@ class VectorPlatformDeviceSkia : public SkPDFDevice, public PlatformDevice { SK_API VectorPlatformDeviceSkia(const SkISize& pageSize, const SkISize& contentSize, const SkMatrix& initialTransform); - virtual ~VectorPlatformDeviceSkia(); + ~VectorPlatformDeviceSkia() override; // PlatformDevice methods. - virtual bool SupportsPlatformPaint() OVERRIDE; + bool SupportsPlatformPaint() override; - virtual PlatformSurface BeginPlatformPaint() OVERRIDE; - virtual void EndPlatformPaint() OVERRIDE; + PlatformSurface BeginPlatformPaint() override; + void EndPlatformPaint() override; #if defined(OS_WIN) virtual void DrawToNativeContext(HDC dc, int x, int y, - const RECT* src_rect) OVERRIDE; + const RECT* src_rect) override; #elif defined(OS_MACOSX) - virtual void DrawToNativeContext(CGContext* context, - int x, - int y, - const CGRect* src_rect) OVERRIDE; - virtual CGContextRef GetBitmapContext() OVERRIDE; + void DrawToNativeContext(CGContext* context, + int x, + int y, + const CGRect* src_rect) override; + CGContextRef GetBitmapContext() override; #elif defined(OS_POSIX) virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, - const PlatformRect* src_rect) OVERRIDE; + const PlatformRect* src_rect) override; #endif private: |