Commit 213fa288 authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Use paint record to back ImageSkiaRep

Currently ImageSkiaReps are backed by SkBitmaps and cc::PaintImages.
While cc::PaintImages are drawables, they are sourced from the SkBitmaps
provided to the constructor. This means images that are sourced from
drawables, such as our vector icons, are rasterized into bitmaps first
and then stored as ImageSkiaReps. This rasterization takes place on the
UI thread.

This patch makes cc::PaintRecord as the backing store for ImageSkiaReps.
cc::PaintRecord are drawables and can be initialized with an SkBitmap if
needed. Having images stored this way means drawables like vector icons
dont need to be rasterized on the UI thread. Their rasterization will be
managed by cc or even the GPU in case of OOPR. This also removes the
constraint that ImageSkias are a rasterized source of image. It also
gives a way to add more drawable sources(CanvasImageSources) like
lottie.

This feature is hidden behind a feature flag UsePaintRecordForImageSkia.

Bug: 882507
Change-Id: Id4a6500ba0e12da382e95d59e5fa8bc5642082ab
Component: ImageSkiaRep, gfx, Image, Image Skia
Reviewed-on: https://chromium-review.googlesource.com/c/1227488Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596402}
parent cbb05f39
...@@ -105,7 +105,6 @@ jumbo_component("gfx") { ...@@ -105,7 +105,6 @@ jumbo_component("gfx") {
"image/image_png_rep.h", "image/image_png_rep.h",
"image/image_skia.cc", "image/image_skia.cc",
"image/image_skia.h", "image/image_skia.h",
"image/image_skia_rep.cc",
"image/image_skia_rep.h", "image/image_skia_rep.h",
"image/image_skia_source.cc", "image/image_skia_source.cc",
"image/image_skia_source.h", "image/image_skia_source.h",
...@@ -213,6 +212,8 @@ jumbo_component("gfx") { ...@@ -213,6 +212,8 @@ jumbo_component("gfx") {
"image/image_generic.cc", "image/image_generic.cc",
"image/image_skia_operations.cc", "image/image_skia_operations.cc",
"image/image_skia_operations.h", "image/image_skia_operations.h",
"image/image_skia_rep_default.cc",
"image/image_skia_rep_default.h",
"paint_throbber.cc", "paint_throbber.cc",
"paint_throbber.h", "paint_throbber.h",
"scoped_canvas.cc", "scoped_canvas.cc",
...@@ -227,6 +228,11 @@ jumbo_component("gfx") { ...@@ -227,6 +228,11 @@ jumbo_component("gfx") {
"skottie_wrapper.cc", "skottie_wrapper.cc",
"skottie_wrapper.h", "skottie_wrapper.h",
] ]
} else {
sources += [
"image/image_skia_rep_ios.cc",
"image/image_skia_rep_ios.h",
]
} }
configs += [ configs += [
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "ui/gfx/scoped_canvas.h" #include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/skia_paint_util.h" #include "ui/gfx/skia_paint_util.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/gfx/switches.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
namespace gfx { namespace gfx {
...@@ -357,8 +358,17 @@ void Canvas::DrawImageInt(const ImageSkia& image, ...@@ -357,8 +358,17 @@ void Canvas::DrawImageInt(const ImageSkia& image,
ScopedCanvas scoper(this); ScopedCanvas scoper(this);
canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale), canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale),
SkFloatToScalar(1.0f / bitmap_scale)); SkFloatToScalar(1.0f / bitmap_scale));
canvas_->drawImage(image_rep.paint_image(), SkFloatToScalar(x * bitmap_scale), if (base::FeatureList::IsEnabled(features::kUsePaintRecordForImageSkia)) {
SkFloatToScalar(y * bitmap_scale), &flags); canvas_->translate(std::round(x * bitmap_scale),
std::round(y * bitmap_scale));
canvas_->saveLayer(nullptr, &flags);
canvas_->drawPicture(image_rep.GetPaintRecord());
canvas_->restore();
} else {
canvas_->drawImage(image_rep.paint_image(),
SkFloatToScalar(x * bitmap_scale),
SkFloatToScalar(y * bitmap_scale), &flags);
}
} }
void Canvas::DrawImageInt(const ImageSkia& image, void Canvas::DrawImageInt(const ImageSkia& image,
......
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
#include "ui/gfx/image/canvas_image_source.h" #include "ui/gfx/image/canvas_image_source.h"
#include "base/logging.h" #include "base/logging.h"
#include "cc/paint/display_item_list.h"
#include "cc/paint/record_paint_canvas.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/switches.h"
namespace gfx { namespace gfx {
...@@ -49,7 +52,26 @@ CanvasImageSource::CanvasImageSource(const Size& size, bool is_opaque) ...@@ -49,7 +52,26 @@ CanvasImageSource::CanvasImageSource(const Size& size, bool is_opaque)
: size_(size), is_opaque_(is_opaque) {} : size_(size), is_opaque_(is_opaque) {}
ImageSkiaRep CanvasImageSource::GetImageForScale(float scale) { ImageSkiaRep CanvasImageSource::GetImageForScale(float scale) {
Canvas canvas(size_, scale, is_opaque_); if (base::FeatureList::IsEnabled(features::kUsePaintRecordForImageSkia)) {
scoped_refptr<cc::DisplayItemList> display_item_list =
base::MakeRefCounted<cc::DisplayItemList>(
cc::DisplayItemList::kToBeReleasedAsPaintOpBuffer);
display_item_list->StartPaint();
cc::RecordPaintCanvas record_canvas(
display_item_list.get(),
SkRect::MakeIWH(size_.width(), size_.height()));
gfx::Canvas canvas(&record_canvas, scale);
canvas.Scale(scale, scale);
Draw(&canvas);
display_item_list->EndPaintOfPairedEnd();
display_item_list->Finalize();
return ImageSkiaRep(display_item_list->ReleaseAsRecord(),
gfx::ScaleToCeiledSize(size_, scale), scale);
}
gfx::Canvas canvas(size_, scale, is_opaque_);
Draw(&canvas); Draw(&canvas);
return ImageSkiaRep(canvas.GetBitmap(), scale); return ImageSkiaRep(canvas.GetBitmap(), scale);
} }
......
...@@ -186,11 +186,11 @@ void ImageSkiaStorage::AddRepresentation(const ImageSkiaRep& image) { ...@@ -186,11 +186,11 @@ void ImageSkiaStorage::AddRepresentation(const ImageSkiaRep& image) {
DCHECK(!HasRepresentationAtAllScales()); DCHECK(!HasRepresentationAtAllScales());
if (image.scale() != 1.0f) { if (image.scale() != 1.0f) {
for (ImageSkia::ImageSkiaReps::iterator it = image_reps_.begin(); ImageSkia::ImageSkiaReps::iterator it;
it < image_reps_.end(); ++it) { for (it = image_reps_.begin(); it < image_reps_.end(); ++it) {
if (it->unscaled()) { if (it->unscaled()) {
DCHECK_EQ(1.0f, it->scale()); DCHECK_EQ(1.0f, it->scale());
it->SetScaled(); *it = ImageSkiaRep(it->GetBitmap(), it->scale());
break; break;
} }
} }
......
...@@ -6,75 +6,11 @@ ...@@ -6,75 +6,11 @@
#define UI_GFX_IMAGE_IMAGE_SKIA_REP_H_ #define UI_GFX_IMAGE_IMAGE_SKIA_REP_H_
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
#if !defined(OS_IOS) #if defined(OS_IOS)
#include "cc/paint/paint_image.h" #include "ui/gfx/image/image_skia_rep_ios.h"
#endif #else
#include "ui/gfx/image/image_skia_rep_default.h"
namespace gfx { #endif // defined(OS_IOS)
// An ImageSkiaRep represents a bitmap and the scale factor it is intended for.
// 0.0f scale is used to indicate that this ImageSkiaRep is used for unscaled
// image (the image that only returns 1.0f scale image).
class GFX_EXPORT ImageSkiaRep {
public:
// Create null bitmap.
ImageSkiaRep();
~ImageSkiaRep();
// Note: This is for testing purpose only.
// Creates a bitmap with kARGB_8888_Config config with given |size| in DIP.
// This allocates pixels in the bitmap. It is guaranteed that the data in the
// bitmap are initialized but the actual values are undefined.
// Specifying 0 scale means the image is for unscaled image. (unscaled()
// returns truen, and scale() returns 1.0f;)
ImageSkiaRep(const gfx::Size& size, float scale);
// Creates a bitmap with given scale.
// Adds ref to |src|.
ImageSkiaRep(const SkBitmap& src, float scale);
// Returns true if the backing bitmap is null.
bool is_null() const { return bitmap_.isNull(); }
// Get width and height of bitmap in DIP.
int GetWidth() const;
int GetHeight() const;
// Get width and height of bitmap in pixels.
int pixel_width() const { return bitmap_.width(); }
int pixel_height() const { return bitmap_.height(); }
Size pixel_size() const {
return Size(pixel_width(), pixel_height());
}
// Retrieves the scale that the bitmap will be painted at.
float scale() const { return unscaled() ? 1.0f : scale_; }
bool unscaled() const { return scale_ == 0.0f; }
// Mark the image to be used as scaled image.
void SetScaled();
// Returns backing bitmap.
const SkBitmap& GetBitmap() const { return bitmap_; }
#if !defined(OS_IOS)
const cc::PaintImage& paint_image() const { return paint_image_; }
#endif
private:
#if !defined(OS_IOS)
cc::PaintImage paint_image_;
#endif
SkBitmap bitmap_;
float scale_;
};
} // namespace gfx
#endif // UI_GFX_IMAGE_IMAGE_SKIA_REP_H_ #endif // UI_GFX_IMAGE_IMAGE_SKIA_REP_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/image/image_skia_rep_default.h"
#include "base/logging.h"
#include "cc/paint/display_item_list.h"
#include "cc/paint/record_paint_canvas.h"
#include "cc/paint/skia_paint_canvas.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace gfx {
ImageSkiaRep::ImageSkiaRep()
: type_(ImageRepType::kImageTypeDrawable), scale_(0.0f) {}
ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale)
: type_(ImageRepType::kImageTypeBitmap), scale_(scale) {
bitmap_.allocN32Pixels(static_cast<int>(size.width() * this->scale()),
static_cast<int>(size.height() * this->scale()));
bitmap_.eraseColor(SK_ColorRED);
bitmap_.setImmutable();
pixel_size_.SetSize(bitmap_.width(), bitmap_.height());
paint_image_ = cc::PaintImage::CreateFromBitmap(bitmap_);
}
ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale)
: type_(ImageRepType::kImageTypeBitmap),
pixel_size_(gfx::Size(src.width(), src.height())),
bitmap_(src),
scale_(scale) {
bitmap_.setImmutable();
paint_image_ = cc::PaintImage::CreateFromBitmap(src);
}
ImageSkiaRep::ImageSkiaRep(sk_sp<cc::PaintRecord> paint_record,
const gfx::Size& pixel_size,
float scale)
: paint_record_(std::move(paint_record)),
type_(ImageRepType::kImageTypeDrawable),
pixel_size_(pixel_size),
scale_(scale) {}
ImageSkiaRep::ImageSkiaRep(const ImageSkiaRep& other)
: paint_image_(other.paint_image_),
paint_record_(other.paint_record_),
type_(other.type_),
pixel_size_(other.pixel_size_),
bitmap_(other.bitmap_),
scale_(other.scale_) {}
ImageSkiaRep::~ImageSkiaRep() {}
int ImageSkiaRep::GetWidth() const {
return static_cast<int>(pixel_width() / scale());
}
int ImageSkiaRep::GetHeight() const {
return static_cast<int>(pixel_height() / scale());
}
sk_sp<cc::PaintRecord> ImageSkiaRep::GetPaintRecord() const {
DCHECK(type_ == ImageRepType::kImageTypeBitmap || !is_null());
// If this image rep is of |kImageTypeDrawable| then it must have a paint
// record.
if (type_ == ImageRepType::kImageTypeDrawable || paint_record_)
return paint_record_;
// If this ImageRep was generated using a bitmap then it may not have a
// paint record generated for it yet. We would have to generate it now.
scoped_refptr<cc::DisplayItemList> display_item_list =
base::MakeRefCounted<cc::DisplayItemList>(
cc::DisplayItemList::kToBeReleasedAsPaintOpBuffer);
cc::RecordPaintCanvas record_canvas(
display_item_list.get(), SkRect::MakeIWH(pixel_width(), pixel_height()));
display_item_list->StartPaint();
record_canvas.drawImage(paint_image(), 0, 0, nullptr);
display_item_list->EndPaintOfPairedEnd();
display_item_list->Finalize();
paint_record_ = display_item_list->ReleaseAsRecord();
return paint_record_;
}
const SkBitmap& ImageSkiaRep::GetBitmap() const {
if (type_ == ImageRepType::kImageTypeDrawable && bitmap_.isNull() &&
paint_record_) {
// TODO(malaykeshav): Add a NOTREACHED() once all instances of this call
// path is removed from the code base.
// A request for bitmap was made even though this ImageSkiaRep is sourced
// form a drawable(e.g. CanvasImageSource). This should not be happenning
// as it forces a rasterization on the UI thread.
bitmap_.allocN32Pixels(pixel_width(), pixel_height());
bitmap_.eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(bitmap_);
paint_record_->Playback(&canvas);
bitmap_.setImmutable();
}
return bitmap_;
}
} // namespace gfx
// Copyright 2018 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 UI_GFX_IMAGE_IMAGE_SKIA_REP_DEFAULT_H_
#define UI_GFX_IMAGE_IMAGE_SKIA_REP_DEFAULT_H_
#include "build/build_config.h"
#include "cc/paint/paint_image.h"
#include "cc/paint/paint_op_buffer.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
// An ImageSkiaRep represents an image and the scale factor it is intended for.
// 0.0f scale is used to indicate that this ImageSkiaRep is used for unscaled
// (ImageSkia does not automatically scale the image).
// TODO(malaykeshav): Support transport of PaintRecord across mojo. This would
// require adding inline serialization support for PaintRecords.
class GFX_EXPORT ImageSkiaRep {
public:
// Create null bitmap.
ImageSkiaRep();
// Note: This is for testing purpose only.
// Creates a bitmap with kARGB_8888_Config config with given |size| in DIP.
// This allocates pixels in the bitmap. It is guaranteed that the data in the
// bitmap are initialized but the actual values are undefined.
// Specifying 0 scale means the image is for unscaled image. (unscaled()
// returns truen, and scale() returns 1.0f;)
ImageSkiaRep(const gfx::Size& size, float scale);
// Creates a bitmap with given scale.
// Adds ref to |src|.
ImageSkiaRep(const SkBitmap& src, float scale);
// Creates an image rep backed by a paint record of given size and scale. This
// is used when the image representation is sourced from a drawable sunch as
// CanvasImageSource.
ImageSkiaRep(sk_sp<cc::PaintRecord> paint_record,
const gfx::Size& size,
float scale);
ImageSkiaRep(const ImageSkiaRep& other);
~ImageSkiaRep();
// Get width and height of the image in pixels.
int pixel_width() const { return pixel_size_.width(); }
int pixel_height() const { return pixel_size_.height(); }
const Size& pixel_size() const { return pixel_size_; }
// Get width and height of the image in DIP.
int GetWidth() const;
int GetHeight() const;
// Retrieves the scale for which this image is a representation of.
float scale() const { return unscaled() ? 1.0f : scale_; }
bool unscaled() const { return scale_ == 0.0f; }
bool is_null() const {
return type_ == ImageRepType::kImageTypeBitmap ? bitmap_.isNull()
: !paint_record_;
}
// Returns the backing bitmap when the image representation is sourced from a
// bitmap. If this is a |kImageTypeDrawable| then it will generate(and cache)
// a bitmap.
const SkBitmap& GetBitmap() const;
// Returns the backing drawable as a PaintRecord. Use this when the type of
// ImageRep is |kImageTypeDrawable|.
sk_sp<cc::PaintRecord> GetPaintRecord() const;
const cc::PaintImage& paint_image() const { return paint_image_; };
bool has_paint_image() const { return !!paint_image_; }
private:
enum class ImageRepType {
kImageTypeBitmap, // When the source image is rasterized. (Bitmaps, PNGs)
kImageTypeDrawable // When the source image is a drawable generated by a
// CanvasImageSource.
};
// TODO(malaykeshav): Remove when migration is complete and it is safe.
cc::PaintImage paint_image_;
mutable sk_sp<cc::PaintRecord> paint_record_;
ImageRepType type_;
Size pixel_size_;
mutable SkBitmap bitmap_;
float scale_;
};
} // namespace gfx
#endif // UI_GFX_IMAGE_IMAGE_SKIA_REP_DEFAULT_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/gfx/image/image_skia_rep.h" #include "ui/gfx/image/image_skia_rep_ios.h"
#include "base/logging.h" #include "base/logging.h"
namespace gfx { namespace gfx {
ImageSkiaRep::ImageSkiaRep() : scale_(0.0f) { ImageSkiaRep::ImageSkiaRep() : scale_(0.0f) {}
}
ImageSkiaRep::~ImageSkiaRep() {
}
ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale) : scale_(scale) { ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale) : scale_(scale) {
bitmap_.allocN32Pixels(static_cast<int>(size.width() * this->scale()), bitmap_.allocN32Pixels(static_cast<int>(size.width() * this->scale()),
static_cast<int>(size.height() * this->scale())); static_cast<int>(size.height() * this->scale()));
bitmap_.eraseColor(SK_ColorRED); bitmap_.eraseColor(SK_ColorRED);
bitmap_.setImmutable(); bitmap_.setImmutable();
#if !defined(OS_IOS) pixel_size_.SetSize(bitmap_.width(), bitmap_.height());
paint_image_ = cc::PaintImage::CreateFromBitmap(bitmap_);
#endif
} }
ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale) ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale)
: bitmap_(src), : pixel_size_(gfx::Size(src.width(), src.height())),
bitmap_(src),
scale_(scale) { scale_(scale) {
bitmap_.setImmutable(); bitmap_.setImmutable();
#if !defined(OS_IOS)
paint_image_ = cc::PaintImage::CreateFromBitmap(bitmap_);
#endif
} }
ImageSkiaRep::ImageSkiaRep(const ImageSkiaRep& other)
: pixel_size_(other.pixel_size_),
bitmap_(other.bitmap_),
scale_(other.scale_) {}
ImageSkiaRep::~ImageSkiaRep() {}
int ImageSkiaRep::GetWidth() const { int ImageSkiaRep::GetWidth() const {
return static_cast<int>(bitmap_.width() / scale()); return static_cast<int>(pixel_width() / scale());
} }
int ImageSkiaRep::GetHeight() const { int ImageSkiaRep::GetHeight() const {
return static_cast<int>(bitmap_.height() / scale()); return static_cast<int>(pixel_height() / scale());
} }
void ImageSkiaRep::SetScaled() { const SkBitmap& ImageSkiaRep::GetBitmap() const {
DCHECK_EQ(0.0f, scale_); return bitmap_;
if (scale_ == 0.0f)
scale_ = 1.0f;
} }
} // namespace gfx } // namespace gfx
// Copyright 2018 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 UI_GFX_IMAGE_IMAGE_SKIA_REP_IOS_H_
#define UI_GFX_IMAGE_IMAGE_SKIA_REP_IOS_H_
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
// An ImageSkiaRep represents an image and the scale factor it is intended for.
// 0.0f scale is used to indicate that this ImageSkiaRep is used for unscaled
// image (ImageSkia does not automatically scale the image).
// iOS does not support cc's PaintOpBuffer and instead uses cocoa frameworks
// image formats.
class GFX_EXPORT ImageSkiaRep {
public:
// Create null bitmap.
ImageSkiaRep();
// Note: This is for testing purpose only.
// Creates a bitmap with kARGB_8888_Config config with given |size| in DIP.
// This allocates pixels in the bitmap. It is guaranteed that the data in the
// bitmap are initialized but the actual values are undefined.
// Specifying 0 scale means the image is for unscaled image. (unscaled()
// returns truen, and scale() returns 1.0f;)
ImageSkiaRep(const gfx::Size& size, float scale);
// Creates a bitmap with given scale.
// Adds ref to |src|.
ImageSkiaRep(const SkBitmap& src, float scale);
ImageSkiaRep(const ImageSkiaRep& other);
~ImageSkiaRep();
// Get width and height of the image in pixels.
int pixel_width() const { return bitmap_.width(); }
int pixel_height() const { return bitmap_.height(); }
Size pixel_size() const { return gfx::Size(pixel_width(), pixel_height()); }
// Get width and height of the image in DIP.
int GetWidth() const;
int GetHeight() const;
// Retrieves the scale for which this image is a representation of.
float scale() const { return unscaled() ? 1.0f : scale_; }
bool unscaled() const { return scale_ == 0.0f; }
bool is_null() const { return bitmap_.isNull(); }
// Returns the backing bitmap when the image representation is sourced from a
// bitmap.
const SkBitmap& GetBitmap() const;
private:
Size pixel_size_;
SkBitmap bitmap_;
float scale_;
};
} // namespace gfx
#endif // UI_GFX_IMAGE_IMAGE_SKIA_REP_IOS_H_
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/skia/include/effects/SkGradientShader.h" #include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/effects/SkLayerDrawLooper.h" #include "third_party/skia/include/effects/SkLayerDrawLooper.h"
#include "ui/gfx/image/image_skia_rep.h" #include "ui/gfx/image/image_skia_rep.h"
#include "ui/gfx/switches.h"
namespace gfx { namespace gfx {
...@@ -39,8 +40,22 @@ sk_sp<cc::PaintShader> CreateImageRepShaderForScale( ...@@ -39,8 +40,22 @@ sk_sp<cc::PaintShader> CreateImageRepShaderForScale(
shader_scale.setScaleX(local_matrix.getScaleX() / scale); shader_scale.setScaleX(local_matrix.getScaleX() / scale);
shader_scale.setScaleY(local_matrix.getScaleY() / scale); shader_scale.setScaleY(local_matrix.getScaleY() / scale);
return cc::PaintShader::MakeImage(image_rep.paint_image(), tile_mode_x, // TODO(malaykeshav): The check for has_paint_image was only added here to
tile_mode_y, &shader_scale); // prevent generating a paint record in tests. Tests need an instance of
// base::DiscardableMemoryAllocator to generate the PaintRecord. However most
// test suites dont have this set. Ensure that the check is removed before
// enabling the |kUsePaintRecordForImageSkia| feature by default.
// https://crbug.com/891469
if (base::FeatureList::IsEnabled(features::kUsePaintRecordForImageSkia) &&
!image_rep.has_paint_image()) {
return cc::PaintShader::MakePaintRecord(
image_rep.GetPaintRecord(),
SkRect::MakeIWH(image_rep.pixel_width(), image_rep.pixel_height()),
tile_mode_x, tile_mode_y, &shader_scale);
} else {
return cc::PaintShader::MakeImage(image_rep.paint_image(), tile_mode_x,
tile_mode_y, &shader_scale);
}
} }
sk_sp<cc::PaintShader> CreateGradientShader(int start_point, sk_sp<cc::PaintShader> CreateGradientShader(int start_point,
......
...@@ -31,4 +31,10 @@ namespace features { ...@@ -31,4 +31,10 @@ namespace features {
const base::Feature kLeftToRightUrls{"LeftToRightUrls", const base::Feature kLeftToRightUrls{"LeftToRightUrls",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// Enables or disables the use of cc::PaintRecords as a backing store for
// ImageSkiaReps. This may reduce load on the UI thread by moving rasterization
// of drawables away from this thread.
const base::Feature kUsePaintRecordForImageSkia{
"UsePaintRecordForImageSkia", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features } // namespace features
...@@ -25,6 +25,8 @@ namespace features { ...@@ -25,6 +25,8 @@ namespace features {
GFX_SWITCHES_EXPORT extern const base::Feature kLeftToRightUrls; GFX_SWITCHES_EXPORT extern const base::Feature kLeftToRightUrls;
GFX_SWITCHES_EXPORT extern const base::Feature kUsePaintRecordForImageSkia;
} // namespace features } // namespace features
#endif // UI_GFX_SWITCHES_H_ #endif // UI_GFX_SWITCHES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment