summaryrefslogtreecommitdiff
path: root/chromium/skia/ext
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-31 16:33:43 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-02-06 16:33:22 +0000
commitda51f56cc21233c2d30f0fe0d171727c3102b2e0 (patch)
tree4e579ab70ce4b19bee7984237f3ce05a96d59d83 /chromium/skia/ext
parentc8c2d1901aec01e934adf561a9fdf0cc776cdef8 (diff)
downloadqtwebengine-chromium-da51f56cc21233c2d30f0fe0d171727c3102b2e0.tar.gz
BASELINE: Update Chromium to 65.0.3525.40
Also imports missing submodules Change-Id: I36901b7c6a325cda3d2c10cedb2186c25af3b79b Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/skia/ext')
-rw-r--r--chromium/skia/ext/SkMemory_new_handler.cpp48
-rw-r--r--chromium/skia/ext/analysis_canvas.cc509
-rw-r--r--chromium/skia/ext/analysis_canvas.h141
-rw-r--r--chromium/skia/ext/analysis_canvas_unittest.cc456
-rw-r--r--chromium/skia/ext/raster_handle_allocator_win.cc2
-rw-r--r--chromium/skia/ext/skia_commit_hash.h2
-rw-r--r--chromium/skia/ext/skia_utils_base.cc62
-rw-r--r--chromium/skia/ext/skia_utils_base_unittest.cc142
-rw-r--r--chromium/skia/ext/skia_utils_mac.h5
-rw-r--r--chromium/skia/ext/skia_utils_mac.mm15
-rw-r--r--chromium/skia/ext/texture_handle.h7
11 files changed, 98 insertions, 1291 deletions
diff --git a/chromium/skia/ext/SkMemory_new_handler.cpp b/chromium/skia/ext/SkMemory_new_handler.cpp
index c90a892182e..42ce498a9c9 100644
--- a/chromium/skia/ext/SkMemory_new_handler.cpp
+++ b/chromium/skia/ext/SkMemory_new_handler.cpp
@@ -8,6 +8,7 @@
#include "base/process/memory.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkTypes.h"
+#include "third_party/skia/include/private/SkMalloc.h"
#if defined(OS_WIN)
#include <windows.h>
@@ -60,14 +61,14 @@ static void* prevent_overcommit(int fill, size_t size, void* p) {
return p;
}
-void* sk_malloc_throw(size_t size) {
- return prevent_overcommit(0x42, size, throw_on_failure(size, malloc(size)));
+static void* malloc_throw(size_t size) {
+ return prevent_overcommit(0x42, size, throw_on_failure(size, malloc(size)));
}
-static void* sk_malloc_nothrow(size_t size) {
- // TODO(b.kelemen): we should always use UncheckedMalloc but currently it
- // doesn't work as intended everywhere.
- void* result;
+static void* malloc_nothrow(size_t size) {
+ // TODO(b.kelemen): we should always use UncheckedMalloc but currently it
+ // doesn't work as intended everywhere.
+ void* result;
#if defined(OS_IOS)
result = malloc(size);
#else
@@ -80,21 +81,14 @@ static void* sk_malloc_nothrow(size_t size) {
return result;
}
-void* sk_malloc_flags(size_t size, unsigned flags) {
- if (flags & SK_MALLOC_THROW) {
- return sk_malloc_throw(size);
- }
- return sk_malloc_nothrow(size);
+static void* calloc_throw(size_t size) {
+ return prevent_overcommit(0, size, throw_on_failure(size, calloc(size, 1)));
}
-void* sk_calloc_throw(size_t size) {
- return prevent_overcommit(0, size, throw_on_failure(size, calloc(size, 1)));
-}
-
-void* sk_calloc(size_t size) {
- // TODO(b.kelemen): we should always use UncheckedCalloc but currently it
- // doesn't work as intended everywhere.
- void* result;
+static void* calloc_nothrow(size_t size) {
+ // TODO(b.kelemen): we should always use UncheckedCalloc but currently it
+ // doesn't work as intended everywhere.
+ void* result;
#if defined(OS_IOS)
result = calloc(1, size);
#else
@@ -106,3 +100,19 @@ void* sk_calloc(size_t size) {
}
return result;
}
+
+void* sk_malloc_flags(size_t size, unsigned flags) {
+ if (flags & SK_MALLOC_ZERO_INITIALIZE) {
+ if (flags & SK_MALLOC_THROW) {
+ return calloc_throw(size);
+ } else {
+ return calloc_nothrow(size);
+ }
+ } else {
+ if (flags & SK_MALLOC_THROW) {
+ return malloc_throw(size);
+ } else {
+ return malloc_nothrow(size);
+ }
+ }
+}
diff --git a/chromium/skia/ext/analysis_canvas.cc b/chromium/skia/ext/analysis_canvas.cc
deleted file mode 100644
index cd98ee75c95..00000000000
--- a/chromium/skia/ext/analysis_canvas.cc
+++ /dev/null
@@ -1,509 +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/analysis_canvas.h"
-#include "base/logging.h"
-#include "base/trace_event/trace_event.h"
-#include "third_party/skia/include/core/SkPath.h"
-#include "third_party/skia/include/core/SkRRect.h"
-#include "third_party/skia/include/core/SkRegion.h"
-#include "third_party/skia/include/core/SkShader.h"
-
-namespace {
-
-const int kNoLayer = -1;
-
-bool ActsLikeClear(SkBlendMode mode, unsigned src_alpha) {
- switch (mode) {
- case SkBlendMode::kClear:
- return true;
- case SkBlendMode::kSrc:
- case SkBlendMode::kSrcIn:
- case SkBlendMode::kDstIn:
- case SkBlendMode::kSrcOut:
- case SkBlendMode::kDstATop:
- return src_alpha == 0;
- case SkBlendMode::kDstOut:
- return src_alpha == 0xFF;
- default:
- return false;
- }
-}
-
-bool IsSolidColorPaint(const SkPaint& paint) {
- SkBlendMode blendmode = paint.getBlendMode();
-
- // Paint is solid color if the following holds:
- // - Alpha is 1.0, style is fill, and there are no special effects
- // - Xfer mode is either kSrc or kSrcOver (kSrcOver is equivalent
- // to kSrc if source alpha is 1.0, which is already checked).
- return (
- paint.getAlpha() == 255 && !paint.getShader() && !paint.getLooper() &&
- !paint.getMaskFilter() && !paint.getColorFilter() &&
- !paint.getImageFilter() && paint.getStyle() == SkPaint::kFill_Style &&
- (blendmode == SkBlendMode::kSrc || blendmode == SkBlendMode::kSrcOver));
-}
-
-// Returns true if the specified drawn_rect will cover the entire canvas, and
-// that the canvas is not clipped (i.e. it covers ALL of the canvas).
-bool IsFullQuad(SkCanvas* canvas, const SkRect& drawn_rect) {
- if (!canvas->isClipRect())
- return false;
-
- SkIRect clip_irect;
- if (!canvas->getDeviceClipBounds(&clip_irect))
- return false;
-
- // if the clip is smaller than the canvas, we're partly clipped, so abort.
- if (!clip_irect.contains(SkIRect::MakeSize(canvas->getBaseLayerSize())))
- return false;
-
- const SkMatrix& matrix = canvas->getTotalMatrix();
- // If the transform results in a non-axis aligned
- // rect, then be conservative and return false.
- if (!matrix.rectStaysRect())
- return false;
-
- SkRect device_rect;
- matrix.mapRect(&device_rect, drawn_rect);
- SkRect clip_rect;
- clip_rect.set(clip_irect);
- return device_rect.contains(clip_rect);
-}
-
-} // namespace
-
-namespace skia {
-
-void AnalysisCanvas::SetForceNotSolid(bool flag) {
- is_forced_not_solid_ = flag;
- if (is_forced_not_solid_)
- is_solid_color_ = false;
-}
-
-void AnalysisCanvas::SetForceNotTransparent(bool flag) {
- is_forced_not_transparent_ = flag;
- if (is_forced_not_transparent_)
- is_transparent_ = false;
-}
-
-void AnalysisCanvas::onDrawPaint(const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawPaint");
- SkRect rect;
- if (getLocalClipBounds(&rect))
- drawRect(rect, paint);
-}
-
-void AnalysisCanvas::onDrawPoints(SkCanvas::PointMode mode,
- size_t count,
- const SkPoint points[],
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawPoints");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawRect");
- // This recreates the early-exit logic in SkCanvas.cpp.
- SkRect scratch;
- if (paint.canComputeFastBounds() &&
- quickReject(paint.computeFastBounds(rect, &scratch))) {
- TRACE_EVENT_INSTANT0("disabled-by-default-skia", "Quick reject.",
- TRACE_EVENT_SCOPE_THREAD);
- ++rejected_op_count_;
- return;
- }
-
- // An extra no-op check SkCanvas.cpp doesn't do.
- if (paint.nothingToDraw()) {
- TRACE_EVENT_INSTANT0("disabled-by-default-skia", "Nothing to draw.",
- TRACE_EVENT_SCOPE_THREAD);
- return;
- }
-
- bool does_cover_canvas = IsFullQuad(this, rect);
-
- SkBlendMode blendmode = paint.getBlendMode();
-
- // This canvas will become transparent if the following holds:
- // - The quad is a full tile quad
- // - We're not in "forced not transparent" mode
- // - Transfer mode is clear (0 color, 0 alpha)
- //
- // If the paint alpha is not 0, or if the transfrer mode is
- // not src, then this canvas will not be transparent.
- //
- // In all other cases, we keep the current transparent value
- if (does_cover_canvas && !is_forced_not_transparent_ &&
- ActsLikeClear(blendmode, paint.getAlpha())) {
- is_transparent_ = true;
- } else if (paint.getAlpha() != 0 || blendmode != SkBlendMode::kSrc) {
- is_transparent_ = false;
- }
-
- // This bitmap is solid if and only if the following holds.
- // Note that this might be overly conservative:
- // - We're not in "forced not solid" mode
- // - Paint is solid color
- // - The quad is a full tile quad
- if (!is_forced_not_solid_ && IsSolidColorPaint(paint) && does_cover_canvas) {
- is_solid_color_ = true;
- color_ = paint.getColor();
- } else {
- is_solid_color_ = false;
- }
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawOval");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawArc(const SkRect& oval,
- SkScalar startAngle,
- SkScalar sweepAngle,
- bool useCenter,
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawArc");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawRRect(const SkRRect& rr, const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawRRect");
- // This should add the SkRRect to an SkPath, and call
- // drawPath, but since drawPath ignores the SkPath, just
- // do the same work here.
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawPath");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawBitmap(const SkBitmap& bitmap,
- SkScalar left,
- SkScalar top,
- const SkPaint*) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawBitmap");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawBitmapRect(const SkBitmap&,
- const SkRect* src,
- const SkRect& dst,
- const SkPaint* paint,
- SrcRectConstraint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawBitmapRect");
- // Call drawRect to determine transparency,
- // but reset solid color to false.
- SkPaint tmpPaint;
- if (!paint)
- paint = &tmpPaint;
- drawRect(dst, *paint);
- is_solid_color_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawBitmapNine(const SkBitmap& bitmap,
- const SkIRect& center,
- const SkRect& dst,
- const SkPaint* paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawBitmapNine");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawImage(const SkImage*,
- SkScalar left,
- SkScalar top,
- const SkPaint*) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawImage");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawImageRect(const SkImage*,
- const SkRect* src,
- const SkRect& dst,
- const SkPaint* paint,
- SrcRectConstraint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawImageRect");
- // Call drawRect to determine transparency,
- // but reset solid color to false.
- SkPaint tmpPaint;
- if (!paint)
- paint = &tmpPaint;
- drawRect(dst, *paint);
- is_solid_color_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawText(const void* text,
- size_t len,
- SkScalar x,
- SkScalar y,
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawText");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawPosText(const void* text,
- size_t byteLength,
- const SkPoint pos[],
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawPosText");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawPosTextH(const void* text,
- size_t byteLength,
- const SkScalar xpos[],
- SkScalar constY,
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawPosTextH");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawTextOnPath(const void* text,
- size_t len,
- const SkPath& path,
- const SkMatrix* matrix,
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawTextOnPath");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawTextBlob(const SkTextBlob* blob,
- SkScalar x,
- SkScalar y,
- const SkPaint &paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawTextBlob");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawDRRect(const SkRRect& outer,
- const SkRRect& inner,
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawDRRect");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-void AnalysisCanvas::onDrawVerticesObject(const SkVertices* vertices,
- SkBlendMode bmode,
- const SkPaint& paint) {
- TRACE_EVENT0("disabled-by-default-skia",
- "AnalysisCanvas::onDrawVerticesObject");
- is_solid_color_ = false;
- is_transparent_ = false;
- ++draw_op_count_;
-}
-
-AnalysisCanvas::AnalysisCanvas(int width, int height)
- : INHERITED(width, height),
- saved_stack_size_(0),
- force_not_solid_stack_level_(kNoLayer),
- force_not_transparent_stack_level_(kNoLayer),
- is_forced_not_solid_(false),
- is_forced_not_transparent_(false),
- is_solid_color_(true),
- color_(SK_ColorTRANSPARENT),
- is_transparent_(true),
- draw_op_count_(0),
- rejected_op_count_(0) {}
-
-AnalysisCanvas::~AnalysisCanvas() = default;
-
-bool AnalysisCanvas::GetColorIfSolid(SkColor* color) const {
- if (is_transparent_) {
- *color = SK_ColorTRANSPARENT;
- return true;
- }
- if (is_solid_color_) {
- *color = color_;
- return true;
- }
- return false;
-}
-
-bool AnalysisCanvas::abort() {
- // Early out as soon as we have more than 1 draw op or 5 rejected ops.
- // TODO(vmpstr): Investigate if 1 and 5 are the correct metrics here. We need
- // to balance the amount of time we spend analyzing vs how many tiles would be
- // solid if the numbers were higher.
- if (draw_op_count_ > 1 || rejected_op_count_ > 5) {
- TRACE_EVENT0("disabled-by-default-skia",
- "AnalysisCanvas::abort() -- aborting");
- // 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::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) {
- 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);
- }
-}
-
-void AnalysisCanvas::onClipRect(const SkRect& rect,
- SkClipOp op,
- ClipEdgeStyle edge_style) {
- INHERITED::onClipRect(rect, op, edge_style);
-}
-
-void AnalysisCanvas::onClipPath(const SkPath& path,
- SkClipOp op,
- ClipEdgeStyle edge_style) {
- OnComplexClip();
- INHERITED::onClipRect(path.getBounds(), op, edge_style);
-}
-
-bool doesCoverCanvas(const SkRRect& rr,
- const SkMatrix& total_matrix,
- const SkIRect& clip_device_bounds) {
- // We cannot handle non axis aligned rectangles at the moment.
- if (!total_matrix.isScaleTranslate()) {
- return false;
- }
-
- SkMatrix inverse;
- if (!total_matrix.invert(&inverse)) {
- return false;
- }
-
- SkRect clip_rect = SkRect::Make(clip_device_bounds);
- inverse.mapRectScaleTranslate(&clip_rect, clip_rect);
- return rr.contains(clip_rect);
-}
-
-void AnalysisCanvas::onClipRRect(const SkRRect& rrect,
- SkClipOp op,
- ClipEdgeStyle edge_style) {
- SkIRect clip_device_bounds;
- if (getDeviceClipBounds(&clip_device_bounds) &&
- doesCoverCanvas(rrect, getTotalMatrix(), clip_device_bounds)) {
- // If the canvas is fully contained within the clip, it is as if we weren't
- // clipped at all, so bail early.
- return;
- }
-
- OnComplexClip();
- INHERITED::onClipRect(rrect.getBounds(), op, edge_style);
-}
-
-void AnalysisCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp 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();
-}
-
-SkCanvas::SaveLayerStrategy AnalysisCanvas::getSaveLayerStrategy(
- const SaveLayerRec& rec) {
- const SkPaint* paint = rec.fPaint;
-
- ++saved_stack_size_;
-
- SkIRect canvas_ibounds = SkIRect::MakeSize(this->getBaseLayerSize());
- SkRect canvas_bounds;
- canvas_bounds.set(canvas_ibounds);
-
- // If after we draw to the saved layer, we have to blend with the current
- // layer, then we can conservatively say that the canvas will not be of
- // solid color.
- if ((paint && !IsSolidColorPaint(*paint)) ||
- (rec.fBounds && !rec.fBounds->contains(canvas_bounds))) {
- if (force_not_solid_stack_level_ == kNoLayer) {
- force_not_solid_stack_level_ = saved_stack_size_;
- SetForceNotSolid(true);
- }
- }
-
- // If after we draw to the save layer, we have to blend with the current
- // layer using any part of the current layer's alpha, then we can
- // conservatively say that the canvas will not be transparent.
- SkBlendMode blendmode = SkBlendMode::kSrc;
- if (paint)
- blendmode = paint->getBlendMode();
- if (blendmode != SkBlendMode::kDst) {
- if (force_not_transparent_stack_level_ == kNoLayer) {
- force_not_transparent_stack_level_ = saved_stack_size_;
- SetForceNotTransparent(true);
- }
- }
-
- INHERITED::getSaveLayerStrategy(rec);
- // Actually saving a layer here could cause a new bitmap to be created
- // and real rendering to occur.
- return kNoLayer_SaveLayerStrategy;
-}
-
-void AnalysisCanvas::willRestore() {
- DCHECK(saved_stack_size_);
- if (saved_stack_size_) {
- --saved_stack_size_;
- if (saved_stack_size_ < force_not_solid_stack_level_) {
- SetForceNotSolid(false);
- force_not_solid_stack_level_ = kNoLayer;
- }
- if (saved_stack_size_ < force_not_transparent_stack_level_) {
- SetForceNotTransparent(false);
- force_not_transparent_stack_level_ = kNoLayer;
- }
- }
-
- INHERITED::willRestore();
-}
-
-} // namespace skia
-
-
diff --git a/chromium/skia/ext/analysis_canvas.h b/chromium/skia/ext/analysis_canvas.h
deleted file mode 100644
index 1e582af0b40..00000000000
--- a/chromium/skia/ext/analysis_canvas.h
+++ /dev/null
@@ -1,141 +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_ANALYSIS_CANVAS_H_
-#define SKIA_EXT_ANALYSIS_CANVAS_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "base/compiler_specific.h"
-#include "third_party/skia/include/core/SkPicture.h"
-#include "third_party/skia/include/utils/SkNoDrawCanvas.h"
-
-namespace skia {
-
-// Does not render anything, but gathers statistics about a region
-// (specified as a clip rectangle) of an SkPicture as the picture is
-// played back through it.
-// To use: play a picture into the canvas, and then check result.
-class SK_API AnalysisCanvas final : public SkNoDrawCanvas,
- public SkPicture::AbortCallback {
- public:
- AnalysisCanvas(int width, int height);
- ~AnalysisCanvas() override;
-
- // Returns true when a SkColor can be used to represent result.
- bool GetColorIfSolid(SkColor* color) const;
-
- void SetForceNotSolid(bool flag);
- void SetForceNotTransparent(bool flag);
-
- // SkPicture::AbortCallback override.
- bool abort() override;
-
- // SkCanvas overrides.
- void onDrawPaint(const SkPaint& paint) override;
- void onDrawPoints(PointMode,
- size_t count,
- const SkPoint pts[],
- const SkPaint&) override;
- void onDrawOval(const SkRect&, const SkPaint&) override;
- void onDrawArc(const SkRect&,
- SkScalar startAngle,
- SkScalar sweepAngle,
- bool useCenter,
- const SkPaint&) override;
- void onDrawRect(const SkRect&, const SkPaint&) override;
- void onDrawRRect(const SkRRect&, const SkPaint&) override;
- void onDrawPath(const SkPath& path, const SkPaint&) override;
- void onDrawBitmap(const SkBitmap&,
- SkScalar left,
- SkScalar top,
- const SkPaint* paint = NULL) override;
- void onDrawBitmapRect(const SkBitmap&,
- const SkRect* src,
- const SkRect& dst,
- const SkPaint* paint,
- SrcRectConstraint) override;
- void onDrawBitmapNine(const SkBitmap& bitmap,
- const SkIRect& center,
- const SkRect& dst,
- const SkPaint* paint = NULL) override;
- void onDrawImage(const SkImage*,
- SkScalar left,
- SkScalar top,
- const SkPaint* paint = NULL) override;
- void onDrawImageRect(const SkImage*,
- const SkRect* src,
- const SkRect& dst,
- const SkPaint* paint,
- SrcRectConstraint) override;
- void onDrawVerticesObject(const SkVertices*,
- SkBlendMode,
- const SkPaint&) override;
-
- protected:
- void willSave() override;
- SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
- void willRestore() override;
-
- void onClipRect(const SkRect& rect,
- SkClipOp op,
- ClipEdgeStyle edge_style) override;
- void onClipRRect(const SkRRect& rrect,
- SkClipOp op,
- ClipEdgeStyle edge_style) override;
- void onClipPath(const SkPath& path,
- SkClipOp op,
- ClipEdgeStyle edge_style) override;
- void onClipRegion(const SkRegion& deviceRgn, SkClipOp 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 SkNoDrawCanvas INHERITED;
-
- int saved_stack_size_;
- int force_not_solid_stack_level_;
- int force_not_transparent_stack_level_;
-
- bool is_forced_not_solid_;
- bool is_forced_not_transparent_;
- bool is_solid_color_;
- SkColor color_;
- bool is_transparent_;
- int draw_op_count_;
- int rejected_op_count_;
-};
-
-} // namespace skia
-
-#endif // SKIA_EXT_ANALYSIS_CANVAS_H_
-
diff --git a/chromium/skia/ext/analysis_canvas_unittest.cc b/chromium/skia/ext/analysis_canvas_unittest.cc
deleted file mode 100644
index a26a1bab2db..00000000000
--- a/chromium/skia/ext/analysis_canvas_unittest.cc
+++ /dev/null
@@ -1,456 +0,0 @@
-// Copyright 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/analysis_canvas.h"
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/core/SkPath.h"
-#include "third_party/skia/include/core/SkPicture.h"
-#include "third_party/skia/include/core/SkPictureRecorder.h"
-#include "third_party/skia/include/core/SkRRect.h"
-#include "third_party/skia/include/core/SkRegion.h"
-#include "third_party/skia/include/core/SkShader.h"
-#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
-
-namespace {
-
-void SolidColorFill(skia::AnalysisCanvas& canvas) {
- canvas.clear(SkColorSetARGB(255, 255, 255, 255));
-}
-
-void TransparentFill(skia::AnalysisCanvas& canvas) {
- canvas.clear(SkColorSetARGB(0, 0, 0, 0));
-}
-
-} // namespace
-namespace skia {
-
-TEST(AnalysisCanvasTest, EmptyCanvas) {
- skia::AnalysisCanvas canvas(255, 255);
-
- SkColor color;
- EXPECT_TRUE(canvas.GetColorIfSolid(&color));
- EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0));
-}
-
-TEST(AnalysisCanvasTest, ClearCanvas) {
- skia::AnalysisCanvas canvas(255, 255);
-
- // Transparent color
- SkColor color = SkColorSetARGB(0, 12, 34, 56);
- canvas.clear(color);
-
- SkColor outputColor;
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- // Solid color
- color = SkColorSetARGB(255, 65, 43, 21);
- canvas.clear(color);
-
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- EXPECT_EQ(outputColor, color);
-
- // Translucent color
- color = SkColorSetARGB(128, 11, 22, 33);
- canvas.clear(color);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- // Test helper methods
- SolidColorFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- TransparentFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-}
-
-TEST(AnalysisCanvasTest, ComplexActions) {
- skia::AnalysisCanvas canvas(255, 255);
-
- // Draw paint test.
- SkColor color = SkColorSetARGB(255, 11, 22, 33);
- SkPaint paint;
- paint.setColor(color);
-
- canvas.drawPaint(paint);
-
- SkColor outputColor;
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
-
- // Draw points test.
- SkPoint points[4] = {
- SkPoint::Make(0, 0),
- SkPoint::Make(255, 0),
- SkPoint::Make(255, 255),
- SkPoint::Make(0, 255)
- };
-
- SolidColorFill(canvas);
- canvas.drawPoints(SkCanvas::kLines_PointMode, 4, points, paint);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- // Draw oval test.
- SolidColorFill(canvas);
- canvas.drawOval(SkRect::MakeWH(255, 255), paint);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- // Draw bitmap test.
- SolidColorFill(canvas);
- SkBitmap secondBitmap;
- secondBitmap.allocN32Pixels(255, 255);
- canvas.drawBitmap(secondBitmap, 0, 0);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-}
-
-TEST(AnalysisCanvasTest, SimpleDrawRect) {
- skia::AnalysisCanvas canvas(255, 255);
-
- SkColor color = SkColorSetARGB(255, 11, 22, 33);
- SkPaint paint;
- paint.setColor(color);
- canvas.clipRect(SkRect::MakeWH(255, 255));
- canvas.drawRect(SkRect::MakeWH(255, 255), paint);
-
- SkColor outputColor;
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- EXPECT_EQ(color, outputColor);
-
- color = SkColorSetARGB(255, 22, 33, 44);
- paint.setColor(color);
- canvas.translate(-128, -128);
- canvas.drawRect(SkRect::MakeWH(382, 382), paint);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- color = SkColorSetARGB(255, 33, 44, 55);
- paint.setColor(color);
- canvas.drawRect(SkRect::MakeWH(383, 383), paint);
-
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- EXPECT_EQ(color, outputColor);
-
- color = SkColorSetARGB(0, 0, 0, 0);
- paint.setColor(color);
- canvas.drawRect(SkRect::MakeWH(383, 383), paint);
-
- // This test relies on canvas treating a paint with 0-color as a no-op
- // thus not changing its "is_solid" status.
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- EXPECT_EQ(outputColor, SkColorSetARGB(255, 33, 44, 55));
-
- color = SkColorSetARGB(128, 128, 128, 128);
- paint.setColor(color);
- canvas.drawRect(SkRect::MakeWH(383, 383), paint);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- paint.setBlendMode(SkBlendMode::kClear);
- canvas.drawRect(SkRect::MakeWH(382, 382), paint);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- canvas.drawRect(SkRect::MakeWH(383, 383), paint);
-
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- canvas.translate(128, 128);
- color = SkColorSetARGB(255, 11, 22, 33);
- paint.setColor(color);
- paint.setBlendMode(SkBlendMode::kSrcOver);
- canvas.drawRect(SkRect::MakeWH(255, 255), paint);
-
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- EXPECT_EQ(color, outputColor);
-
- canvas.rotate(50);
- canvas.drawRect(SkRect::MakeWH(255, 255), paint);
-
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-}
-
-TEST(AnalysisCanvasTest, FilterPaint) {
- skia::AnalysisCanvas canvas(255, 255);
- SkPaint paint;
-
- paint.setImageFilter(SkOffsetImageFilter::Make(10, 10, nullptr));
- canvas.drawRect(SkRect::MakeWH(255, 255), paint);
-
- SkColor outputColor;
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-}
-
-TEST(AnalysisCanvasTest, ClipPath) {
- skia::AnalysisCanvas canvas(255, 255);
-
- // Skia will look for paths that are actually rects and treat
- // them as such. We add a divot to the following path to prevent
- // this optimization and truly test clipPath's behavior.
- SkPath path;
- path.moveTo(0, 0);
- path.lineTo(128, 50);
- path.lineTo(255, 0);
- path.lineTo(255, 255);
- path.lineTo(0, 255);
-
- SkColor outputColor;
- SolidColorFill(canvas);
- canvas.clipPath(path);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- canvas.save();
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- canvas.clipPath(path);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- canvas.restore();
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- SolidColorFill(canvas);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-}
-
-TEST(AnalysisCanvasTest, SaveLayerWithXfermode) {
- skia::AnalysisCanvas canvas(255, 255);
- SkRect bounds = SkRect::MakeWH(255, 255);
- SkColor outputColor;
-
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- SkPaint paint;
-
- // Note: nothing is draw to the the save layer, but solid color
- // and transparency are handled conservatively in case the layer's
- // SkPaint draws something. For example, there could be an
- // SkPictureImageFilter. If someday analysis_canvas starts doing
- // a deeper analysis of the SkPaint, this test may need to be
- // redesigned.
- TransparentFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- paint.setBlendMode(SkBlendMode::kSrc);
- canvas.saveLayer(&bounds, &paint);
- canvas.restore();
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- TransparentFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- paint.setBlendMode(SkBlendMode::kSrcOver);
- canvas.saveLayer(&bounds, &paint);
- canvas.restore();
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- // Layer with dst xfermode is a no-op, so this is the only case
- // where solid color is unaffected by the layer.
- TransparentFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
- paint.setBlendMode(SkBlendMode::kDst);
- canvas.saveLayer(&bounds, &paint);
- canvas.restore();
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-}
-
-TEST(AnalysisCanvasTest, SaveLayerRestore) {
- skia::AnalysisCanvas canvas(255, 255);
-
- SkColor outputColor;
- SolidColorFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
-
- SkRect bounds = SkRect::MakeWH(255, 255);
- SkPaint paint;
- paint.setColor(SkColorSetARGB(255, 255, 255, 255));
- paint.setBlendMode(SkBlendMode::kSrcOver);
-
- // This should force non-transparency
- canvas.saveLayer(&bounds, &paint);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- TransparentFill(canvas);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- SolidColorFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- paint.setBlendMode(SkBlendMode::kDst);
-
- // This should force non-solid color
- canvas.saveLayer(&bounds, &paint);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- TransparentFill(canvas);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- SolidColorFill(canvas);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- canvas.restore();
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- TransparentFill(canvas);
- EXPECT_FALSE(canvas.GetColorIfSolid(&outputColor));
-
- SolidColorFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- canvas.restore();
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- TransparentFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-
- SolidColorFill(canvas);
- EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor));
- EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor);
-}
-
-TEST(AnalysisCanvasTest, EarlyOutNotSolid) {
- SkPictureRecorder recorder;
-
- // Create a picture with 3 commands, last of which is non-solid.
- SkCanvas* record_canvas = recorder.beginRecording(256, 256);
-
- std::string text = "text";
- SkPoint point = SkPoint::Make(SkIntToScalar(25), SkIntToScalar(25));
-
- SkPaint paint;
- paint.setColor(SkColorSetARGB(255, 255, 255, 255));
- paint.setBlendMode(SkBlendMode::kSrcOver);
-
- 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);
-
- sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
-
- // Draw the picture into the analysis canvas, using the canvas as a callback
- // as well.
- skia::AnalysisCanvas canvas(256, 256);
- picture->playback(&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.abort());
-}
-
-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));
-}
-
-TEST(AnalysisCanvasTest, ClipRRectCoversCanvas) {
-
- SkVector radii[4] = {
- SkVector::Make(10.0, 15.0),
- SkVector::Make(20.0, 25.0),
- SkVector::Make(30.0, 35.0),
- SkVector::Make(40.0, 45.0),
- };
-
- int rr_size = 600;
- int canvas_size = 255;
-
- struct {
- SkVector offset;
- bool expected;
- } cases [] = {
- // Not within bounding box of |rr|.
- { SkVector::Make(100.0, 100.0), false },
-
- // Intersects UL corner.
- { SkVector::Make(0.0, 0.0), false },
-
- // Between UL and UR.
- { SkVector::Make(-50.0, 0), true },
-
- // Intersects UR corner.
- { SkVector::Make(canvas_size - rr_size, 0), false },
-
- // Between UR and LR.
- { SkVector::Make(canvas_size - rr_size, -50.0), true },
-
- // Intersects LR corner.
- { SkVector::Make(canvas_size - rr_size, canvas_size - rr_size), false },
-
- // Between LL and LR
- { SkVector::Make(-50, canvas_size - rr_size), true },
-
- // Intersects LL corner
- { SkVector::Make(0, canvas_size - rr_size), false },
-
- // Between UL and LL
- { SkVector::Make(0, -50), true },
-
- // In center
- { SkVector::Make(-100, -100), true},
- };
-
- SkColor outputColor;
-
- for (size_t i = 0; i < arraysize(cases); ++i) {
- skia::AnalysisCanvas canvas(canvas_size, canvas_size);
-
- SkRect bounding_rect = SkRect::MakeXYWH(
- cases[i].offset.x(), cases[i].offset.y(), rr_size, rr_size);
-
- SkRRect rr;
- rr.setRectRadii(bounding_rect, radii);
-
- canvas.clipRRect(rr);
- EXPECT_EQ(cases[i].expected, canvas.GetColorIfSolid(&outputColor)) << i;
- }
-}
-
-} // namespace skia
diff --git a/chromium/skia/ext/raster_handle_allocator_win.cc b/chromium/skia/ext/raster_handle_allocator_win.cc
index 1f136bd3598..08f3206c1d5 100644
--- a/chromium/skia/ext/raster_handle_allocator_win.cc
+++ b/chromium/skia/ext/raster_handle_allocator_win.cc
@@ -57,7 +57,7 @@ static bool Create(int width,
size_t row_bytes = skia::PlatformCanvasStrideForWidth(width);
if (do_clear)
- sk_bzero(pixels, row_bytes * height);
+ bzero(pixels, row_bytes * height);
HDC hdc = CreateCompatibleDC(nullptr);
if (!hdc) {
diff --git a/chromium/skia/ext/skia_commit_hash.h b/chromium/skia/ext/skia_commit_hash.h
index 22d3b2c2d1d..3ee7fa32442 100644
--- a/chromium/skia/ext/skia_commit_hash.h
+++ b/chromium/skia/ext/skia_commit_hash.h
@@ -3,6 +3,6 @@
#ifndef SKIA_EXT_SKIA_COMMIT_HASH_H_
#define SKIA_EXT_SKIA_COMMIT_HASH_H_
-#define SKIA_COMMIT_HASH "3638057df2d702be034b3c3421aac61888af3ba6-"
+#define SKIA_COMMIT_HASH "dabbbe5b486443fd6e5ead56c01ba5bd877c80bd-"
#endif // SKIA_EXT_SKIA_COMMIT_HASH_H_
diff --git a/chromium/skia/ext/skia_utils_base.cc b/chromium/skia/ext/skia_utils_base.cc
index 5d9e9286fa1..695226eef5e 100644
--- a/chromium/skia/ext/skia_utils_base.cc
+++ b/chromium/skia/ext/skia_utils_base.cc
@@ -8,43 +8,11 @@
#include "base/pickle.h"
#include "third_party/skia/include/core/SkData.h"
-#include "third_party/skia/include/core/SkImageDeserializer.h"
-#include "third_party/skia/include/core/SkWriteBuffer.h"
-#include "third_party/skia/src/core/SkValidatingReadBuffer.h"
+#include "third_party/skia/include/core/SkEncodedImageFormat.h"
+#include "third_party/skia/include/core/SkImage.h"
+#include "third_party/skia/include/core/SkSerialProcs.h"
namespace skia {
-namespace {
-
-class CodecDecodingPixelSerializer : public SkPixelSerializer {
- public:
- CodecDecodingPixelSerializer() = default;
- ~CodecDecodingPixelSerializer() override = default;
-
- protected:
- // Disallowing serializing the encoded data.
- bool onUseEncodedData(const void* data, size_t len) override { return false; }
-
- // Don't return any encoded data to ensure the decoded bitmap is serialized.
- SkData* onEncode(const SkPixmap&) override { return nullptr; }
-};
-
-class CodecDisallowingImageDeserializer : public SkImageDeserializer {
- public:
- ~CodecDisallowingImageDeserializer() override = default;
-
- sk_sp<SkImage> makeFromData(SkData*, const SkIRect* subset) override {
- LOG(ERROR) << "Encoded image rejected during SkFlattenable deserialization";
- return nullptr;
- }
- sk_sp<SkImage> makeFromMemory(const void* data,
- size_t length,
- const SkIRect* subset) override {
- LOG(ERROR) << "Encoded image rejected during SkFlattenable deserialization";
- return nullptr;
- }
-};
-
-} // namespace
bool ReadSkString(base::PickleIterator* iter, SkString* str) {
int reply_length;
@@ -114,22 +82,24 @@ void WriteSkFontStyle(base::Pickle* pickle, SkFontStyle style) {
}
sk_sp<SkData> ValidatingSerializeFlattenable(SkFlattenable* flattenable) {
- SkBinaryWriteBuffer writer;
- writer.setPixelSerializer(sk_make_sp<CodecDecodingPixelSerializer>());
- writer.writeFlattenable(flattenable);
- size_t size = writer.bytesWritten();
- auto data = SkData::MakeUninitialized(size);
- writer.writeToMemory(data->writable_data());
- return data;
+ SkSerialProcs procs;
+ procs.fImageProc = [](SkImage* image, void*) {
+ // We choose to not trust natively encoded images, but we are fine to force
+ // a "clean" encoded version for transport.
+ return image->encodeToData(SkEncodedImageFormat::kPNG, 100);
+ };
+ return flattenable->serialize(&procs);
}
SkFlattenable* ValidatingDeserializeFlattenable(const void* data,
size_t size,
SkFlattenable::Type type) {
- SkValidatingReadBuffer buffer(data, size);
- CodecDisallowingImageDeserializer image_deserializer;
- buffer.setImageDeserializer(&image_deserializer);
- return buffer.readFlattenable(type);
+ SkDeserialProcs procs;
+ procs.fImageProc = [](const void* data, size_t length, void*) {
+ // Our custom encode is standard, so we can just call Skia to deserialize
+ return SkImage::MakeFromEncoded(SkData::MakeWithCopy(data, length));
+ };
+ return SkFlattenable::Deserialize(type, data, size, &procs).release();
}
} // namespace skia
diff --git a/chromium/skia/ext/skia_utils_base_unittest.cc b/chromium/skia/ext/skia_utils_base_unittest.cc
index ab6f3af2f67..b7dac6d9fb1 100644
--- a/chromium/skia/ext/skia_utils_base_unittest.cc
+++ b/chromium/skia/ext/skia_utils_base_unittest.cc
@@ -7,121 +7,55 @@
#include "base/memory/ptr_util.h"
#include "base/test/gtest_util.h"
#include "base/test/test_discardable_memory_allocator.h"
+#include "build/build_config.h"
+#include "skia/ext/skia_utils_base.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/core/SkFlattenableSerialization.h"
-#include "third_party/skia/include/core/SkImageGenerator.h"
-#include "third_party/skia/include/core/SkPixelSerializer.h"
-#include "third_party/skia/include/core/SkWriteBuffer.h"
+#include "third_party/skia/include/core/SkImage.h"
+#include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/effects/SkImageSource.h"
-#include "third_party/skia/include/effects/SkPaintImageFilter.h"
+#include "ui/gfx/codec/png_codec.h"
namespace skia {
namespace {
-// Raw data for a PNG file with 1x1 white pixels.
-const unsigned char kWhitePNG[] = {
- 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
- 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
- 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xde, 0x00, 0x00, 0x00,
- 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
- 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00,
- 0x0b, 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x49,
- 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0xff, 0xff, 0x3f, 0x00, 0x05,
- 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x49,
- 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
-};
-
-class FakeImageGenerator : public SkImageGenerator {
- public:
- FakeImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {}
- ~FakeImageGenerator() override { EXPECT_TRUE(decoded_); }
-
- SkData* onRefEncodedData() override {
- // Use a generator that lets the caller encode it.
- return SkData::MakeWithCString("evilimage").release();
- }
-
- bool onGetPixels(const SkImageInfo& info,
- void* pixels,
- size_t,
- const Options&) override {
- decoded_ = true;
- memset(pixels, 0, info.computeMinByteSize());
- return true;
- }
-
- private:
- bool decoded_ = false;
-};
-
-class PixelSerializer : public SkPixelSerializer {
- public:
- bool onUseEncodedData(const void* data, size_t len) override {
- CHECK(false);
- return false;
- }
-
- SkData* onEncode(const SkPixmap&) override {
- EXPECT_TRUE(has_decoded_images_);
- return nullptr;
- }
-
- bool has_decoded_images_ = false;
-};
-
-TEST(SkiaUtilsBaseTest, ImageSerializationDecodesImage) {
- base::TestDiscardableMemoryAllocator allocator;
- base::DiscardableMemoryAllocator::SetInstance(&allocator);
-
- auto image =
- SkImage::MakeFromGenerator(base::MakeUnique<FakeImageGenerator>());
- auto filter = SkImageSource::Make(image);
-
- // Serialize the filter. This decodes the image.
- sk_sp<SkData> data = ValidatingSerializeFlattenable(filter.get());
-
- // Deserialize.
- auto deserialized_filter =
- sk_sp<SkImageFilter>((SkImageFilter*)ValidatingDeserializeFlattenable(
- data->data(), data->size(), SkImageFilter::GetFlattenableType()));
-
- // Now serialize again to ensure that the deserialized filter did not have any
- // encoded images. Serialization is the only way to deep inspect the filter.
- SkBinaryWriteBuffer writer;
- auto pixel_serializer = sk_make_sp<PixelSerializer>();
- pixel_serializer->has_decoded_images_ = true;
- writer.setPixelSerializer(pixel_serializer);
- writer.writeFlattenable(deserialized_filter.get());
- EXPECT_GT(writer.bytesWritten(), 0u);
-
- base::DiscardableMemoryAllocator::SetInstance(nullptr);
-}
-
-TEST(SkiaUtilsBaseTest, DeserializationWithEncodedImagesFails) {
+TEST(SkiaUtilsBaseTest, DeserializationWithEncodedImages) {
+// codecs are not available on iOS, so skip this test crbug.com/794298
+#if !defined(OS_IOS)
base::TestDiscardableMemoryAllocator allocator;
base::DiscardableMemoryAllocator::SetInstance(&allocator);
- auto image = SkImage::MakeFromGenerator(SkImageGenerator::MakeFromEncoded(
- SkData::MakeWithoutCopy(kWhitePNG, sizeof(kWhitePNG))));
- auto filter = SkImageSource::Make(image);
-
- // Serialize the filter using default serialization.
- sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
-
- // Deserialize with images disabled.
- auto deserialized_filter =
- sk_sp<SkImageFilter>((SkImageFilter*)ValidatingDeserializeFlattenable(
- data->data(), data->size(), SkImageFilter::GetFlattenableType()));
-
- // Now serialize again to make sure that all encoded images were rejected
- // during serialization.
- SkBinaryWriteBuffer writer;
- auto pixel_serializer = sk_make_sp<PixelSerializer>();
- writer.setPixelSerializer(pixel_serializer);
- writer.writeFlattenable(deserialized_filter.get());
- EXPECT_GT(writer.bytesWritten(), 0u);
+ SkPMColor pixel = 0xFFFFFFFF; // white;
+ SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
+ SkPixmap pm = {info, &pixel, sizeof(SkPMColor)};
+ auto image = SkImage::MakeRasterCopy(pm);
+ EXPECT_TRUE(image);
+ auto jpeg_data = image->encodeToData(SkEncodedImageFormat::kJPEG, 100);
+ EXPECT_TRUE(jpeg_data);
+ auto filter = SkImageSource::Make(SkImage::MakeFromEncoded(jpeg_data));
+ EXPECT_TRUE(filter);
+
+ sk_sp<SkData> data(ValidatingSerializeFlattenable(filter.get()));
+
+ // Now we install a proc to see that all embedded images have been converted
+ // to png.
+ bool was_called = false;
+ SkDeserialProcs procs;
+ procs.fImageProc = [](const void* data, size_t length,
+ void* was_called) -> sk_sp<SkImage> {
+ *(bool*)was_called = true;
+ SkBitmap bitmap;
+ EXPECT_TRUE(gfx::PNGCodec::Decode(static_cast<const uint8_t*>(data), length,
+ &bitmap));
+ return nullptr; // allow for normal deserialization
+ };
+ procs.fImageCtx = &was_called;
+ auto flat = SkFlattenable::Deserialize(SkImageFilter::GetFlattenableType(),
+ data->data(), data->size(), &procs);
+ EXPECT_TRUE(flat);
+ EXPECT_TRUE(was_called);
base::DiscardableMemoryAllocator::SetInstance(nullptr);
+#endif
}
} // namespace
diff --git a/chromium/skia/ext/skia_utils_mac.h b/chromium/skia/ext/skia_utils_mac.h
index fda4ee98ae7..38613d20dc4 100644
--- a/chromium/skia/ext/skia_utils_mac.h
+++ b/chromium/skia/ext/skia_utils_mac.h
@@ -45,10 +45,11 @@ SK_API SkRect CGRectToSkRect(const CGRect& rect);
CGRect SkIRectToCGRect(const SkIRect& rect);
CGRect SkRectToCGRect(const SkRect& rect);
-// Converts CGColorRef to the ARGB layout Skia expects.
+// Converts CGColorRef to the ARGB layout Skia expects. The given CGColorRef
+// should be in the sRGB color space and include alpha.
SK_API SkColor CGColorRefToSkColor(CGColorRef color);
-// Converts ARGB to CGColorRef.
+// Converts a Skia ARGB color to CGColorRef. Assumes sRGB color space.
SK_API CGColorRef CGColorCreateFromSkColor(SkColor color);
// Converts NSColor to ARGB. Returns raw rgb values and does no colorspace
diff --git a/chromium/skia/ext/skia_utils_mac.mm b/chromium/skia/ext/skia_utils_mac.mm
index a851888523b..9e2164953b1 100644
--- a/chromium/skia/ext/skia_utils_mac.mm
+++ b/chromium/skia/ext/skia_utils_mac.mm
@@ -10,6 +10,7 @@
#include <memory>
#include "base/logging.h"
+#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsobject.h"
#include "skia/ext/platform_canvas.h"
@@ -125,8 +126,10 @@ CGRect SkRectToCGRect(const SkRect& rect) {
return cg_rect;
}
-// Converts CGColorRef to the ARGB layout Skia expects.
SkColor CGColorRefToSkColor(CGColorRef color) {
+ // TODO(ccameron): This assumes that |color| is already in sRGB. Ideally we'd
+ // use something like CGColorCreateCopyByMatchingToColorSpace, but that's
+ // only available in macOS 10.11.
DCHECK(CGColorGetNumberOfComponents(color) == 4);
const CGFloat* components = CGColorGetComponents(color);
return SkColorSetARGB(SkScalarRoundToInt(255.0 * components[3]), // alpha
@@ -135,12 +138,12 @@ SkColor CGColorRefToSkColor(CGColorRef color) {
SkScalarRoundToInt(255.0 * components[2])); // blue
}
-// Converts ARGB to CGColorRef.
CGColorRef CGColorCreateFromSkColor(SkColor color) {
- return CGColorCreateGenericRGB(SkColorGetR(color) / 255.0,
- SkColorGetG(color) / 255.0,
- SkColorGetB(color) / 255.0,
- SkColorGetA(color) / 255.0);
+ double components[] = {SkColorGetR(color) / 255.0,
+ SkColorGetG(color) / 255.0,
+ SkColorGetB(color) / 255.0,
+ SkColorGetA(color) / 255.0};
+ return CGColorCreate(base::mac::GetSRGBColorSpace(), components);
}
// Converts NSColor to ARGB
diff --git a/chromium/skia/ext/texture_handle.h b/chromium/skia/ext/texture_handle.h
index a5409c5f4c9..83cb7597870 100644
--- a/chromium/skia/ext/texture_handle.h
+++ b/chromium/skia/ext/texture_handle.h
@@ -9,12 +9,7 @@
namespace skia {
-// TODO(bsalomon): Remove both of these conversions when Skia bug 5019 is fixed.
-inline GrBackendObject GrGLTextureInfoToGrBackendObject(
- const GrGLTextureInfo& info) {
- return reinterpret_cast<GrBackendObject>(&info);
-}
-
+// TODO(bsalomon): Remove this conversion when Skia bug 5019 is fixed.
inline const GrGLTextureInfo* GrBackendObjectToGrGLTextureInfo(
GrBackendObject object) {
return reinterpret_cast<const GrGLTextureInfo*>(object);