diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-25 11:39:07 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-01-25 15:20:42 +0000 |
commit | 6c91641271e536ffaa88a1dff5127e42ee99a91e (patch) | |
tree | 703d9dd49602377ddc90cbf886aad37913f2496b /chromium/skia | |
parent | b145b7fafd36f0c260d6a768c81fc14e32578099 (diff) | |
download | qtwebengine-chromium-6c91641271e536ffaa88a1dff5127e42ee99a91e.tar.gz |
BASELINE: Update Chromium to 49.0.2623.23
Also adds missing printing sources.
Change-Id: I3726b8f0c7d6751c9fc846096c571fadca7108cd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'chromium/skia')
62 files changed, 737 insertions, 775 deletions
diff --git a/chromium/skia/BUILD.gn b/chromium/skia/BUILD.gn index 4fbec309e58..1b38d807d8e 100644 --- a/chromium/skia/BUILD.gn +++ b/chromium/skia/BUILD.gn @@ -278,9 +278,11 @@ config("skia_library_config") { component("skia") { sources = [ # Chrome sources. + "config/SkUserConfig.h", + "config/sk_ref_cnt_ext_debug.h", + "config/sk_ref_cnt_ext_release.h", "ext/SkDiscardableMemory_chrome.cc", "ext/SkMemory_new_handler.cpp", - "ext/SkTraceMemoryDump_chrome.cc", "ext/analysis_canvas.cc", "ext/benchmarking_canvas.cc", "ext/convolver.cc", @@ -295,6 +297,7 @@ component("skia") { "ext/platform_device_win.cc", "ext/recursive_gaussian_convolution.cc", "ext/skia_memory_dump_provider.cc", + "ext/skia_trace_memory_dump_impl.cc", "ext/skia_utils_base.cc", "ext/skia_utils_ios.mm", "ext/skia_utils_mac.mm", @@ -334,8 +337,6 @@ component("skia") { "//third_party/skia/src/utils/SkBitmapHasher.cpp", "//third_party/skia/src/utils/SkBoundaryPatch.cpp", "//third_party/skia/src/utils/SkCamera.cpp", - "//third_party/skia/src/utils/SkCubicInterval.cpp", - "//third_party/skia/src/utils/SkCullPoints.cpp", "//third_party/skia/src/utils/SkDumpCanvas.cpp", "//third_party/skia/src/utils/SkFrontBufferedStream.cpp", "//third_party/skia/src/utils/SkInterpolator.cpp", @@ -347,10 +348,6 @@ component("skia") { "//third_party/skia/src/utils/SkParsePath.cpp", "//third_party/skia/src/utils/SkSHA1.cpp", - # We don't currently need to change thread affinity, so leave out this complexity for now. - "//third_party/skia/src/utils/SkThreadUtils_pthread_linux.cpp", - "//third_party/skia/src/utils/SkThreadUtils_pthread_mach.cpp", - #testing "//third_party/skia/src/fonts/SkGScalerContext.cpp", ] @@ -359,11 +356,10 @@ component("skia") { sources -= [ # Keeping _win.cpp "//third_party/skia/src/utils/SkThreadUtils_pthread.cpp", - "//third_party/skia/src/utils/SkThreadUtils_pthread_other.cpp", ] } else { sources -= [ - # Keeping _pthread.cpp and _pthread_other.cpp. + # Keeping _pthread.cpp "//third_party/skia/src/utils/SkThreadUtils_win.cpp", ] } @@ -416,6 +412,7 @@ component("skia") { sources -= [ "//third_party/skia/src/fonts/SkFontMgr_fontconfig.cpp", "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp", + "//third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp", "//third_party/skia/src/ports/SkFontHost_fontconfig.cpp", ] } @@ -447,8 +444,8 @@ component("skia") { configs -= [ "//build/config/compiler:chromium_code" ] configs += [ + ":skia_config", ":skia_library_config", - "//build/config:precompiled_headers", "//build/config/compiler:no_chromium_code", ] public_configs = [ ":skia_config" ] @@ -477,9 +474,9 @@ component("skia") { sources += [ "ext/platform_device_linux.cc" ] set_sources_assignment_filter(sources_assignment_filter) deps += [ + "//third_party/android_tools:cpu_features", "//third_party/expat", "//third_party/freetype-android:freetype", - "//third_party/android_tools:cpu_features", ] } @@ -526,7 +523,7 @@ if (current_cpu == "x86" || current_cpu == "x64") { "//build/config/compiler:no_chromium_code", ] } - source_set("skia_opts_sse4") { + source_set("skia_opts_sse41") { sources = gypi_skia_opts.sse41_sources if (!is_win || is_clang) { cflags = [ "-msse4.1" ] @@ -542,6 +539,54 @@ if (current_cpu == "x86" || current_cpu == "x64") { "//build/config/compiler:no_chromium_code", ] } + source_set("skia_opts_sse42") { + sources = gypi_skia_opts.sse42_sources + if (!is_win || is_clang) { + cflags = [ "-msse4.2" ] + } + if (is_win) { + defines = [ "SK_CPU_SSE_LEVEL=42" ] + } + visibility = [ ":skia_opts" ] + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ + ":skia_config", + ":skia_library_config", + "//build/config/compiler:no_chromium_code", + ] + } + source_set("skia_opts_avx") { + sources = gypi_skia_opts.avx_sources + if (!is_win) { + cflags = [ "-mavx" ] + } + if (is_win) { + cflags = [ "/arch:AVX" ] + } + visibility = [ ":skia_opts" ] + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ + ":skia_config", + ":skia_library_config", + "//build/config/compiler:no_chromium_code", + ] + } + source_set("skia_opts_avx2") { + sources = gypi_skia_opts.avx2_sources + if (!is_win) { + cflags = [ "-mavx2" ] + } + if (is_win) { + cflags = [ "/arch:AVX2" ] + } + visibility = [ ":skia_opts" ] + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ + ":skia_config", + ":skia_library_config", + "//build/config/compiler:no_chromium_code", + ] + } } source_set("skia_opts") { cflags = [] @@ -554,8 +599,11 @@ source_set("skia_opts") { if (current_cpu == "x86" || current_cpu == "x64") { sources = gypi_skia_opts.sse2_sources deps += [ + ":skia_opts_avx", + ":skia_opts_avx2", ":skia_opts_sse3", - ":skia_opts_sse4", + ":skia_opts_sse41", + ":skia_opts_sse42", ] } else if (current_cpu == "arm") { # The assembly uses the frame pointer register (r7 in Thumb/r11 in @@ -577,6 +625,8 @@ source_set("skia_opts") { } else { sources = gypi_skia_opts.none_sourcees } + } else if (current_cpu == "arm64") { + sources = gypi_skia_opts.arm64_sources } else if (current_cpu == "mipsel") { cflags += [ "-fomit-frame-pointer" ] @@ -585,6 +635,9 @@ source_set("skia_opts") { } else { sources = gypi_skia_opts.none_sources } + } else if (current_cpu == "mips64el") { + cflags += [ "-fomit-frame-pointer" ] + sources = gypi_skia_opts.none_sources } else { assert(false, "Need to port cpu specific stuff from skia_library_opts.gyp") } diff --git a/chromium/skia/config/SkUserConfig.h b/chromium/skia/config/SkUserConfig.h index af0d6bf5196..741f73ddf4a 100644 --- a/chromium/skia/config/SkUserConfig.h +++ b/chromium/skia/config/SkUserConfig.h @@ -214,6 +214,10 @@ SK_API void SkDebugf_FileLine(const char* file, int line, bool fatal, # define SK_SUPPORT_LEGACY_GETDEVICE #endif +#ifndef SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX +# define SK_SUPPORT_LEGACY_REFENCODEDDATA_NOCTX +#endif + #ifndef SK_IGNORE_ETC1_SUPPORT # define SK_IGNORE_ETC1_SUPPORT #endif @@ -222,8 +226,16 @@ SK_API void SkDebugf_FileLine(const char* file, int line, bool fatal, # define SK_IGNORE_GPU_DITHER #endif -#ifndef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED -# define SK_SAVE_LAYER_BOUNDS_ARE_FILTERED +#ifndef SK_SUPPORT_LEGACY_HQ_DOWNSAMPLING +# define SK_SUPPORT_LEGACY_HQ_DOWNSAMPLING +#endif + +#ifndef SK_SUPPORT_LEGACY_PATH_MEASURE_TVALUE +# define SK_SUPPORT_LEGACY_PATH_MEASURE_TVALUE +#endif + +#ifndef SK_SUPPORT_LEGACY_BITMAP_FILTER +# define SK_SUPPORT_LEGACY_BITMAP_FILTER #endif ///////////////////////// Imported from BUILD.gn and skia_common.gypi @@ -233,15 +245,13 @@ SK_API void SkDebugf_FileLine(const char* file, int line, bool fatal, */ #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0 -/* Forcing the unoptimized path for the offset image filter in skia until - * all filters used in Blink support the optimized path properly - */ -#define SK_DISABLE_OFFSETIMAGEFILTER_OPTIMIZATION - /* This flag forces Skia not to use typographic metrics with GDI. */ #define SK_GDI_ALWAYS_USE_TEXTMETRICS_FOR_FONT_METRICS +#ifndef SK_IGNORE_GL_TEXTURE_TARGET +# define SK_IGNORE_GL_TEXTURE_TARGET +#endif #define SK_IGNORE_BLURRED_RRECT_OPT #define SK_USE_DISCARDABLE_SCALEDIMAGECACHE #define SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT @@ -250,6 +260,14 @@ SK_API void SkDebugf_FileLine(const char* file, int line, bool fatal, #define SK_ENABLE_INST_COUNT 0 #define GR_GL_CUSTOM_SETUP_HEADER "GrGLConfig_chrome.h" +// Blink layout tests are baselined to Clang optimizing through the UB in SkDivBits. +#define SK_SUPPORT_LEGACY_DIVBITS_UB + +// mtklein's fiddling with Src / SrcOver. Will rebaseline these only once when done. +#define SK_SUPPORT_LEGACY_X86_BLITS + +#define SK_DISABLE_TILE_IMAGE_FILTER_OPTIMIZATION + // ===== End Chrome-specific definitions ===== #endif diff --git a/chromium/skia/config/sk_ref_cnt_ext_debug.h b/chromium/skia/config/sk_ref_cnt_ext_debug.h index b2b66adba72..78a39a3789f 100644 --- a/chromium/skia/config/sk_ref_cnt_ext_debug.h +++ b/chromium/skia/config/sk_ref_cnt_ext_debug.h @@ -9,23 +9,31 @@ #error Only one SkRefCnt should be used. #endif +#include <atomic> + // Alternate implementation of SkRefCnt for Chromium debug builds class SK_API SkRefCnt : public SkRefCntBase { public: - SkRefCnt() : flags_(0) {} - void ref() const { SkASSERT(flags_ != AdoptionRequired_Flag); SkRefCntBase::ref(); } + SkRefCnt(); + ~SkRefCnt() override; + void ref() const { SkASSERT(flags_.load() != AdoptionRequired_Flag); SkRefCntBase::ref(); } void adopted() const { flags_ |= Adopted_Flag; } void requireAdoption() const { flags_ |= AdoptionRequired_Flag; } void deref() const { SkRefCntBase::unref(); } private: + enum { Adopted_Flag = 0x1, AdoptionRequired_Flag = 0x2, }; - mutable int flags_; + mutable std::atomic<int> flags_; }; +inline SkRefCnt::SkRefCnt() : flags_(0) { } + +inline SkRefCnt::~SkRefCnt() { } + // Bootstrap for Blink's WTF::RefPtr namespace WTF { diff --git a/chromium/skia/ext/SkDiscardableMemory_chrome.cc b/chromium/skia/ext/SkDiscardableMemory_chrome.cc index 30a7f93c836..95019b125f3 100644 --- a/chromium/skia/ext/SkDiscardableMemory_chrome.cc +++ b/chromium/skia/ext/SkDiscardableMemory_chrome.cc @@ -2,7 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "SkDiscardableMemory_chrome.h" +#include "skia/ext/SkDiscardableMemory_chrome.h" + +#include <stddef.h> + +#include <utility> #include "base/memory/discardable_memory.h" #include "base/memory/discardable_memory_allocator.h" @@ -23,8 +27,7 @@ void SkDiscardableMemoryChrome::unlock() { SkDiscardableMemoryChrome::SkDiscardableMemoryChrome( scoped_ptr<base::DiscardableMemory> memory) - : discardable_(memory.Pass()) { -} + : discardable_(std::move(memory)) {} base::trace_event::MemoryAllocatorDump* SkDiscardableMemoryChrome::CreateMemoryAllocatorDump( diff --git a/chromium/skia/ext/SkMemory_new_handler.cpp b/chromium/skia/ext/SkMemory_new_handler.cpp index d4080a13447..b20d31b755b 100644 --- a/chromium/skia/ext/SkMemory_new_handler.cpp +++ b/chromium/skia/ext/SkMemory_new_handler.cpp @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> #include <stdlib.h> #include "base/process/memory.h" - +#include "build/build_config.h" #include "third_party/skia/include/core/SkTypes.h" // This implementation of sk_malloc_flags() and friends is similar to diff --git a/chromium/skia/ext/SkTypeface_fake.cpp b/chromium/skia/ext/SkTypeface_fake.cpp index dea36a1ff45..954b304a5f6 100644 --- a/chromium/skia/ext/SkTypeface_fake.cpp +++ b/chromium/skia/ext/SkTypeface_fake.cpp @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stdint.h> + #include "SkTypeface.h" // ===== Begin Chrome-specific definitions ===== diff --git a/chromium/skia/ext/analysis_canvas.cc b/chromium/skia/ext/analysis_canvas.cc index ec40825f5b7..043946d8351 100644 --- a/chromium/skia/ext/analysis_canvas.cc +++ b/chromium/skia/ext/analysis_canvas.cc @@ -65,7 +65,7 @@ bool IsFullQuad(SkCanvas* canvas, const SkRect& drawn_rect) { return false; // if the clip is smaller than the canvas, we're partly clipped, so abort. - if (!clip_irect.contains(SkIRect::MakeSize(canvas->getDeviceSize()))) + if (!clip_irect.contains(SkIRect::MakeSize(canvas->getBaseLayerSize()))) return false; const SkMatrix& matrix = canvas->getTotalMatrix(); @@ -98,6 +98,7 @@ void AnalysisCanvas::SetForceNotTransparent(bool flag) { } void AnalysisCanvas::onDrawPaint(const SkPaint& paint) { + TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawPaint"); SkRect rect; if (getClipBounds(&rect)) drawRect(rect, paint); @@ -107,22 +108,29 @@ 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); return; } // An extra no-op check SkCanvas.cpp doesn't do. - if (paint.nothingToDraw()) + 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); @@ -161,12 +169,14 @@ void AnalysisCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { } 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::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. @@ -176,6 +186,7 @@ void AnalysisCanvas::onDrawRRect(const SkRRect& rr, const SkPaint& paint) { } 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_; @@ -185,6 +196,7 @@ 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_; @@ -195,6 +207,7 @@ void AnalysisCanvas::onDrawBitmapRect(const SkBitmap&, 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; @@ -209,6 +222,7 @@ 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_; @@ -218,6 +232,7 @@ 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_; @@ -228,6 +243,7 @@ void AnalysisCanvas::onDrawImageRect(const SkImage*, 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; @@ -238,20 +254,12 @@ void AnalysisCanvas::onDrawImageRect(const SkImage*, ++draw_op_count_; } -void AnalysisCanvas::onDrawSprite(const SkBitmap& bitmap, - int left, - int top, - const SkPaint* paint) { - is_solid_color_ = false; - is_transparent_ = 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_; @@ -261,6 +269,7 @@ 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_; @@ -271,6 +280,7 @@ void AnalysisCanvas::onDrawPosTextH(const void* text, 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_; @@ -281,6 +291,7 @@ void AnalysisCanvas::onDrawTextOnPath(const void* text, 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_; @@ -290,6 +301,7 @@ 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_; @@ -298,6 +310,7 @@ void AnalysisCanvas::onDrawTextBlob(const SkTextBlob* blob, 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_; @@ -312,6 +325,7 @@ void AnalysisCanvas::onDrawVertices(SkCanvas::VertexMode, const uint16_t indices[], int index_count, const SkPaint& paint) { + TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawVertices"); is_solid_color_ = false; is_transparent_ = false; ++draw_op_count_; @@ -358,6 +372,8 @@ bool AnalysisCanvas::abort() { // 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) { + 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; @@ -417,14 +433,13 @@ void AnalysisCanvas::willSave() { INHERITED::willSave(); } -SkCanvas::SaveLayerStrategy AnalysisCanvas::willSaveLayer( - const SkRect* bounds, - const SkPaint* paint, - SkCanvas::SaveFlags flags) { +SkCanvas::SaveLayerStrategy AnalysisCanvas::getSaveLayerStrategy( + const SaveLayerRec& rec) { + const SkPaint* paint = rec.fPaint; ++saved_stack_size_; - SkIRect canvas_ibounds = SkIRect::MakeSize(this->getDeviceSize()); + SkIRect canvas_ibounds = SkIRect::MakeSize(this->getBaseLayerSize()); SkRect canvas_bounds; canvas_bounds.set(canvas_ibounds); @@ -432,7 +447,7 @@ SkCanvas::SaveLayerStrategy AnalysisCanvas::willSaveLayer( // layer, then we can conservatively say that the canvas will not be of // solid color. if ((paint && !IsSolidColorPaint(*paint)) || - (bounds && !bounds->contains(canvas_bounds))) { + (rec.fBounds && !rec.fBounds->contains(canvas_bounds))) { if (force_not_solid_stack_level_ == kNoLayer) { force_not_solid_stack_level_ = saved_stack_size_; SetForceNotSolid(true); @@ -452,7 +467,7 @@ SkCanvas::SaveLayerStrategy AnalysisCanvas::willSaveLayer( } } - INHERITED::willSaveLayer(bounds, paint, flags); + INHERITED::getSaveLayerStrategy(rec); // Actually saving a layer here could cause a new bitmap to be created // and real rendering to occur. return kNoLayer_SaveLayerStrategy; diff --git a/chromium/skia/ext/analysis_canvas.h b/chromium/skia/ext/analysis_canvas.h index 4c53e3d8925..093a613447d 100644 --- a/chromium/skia/ext/analysis_canvas.h +++ b/chromium/skia/ext/analysis_canvas.h @@ -5,6 +5,9 @@ #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/SkCanvas.h" #include "third_party/skia/include/core/SkPicture.h" @@ -61,10 +64,6 @@ class SK_API AnalysisCanvas : public SkCanvas, public SkPicture::AbortCallback { const SkRect& dst, const SkPaint* paint, SrcRectConstraint) override; - void onDrawSprite(const SkBitmap&, - int left, - int top, - const SkPaint* paint = NULL) override; void onDrawVertices(VertexMode, int vertexCount, const SkPoint vertices[], @@ -77,9 +76,7 @@ class SK_API AnalysisCanvas : public SkCanvas, public SkPicture::AbortCallback { protected: void willSave() override; - SaveLayerStrategy willSaveLayer(const SkRect*, - const SkPaint*, - SaveFlags) override; + SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; void willRestore() override; void onClipRect(const SkRect& rect, diff --git a/chromium/skia/ext/benchmarking_canvas.cc b/chromium/skia/ext/benchmarking_canvas.cc index 752e398eeec..cb299c7bc43 100644 --- a/chromium/skia/ext/benchmarking_canvas.cc +++ b/chromium/skia/ext/benchmarking_canvas.cc @@ -2,20 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "skia/ext/benchmarking_canvas.h" + +#include <utility> + #include "base/logging.h" #include "base/strings/stringprintf.h" #include "base/time/time.h" -#include "skia/ext/benchmarking_canvas.h" #include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkImageFilter.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPicture.h" -#include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkRRect.h" +#include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkString.h" -#include "third_party/skia/include/core/SkTextBlob.h" #include "third_party/skia/include/core/SkTLazy.h" +#include "third_party/skia/include/core/SkTextBlob.h" #include "third_party/skia/include/core/SkXfermode.h" namespace { @@ -47,14 +50,14 @@ WARN_UNUSED_RESULT scoped_ptr<base::Value> AsValue(bool b) { scoped_ptr<base::FundamentalValue> val(new base::FundamentalValue(b)); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT scoped_ptr<base::Value> AsValue(SkScalar scalar) { scoped_ptr<base::FundamentalValue> val(new base::FundamentalValue(scalar)); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -63,7 +66,7 @@ scoped_ptr<base::Value> AsValue(const SkSize& size) { val->Set("width", AsValue(size.width())); val->Set("height", AsValue(size.height())); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -72,7 +75,7 @@ scoped_ptr<base::Value> AsValue(const SkPoint& point) { val->Set("x", AsValue(point.x())); val->Set("y", AsValue(point.y())); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -83,7 +86,7 @@ scoped_ptr<base::Value> AsValue(const SkRect& rect) { val->Set("right", AsValue(rect.fRight)); val->Set("bottom", AsValue(rect.fBottom)); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -96,9 +99,9 @@ scoped_ptr<base::Value> AsValue(const SkRRect& rrect) { scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); val->Set("rect", AsValue(rrect.rect())); - val->Set("radii", radii_val.Pass()); + val->Set("radii", std::move(radii_val)); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -107,7 +110,7 @@ scoped_ptr<base::Value> AsValue(const SkMatrix& matrix) { for (int i = 0; i < 9; ++i) val->Append(AsValue(matrix[i]).release()); // no scoped_ptr-aware Append() variant - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -118,7 +121,7 @@ scoped_ptr<base::Value> AsValue(SkColor color) { val->SetInteger("g", SkColorGetG(color)); val->SetInteger("b", SkColorGetB(color)); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -126,7 +129,7 @@ scoped_ptr<base::Value> AsValue(SkXfermode::Mode mode) { scoped_ptr<base::StringValue> val( new base::StringValue(SkXfermode::ModeName(mode))); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -136,7 +139,7 @@ scoped_ptr<base::Value> AsValue(SkCanvas::PointMode mode) { scoped_ptr<base::StringValue> val(new base::StringValue(gModeStrings[mode])); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -146,7 +149,7 @@ scoped_ptr<base::Value> AsValue(const SkXfermode& xfermode) { return AsValue(mode); scoped_ptr<base::StringValue> val(new base::StringValue("unknown")); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -167,7 +170,7 @@ scoped_ptr<base::Value> AsValue(const SkColorFilter& filter) { for (unsigned i = 0; i < 20; ++i) color_matrix_val->Append(AsValue(color_matrix[i]).release()); - val->Set("color_matrix", color_matrix_val.Pass()); + val->Set("color_matrix", std::move(color_matrix_val)); } SkColor color; @@ -178,17 +181,17 @@ scoped_ptr<base::Value> AsValue(const SkColorFilter& filter) { color_mode_val->Set("color", AsValue(color)); color_mode_val->Set("mode", AsValue(mode)); - val->Set("color_mode", color_mode_val.Pass()); + val->Set("color_mode", std::move(color_mode_val)); } if (filter.asComponentTable(nullptr)) { scoped_ptr<base::DictionaryValue> component_table_val( new base::DictionaryValue()); // use this as a marker for now - val->Set("component_table", component_table_val.Pass()); + val->Set("component_table", std::move(component_table_val)); } - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -202,7 +205,7 @@ scoped_ptr<base::Value> AsValue(const SkImageFilter& filter) { SkSafeUnref(color_filter); // ref'd in asColorFilter } - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -239,8 +242,6 @@ scoped_ptr<base::Value> AsValue(const SkPaint& paint) { builder.addFlag(paint.isEmbeddedBitmapText(), "EmbeddedBitmapText"); builder.addFlag(paint.isAutohinted(), "Autohinted"); builder.addFlag(paint.isVerticalText(), "VerticalText"); - builder.addFlag(paint.getFlags() & SkPaint::kGenA8FromLCD_Flag, - "GenA8FromLCD"); val->SetString("Flags", builder.str()); } @@ -269,22 +270,20 @@ scoped_ptr<base::Value> AsValue(const SkPaint& paint) { if (paint.getImageFilter()) val->Set("ImageFilter", AsValue(*paint.getImageFilter())); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT -scoped_ptr<base::Value> AsValue(SkCanvas::SaveFlags flags) { +scoped_ptr<base::Value> SaveLayerFlagsAsValue(SkCanvas::SaveLayerFlags flags) { FlagsBuilder builder('|'); - builder.addFlag(flags & SkCanvas::kHasAlphaLayer_SaveFlag, - "kHasAlphaLayer"); - builder.addFlag(flags & SkCanvas::kFullColorLayer_SaveFlag, - "kFullColorLayer"); - builder.addFlag(flags & SkCanvas::kClipToLayer_SaveFlag, - "kClipToLayer"); + builder.addFlag(flags & SkCanvas::kIsOpaque_SaveLayerFlag, + "kIsOpaque"); + builder.addFlag(flags & SkCanvas::kPreserveLCDText_SaveLayerFlag, + "kPreserveLCDText"); scoped_ptr<base::StringValue> val(new base::StringValue(builder.str())); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -298,7 +297,7 @@ scoped_ptr<base::Value> AsValue(SkRegion::Op op) { }; DCHECK_LT(static_cast<size_t>(op), SK_ARRAY_COUNT(gOpStrings)); scoped_ptr<base::StringValue> val(new base::StringValue(gOpStrings[op])); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -306,7 +305,7 @@ scoped_ptr<base::Value> AsValue(const SkRegion& region) { scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); val->Set("bounds", AsValue(SkRect::Make(region.getBounds()))); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -314,7 +313,7 @@ scoped_ptr<base::Value> AsValue(const SkBitmap& bitmap) { scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); val->Set("size", AsValue(SkSize::Make(bitmap.width(), bitmap.height()))); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -322,7 +321,7 @@ scoped_ptr<base::Value> AsValue(const SkImage& image) { scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); val->Set("size", AsValue(SkSize::Make(image.width(), image.height()))); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -330,7 +329,7 @@ scoped_ptr<base::Value> AsValue(const SkTextBlob& blob) { scoped_ptr<base::DictionaryValue> val(new base::DictionaryValue()); val->Set("bounds", AsValue(blob.bounds())); - return val.Pass(); + return std::move(val); } WARN_UNUSED_RESULT @@ -379,16 +378,16 @@ scoped_ptr<base::Value> AsValue(const SkPath& path) { for (int i = 0; i < gPtsPerVerb[verb]; ++i) pts_val->Append(AsValue(points[i + gPtOffsetPerVerb[verb]]).release()); - verb_val->Set(gVerbStrings[verb], pts_val.Pass()); + verb_val->Set(gVerbStrings[verb], std::move(pts_val)); if (SkPath::kConic_Verb == verb) verb_val->Set("weight", AsValue(iter.conicWeight())); verbs_val->Append(verb_val.release()); } - val->Set("verbs", verbs_val.Pass()); + val->Set("verbs", std::move(verbs_val)); - return val.Pass(); + return std::move(val); } template<typename T> @@ -399,7 +398,7 @@ scoped_ptr<base::Value> AsListValue(const T array[], size_t count) { for (size_t i = 0; i < count; ++i) val->Append(AsValue(array[i]).release()); - return val.Pass(); + return std::move(val); } class OverdrawXfermode : public SkXfermode { @@ -487,7 +486,7 @@ public: void addParam(const char name[], scoped_ptr<base::Value> value) { scoped_ptr<base::DictionaryValue> param(new base::DictionaryValue()); - param->Set(name, value.Pass()); + param->Set(name, std::move(value)); op_params_->Append(param.release()); } @@ -543,16 +542,15 @@ void BenchmarkingCanvas::willSave() { INHERITED::willSave(); } -SkCanvas::SaveLayerStrategy BenchmarkingCanvas::willSaveLayer(const SkRect* rect, - const SkPaint* paint, - SaveFlags flags) { - AutoOp op(this, "SaveLayer", paint); - if (rect) - op.addParam("bounds", AsValue(*rect)); - if (flags) - op.addParam("flags", AsValue(flags)); +SkCanvas::SaveLayerStrategy BenchmarkingCanvas::getSaveLayerStrategy( + const SaveLayerRec& rec) { + AutoOp op(this, "SaveLayer", rec.fPaint); + if (rec.fBounds) + op.addParam("bounds", AsValue(*rec.fBounds)); + if (rec.fSaveLayerFlags) + op.addParam("flags", SaveLayerFlagsAsValue(rec.fSaveLayerFlags)); - return INHERITED::willSaveLayer(rect, op.paint(), flags); + return INHERITED::getSaveLayerStrategy(rec); } void BenchmarkingCanvas::willRestore() { @@ -745,16 +743,6 @@ void BenchmarkingCanvas::onDrawBitmapNine(const SkBitmap& bitmap, INHERITED::onDrawBitmapNine(bitmap, center, dst, op.paint()); } -void BenchmarkingCanvas::onDrawSprite(const SkBitmap& bitmap, int left, int top, - const SkPaint* paint) { - AutoOp op(this, "DrawSprite", paint); - op.addParam("bitmap", AsValue(bitmap)); - op.addParam("left", AsValue(SkIntToScalar(left))); - op.addParam("top", AsValue(SkIntToScalar(top))); - - INHERITED::onDrawSprite(bitmap, left, top, op.paint()); -} - void BenchmarkingCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint& paint) { diff --git a/chromium/skia/ext/benchmarking_canvas.h b/chromium/skia/ext/benchmarking_canvas.h index 8fbbae44bfd..29351175071 100644 --- a/chromium/skia/ext/benchmarking_canvas.h +++ b/chromium/skia/ext/benchmarking_canvas.h @@ -5,6 +5,8 @@ #ifndef SKIA_EXT_BENCHMARKING_CANVAS_H_ #define SKIA_EXT_BENCHMARKING_CANVAS_H_ +#include <stddef.h> + #include "base/values.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/utils/SkNWayCanvas.h" @@ -34,9 +36,7 @@ public: protected: // SkCanvas overrides void willSave() override; - SaveLayerStrategy willSaveLayer(const SkRect*, - const SkPaint*, - SaveFlags) override; + SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; void willRestore() override; void didConcat(const SkMatrix&) override; @@ -66,7 +66,6 @@ protected: const SkPaint*, SrcRectConstraint) override; void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, const SkPaint*) override; - void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) override; void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint&) override; diff --git a/chromium/skia/ext/bitmap_platform_device.h b/chromium/skia/ext/bitmap_platform_device.h index a0770f71717..11acd9550ee 100644 --- a/chromium/skia/ext/bitmap_platform_device.h +++ b/chromium/skia/ext/bitmap_platform_device.h @@ -8,6 +8,8 @@ // This file provides an easy way to include the appropriate // BitmapPlatformDevice header file for your platform. +#include <stdint.h> + #if defined(WIN32) #include "skia/ext/bitmap_platform_device_win.h" #elif defined(__APPLE__) diff --git a/chromium/skia/ext/bitmap_platform_device_cairo.cc b/chromium/skia/ext/bitmap_platform_device_cairo.cc index 246984a8a41..541e263bb83 100644 --- a/chromium/skia/ext/bitmap_platform_device_cairo.cc +++ b/chromium/skia/ext/bitmap_platform_device_cairo.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "build/build_config.h" #include "skia/ext/bitmap_platform_device_cairo.h" #include "skia/ext/platform_canvas.h" @@ -35,8 +36,10 @@ bool InstallCairoSurfacePixels(SkBitmap* dst, return false; } SkImageInfo info - = SkImageInfo::MakeN32Premul(cairo_image_surface_get_width(surface), - cairo_image_surface_get_height(surface)); + = SkImageInfo::MakeN32(cairo_image_surface_get_width(surface), + cairo_image_surface_get_height(surface), + is_opaque ? kOpaque_SkAlphaType + : kPremul_SkAlphaType); return dst->installPixels(info, cairo_image_surface_get_data(surface), cairo_image_surface_get_stride(surface), @@ -134,14 +137,6 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, return device; } -BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, - int height, - bool is_opaque) { - // The Linux port always constructs initialized bitmaps, so there is no extra - // work to perform here. - return Create(width, height, is_opaque); -} - BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, bool is_opaque, uint8_t* data) { @@ -200,26 +195,4 @@ SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, return CreateCanvas(dev, failureType); } -// Port of PlatformBitmap to linux -PlatformBitmap::~PlatformBitmap() { - cairo_destroy(surface_); -} - -bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { - // The SkBitmap allocates and owns the bitmap memory; PlatformBitmap owns the - // cairo drawing context tied to the bitmap. The SkBitmap's pixelRef can - // outlive the PlatformBitmap if additional copies are made. - int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); - - cairo_surface_t* surf = cairo_image_surface_create( - CAIRO_FORMAT_ARGB32, - width, - height); - if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) { - cairo_surface_destroy(surf); - return false; - } - return InstallCairoSurfacePixels(&bitmap_, surf, is_opaque); -} - } // namespace skia diff --git a/chromium/skia/ext/bitmap_platform_device_cairo.h b/chromium/skia/ext/bitmap_platform_device_cairo.h index 96a1e17972d..6a81c725e82 100644 --- a/chromium/skia/ext/bitmap_platform_device_cairo.h +++ b/chromium/skia/ext/bitmap_platform_device_cairo.h @@ -5,8 +5,10 @@ #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_CAIRO_H_ #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_CAIRO_H_ -#include "base/basictypes.h" +#include <stdint.h> + #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "skia/ext/platform_device.h" @@ -72,12 +74,6 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { // completely opaque and allows some optimizations. static BitmapPlatformDevice* Create(int width, int height, bool is_opaque); - // Performs the same construction as Create. - // Other ports require a separate construction routine because Create does not - // initialize the bitmap to 0. - static BitmapPlatformDevice* CreateAndClear(int width, int height, - bool is_opaque); - // This doesn't take ownership of |data|. If |data| is NULL, the contents // of the device are initialized to 0. 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 087cf39d7fd..e2b2c02a5f3 100644 --- a/chromium/skia/ext/bitmap_platform_device_mac.cc +++ b/chromium/skia/ext/bitmap_platform_device_mac.cc @@ -5,6 +5,7 @@ #include "skia/ext/bitmap_platform_device_mac.h" #import <ApplicationServices/ApplicationServices.h> +#include <stddef.h> #include <time.h> #include "base/mac/mac_util.h" @@ -99,7 +100,7 @@ static void LoadTransformToCGContext(CGContextRef context, transformed_matrix.setTranslateY(ty + (SkScalar)height); CGAffineTransform cg_matrix = - gfx::SkMatrixToCGAffineTransform(transformed_matrix); + skia::SkMatrixToCGAffineTransform(transformed_matrix); // Load final transform into context. CGContextConcatCTM(context, cg_matrix); @@ -113,7 +114,7 @@ static void LoadClippingRegionToCGContext(CGContextRef context, // region can be empty, in which case everything will be clipped. SkRect rect; rect.setEmpty(); - CGContextClipToRect(context, gfx::SkRectToCGRect(rect)); + CGContextClipToRect(context, skia::SkRectToCGRect(rect)); } else if (region.isRect()) { // CoreGraphics applies the current transform to clip rects, which is // unwanted. Inverse-transform the rect before sending it to CG. This only @@ -129,7 +130,7 @@ static void LoadClippingRegionToCGContext(CGContextRef context, t.mapRect(&rect); SkIRect irect; rect.round(&irect); - CGContextClipToRect(context, gfx::SkIRectToCGRect(irect)); + CGContextClipToRect(context, skia::SkIRectToCGRect(irect)); } else { // It is complex. SkPath path; @@ -298,26 +299,4 @@ SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, return CreateCanvas(dev, failureType); } -// Port of PlatformBitmap to mac - -PlatformBitmap::~PlatformBitmap() { - if (surface_) - CGContextRelease(surface_); -} - -bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { - if (RasterDeviceTooBigToAllocate(width, height)) - return false; - - if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque)) - return false; - - if (!is_opaque) - bitmap_.eraseColor(0); - - surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), - bitmap_.height()); - return true; -} - } // namespace skia diff --git a/chromium/skia/ext/bitmap_platform_device_mac.h b/chromium/skia/ext/bitmap_platform_device_mac.h index 566924bb8d1..69c375d58ff 100644 --- a/chromium/skia/ext/bitmap_platform_device_mac.h +++ b/chromium/skia/ext/bitmap_platform_device_mac.h @@ -5,8 +5,10 @@ #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ -#include "base/basictypes.h" +#include <stdint.h> + #include "base/compiler_specific.h" +#include "base/macros.h" #include "skia/ext/platform_device.h" #include "skia/ext/refptr.h" diff --git a/chromium/skia/ext/bitmap_platform_device_mac_unittest.cc b/chromium/skia/ext/bitmap_platform_device_mac_unittest.cc index 7265bc4cfb3..0ba67727013 100644 --- a/chromium/skia/ext/bitmap_platform_device_mac_unittest.cc +++ b/chromium/skia/ext/bitmap_platform_device_mac_unittest.cc @@ -38,7 +38,7 @@ TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithTranslate) { bitmap_->setMatrixClip(transform, clip_region, ignore); CGContextRef context = bitmap_->GetBitmapContext(); - SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); + SkRect clip_rect = skia::CGRectToSkRect(CGContextGetClipBoundingBox(context)); transform.mapRect(&clip_rect); EXPECT_EQ(0, clip_rect.fLeft); EXPECT_EQ(0, clip_rect.fTop); @@ -58,7 +58,7 @@ TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithScale) { bitmap_->setMatrixClip(transform, clip_region, unused); CGContextRef context = bitmap_->GetBitmapContext(); - SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); + SkRect clip_rect = skia::CGRectToSkRect(CGContextGetClipBoundingBox(context)); transform.mapRect(&clip_rect); EXPECT_EQ(0, clip_rect.fLeft); EXPECT_EQ(0, clip_rect.fTop); diff --git a/chromium/skia/ext/bitmap_platform_device_skia.cc b/chromium/skia/ext/bitmap_platform_device_skia.cc index 04fc950f560..f3c97eb9bc9 100644 --- a/chromium/skia/ext/bitmap_platform_device_skia.cc +++ b/chromium/skia/ext/bitmap_platform_device_skia.cc @@ -64,17 +64,4 @@ SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, return CreateCanvas(dev, failureType); } -// Port of PlatformBitmap to android -PlatformBitmap::~PlatformBitmap() { - // Nothing to do. -} - -bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { - if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque)) - return false; - - surface_ = bitmap_.getPixels(); - return true; -} - } // namespace skia diff --git a/chromium/skia/ext/bitmap_platform_device_skia.h b/chromium/skia/ext/bitmap_platform_device_skia.h index 0e21929112a..4a0d67a9769 100644 --- a/chromium/skia/ext/bitmap_platform_device_skia.h +++ b/chromium/skia/ext/bitmap_platform_device_skia.h @@ -5,7 +5,10 @@ #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_SKIA_H_ #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_SKIA_H_ +#include <stdint.h> + #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "skia/ext/platform_device.h" diff --git a/chromium/skia/ext/bitmap_platform_device_win.cc b/chromium/skia/ext/bitmap_platform_device_win.cc index 5712df3eaea..c636ba95c94 100644 --- a/chromium/skia/ext/bitmap_platform_device_win.cc +++ b/chromium/skia/ext/bitmap_platform_device_win.cc @@ -4,12 +4,14 @@ #include <windows.h> #include <psapi.h> +#include <stddef.h> #include "base/debug/gdi_debug_util_win.h" #include "base/logging.h" #include "base/win/win_util.h" #include "skia/ext/bitmap_platform_device_win.h" #include "skia/ext/platform_canvas.h" +#include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkMatrix.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRegion.h" @@ -317,35 +319,4 @@ SkCanvas* CreatePlatformCanvas(int width, return CreateCanvas(dev, failureType); } -// Port of PlatformBitmap to win - -PlatformBitmap::~PlatformBitmap() { - if (surface_) { - if (platform_extra_) - SelectObject(surface_, reinterpret_cast<HGDIOBJ>(platform_extra_)); - DeleteDC(surface_); - } -} - -bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { - void* data; - HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, 0, &data); - if (!hbitmap) - return false; - - surface_ = CreateCompatibleDC(NULL); - InitializeDC(surface_); - // When the memory DC is created, its display surface is exactly one - // monochrome pixel wide and one monochrome pixel high. Save this object - // off, we'll restore it just before deleting the memory DC. - HGDIOBJ stock_bitmap = SelectObject(surface_, hbitmap); - platform_extra_ = reinterpret_cast<intptr_t>(stock_bitmap); - - if (!InstallHBitmapPixels(&bitmap_, width, height, is_opaque, data, hbitmap)) - return false; - bitmap_.lockPixels(); - - return true; -} - } // namespace skia diff --git a/chromium/skia/ext/bitmap_platform_device_win.h b/chromium/skia/ext/bitmap_platform_device_win.h index 8acfd42bbab..3f3a5e15f74 100644 --- a/chromium/skia/ext/bitmap_platform_device_win.h +++ b/chromium/skia/ext/bitmap_platform_device_win.h @@ -5,8 +5,8 @@ #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "skia/ext/platform_device.h" #include "skia/ext/refptr.h" @@ -18,12 +18,6 @@ namespace skia { // format that Skia supports and can then use this to draw ClearType into, etc. // This pixel data is provided to the bitmap that the device contains so that it // can be shared. -// -// The GDI bitmap created for drawing is actually owned by a -// PlatformBitmapPixelRef, and stored in an SkBitmap via the normal skia -// SkPixelRef refcounting mechanism. In this way, the GDI bitmap can outlive -// the device created to draw into it. So it is safe to call accessBitmap() on -// the device, and retain the returned SkBitmap. class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { public: // Factory function. is_opaque should be set if the caller knows the bitmap diff --git a/chromium/skia/ext/convolver.h b/chromium/skia/ext/convolver.h index 1f61f23a2ca..1f33d4c0f79 100644 --- a/chromium/skia/ext/convolver.h +++ b/chromium/skia/ext/convolver.h @@ -5,10 +5,12 @@ #ifndef SKIA_EXT_CONVOLVER_H_ #define SKIA_EXT_CONVOLVER_H_ +#include <stdint.h> + #include <cmath> #include <vector> -#include "base/basictypes.h" +#include "build/build_config.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkTypes.h" @@ -16,7 +18,7 @@ // except when building for the IOS emulator. #if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_IOS) #define SIMD_SSE2 1 -#define SIMD_PADDING 8 // 8 * int16 +#define SIMD_PADDING 8 // 8 * int16_t #endif #if defined (ARCH_CPU_MIPS_FAMILY) && \ diff --git a/chromium/skia/ext/convolver_SSE2.cc b/chromium/skia/ext/convolver_SSE2.cc index a77a1f45c41..4213bb5d397 100644 --- a/chromium/skia/ext/convolver_SSE2.cc +++ b/chromium/skia/ext/convolver_SSE2.cc @@ -4,6 +4,7 @@ #include <algorithm> +#include "build/build_config.h" #include "skia/ext/convolver.h" #include "skia/ext/convolver_SSE2.h" #include "third_party/skia/include/core/SkTypes.h" diff --git a/chromium/skia/ext/convolver_unittest.cc b/chromium/skia/ext/convolver_unittest.cc index e833b45a713..626b9a94ff4 100644 --- a/chromium/skia/ext/convolver_unittest.cc +++ b/chromium/skia/ext/convolver_unittest.cc @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stdint.h> #include <string.h> #include <time.h> #include <algorithm> #include <numeric> #include <vector> -#include "base/basictypes.h" #include "base/logging.h" +#include "base/macros.h" #include "base/time/time.h" #include "skia/ext/convolver.h" #include "testing/gtest/include/gtest/gtest.h" @@ -258,18 +259,16 @@ void VerifySIMD(unsigned int source_width, unsigned char* r2 = static_cast<unsigned char*>(result_sse.getPixels()); resize_start = base::TimeTicks::Now(); - BGRAConvolve2D(static_cast<const uint8*>(source.getPixels()), - static_cast<int>(source.rowBytes()), - (alpha != 0), x_filter, y_filter, - static_cast<int>(result_c.rowBytes()), r1, false); + BGRAConvolve2D(static_cast<const uint8_t*>(source.getPixels()), + static_cast<int>(source.rowBytes()), (alpha != 0), x_filter, + y_filter, static_cast<int>(result_c.rowBytes()), r1, false); delta_c = base::TimeTicks::Now() - resize_start; resize_start = base::TimeTicks::Now(); // Convolve using SSE2 code - BGRAConvolve2D(static_cast<const uint8*>(source.getPixels()), - static_cast<int>(source.rowBytes()), - (alpha != 0), x_filter, y_filter, - static_cast<int>(result_sse.rowBytes()), r2, true); + BGRAConvolve2D(static_cast<const uint8_t*>(source.getPixels()), + static_cast<int>(source.rowBytes()), (alpha != 0), x_filter, + y_filter, static_cast<int>(result_sse.rowBytes()), r2, true); delta_sse = base::TimeTicks::Now() - resize_start; // Unfortunately I could not enable the performance check now. @@ -281,8 +280,8 @@ void VerifySIMD(unsigned int source_width, // debug version too. // EXPECT_LE(delta_sse, delta_c); - int64 c_us = delta_c.InMicroseconds(); - int64 sse_us = delta_sse.InMicroseconds(); + int64_t c_us = delta_c.InMicroseconds(); + int64_t sse_us = delta_sse.InMicroseconds(); VLOG(1) << "from:" << source_width << "x" << source_height << " to:" << dest_width << "x" << dest_height << (alpha ? " with alpha" : " w/o alpha"); diff --git a/chromium/skia/ext/event_tracer_impl.cc b/chromium/skia/ext/event_tracer_impl.cc index f6e12f05d60..55b704bf9e2 100644 --- a/chromium/skia/ext/event_tracer_impl.cc +++ b/chromium/skia/ext/event_tracer_impl.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stdint.h> + #include "base/trace_event/trace_event.h" #include "skia/ext/event_tracer_impl.h" #include "third_party/skia/include/utils/SkEventTracer.h" @@ -70,5 +72,6 @@ void void InitSkiaEventTracer() { // Initialize the binding to Skia's tracing events. Skia will // take ownership of and clean up the memory allocated here. - SkEventTracer::SetInstance(new skia::SkChromiumEventTracer()); + if (!SkEventTracer::GetInstance()) + SkEventTracer::SetInstance(new skia::SkChromiumEventTracer()); } diff --git a/chromium/skia/ext/image_operations.cc b/chromium/skia/ext/image_operations.cc index a14344d319e..985787bae38 100644 --- a/chromium/skia/ext/image_operations.cc +++ b/chromium/skia/ext/image_operations.cc @@ -3,6 +3,10 @@ // found in the LICENSE file. #define _USE_MATH_DEFINES + +#include <stddef.h> +#include <stdint.h> + #include <algorithm> #include <cmath> #include <limits> @@ -12,6 +16,7 @@ // TODO(pkasting): skia/ext should not depend on base/! #include "base/containers/stack_container.h" #include "base/logging.h" +#include "base/macros.h" #include "base/metrics/histogram.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" @@ -113,10 +118,6 @@ class ResizeFilter { // The Hamming filter takes as much space in the source image in // each direction as the size of the window = 1 for Hamming1. return 1.0f; - case ImageOperations::RESIZE_LANCZOS2: - // The Lanczos filter takes as much space in the source image in - // each direction as the size of the window = 2 for Lanczos2. - return 2.0f; case ImageOperations::RESIZE_LANCZOS3: // The Lanczos filter takes as much space in the source image in // each direction as the size of the window = 3 for Lanczos3. @@ -149,8 +150,6 @@ class ResizeFilter { return EvalBox(pos); case ImageOperations::RESIZE_HAMMING1: return EvalHamming(1, pos); - case ImageOperations::RESIZE_LANCZOS2: - return EvalLanczos(2, pos); case ImageOperations::RESIZE_LANCZOS3: return EvalLanczos(3, pos); default: @@ -228,7 +227,7 @@ void ResizeFilter::ComputeFilters(int src_size, float inv_scale = 1.0f / scale; base::StackVector<float, 64> filter_values; - base::StackVector<int16, 64> fixed_filter_values; + base::StackVector<int16_t, 64> fixed_filter_values; // Loop over all pixels in the output range. We will generate one set of // filter values for each one. Those values will tell us how to blend the @@ -279,9 +278,9 @@ void ResizeFilter::ComputeFilters(int src_size, // The filter must be normalized so that we don't affect the brightness of // the image. Convert to normalized fixed point. - int16 fixed_sum = 0; + int16_t fixed_sum = 0; for (size_t i = 0; i < filter_values->size(); i++) { - int16 cur_fixed = output->FloatToFixed(filter_values[i] / filter_sum); + int16_t cur_fixed = output->FloatToFixed(filter_values[i] / filter_sum); fixed_sum += cur_fixed; fixed_filter_values->push_back(cur_fixed); } @@ -291,7 +290,7 @@ void ResizeFilter::ComputeFilters(int src_size, // arbitrarily add this to the center of the filter array (this won't always // be the center of the filter function since it could get clipped on the // edges, but it doesn't matter enough to worry about that case). - int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum; + int16_t leftovers = output->FloatToFixed(1.0f) - fixed_sum; fixed_filter_values[fixed_filter_values->size() / 2] += leftovers; // Now it's ready to go. @@ -378,8 +377,8 @@ SkBitmap ImageOperations::Resize(const SkBitmap& source, // Get a source bitmap encompassing this touched area. We construct the // offsets and row strides such that it looks like a new bitmap, while // referring to the old data. - const uint8* source_subset = - reinterpret_cast<const uint8*>(source.getPixels()); + const uint8_t* source_subset = + reinterpret_cast<const uint8_t*>(source.getPixels()); // Convolve into the result. SkBitmap result; diff --git a/chromium/skia/ext/image_operations.h b/chromium/skia/ext/image_operations.h index 9e0b073cc2f..01d364b99e4 100644 --- a/chromium/skia/ext/image_operations.h +++ b/chromium/skia/ext/image_operations.h @@ -70,11 +70,6 @@ class SK_API ImageOperations { // a 2-cycle Lanczos. RESIZE_HAMMING1, - // 2-cycle Lanczos filter. This is tall in the middle, goes negative on - // each side, then returns to zero. Does not provide as good a frequency - // response as a 3-cycle Lanczos but is roughly 30% faster. - RESIZE_LANCZOS2, - // 3-cycle Lanczos filter. This is tall in the middle, goes negative on // each side, then oscillates 2 more times. It gives nice sharp edges. RESIZE_LANCZOS3, diff --git a/chromium/skia/ext/image_operations_bench.cc b/chromium/skia/ext/image_operations_bench.cc index 9b2667fec35..2c1c16772f7 100644 --- a/chromium/skia/ext/image_operations_bench.cc +++ b/chromium/skia/ext/image_operations_bench.cc @@ -14,16 +14,19 @@ // This number is somewhat reasonable way to measure this, given our current // implementation which somewhat scales this way. +#include <stddef.h> +#include <stdint.h> #include <stdio.h> -#include "base/basictypes.h" #include "base/command_line.h" #include "base/format_macros.h" +#include "base/macros.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" +#include "build/build_config.h" #include "skia/ext/image_operations.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkRect.h" @@ -41,7 +44,6 @@ const StringMethodPair resize_methods[] = { ADD_METHOD(BEST), ADD_METHOD(BOX), ADD_METHOD(HAMMING1), - ADD_METHOD(LANCZOS2), ADD_METHOD(LANCZOS3), }; @@ -241,15 +243,15 @@ bool Benchmark::Run() const { dest_.width(), dest_.height()); } - const int64 elapsed_us = (base::TimeTicks::Now() - start).InMicroseconds(); + const int64_t elapsed_us = (base::TimeTicks::Now() - start).InMicroseconds(); - const uint64 num_bytes = static_cast<uint64>(num_iterations_) * - (GetBitmapSize(&source) + GetBitmapSize(&dest)); + const uint64_t num_bytes = static_cast<uint64_t>(num_iterations_) * + (GetBitmapSize(&source) + GetBitmapSize(&dest)); printf("%" PRIu64 " MB/s,\telapsed = %" PRIu64 " source=%d dest=%d\n", - static_cast<uint64>(elapsed_us == 0 ? 0 : num_bytes / elapsed_us), - static_cast<uint64>(elapsed_us), - GetBitmapSize(&source), GetBitmapSize(&dest)); + static_cast<uint64_t>(elapsed_us == 0 ? 0 : num_bytes / elapsed_us), + static_cast<uint64_t>(elapsed_us), GetBitmapSize(&source), + GetBitmapSize(&dest)); return true; } diff --git a/chromium/skia/ext/image_operations_unittest.cc b/chromium/skia/ext/image_operations_unittest.cc index 8f6d756f25f..e88c5e28f29 100644 --- a/chromium/skia/ext/image_operations_unittest.cc +++ b/chromium/skia/ext/image_operations_unittest.cc @@ -2,14 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> +#include <stdint.h> + #include <algorithm> #include <cmath> #include <iomanip> #include <vector> -#include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/files/file_util.h" +#include "base/macros.h" #include "base/strings/string_util.h" #include "skia/ext/image_operations.h" #include "testing/gtest/include/gtest/gtest.h" @@ -123,35 +126,6 @@ void FillDataToBitmap(int w, int h, SkBitmap* bmp) { } } -// Draws a horizontal and vertical grid into the w x h bitmap passed in. -// Each line in the grid is drawn with a width of "grid_width" pixels, -// and those lines repeat every "grid_pitch" pixels. The top left pixel (0, 0) -// is considered to be part of a grid line. -// The pixels that fall on a line are colored with "grid_color", while those -// outside of the lines are colored in "background_color". -// Note that grid_with can be greather than or equal to grid_pitch, in which -// case the resulting bitmap will be a solid color "grid_color". -void DrawGridToBitmap(int w, int h, - SkColor background_color, SkColor grid_color, - int grid_pitch, int grid_width, - SkBitmap* bmp) { - ASSERT_GT(grid_pitch, 0); - ASSERT_GT(grid_width, 0); - ASSERT_NE(background_color, grid_color); - - bmp->allocN32Pixels(w, h); - - for (int y = 0; y < h; ++y) { - bool y_on_grid = ((y % grid_pitch) < grid_width); - - for (int x = 0; x < w; ++x) { - bool on_grid = (y_on_grid || ((x % grid_pitch) < grid_width)); - - *bmp->getAddr32(x, y) = (on_grid ? grid_color : background_color); - } - } -} - // Draws a checkerboard pattern into the w x h bitmap passed in. // Each rectangle is rect_w in width, rect_h in height. // The colors alternate between color1 and color2, color1 being used @@ -473,10 +447,6 @@ TEST(ImageOperations, ResampleToSameHamming1) { CheckResampleToSame(skia::ImageOperations::RESIZE_HAMMING1); } -TEST(ImageOperations, ResampleToSameLanczos2) { - CheckResampleToSame(skia::ImageOperations::RESIZE_LANCZOS2); -} - TEST(ImageOperations, ResampleToSameLanczos3) { CheckResampleToSame(skia::ImageOperations::RESIZE_LANCZOS3); } @@ -501,7 +471,6 @@ TEST(ImageOperations, ResizeShouldAverageColors) { { skia::ImageOperations::RESIZE_BEST, "BEST", 0.0f }, { skia::ImageOperations::RESIZE_BOX, "BOX", 0.0f }, { skia::ImageOperations::RESIZE_HAMMING1, "HAMMING1", 0.0f }, - { skia::ImageOperations::RESIZE_LANCZOS2, "LANCZOS2", 0.0f }, { skia::ImageOperations::RESIZE_LANCZOS3, "LANCZOS3", 0.0f }, }; @@ -537,89 +506,6 @@ TEST(ImageOperations, ResizeShouldAverageColors) { } -// Check that Lanczos2 and Lanczos3 thumbnails produce similar results -TEST(ImageOperations, CompareLanczosMethods) { - const int src_w = 640, src_h = 480, src_grid_pitch = 8, src_grid_width = 4; - - const int dest_w = src_w / 4; - const int dest_h = src_h / 4; - - // 5.0f is the maximum distance we see in this test given the current - // parameters. The value is very ad-hoc and the parameters of the scaling - // were picked to produce a small value. So this test is very much about - // revealing egregious regression rather than doing a good job at checking - // the math behind the filters. - // TODO(evannier): because of the half pixel error mentioned inside - // image_operations.cc, this distance is much larger than it should be. - // This should read: - // const float max_color_distance = 5.0f; - const float max_color_distance = 12.1f; - - // Make our source bitmap. - SkColor grid_color = SK_ColorRED, background_color = SK_ColorBLUE; - SkBitmap src; - DrawGridToBitmap(src_w, src_h, - background_color, grid_color, - src_grid_pitch, src_grid_width, - &src); - - // Resize the src using both methods. - SkBitmap dest_l2 = skia::ImageOperations::Resize( - src, - skia::ImageOperations::RESIZE_LANCZOS2, - dest_w, dest_h); - ASSERT_EQ(dest_w, dest_l2.width()); - ASSERT_EQ(dest_h, dest_l2.height()); - - SkBitmap dest_l3 = skia::ImageOperations::Resize( - src, - skia::ImageOperations::RESIZE_LANCZOS3, - dest_w, dest_h); - ASSERT_EQ(dest_w, dest_l3.width()); - ASSERT_EQ(dest_h, dest_l3.height()); - - // Compare the pixels produced by both methods. - float max_observed_distance = 0.0f; - bool all_pixels_ok = true; - - SkAutoLockPixels l2_lock(dest_l2); - SkAutoLockPixels l3_lock(dest_l3); - for (int y = 0; y < dest_h; ++y) { - for (int x = 0; x < dest_w; ++x) { - const SkColor color_lanczos2 = *dest_l2.getAddr32(x, y); - const SkColor color_lanczos3 = *dest_l3.getAddr32(x, y); - - float distance = ColorsEuclidianDistance(color_lanczos2, color_lanczos3); - - EXPECT_LE(distance, max_color_distance) - << "pixel tested: (" << x << ", " << y - << std::hex << std::showbase - << "), lanczos2 hex: " << color_lanczos2 - << ", lanczos3 hex: " << color_lanczos3 - << std::setprecision(2) - << ", distance: " << distance; - - if (distance > max_color_distance) { - all_pixels_ok = false; - } - if (distance > max_observed_distance) { - max_observed_distance = distance; - } - } - } - - if (!all_pixels_ok) { - ADD_FAILURE() << "Maximum observed color distance: " - << max_observed_distance; - -#if DEBUG_BITMAP_GENERATION - SaveBitmapToPNG(src, "/tmp/CompareLanczosMethods_source.png"); - SaveBitmapToPNG(dest_l2, "/tmp/CompareLanczosMethods_lanczos2.png"); - SaveBitmapToPNG(dest_l3, "/tmp/CompareLanczosMethods_lanczos3.png"); -#endif // #if DEBUG_BITMAP_GENERATION - } -} - #ifndef M_PI // No M_PI in math.h on windows? No problem. #define M_PI 3.14159265358979323846 diff --git a/chromium/skia/ext/opacity_filter_canvas.cc b/chromium/skia/ext/opacity_filter_canvas.cc index 53d3580069c..d7867591ca5 100644 --- a/chromium/skia/ext/opacity_filter_canvas.cc +++ b/chromium/skia/ext/opacity_filter_canvas.cc @@ -15,24 +15,28 @@ OpacityFilterCanvas::OpacityFilterCanvas(SkCanvas* canvas, alpha_(SkScalarRoundToInt(opacity * 255)), disable_image_filtering_(disable_image_filtering) { } -void OpacityFilterCanvas::onFilterPaint(SkPaint* paint, Type) const { - if (alpha_ < 255) - paint->setAlpha(alpha_); +bool OpacityFilterCanvas::onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const { + // TODO(fmalita): with the new onFilter() API we could override alpha even + // when the original paint is null; is this something we should do? + if (*paint) { + if (alpha_ < 255) + paint->writable()->setAlpha(alpha_); + + if (disable_image_filtering_) + paint->writable()->setFilterQuality(kNone_SkFilterQuality); + } - if (disable_image_filtering_) - paint->setFilterQuality(kNone_SkFilterQuality); + return true; } void OpacityFilterCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) { - SkTLazy<SkPaint> filteredPaint; - if (paint) { - this->onFilterPaint(filteredPaint.set(*paint), kPicture_Type); + SkTCopyOnFirstWrite<SkPaint> filteredPaint(paint); + if (this->onFilter(&filteredPaint, kPicture_Type)) { + // Unfurl pictures in order to filter nested paints. + this->SkCanvas::onDrawPicture(picture, matrix, filteredPaint); } - - // Unfurl pictures in order to filter nested paints. - this->SkCanvas::onDrawPicture(picture, matrix, filteredPaint.getMaybeNull()); } } // namespace skia diff --git a/chromium/skia/ext/opacity_filter_canvas.h b/chromium/skia/ext/opacity_filter_canvas.h index ee3eca6e1d6..450e3784e5c 100644 --- a/chromium/skia/ext/opacity_filter_canvas.h +++ b/chromium/skia/ext/opacity_filter_canvas.h @@ -20,7 +20,7 @@ class SK_API OpacityFilterCanvas : public SkPaintFilterCanvas { bool disable_image_filtering); protected: - void onFilterPaint(SkPaint* paint, Type type) const override; + bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const override; void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, diff --git a/chromium/skia/ext/pixel_ref_utils_unittest.cc b/chromium/skia/ext/pixel_ref_utils_unittest.cc index ffe1dc068ea..7af706b73cf 100644 --- a/chromium/skia/ext/pixel_ref_utils_unittest.cc +++ b/chromium/skia/ext/pixel_ref_utils_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stdint.h> + #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "cc/test/geometry_test_utils.h" diff --git a/chromium/skia/ext/platform_canvas.cc b/chromium/skia/ext/platform_canvas.cc index 92359671a1a..0437abed465 100644 --- a/chromium/skia/ext/platform_canvas.cc +++ b/chromium/skia/ext/platform_canvas.cc @@ -4,15 +4,64 @@ #include "skia/ext/platform_canvas.h" +#include "base/logging.h" +#include "build/build_config.h" #include "skia/ext/bitmap_platform_device.h" +#include "skia/ext/platform_device.h" +#include "third_party/skia/include/core/SkMetaData.h" #include "third_party/skia/include/core/SkTypes.h" +namespace { + +#if defined(OS_MACOSX) +const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile"; + +void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) { + SkMetaData& meta = skia::GetMetaData(canvas); + meta.setBool(key, value); +} + +bool GetBoolMetaData(const SkCanvas& canvas, const char* key) { + bool value; + SkMetaData& meta = skia::GetMetaData(canvas); + if (!meta.findBool(key, &value)) + value = false; + return value; +} +#endif + +} // namespace + namespace skia { SkBaseDevice* GetTopDevice(const SkCanvas& canvas) { return canvas.getTopDevice(true); } +SkBitmap ReadPixels(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(canvas->imageInfo()); + canvas->readPixels(&bitmap, 0, 0); + return bitmap; +} + +bool GetWritablePixels(SkCanvas* canvas, SkPixmap* result) { + if (!canvas || !result) { + return false; + } + + SkImageInfo info; + size_t row_bytes; + void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes); + if (!pixels) { + result->reset(); + return false; + } + + result->reset(info, pixels, row_bytes); + return true; +} + bool SupportsPlatformPaint(const SkCanvas* canvas) { PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas)); return platform_device && platform_device->SupportsPlatformPaint(); @@ -53,11 +102,34 @@ SkCanvas* CreateCanvas(const skia::RefPtr<SkBaseDevice>& device, OnFailureType f if (!device) { if (CRASH_ON_FAILURE == failureType) SK_CRASH(); - return NULL; + return nullptr; } return new SkCanvas(device.get()); } -PlatformBitmap::PlatformBitmap() : surface_(0), platform_extra_(0) {} +SkMetaData& GetMetaData(const SkCanvas& canvas) { + SkBaseDevice* device = canvas.getDevice(); + DCHECK(device != nullptr); + return device->getMetaData(); +} + +#if defined(OS_MACOSX) +void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { + SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); +} + +bool IsPreviewMetafile(const SkCanvas& canvas) { + return GetBoolMetaData(canvas, kIsPreviewMetafileKey); +} + +CGContextRef GetBitmapContext(const SkCanvas& canvas) { + SkBaseDevice* device = GetTopDevice(canvas); + PlatformDevice* platform_device = GetPlatformDevice(device); + return platform_device ? platform_device->GetBitmapContext() : + nullptr; +} + +#endif + } // namespace skia diff --git a/chromium/skia/ext/platform_canvas.h b/chromium/skia/ext/platform_canvas.h index 75458b5dd54..89b8c326ebb 100644 --- a/chromium/skia/ext/platform_canvas.h +++ b/chromium/skia/ext/platform_canvas.h @@ -5,14 +5,20 @@ #ifndef SKIA_EXT_PLATFORM_CANVAS_H_ #define SKIA_EXT_PLATFORM_CANVAS_H_ +#include <stddef.h> +#include <stdint.h> + // The platform-specific device will include the necessary platform headers // to get the surface type. -#include "base/basictypes.h" -#include "skia/ext/platform_device.h" +#include "build/build_config.h" +#include "skia/ext/platform_surface.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPixelRef.h" +#include "third_party/skia/include/core/SkPixmap.h" + +class SkBaseDevice; namespace skia { @@ -116,6 +122,22 @@ SK_API size_t PlatformCanvasStrideForWidth(unsigned width); // by the next call to save() or restore(). SK_API SkBaseDevice* GetTopDevice(const SkCanvas& canvas); +// Copies pixels from the SkCanvas into an SkBitmap, fetching pixels from +// GPU memory if necessary. +// +// The bitmap will remain empty if we can't allocate enough memory for a copy +// of the pixels. +SK_API SkBitmap ReadPixels(SkCanvas* canvas); + +// Gives the pixmap passed in *writable* access to the pixels backing this +// canvas. All writes to the pixmap should be visible if the canvas is +// raster-backed. +// +// Returns false on failure: if either argument is nullptr, or if the +// pixels can not be retrieved from the canvas. In the latter case resets +// the pixmap to empty. +SK_API bool GetWritablePixels(SkCanvas* canvas, SkPixmap* pixmap); + // Returns true if native platform routines can be used to draw on the // given canvas. If this function returns false, BeginPlatformPaint will // return NULL PlatformSurface. @@ -154,33 +176,18 @@ class SK_API ScopedPlatformPaint { ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); }; -// PlatformBitmap holds a PlatformSurface that can also be used as an SkBitmap. -class SK_API PlatformBitmap { - public: - PlatformBitmap(); - ~PlatformBitmap(); +// Following routines are used in print preview workflow to mark the +// preview metafile. +SK_API SkMetaData& GetMetaData(const SkCanvas& canvas); - // Returns true if the bitmap was able to allocate its surface. - bool Allocate(int width, int height, bool is_opaque); +#if defined(OS_MACOSX) +SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); +SK_API bool IsPreviewMetafile(const SkCanvas& canvas); - // Returns the platform surface, or 0 if Allocate() did not return true. - PlatformSurface GetSurface() { return surface_; } - - // Return the skia bitmap, which will be empty if Allocate() did not - // return true. - // - // The resulting SkBitmap holds a refcount on the underlying platform surface, - // so the surface will remain allocated so long as the SkBitmap or its copies - // stay around. - const SkBitmap& GetBitmap() { return bitmap_; } - - private: - SkBitmap bitmap_; - PlatformSurface surface_; // initialized to 0 - intptr_t platform_extra_; // platform specific, initialized to 0 - - DISALLOW_COPY_AND_ASSIGN(PlatformBitmap); -}; +// Returns the CGContext that backing the SkCanvas. +// Returns NULL if none is bound. +SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); +#endif } // namespace skia diff --git a/chromium/skia/ext/platform_canvas_unittest.cc b/chromium/skia/ext/platform_canvas_unittest.cc index 22a20a1aa33..57b37f8d891 100644 --- a/chromium/skia/ext/platform_canvas_unittest.cc +++ b/chromium/skia/ext/platform_canvas_unittest.cc @@ -6,6 +6,8 @@ #include "skia/ext/platform_canvas.h" +#include <stdint.h> + #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "build/build_config.h" @@ -42,8 +44,7 @@ bool IsOfColor(const SkBitmap& bitmap, int x, int y, uint32_t color) { bool VerifyRect(const PlatformCanvas& canvas, uint32_t canvas_color, uint32_t rect_color, int x, int y, int w, int h) { - SkBaseDevice* device = skia::GetTopDevice(canvas); - const SkBitmap& bitmap = device->accessBitmap(false); + const SkBitmap bitmap = skia::ReadPixels(const_cast<PlatformCanvas*>(&canvas)); SkAutoLockPixels lock(bitmap); for (int cur_y = 0; cur_y < bitmap.height(); cur_y++) { @@ -397,65 +398,4 @@ TEST(PlatformCanvas, TranslateLayer) { #endif // #if !defined(USE_AURA) -TEST(PlatformBitmapTest, PlatformBitmap) { - const int kWidth = 400; - const int kHeight = 300; - scoped_ptr<PlatformBitmap> platform_bitmap(new PlatformBitmap); - - EXPECT_TRUE(0 == platform_bitmap->GetSurface()); - EXPECT_TRUE(platform_bitmap->GetBitmap().empty()); - EXPECT_TRUE(platform_bitmap->GetBitmap().isNull()); - - EXPECT_TRUE(platform_bitmap->Allocate(kWidth, kHeight, /*is_opaque=*/false)); - - EXPECT_TRUE(0 != platform_bitmap->GetSurface()); - EXPECT_FALSE(platform_bitmap->GetBitmap().empty()); - EXPECT_FALSE(platform_bitmap->GetBitmap().isNull()); - EXPECT_EQ(kWidth, platform_bitmap->GetBitmap().width()); - EXPECT_EQ(kHeight, platform_bitmap->GetBitmap().height()); - EXPECT_LE(static_cast<size_t>(platform_bitmap->GetBitmap().width()*4), - platform_bitmap->GetBitmap().rowBytes()); - EXPECT_EQ(kN32_SkColorType, // Same for all platforms. - platform_bitmap->GetBitmap().colorType()); - EXPECT_TRUE(platform_bitmap->GetBitmap().lockPixelsAreWritable()); -#if defined(SK_DEBUG) - EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->isLocked()); -#endif - EXPECT_TRUE(platform_bitmap->GetBitmap().pixelRef()->unique()); - - *(platform_bitmap->GetBitmap().getAddr32(10, 20)) = 0xDEED1020; - *(platform_bitmap->GetBitmap().getAddr32(20, 30)) = 0xDEED2030; - - SkBitmap sk_bitmap = platform_bitmap->GetBitmap(); - sk_bitmap.lockPixels(); - - EXPECT_FALSE(platform_bitmap->GetBitmap().pixelRef()->unique()); - EXPECT_FALSE(sk_bitmap.pixelRef()->unique()); - - EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); - EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); - - *(platform_bitmap->GetBitmap().getAddr32(30, 40)) = 0xDEED3040; - - // The SkBitmaps derived from a PlatformBitmap must be capable of outliving - // the PlatformBitmap. - platform_bitmap.reset(); - - EXPECT_TRUE(sk_bitmap.pixelRef()->unique()); - - EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); - EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); - EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); - sk_bitmap.unlockPixels(); - - EXPECT_EQ(NULL, sk_bitmap.getPixels()); - - sk_bitmap.lockPixels(); - EXPECT_EQ(0xDEED1020, *sk_bitmap.getAddr32(10, 20)); - EXPECT_EQ(0xDEED2030, *sk_bitmap.getAddr32(20, 30)); - EXPECT_EQ(0xDEED3040, *sk_bitmap.getAddr32(30, 40)); - sk_bitmap.unlockPixels(); -} - - } // namespace skia diff --git a/chromium/skia/ext/platform_device.cc b/chromium/skia/ext/platform_device.cc index ae720dfb45a..cd4aa09433e 100644 --- a/chromium/skia/ext/platform_device.cc +++ b/chromium/skia/ext/platform_device.cc @@ -7,32 +7,14 @@ #include "third_party/skia/include/core/SkMetaData.h" -namespace skia { - namespace { -const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; -const char* kDraftModeKey = "CrDraftMode"; - -#if defined(OS_MACOSX) || defined(OS_WIN) -const char* kIsPreviewMetafileKey = "CrIsPreviewMetafile"; -#endif - -void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) { - SkMetaData& meta = skia::getMetaData(canvas); - meta.setBool(key, value); -} - -bool GetBoolMetaData(const SkCanvas& canvas, const char* key) { - bool value; - SkMetaData& meta = skia::getMetaData(canvas); - if (!meta.findBool(key, &value)) - value = false; - return value; -} +const char kDevicePlatformBehaviour[] = "CrDevicePlatformBehaviour"; } // namespace +namespace skia { + void SetPlatformDevice(SkBaseDevice* device, PlatformDevice* platform_behaviour) { SkMetaData& meta_data = device->getMetaData(); meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); @@ -49,30 +31,6 @@ PlatformDevice* GetPlatformDevice(SkBaseDevice* device) { return NULL; } -SkMetaData& getMetaData(const SkCanvas& canvas) { - SkBaseDevice* device = canvas.getDevice(); - DCHECK(device != NULL); - return device->getMetaData(); -} - -void SetIsDraftMode(const SkCanvas& canvas, bool draft_mode) { - SetBoolMetaData(canvas, kDraftModeKey, draft_mode); -} - -bool IsDraftMode(const SkCanvas& canvas) { - return GetBoolMetaData(canvas, kDraftModeKey); -} - -#if defined(OS_MACOSX) || defined(OS_WIN) -void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { - SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); -} - -bool IsPreviewMetafile(const SkCanvas& canvas) { - return GetBoolMetaData(canvas, kIsPreviewMetafileKey); -} -#endif - bool PlatformDevice::SupportsPlatformPaint() { return true; } diff --git a/chromium/skia/ext/platform_device.h b/chromium/skia/ext/platform_device.h index f3b2fe34e27..628732bc1e8 100644 --- a/chromium/skia/ext/platform_device.h +++ b/chromium/skia/ext/platform_device.h @@ -12,41 +12,18 @@ #include <vector> #endif -#include "third_party/skia/include/core/SkColor.h" +#include "skia/ext/platform_surface.h" #include "third_party/skia/include/core/SkBitmapDevice.h" #include "third_party/skia/include/core/SkTypes.h" class SkMatrix; -class SkMetaData; class SkPath; class SkRegion; -#if defined(USE_CAIRO) -typedef struct _cairo cairo_t; -typedef struct _cairo_rectangle cairo_rectangle_t; -#elif defined(OS_MACOSX) -typedef struct CGContext* CGContextRef; -typedef struct CGRect CGRect; -#endif - namespace skia { class PlatformDevice; -#if defined(OS_WIN) -typedef HDC PlatformSurface; -typedef RECT PlatformRect; -#elif defined(USE_CAIRO) -typedef cairo_t* PlatformSurface; -typedef cairo_rectangle_t PlatformRect; -#elif defined(OS_MACOSX) -typedef CGContextRef PlatformSurface; -typedef CGRect PlatformRect; -#else -typedef void* PlatformSurface; -typedef SkIRect* PlatformRect; -#endif - // The following routines provide accessor points for the functionality // exported by the various PlatformDevice ports. // All calls to PlatformDevice::* should be routed through these @@ -61,27 +38,6 @@ SK_API void SetPlatformDevice(SkBaseDevice* device, PlatformDevice* platform_device); SK_API PlatformDevice* GetPlatformDevice(SkBaseDevice* device); - -#if defined(OS_WIN) -// Initializes the default settings and colors in a device context. -SK_API void InitializeDC(HDC context); -#elif defined(OS_MACOSX) -// Returns the CGContext that backing the SkBaseDevice. Forwards to the bound -// PlatformDevice. Returns NULL if no PlatformDevice is bound. -SK_API CGContextRef GetBitmapContext(SkBaseDevice* device); -#endif - -// Following routines are used in print preview workflow to mark the draft mode -// metafile and preview metafile. -SK_API SkMetaData& getMetaData(const SkCanvas& canvas); -SK_API void SetIsDraftMode(const SkCanvas& canvas, bool draft_mode); -SK_API bool IsDraftMode(const SkCanvas& canvas); - -#if defined(OS_MACOSX) || defined(OS_WIN) -SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); -SK_API bool IsPreviewMetafile(const SkCanvas& canvas); -#endif - // A SkBitmapDevice is basically a wrapper around SkBitmap that provides a // surface for SkCanvas to draw into. PlatformDevice provides a surface // Windows can also write to. It also provides functionality to play well diff --git a/chromium/skia/ext/platform_device_mac.cc b/chromium/skia/ext/platform_device_mac.cc index 065b7670556..5dfa211c3b4 100644 --- a/chromium/skia/ext/platform_device_mac.cc +++ b/chromium/skia/ext/platform_device_mac.cc @@ -7,21 +7,9 @@ #import <ApplicationServices/ApplicationServices.h> #include "skia/ext/skia_utils_mac.h" -#include "third_party/skia/include/core/SkMatrix.h" -#include "third_party/skia/include/core/SkPath.h" -#include "third_party/skia/include/core/SkTypes.h" -#include "third_party/skia/include/core/SkUtils.h" namespace skia { -CGContextRef GetBitmapContext(SkBaseDevice* device) { - PlatformDevice* platform_device = GetPlatformDevice(device); - if (platform_device) - return platform_device->GetBitmapContext(); - - return NULL; -} - CGContextRef PlatformDevice::BeginPlatformPaint() { return GetBitmapContext(); } diff --git a/chromium/skia/ext/platform_device_win.cc b/chromium/skia/ext/platform_device_win.cc index ef48fbd3a38..d1b37ef638e 100644 --- a/chromium/skia/ext/platform_device_win.cc +++ b/chromium/skia/ext/platform_device_win.cc @@ -8,49 +8,9 @@ #include "third_party/skia/include/core/SkMatrix.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkRegion.h" -#include "third_party/skia/include/core/SkUtils.h" namespace skia { -void InitializeDC(HDC context) { - // Enables world transformation. - // If the GM_ADVANCED graphics mode is set, GDI always draws arcs in the - // counterclockwise direction in logical space. This is equivalent to the - // statement that, in the GM_ADVANCED graphics mode, both arc control points - // and arcs themselves fully respect the device context's world-to-device - // transformation. - BOOL res = SetGraphicsMode(context, GM_ADVANCED); - SkASSERT(res != 0); - - // Enables dithering. - res = SetStretchBltMode(context, HALFTONE); - SkASSERT(res != 0); - // As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called - // right after. - res = SetBrushOrgEx(context, 0, 0, NULL); - SkASSERT(res != 0); - - // Sets up default orientation. - res = SetArcDirection(context, AD_CLOCKWISE); - SkASSERT(res != 0); - - // Sets up default colors. - res = SetBkColor(context, RGB(255, 255, 255)); - SkASSERT(res != CLR_INVALID); - res = SetTextColor(context, RGB(0, 0, 0)); - SkASSERT(res != CLR_INVALID); - res = SetDCBrushColor(context, RGB(255, 255, 255)); - SkASSERT(res != CLR_INVALID); - res = SetDCPenColor(context, RGB(0, 0, 0)); - SkASSERT(res != CLR_INVALID); - - // Sets up default transparency. - res = SetBkMode(context, OPAQUE); - SkASSERT(res != 0); - res = SetROP2(context, R2_COPYPEN); - SkASSERT(res != 0); -} - PlatformSurface PlatformDevice::BeginPlatformPaint() { return 0; } diff --git a/chromium/skia/ext/platform_surface.h b/chromium/skia/ext/platform_surface.h new file mode 100644 index 00000000000..b0d5173c40f --- /dev/null +++ b/chromium/skia/ext/platform_surface.h @@ -0,0 +1,39 @@ +// Copyright (c) 2015 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_PLATFORM_SURFACE_H_ +#define SKIA_EXT_PLATFORM_SURFACE_H_ + +#include "build/build_config.h" + +#include "third_party/skia/include/core/SkTypes.h" +#include "third_party/skia/include/core/SkRect.h" + +#if defined(USE_CAIRO) +typedef struct _cairo cairo_t; +typedef struct _cairo_rectangle cairo_rectangle_t; +#elif defined(OS_MACOSX) +typedef struct CGContext* CGContextRef; +typedef struct CGRect CGRect; +#endif + +namespace skia { + +#if defined(OS_WIN) +typedef HDC PlatformSurface; +typedef RECT PlatformRect; +#elif defined(USE_CAIRO) +typedef cairo_t* PlatformSurface; +typedef cairo_rectangle_t PlatformRect; +#elif defined(OS_MACOSX) +typedef CGContextRef PlatformSurface; +typedef CGRect PlatformRect; +#else +typedef void* PlatformSurface; +typedef SkIRect* PlatformRect; +#endif + +} // namespace skia + +#endif // SKIA_EXT_PLATFORM_SURFACE_H_ diff --git a/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc b/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc index 9fe386b7c56..57c5ef4c2f2 100644 --- a/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc +++ b/chromium/skia/ext/recursive_gaussian_convolution_unittest.cc @@ -6,7 +6,6 @@ #include <numeric> #include <vector> -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/logging.h" @@ -211,7 +210,7 @@ TEST(RecursiveGaussian, SmoothingImpulse) { // Smooth the inverse now. std::vector<unsigned char> output2(dest_byte_count); std::transform(input.begin(), input.end(), input.begin(), - std::bind1st(std::minus<unsigned char>(), 255U)); + [](unsigned char c) { return 255U - c; }); SingleChannelRecursiveGaussianY(&input[0], src_row_stride, kChannelIndex, kChannelCount, recursive_filter, image_size, @@ -296,7 +295,7 @@ TEST(RecursiveGaussian, FirstDerivative) { // Try inverted image. Behaviour should be very similar (modulo rounding). std::transform(input.begin(), input.end(), input.begin(), - std::bind1st(std::minus<unsigned char>(), 255U)); + [](unsigned char c) { return 255U - c; }); SingleChannelRecursiveGaussianX(&input[0], src_row_stride, kChannelIndex, kChannelCount, recursive_filter, image_size, diff --git a/chromium/skia/ext/refptr.h b/chromium/skia/ext/refptr.h index a7ba7ffb785..b6bae4f29b9 100644 --- a/chromium/skia/ext/refptr.h +++ b/chromium/skia/ext/refptr.h @@ -6,8 +6,8 @@ #define SKIA_EXT_REFPTR_H_ #include <algorithm> +#include <cstddef> -#include "base/move.h" #include "third_party/skia/include/core/SkRefCnt.h" namespace skia { @@ -44,7 +44,7 @@ namespace skia { // count): // // skia::RefPtr<SkShader> shader = ...; -// UseThisShader(shader.Pass()); +// UseThisShader(std::move(shader)); // // Never call ref() or unref() on the underlying ref-counted pointer. If you // AdoptRef() the raw pointer immediately into a skia::RefPtr and always work @@ -52,23 +52,29 @@ namespace skia { // for you. template<typename T> class RefPtr { - TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(RefPtr) public: RefPtr() : ptr_(nullptr) {} - RefPtr(decltype(nullptr)) : ptr_(nullptr) {} + RefPtr(std::nullptr_t) : ptr_(nullptr) {} + // Copy constructor. RefPtr(const RefPtr& other) : ptr_(other.get()) { SkSafeRef(ptr_); } + // Copy conversion constructor. template<typename U> RefPtr(const RefPtr<U>& other) : ptr_(other.get()) { SkSafeRef(ptr_); } + // Move constructor. This is required in addition to the conversion + // constructor below in order for clang to warn about pessimizing moves. + RefPtr(RefPtr&& other) : ptr_(other.get()) { other.ptr_ = nullptr; } + + // Move conversion constructor. template <typename U> RefPtr(RefPtr<U>&& other) : ptr_(other.get()) { @@ -79,7 +85,7 @@ class RefPtr { clear(); } - RefPtr& operator=(decltype(nullptr)) { + RefPtr& operator=(std::nullptr_t) { clear(); return *this; } @@ -97,7 +103,7 @@ class RefPtr { template <typename U> RefPtr& operator=(RefPtr<U>&& other) { - RefPtr<T> temp(other.Pass()); + RefPtr<T> temp(std::move(other)); std::swap(ptr_, temp.ptr_); return *this; } diff --git a/chromium/skia/ext/refptr_unittest.cc b/chromium/skia/ext/refptr_unittest.cc index a356a64a2ed..237f43909d8 100644 --- a/chromium/skia/ext/refptr_unittest.cc +++ b/chromium/skia/ext/refptr_unittest.cc @@ -180,11 +180,11 @@ TEST(RefPtrTest, AssignmentFromTemporary) { TEST(RefPtrTest, PassIntoArguments) { // No ref count changes when passing an argument with Pass(). RefPtr<RefCountCounter> object = skia::AdoptRef(new RefCountCounter); - RefPtr<RefCountCounter> object2 = object.Pass(); + RefPtr<RefCountCounter> object2 = std::move(object); auto lambda = [](RefPtr<RefCountCounter> arg) { EXPECT_EQ(0, arg->ref_count_changes()); }; - lambda(object2.Pass()); + lambda(std::move(object2)); } class DestructionNotifier : public SkRefCnt { @@ -196,15 +196,6 @@ class DestructionNotifier : public SkRefCnt { bool* flag_; }; -TEST(RefPtrTest, PassIntoSelf) { - bool is_destroyed = false; - RefPtr<DestructionNotifier> object = - skia::AdoptRef(new DestructionNotifier(&is_destroyed)); - object = object.Pass(); - ASSERT_FALSE(is_destroyed); - EXPECT_TRUE(object->unique()); -} - TEST(RefPtrTest, Nullptr) { RefPtr<SkRefCnt> null(nullptr); EXPECT_FALSE(null); diff --git a/chromium/skia/ext/skia_memory_dump_provider.cc b/chromium/skia/ext/skia_memory_dump_provider.cc index aaef11f1a2b..e0767526bea 100644 --- a/chromium/skia/ext/skia_memory_dump_provider.cc +++ b/chromium/skia/ext/skia_memory_dump_provider.cc @@ -7,7 +7,7 @@ #include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/process_memory_dump.h" -#include "skia/ext/SkTraceMemoryDump_chrome.h" +#include "skia/ext/skia_trace_memory_dump_impl.h" #include "third_party/skia/include/core/SkGraphics.h" namespace skia { @@ -26,8 +26,8 @@ SkiaMemoryDumpProvider::~SkiaMemoryDumpProvider() {} bool SkiaMemoryDumpProvider::OnMemoryDump( const base::trace_event::MemoryDumpArgs& args, base::trace_event::ProcessMemoryDump* process_memory_dump) { - SkTraceMemoryDump_Chrome skia_dumper(args.level_of_detail, - process_memory_dump); + SkiaTraceMemoryDumpImpl skia_dumper(args.level_of_detail, + process_memory_dump); SkGraphics::DumpMemoryStatistics(&skia_dumper); return true; diff --git a/chromium/skia/ext/skia_memory_dump_provider.h b/chromium/skia/ext/skia_memory_dump_provider.h index c343731165a..d9557d8b431 100644 --- a/chromium/skia/ext/skia_memory_dump_provider.h +++ b/chromium/skia/ext/skia_memory_dump_provider.h @@ -5,6 +5,7 @@ #ifndef SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ #define SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ +#include "base/macros.h" #include "base/memory/singleton.h" #include "base/trace_event/memory_dump_provider.h" #include "third_party/skia/include/core/SkTypes.h" diff --git a/chromium/skia/ext/SkTraceMemoryDump_chrome.cc b/chromium/skia/ext/skia_trace_memory_dump_impl.cc index c4bda0cd672..b7784e722ff 100644 --- a/chromium/skia/ext/SkTraceMemoryDump_chrome.cc +++ b/chromium/skia/ext/skia_trace_memory_dump_impl.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "skia/ext/SkTraceMemoryDump_chrome.h" +#include "skia/ext/skia_trace_memory_dump_impl.h" #include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_dump_manager.h" @@ -15,12 +15,12 @@ namespace { const char kMallocBackingType[] = "malloc"; } -SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome( +SkiaTraceMemoryDumpImpl::SkiaTraceMemoryDumpImpl( base::trace_event::MemoryDumpLevelOfDetail level_of_detail, base::trace_event::ProcessMemoryDump* process_memory_dump) - : SkTraceMemoryDump_Chrome("", level_of_detail, process_memory_dump) {} + : SkiaTraceMemoryDumpImpl("", level_of_detail, process_memory_dump) {} -SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome( +SkiaTraceMemoryDumpImpl::SkiaTraceMemoryDumpImpl( const std::string& dump_name_prefix, base::trace_event::MemoryDumpLevelOfDetail level_of_detail, base::trace_event::ProcessMemoryDump* process_memory_dump) @@ -31,21 +31,21 @@ SkTraceMemoryDump_Chrome::SkTraceMemoryDump_Chrome( ? SkTraceMemoryDump::kLight_LevelOfDetail : SkTraceMemoryDump::kObjectsBreakdowns_LevelOfDetail) {} -SkTraceMemoryDump_Chrome::~SkTraceMemoryDump_Chrome() {} +SkiaTraceMemoryDumpImpl::~SkiaTraceMemoryDumpImpl() {} -void SkTraceMemoryDump_Chrome::dumpNumericValue(const char* dumpName, - const char* valueName, - const char* units, - uint64_t value) { - auto dump = GetOrCreateAllocatorDump(dumpName); +void SkiaTraceMemoryDumpImpl::dumpNumericValue(const char* dumpName, + const char* valueName, + const char* units, + uint64_t value) { + auto dump = process_memory_dump_->GetOrCreateAllocatorDump(dumpName); dump->AddScalar(valueName, units, value); } -void SkTraceMemoryDump_Chrome::setMemoryBacking(const char* dumpName, - const char* backingType, - const char* backingObjectId) { +void SkiaTraceMemoryDumpImpl::setMemoryBacking(const char* dumpName, + const char* backingType, + const char* backingObjectId) { if (strcmp(backingType, kMallocBackingType) == 0) { - auto dump = GetOrCreateAllocatorDump(dumpName); + auto dump = process_memory_dump_->GetOrCreateAllocatorDump(dumpName); const char* system_allocator_name = base::trace_event::MemoryDumpManager::GetInstance() ->system_allocator_pool_name(); @@ -58,7 +58,7 @@ void SkTraceMemoryDump_Chrome::setMemoryBacking(const char* dumpName, } } -void SkTraceMemoryDump_Chrome::setDiscardableMemoryBacking( +void SkiaTraceMemoryDumpImpl::setDiscardableMemoryBacking( const char* dumpName, const SkDiscardableMemory& discardableMemoryObject) { std::string name = dump_name_prefix_ + dumpName; @@ -70,18 +70,9 @@ void SkTraceMemoryDump_Chrome::setDiscardableMemoryBacking( DCHECK(dump); } -SkTraceMemoryDump::LevelOfDetail SkTraceMemoryDump_Chrome::getRequestedDetails() +SkTraceMemoryDump::LevelOfDetail SkiaTraceMemoryDumpImpl::getRequestedDetails() const { return request_level_; } -base::trace_event::MemoryAllocatorDump* -SkTraceMemoryDump_Chrome::GetOrCreateAllocatorDump(const char* dumpName) { - std::string name = dump_name_prefix_ + dumpName; - auto dump = process_memory_dump_->GetAllocatorDump(name); - if (!dump) - dump = process_memory_dump_->CreateAllocatorDump(name); - return dump; -} - } // namespace skia diff --git a/chromium/skia/ext/SkTraceMemoryDump_chrome.h b/chromium/skia/ext/skia_trace_memory_dump_impl.h index 42a0e0e2c86..e159a9c2ace 100644 --- a/chromium/skia/ext/SkTraceMemoryDump_chrome.h +++ b/chromium/skia/ext/skia_trace_memory_dump_impl.h @@ -5,9 +5,10 @@ #ifndef SKIA_EXT_SK_TRACE_MEMORY_DUMP_CHROME_H_ #define SKIA_EXT_SK_TRACE_MEMORY_DUMP_CHROME_H_ +#include <stdint.h> + #include <string> -#include "base/basictypes.h" #include "base/macros.h" #include "base/trace_event/memory_dump_request_args.h" #include "third_party/skia/include/core/SkTraceMemoryDump.h" @@ -21,22 +22,22 @@ class ProcessMemoryDump; namespace skia { -class SK_API SkTraceMemoryDump_Chrome : public SkTraceMemoryDump { +class SK_API SkiaTraceMemoryDumpImpl : public SkTraceMemoryDump { public: // This should never outlive the OnMemoryDump call since the // ProcessMemoryDump is valid only in that timeframe. Optional // |dump_name_prefix| argument specifies the prefix appended to the dump // name skia provides. By default it is taken as empty string. - SkTraceMemoryDump_Chrome( + SkiaTraceMemoryDumpImpl( base::trace_event::MemoryDumpLevelOfDetail level_of_detail, base::trace_event::ProcessMemoryDump* process_memory_dump); - SkTraceMemoryDump_Chrome( + SkiaTraceMemoryDumpImpl( const std::string& dump_name_prefix, base::trace_event::MemoryDumpLevelOfDetail level_of_detail, base::trace_event::ProcessMemoryDump* process_memory_dump); - ~SkTraceMemoryDump_Chrome() override; + ~SkiaTraceMemoryDumpImpl() override; // SkTraceMemoryDump implementation: void dumpNumericValue(const char* dumpName, @@ -57,10 +58,6 @@ class SK_API SkTraceMemoryDump_Chrome : public SkTraceMemoryDump { } private: - // Helper to create allocator dumps. - base::trace_event::MemoryAllocatorDump* GetOrCreateAllocatorDump( - const char* dumpName); - std::string dump_name_prefix_; base::trace_event::ProcessMemoryDump* process_memory_dump_; @@ -68,7 +65,7 @@ class SK_API SkTraceMemoryDump_Chrome : public SkTraceMemoryDump { // Stores the level of detail for the current dump. LevelOfDetail request_level_; - DISALLOW_COPY_AND_ASSIGN(SkTraceMemoryDump_Chrome); + DISALLOW_COPY_AND_ASSIGN(SkiaTraceMemoryDumpImpl); }; } // namespace skia diff --git a/chromium/skia/ext/skia_utils_base.cc b/chromium/skia/ext/skia_utils_base.cc index af6957dfdde..f026c07adec 100644 --- a/chromium/skia/ext/skia_utils_base.cc +++ b/chromium/skia/ext/skia_utils_base.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stdint.h> + #include "skia/ext/skia_utils_base.h" namespace skia { diff --git a/chromium/skia/ext/skia_utils_ios.h b/chromium/skia/ext/skia_utils_ios.h index 6a854ce6aff..0f2c613414e 100644 --- a/chromium/skia/ext/skia_utils_ios.h +++ b/chromium/skia/ext/skia_utils_ios.h @@ -9,16 +9,19 @@ #include <vector> #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkColor.h" #ifdef __OBJC__ +@class UIColor; @class UIImage; @class NSData; #else +class UIColor; class UIImage; class NSData; #endif -namespace gfx { +namespace skia { // Draws a CGImage into an SkBitmap of the given size. SK_API SkBitmap CGImageToSkBitmap(CGImageRef image, @@ -35,6 +38,9 @@ SK_API UIImage* SkBitmapToUIImageWithColorSpace(const SkBitmap& skia_bitmap, // vector if none can be decoded. SK_API std::vector<SkBitmap> ImageDataToSkBitmaps(NSData* image_data); -} // namespace gfx +// Returns a UIColor for an SKColor. Used by iOS downstream. +SK_API UIColor* UIColorFromSkColor(SkColor color); + +} // namespace skia #endif // SKIA_EXT_SKIA_UTILS_IOS_H_ diff --git a/chromium/skia/ext/skia_utils_ios.mm b/chromium/skia/ext/skia_utils_ios.mm index 5655d22a562..33a6f244ab9 100644 --- a/chromium/skia/ext/skia_utils_ios.mm +++ b/chromium/skia/ext/skia_utils_ios.mm @@ -5,6 +5,8 @@ #include "skia/ext/skia_utils_ios.h" #import <ImageIO/ImageIO.h> +#include <stddef.h> +#include <stdint.h> #import <UIKit/UIKit.h> #include "base/ios/ios_util.h" @@ -15,7 +17,7 @@ namespace { -const uint8 kICOHeaderMagic[4] = {0x00, 0x00, 0x01, 0x00}; +const uint8_t kICOHeaderMagic[4] = {0x00, 0x00, 0x01, 0x00}; // Returns whether the data encodes an ico image. bool EncodesIcoImage(NSData* image_data) { @@ -27,7 +29,7 @@ bool EncodesIcoImage(NSData* image_data) { } // namespace -namespace gfx { +namespace skia { SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) { SkBitmap bitmap; @@ -123,4 +125,11 @@ std::vector<SkBitmap> ImageDataToSkBitmaps(NSData* image_data) { return frames; } -} // namespace gfx +UIColor* UIColorFromSkColor(SkColor color) { + return [UIColor colorWithRed:SkColorGetR(color) / 255.0f + green:SkColorGetG(color) / 255.0f + blue:SkColorGetB(color) / 255.0f + alpha:SkColorGetA(color) / 255.0f]; +} + +} // namespace skia diff --git a/chromium/skia/ext/skia_utils_ios_unittest.mm b/chromium/skia/ext/skia_utils_ios_unittest.mm index 71f46a4e6b3..543f3012f3f 100644 --- a/chromium/skia/ext/skia_utils_ios_unittest.mm +++ b/chromium/skia/ext/skia_utils_ios_unittest.mm @@ -129,7 +129,7 @@ NSData* InvalidData(NSUInteger length) { TEST_F(SkiaUtilsIosTest, ImageDataToSkBitmaps) { std::vector<SkBitmap> bitmaps( - gfx::ImageDataToSkBitmaps(StringToNSData(kIcoEncodedData))); + skia::ImageDataToSkBitmaps(StringToNSData(kIcoEncodedData))); EXPECT_EQ(2UL, bitmaps.size()); EXPECT_EQ(32, bitmaps[0].width()); @@ -139,20 +139,20 @@ TEST_F(SkiaUtilsIosTest, ImageDataToSkBitmaps) { } TEST_F(SkiaUtilsIosTest, InvalidDataFailure) { - std::vector<SkBitmap> bitmaps1(gfx::ImageDataToSkBitmaps(InvalidData(1))); + std::vector<SkBitmap> bitmaps1(skia::ImageDataToSkBitmaps(InvalidData(1))); EXPECT_EQ(0UL, bitmaps1.size()); - std::vector<SkBitmap> bitmaps2(gfx::ImageDataToSkBitmaps(InvalidData(10))); + std::vector<SkBitmap> bitmaps2(skia::ImageDataToSkBitmaps(InvalidData(10))); EXPECT_EQ(0UL, bitmaps2.size()); - std::vector<SkBitmap> bitmaps3(gfx::ImageDataToSkBitmaps(InvalidData(100))); + std::vector<SkBitmap> bitmaps3(skia::ImageDataToSkBitmaps(InvalidData(100))); EXPECT_EQ(0UL, bitmaps3.size()); - std::vector<SkBitmap> bitmaps4(gfx::ImageDataToSkBitmaps(InvalidData(1000))); + std::vector<SkBitmap> bitmaps4(skia::ImageDataToSkBitmaps(InvalidData(1000))); EXPECT_EQ(0UL, bitmaps4.size()); - std::vector<SkBitmap> bitmaps5(gfx::ImageDataToSkBitmaps(InvalidData(5000))); + std::vector<SkBitmap> bitmaps5(skia::ImageDataToSkBitmaps(InvalidData(5000))); EXPECT_EQ(0UL, bitmaps5.size()); } TEST_F(SkiaUtilsIosTest, EmptyDataFailure) { - std::vector<SkBitmap> bitmaps(gfx::ImageDataToSkBitmaps([NSData data])); + std::vector<SkBitmap> bitmaps(skia::ImageDataToSkBitmaps([NSData data])); EXPECT_EQ(0UL, bitmaps.size()); } @@ -742,12 +742,23 @@ const char kIco88x88EncodedData[] = TEST_F(SkiaUtilsIosTest, Image88x88OrLarger) { std::vector<SkBitmap> bitmaps( - gfx::ImageDataToSkBitmaps(StringToNSData(kIco88x88EncodedData))); + skia::ImageDataToSkBitmaps(StringToNSData(kIco88x88EncodedData))); if (base::ios::IsRunningOnOrLater(8, 1, 1)) EXPECT_EQ(0UL, bitmaps.size()); else EXPECT_EQ(1UL, bitmaps.size()); } +TEST_F(SkiaUtilsIosTest, UIColorFromSkColor) { + SkColor color = SkColorSetARGB(50, 100, 150, 200); + UIColor* ios_color = skia::UIColorFromSkColor(color); + CGFloat red, green, blue, alpha; + [ios_color getRed:&red green:&green blue:&blue alpha:&alpha]; + EXPECT_EQ(50, static_cast<int>(alpha * 255 + 0.5f)); + EXPECT_EQ(100, static_cast<int>(red * 255 + 0.5f)); + EXPECT_EQ(150, static_cast<int>(green * 255 + 0.5f)); + EXPECT_EQ(200, static_cast<int>(blue * 255 + 0.5f)); +} + } // namespace diff --git a/chromium/skia/ext/skia_utils_mac.h b/chromium/skia/ext/skia_utils_mac.h index b60f9e8ad53..d15fa568447 100644 --- a/chromium/skia/ext/skia_utils_mac.h +++ b/chromium/skia/ext/skia_utils_mac.h @@ -10,6 +10,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/core/SkPixmap.h" struct SkIRect; struct SkPoint; @@ -34,19 +35,7 @@ class NSImageRep; class NSColor; #endif -namespace gfx { - -// Converts a Skia point to a CoreGraphics CGPoint. -// Both use same in-memory format. -inline const CGPoint& SkPointToCGPoint(const SkPoint& point) { - return reinterpret_cast<const CGPoint&>(point); -} - -// Converts a CoreGraphics point to a Skia CGPoint. -// Both use same in-memory format. -inline const SkPoint& CGPointToSkPoint(const CGPoint& point) { - return reinterpret_cast<const SkPoint&>(point); -} +namespace skia { // Matrix converters. SK_API CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix); @@ -129,12 +118,13 @@ class SK_API SkiaBitLocker { bool userClipRectSpecified_; CGContextRef cgContext_; - SkBitmap bitmap_; + // offscreen_ is only valid if useDeviceBits_ is false + SkBitmap offscreen_; 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 + // True if we are drawing to |canvas_|'s backing store directly. + // Otherwise, the bits in |bitmap_| are our allocation and need to // be copied over to |canvas_|. bool useDeviceBits_; @@ -146,6 +136,6 @@ class SK_API SkiaBitLocker { }; -} // namespace gfx +} // namespace skia #endif // SKIA_EXT_SKIA_UTILS_MAC_H_ diff --git a/chromium/skia/ext/skia_utils_mac.mm b/chromium/skia/ext/skia_utils_mac.mm index 9e552eb77b0..2e12d856aff 100644 --- a/chromium/skia/ext/skia_utils_mac.mm +++ b/chromium/skia/ext/skia_utils_mac.mm @@ -5,12 +5,14 @@ #include "skia/ext/skia_utils_mac.h" #import <AppKit/AppKit.h> +#include <stdint.h> #include "base/logging.h" #include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" #include "skia/ext/bitmap_platform_device_mac.h" +#include "skia/ext/platform_canvas.h" #include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/utils/mac/SkCGUtils.h" @@ -84,7 +86,7 @@ SkBitmap NSImageOrNSImageRepToSkBitmapWithColorSpace( } // namespace -namespace gfx { +namespace skia { CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix) { // CGAffineTransforms don't support perspective transforms, so make sure @@ -189,10 +191,10 @@ SkBitmap CGImageToSkBitmap(CGImageRef image) { int width = CGImageGetWidth(image); int height = CGImageGetHeight(image); - scoped_ptr<SkBaseDevice> device( + scoped_ptr<skia::BitmapPlatformDevice> device( skia::BitmapPlatformDevice::Create(NULL, width, height, false)); - CGContextRef context = skia::GetBitmapContext(device.get()); + CGContextRef context = device->GetBitmapContext(); // We need to invert the y-axis of the canvas so that Core Graphics drawing // happens right-side up. Skia has an upper-left origin and CG has a lower- @@ -297,15 +299,15 @@ 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()); + return SkIRect::MakeWH(offscreen_.width(), offscreen_.height()); // Find the bits that were drawn to. - SkAutoLockPixels lockedPixels(bitmap_); + SkAutoLockPixels lockedPixels(offscreen_); const uint32_t* pixelBase - = reinterpret_cast<uint32_t*>(bitmap_.getPixels()); - int rowPixels = bitmap_.rowBytesAsPixels(); - int width = bitmap_.width(); - int height = bitmap_.height(); + = reinterpret_cast<uint32_t*>(offscreen_.getPixels()); + int rowPixels = offscreen_.rowBytesAsPixels(); + int width = offscreen_.width(); + int height = offscreen_.height(); SkIRect bounds; bounds.fTop = 0; int x; @@ -367,13 +369,11 @@ foundRight: void SkiaBitLocker::releaseIfNeeded() { if (!cgContext_) return; - if (useDeviceBits_) { - bitmap_.unlockPixels(); - } else if (!bitmapIsDummy_) { + if (!useDeviceBits_ && !bitmapIsDummy_) { // Find the bits that were drawn to. SkIRect bounds = computeDirtyRect(); SkBitmap subset; - if (!bitmap_.extractSubset(&subset, bounds)) { + if (!offscreen_.extractSubset(&subset, bounds)) { return; } subset.setImmutable(); // Prevents a defensive copy inside Skia. @@ -414,41 +414,49 @@ CGContextRef SkiaBitLocker::cgContext() { // Now make clip_bounds be relative to the current layer/device clip_bounds.offset(-device->getOrigin()); - const SkBitmap& deviceBits = device->accessBitmap(true); + SkPixmap devicePixels; + skia::GetWritablePixels(canvas_, &devicePixels); // 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() && + useDeviceBits_ = devicePixels.addr() && canvas_->isClipRect() && !bitmapIsDummy_; + base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( + CGColorSpaceCreateDeviceRGB()); + + int displayHeight; if (useDeviceBits_) { - bool result = deviceBits.extractSubset(&bitmap_, clip_bounds); + SkPixmap subset; + bool result = devicePixels.extractSubset(&subset, clip_bounds); DCHECK(result); if (!result) return 0; - bitmap_.lockPixels(); + displayHeight = subset.height(); + cgContext_ = CGBitmapContextCreate(subset.writable_addr(), subset.width(), + subset.height(), 8, subset.rowBytes(), colorSpace, + kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst); } else { - bool result = bitmap_.tryAllocN32Pixels( + bool result = offscreen_.tryAllocN32Pixels( SkScalarCeilToInt(bitmapScaleFactor_ * clip_bounds.width()), SkScalarCeilToInt(bitmapScaleFactor_ * clip_bounds.height())); DCHECK(result); if (!result) return 0; - bitmap_.eraseColor(0); + offscreen_.eraseColor(0); + displayHeight = offscreen_.height(); + cgContext_ = CGBitmapContextCreate(offscreen_.getPixels(), + offscreen_.width(), offscreen_.height(), 8, offscreen_.rowBytes(), + colorSpace, kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst); } - base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( - CGColorSpaceCreateDeviceRGB()); - 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(bitmapScaleFactor_, -bitmapScaleFactor_); - matrix.postTranslate(0, SkIntToScalar(bitmap_.height())); + matrix.postTranslate(0, SkIntToScalar(displayHeight)); CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix)); @@ -459,4 +467,4 @@ bool SkiaBitLocker::hasEmptyClipRegion() const { return canvas_->isClipEmpty(); } -} // namespace gfx +} // namespace skia diff --git a/chromium/skia/ext/skia_utils_mac_unittest.mm b/chromium/skia/ext/skia_utils_mac_unittest.mm index ad505c71af8..9e4505667fa 100644 --- a/chromium/skia/ext/skia_utils_mac_unittest.mm +++ b/chromium/skia/ext/skia_utils_mac_unittest.mm @@ -6,6 +6,7 @@ #import <AppKit/AppKit.h> +#include "base/mac/foundation_util.h" #include "base/mac/scoped_nsobject.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkCanvas.h" @@ -154,7 +155,7 @@ void SkiaUtilsMacTest::RunBitLockerTest(BitLockerTest test) { canvas.clipRect(clipRect); } { - gfx::SkiaBitLocker bitLocker(&canvas); + skia::SkiaBitLocker bitLocker(&canvas); CGContextRef cgContext = bitLocker.cgContext(); CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); CGContextSetFillColorWithColor(cgContext, testColor); @@ -182,14 +183,16 @@ void SkiaUtilsMacTest::ShapeHelper(int width, int height, SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit)); // Confirm size - NSImage* image = gfx::SkBitmapToNSImage(thing); + NSImage* image = skia::SkBitmapToNSImage(thing); EXPECT_DOUBLE_EQ([image size].width, (double)width); EXPECT_DOUBLE_EQ([image size].height, (double)height); EXPECT_TRUE([[image representations] count] == 1); EXPECT_TRUE([[[image representations] lastObject] isKindOfClass:[NSBitmapImageRep class]]); - TestImageRep([[image representations] lastObject], isred); + TestImageRep(base::mac::ObjCCastStrict<NSBitmapImageRep>( + [[image representations] lastObject]), + isred); } TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) { @@ -209,7 +212,7 @@ TEST_F(SkiaUtilsMacTest, BitmapToNSBitmapImageRep_BlueRectangle20x30) { int height = 30; SkBitmap bitmap(CreateSkBitmap(width, height, false, true)); - NSBitmapImageRep* imageRep = gfx::SkBitmapToNSBitmapImageRep(bitmap); + NSBitmapImageRep* imageRep = skia::SkBitmapToNSBitmapImageRep(bitmap); EXPECT_DOUBLE_EQ(width, [imageRep size].width); EXPECT_DOUBLE_EQ(height, [imageRep size].height); @@ -222,9 +225,10 @@ TEST_F(SkiaUtilsMacTest, NSImageRepToSkBitmap) { NSImage* image = CreateNSImage(width, height); EXPECT_EQ(1u, [[image representations] count]); - NSBitmapImageRep* imageRep = [[image representations] lastObject]; + NSBitmapImageRep* imageRep = base::mac::ObjCCastStrict<NSBitmapImageRep>( + [[image representations] lastObject]); NSColorSpace* colorSpace = [NSColorSpace genericRGBColorSpace]; - SkBitmap bitmap(gfx::NSImageRepToSkBitmapWithColorSpace( + SkBitmap bitmap(skia::NSImageRepToSkBitmapWithColorSpace( imageRep, [image size], false, [colorSpace CGColorSpace])); TestSkBitmap(bitmap); } diff --git a/chromium/skia/ext/skia_utils_win.cc b/chromium/skia/ext/skia_utils_win.cc index 3089b242c26..98733737257 100644 --- a/chromium/skia/ext/skia_utils_win.cc +++ b/chromium/skia/ext/skia_utils_win.cc @@ -58,5 +58,44 @@ COLORREF SkColorToCOLORREF(SkColor color) { #endif } +void InitializeDC(HDC context) { + // Enables world transformation. + // If the GM_ADVANCED graphics mode is set, GDI always draws arcs in the + // counterclockwise direction in logical space. This is equivalent to the + // statement that, in the GM_ADVANCED graphics mode, both arc control points + // and arcs themselves fully respect the device context's world-to-device + // transformation. + BOOL res = SetGraphicsMode(context, GM_ADVANCED); + SkASSERT(res != 0); + + // Enables dithering. + res = SetStretchBltMode(context, HALFTONE); + SkASSERT(res != 0); + // As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called + // right after. + res = SetBrushOrgEx(context, 0, 0, NULL); + SkASSERT(res != 0); + + // Sets up default orientation. + res = SetArcDirection(context, AD_CLOCKWISE); + SkASSERT(res != 0); + + // Sets up default colors. + res = SetBkColor(context, RGB(255, 255, 255)); + SkASSERT(res != CLR_INVALID); + res = SetTextColor(context, RGB(0, 0, 0)); + SkASSERT(res != CLR_INVALID); + res = SetDCBrushColor(context, RGB(255, 255, 255)); + SkASSERT(res != CLR_INVALID); + res = SetDCPenColor(context, RGB(0, 0, 0)); + SkASSERT(res != CLR_INVALID); + + // Sets up default transparency. + res = SetBkMode(context, OPAQUE); + SkASSERT(res != 0); + res = SetROP2(context, R2_COPYPEN); + SkASSERT(res != 0); +} + } // namespace skia diff --git a/chromium/skia/ext/skia_utils_win.h b/chromium/skia/ext/skia_utils_win.h index 379cba12004..b116efe19e2 100644 --- a/chromium/skia/ext/skia_utils_win.h +++ b/chromium/skia/ext/skia_utils_win.h @@ -7,6 +7,9 @@ #include "third_party/skia/include/core/SkColor.h" +#include "build/build_config.h" +#include <windows.h> + struct SkIRect; struct SkPoint; struct SkRect; @@ -43,6 +46,9 @@ SK_API SkColor COLORREFToSkColor(COLORREF color); // Converts ARGB to COLORREFs (0BGR). SK_API COLORREF SkColorToCOLORREF(SkColor color); +// Initializes the default settings and colors in a device context. +SK_API void InitializeDC(HDC context); + } // namespace skia #endif // SKIA_EXT_SKIA_UTILS_WIN_H_ diff --git a/chromium/skia/public/BUILD.gn b/chromium/skia/public/BUILD.gn index ce407dfacf0..bcc7a289dd8 100644 --- a/chromium/skia/public/BUILD.gn +++ b/chromium/skia/public/BUILD.gn @@ -14,7 +14,7 @@ source_set("public") { deps = [ "//base", + "//mojo/public/cpp/bindings", "//skia", - "//third_party/mojo/src/mojo/public/cpp/bindings", ] } diff --git a/chromium/skia/public/interfaces/BUILD.gn b/chromium/skia/public/interfaces/BUILD.gn index ea57c5032c6..e2ffdf006ad 100644 --- a/chromium/skia/public/interfaces/BUILD.gn +++ b/chromium/skia/public/interfaces/BUILD.gn @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni") +import("//mojo/public/tools/bindings/mojom.gni") mojom("interfaces") { sources = [ diff --git a/chromium/skia/public/type_converters.cc b/chromium/skia/public/type_converters.cc index 143710b6cc9..ef5a08b0295 100644 --- a/chromium/skia/public/type_converters.cc +++ b/chromium/skia/public/type_converters.cc @@ -4,6 +4,8 @@ #include "skia/public/type_converters.h" +#include <stddef.h> +#include <stdint.h> #include <string.h> #include "base/logging.h" @@ -133,7 +135,7 @@ skia::BitmapPtr TypeConverter<skia::BitmapPtr, SkBitmap>::Convert( result->pixel_data = mojo::Array<uint8_t>::New(size); if (!bitmap.readPixels(info, &result->pixel_data[0], row_bytes, 0, 0)) return nullptr; - return result.Pass(); + return result; } } // namespace mojo diff --git a/chromium/skia/skia_chrome.gypi b/chromium/skia/skia_chrome.gypi index f8c39a99581..492762488c1 100644 --- a/chromium/skia/skia_chrome.gypi +++ b/chromium/skia/skia_chrome.gypi @@ -47,8 +47,8 @@ 'ext/recursive_gaussian_convolution.cc', 'ext/SkDiscardableMemory_chrome.cc', 'ext/SkMemory_new_handler.cpp', - 'ext/SkTraceMemoryDump_chrome.cc', 'ext/skia_memory_dump_provider.cc', + 'ext/skia_trace_memory_dump_impl.cc', 'ext/skia_utils_base.cc', 'ext/skia_utils_ios.mm', 'ext/skia_utils_mac.mm', diff --git a/chromium/skia/skia_gn_files.gypi b/chromium/skia/skia_gn_files.gypi index d693bf67450..1018250f173 100644 --- a/chromium/skia/skia_gn_files.gypi +++ b/chromium/skia/skia_gn_files.gypi @@ -10,6 +10,7 @@ '<(skia_src_path)/fonts/SkRemotableFontMgr.cpp', '<(skia_src_path)/images/SkScaledBitmapSampler.cpp', '<(skia_src_path)/ports/SkFontConfigInterface_direct.cpp', + '<(skia_src_path)/ports/SkFontConfigInterface_direct_factory.cpp', '<(skia_src_path)/ports/SkFontHost_fontconfig.cpp', '<(skia_src_path)/ports/SkFontHost_FreeType_common.cpp', '<(skia_src_path)/ports/SkFontHost_FreeType.cpp', @@ -19,7 +20,7 @@ '<(skia_src_path)/ports/SkFontMgr_android_factory.cpp', '<(skia_src_path)/ports/SkFontMgr_android_parser.cpp', '<(skia_src_path)/ports/SkFontMgr_win_dw.cpp', - '<(skia_src_path)/ports/SkGlobalInitialization_chromium.cpp', + '<(skia_src_path)/ports/SkGlobalInitialization_default.cpp', '<(skia_src_path)/ports/SkImageDecoder_empty.cpp', '<(skia_src_path)/ports/SkOSFile_posix.cpp', '<(skia_src_path)/ports/SkRemotableFontMgr_win_dw.cpp', diff --git a/chromium/skia/skia_library.gypi b/chromium/skia/skia_library.gypi index b61385a701d..61ad34501a8 100644 --- a/chromium/skia/skia_library.gypi +++ b/chromium/skia/skia_library.gypi @@ -29,6 +29,7 @@ '../third_party/skia/src/images/SkScaledBitmapSampler.cpp', '../third_party/skia/src/ports/SkFontConfigInterface_direct.cpp', + '../third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp', '../third_party/skia/src/fonts/SkFontMgr_fontconfig.cpp', '../third_party/skia/src/ports/SkFontHost_fontconfig.cpp', @@ -47,7 +48,7 @@ "../third_party/skia/src/ports/SkFontMgr_android_factory.cpp", '../third_party/skia/src/ports/SkFontMgr_android_parser.cpp', '../third_party/skia/src/ports/SkFontMgr_win_dw.cpp', - '../third_party/skia/src/ports/SkGlobalInitialization_chromium.cpp', + '../third_party/skia/src/ports/SkGlobalInitialization_default.cpp', '../third_party/skia/src/ports/SkOSFile_posix.cpp', '../third_party/skia/src/ports/SkOSFile_stdio.cpp', '../third_party/skia/src/ports/SkOSFile_win.cpp', @@ -67,8 +68,6 @@ '../third_party/skia/src/utils/SkBoundaryPatch.cpp', '../third_party/skia/src/utils/SkFrontBufferedStream.cpp', '../third_party/skia/src/utils/SkCamera.cpp', - '../third_party/skia/src/utils/SkCubicInterval.cpp', - '../third_party/skia/src/utils/SkCullPoints.cpp', '../third_party/skia/src/utils/SkDumpCanvas.cpp', '../third_party/skia/src/utils/SkInterpolator.cpp', '../third_party/skia/src/utils/SkLayer.cpp', @@ -79,10 +78,6 @@ '../third_party/skia/src/utils/SkParsePath.cpp', '../third_party/skia/src/utils/SkSHA1.cpp', - # We don't currently need to change thread affinity, so leave out this complexity for now. - "../third_party/skia/src/utils/SkThreadUtils_pthread_mach.cpp", - "../third_party/skia/src/utils/SkThreadUtils_pthread_linux.cpp", - #windows '../third_party/skia/src/utils/win/SkAutoCoInitialize.cpp', '../third_party/skia/src/utils/win/SkIStream.cpp', @@ -143,11 +138,10 @@ 'sources!': [ # Keeping _win.cpp "../third_party/skia/src/utils/SkThreadUtils_pthread.cpp", - "../third_party/skia/src/utils/SkThreadUtils_pthread_other.cpp", ], },{ 'sources!': [ - # Keeping _pthread.cpp and _pthread_other.cpp + # Keeping _pthread.cpp "../third_party/skia/src/utils/SkThreadUtils_win.cpp", ], }], @@ -184,6 +178,7 @@ [ 'OS=="win" or OS=="mac" or OS=="ios" or OS=="android"', { 'sources!': [ '../third_party/skia/src/ports/SkFontConfigInterface_direct.cpp', + '../third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp', '../third_party/skia/src/ports/SkFontHost_fontconfig.cpp', '../third_party/skia/src/fonts/SkFontMgr_fontconfig.cpp', ], diff --git a/chromium/skia/skia_library_opts.gyp b/chromium/skia/skia_library_opts.gyp index 85fdcb3df3e..e1627e0f95c 100644 --- a/chromium/skia/skia_library_opts.gyp +++ b/chromium/skia/skia_library_opts.gyp @@ -29,7 +29,7 @@ 'target_name': 'skia_opts', 'type': 'static_library', # The optimize: 'max' scattered throughout are particularly - # important when compiled by MSVC 2013, which seems + # important when compiled by MSVC 2013, which seems # to mis-link-time-compile code that's built with # different optimization levels. http://crbug.com/543583 'variables': { @@ -55,6 +55,9 @@ 'dependencies': [ 'skia_opts_ssse3', 'skia_opts_sse41', + 'skia_opts_sse42', + 'skia_opts_avx', + 'skia_opts_avx2', ], }], [ 'target_arch == "arm"', { @@ -110,7 +113,7 @@ 'target_name': 'skia_opts_ssse3', 'type': 'static_library', # The optimize: 'max' scattered throughout are particularly - # important when compiled by MSVC 2013, which seems + # important when compiled by MSVC 2013, which seems # to mis-link-time-compile code that's built with # different optimization levels. http://crbug.com/543583 'variables': { @@ -154,7 +157,7 @@ 'target_name': 'skia_opts_sse41', 'type': 'static_library', # The optimize: 'max' scattered throughout are particularly - # important when compiled by MSVC 2013, which seems + # important when compiled by MSVC 2013, which seems # to mis-link-time-compile code that's built with # different optimization levels. http://crbug.com/543583 'variables': { @@ -188,10 +191,107 @@ ], }, { + 'target_name': 'skia_opts_sse42', + 'type': 'static_library', + # The optimize: 'max' scattered throughout are particularly + # important when compiled by MSVC 2013, which seems + # to mis-link-time-compile code that's built with + # different optimization levels. http://crbug.com/543583 + 'variables': { + 'optimize': 'max', + }, + 'includes': [ + 'skia_common.gypi', + '../build/android/increase_size_for_speed.gypi', + ], + 'include_dirs': [ '<@(include_dirs)' ], + 'sources': [ '<@(sse42_sources)' ], + 'conditions': [ + [ 'OS in ["linux", "freebsd", "openbsd", "solaris", "android"]', { + 'cflags': [ '-msse4.2' ], + }], + [ 'OS == "mac"', { + 'xcode_settings': { + 'GCC_ENABLE_SSE42_EXTENSIONS': 'YES', + }, + }], + [ 'OS == "win" and clang == 1', { + # cl.exe's /arch flag doesn't have a setting for SSE4.2, and cl.exe + # doesn't need it for intrinsics. clang-cl does need it, though. + 'msvs_settings': { + 'VCCLCompilerTool': { 'AdditionalOptions': [ '-msse4.2' ] }, + }, + }], + [ 'OS == "win"', { + 'defines' : [ 'SK_CPU_SSE_LEVEL=42' ], + }], + ], + }, + { + 'target_name': 'skia_opts_avx', + 'type': 'static_library', + # The optimize: 'max' scattered throughout are particularly + # important when compiled by MSVC 2013, which seems + # to mis-link-time-compile code that's built with + # different optimization levels. http://crbug.com/543583 + 'variables': { + 'optimize': 'max', + }, + 'includes': [ + 'skia_common.gypi', + '../build/android/increase_size_for_speed.gypi', + ], + 'include_dirs': [ '<@(include_dirs)' ], + 'sources': [ '<@(avx_sources)' ], + 'conditions': [ + [ 'OS in ["linux", "freebsd", "openbsd", "solaris", "android"]', { + 'cflags': [ '-mavx' ], + }], + [ 'OS == "mac"', { + 'xcode_settings': { + 'OTHER_CFLAGS': [ '-mavx' ], + }, + }], + [ 'OS == "win"', { + 'msvs_settings': { 'VCCLCompilerTool': { 'EnableEnhancedInstructionSet': '3' } }, + }], + ], + }, + { + 'target_name': 'skia_opts_avx2', + 'type': 'static_library', + # The optimize: 'max' scattered throughout are particularly + # important when compiled by MSVC 2013, which seems + # to mis-link-time-compile code that's built with + # different optimization levels. http://crbug.com/543583 + 'variables': { + 'optimize': 'max', + }, + 'includes': [ + 'skia_common.gypi', + '../build/android/increase_size_for_speed.gypi', + ], + 'include_dirs': [ '<@(include_dirs)' ], + 'sources': [ '<@(avx2_sources)' ], + 'conditions': [ + [ 'OS in ["linux", "freebsd", "openbsd", "solaris", "android"]', { + 'cflags': [ '-mavx2' ], + }], + [ 'OS == "mac"', { + 'xcode_settings': { + 'OTHER_CFLAGS': [ '-mavx2' ], + }, + }], + [ 'OS == "win"', { + 'msvs_settings': { 'VCCLCompilerTool': { 'EnableEnhancedInstructionSet': '5' } }, + }], + ], + }, + { 'target_name': 'skia_opts_none', 'type': 'static_library', # The optimize: 'max' scattered throughout are particularly - # important when compiled by MSVC 2013, which seems + # important when compiled by MSVC 2013, which seems # to mis-link-time-compile code that's built with # different optimization levels. http://crbug.com/543583 'variables': { |