Commit f93f8b7c authored by Khushal's avatar Khushal

blink/canvas: Ensure constant PaintImage::ContentId for canvas snapshots.

Its important for Canvas snapshots to have a constant
PaintImage::ContentId to get a cache-hit in cc's ImageDecodeCache. The
logic was missing the case where the CanvasResourceProvider has a valid
ContextProvider but is still using software raster, thus creating
bitmaps which were being allocated new ids.

R=fserb@chromium.org

Bug: 868369, 872117
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Iadc76f35483c0aed9c31aba38a7808aee1dc8863
Reviewed-on: https://chromium-review.googlesource.com/1180423Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584588}
parent 98fa462d
...@@ -94,13 +94,13 @@ class CanvasResourceProviderTexture : public CanvasResourceProvider { ...@@ -94,13 +94,13 @@ class CanvasResourceProviderTexture : public CanvasResourceProvider {
SkSurface::kRetain_ContentChangeMode); SkSurface::kRetain_ContentChangeMode);
} }
sk_sp<SkImage> skia_image = GetSkSurface()->makeImageSnapshot(); auto paint_image = MakeImageSnapshot();
if (!skia_image) if (!paint_image)
return nullptr; return nullptr;
DCHECK(skia_image->isTextureBacked()); DCHECK(paint_image.GetSkImage()->isTextureBacked());
scoped_refptr<StaticBitmapImage> image = scoped_refptr<StaticBitmapImage> image = StaticBitmapImage::Create(
StaticBitmapImage::Create(skia_image, ContextProviderWrapper()); paint_image.GetSkImage(), ContextProviderWrapper());
scoped_refptr<CanvasResource> resource = CanvasResourceBitmap::Create( scoped_refptr<CanvasResource> resource = CanvasResourceBitmap::Create(
image, CreateWeakPtr(), FilterQuality(), ColorParams()); image, CreateWeakPtr(), FilterQuality(), ColorParams());
...@@ -190,12 +190,13 @@ class CanvasResourceProviderTextureGpuMemoryBuffer final ...@@ -190,12 +190,13 @@ class CanvasResourceProviderTextureGpuMemoryBuffer final
return CanvasResourceProviderTexture::ProduceFrame(); return CanvasResourceProviderTexture::ProduceFrame();
} }
sk_sp<SkImage> image = GetSkSurface()->makeImageSnapshot(); auto paint_image = MakeImageSnapshot();
if (!image) if (!paint_image)
return nullptr; return nullptr;
DCHECK(image->isTextureBacked()); DCHECK(paint_image.GetSkImage()->isTextureBacked());
GrBackendTexture backend_texture = image->getBackendTexture(true); GrBackendTexture backend_texture =
paint_image.GetSkImage()->getBackendTexture(true);
DCHECK(backend_texture.isValid()); DCHECK(backend_texture.isValid());
GrGLTextureInfo info; GrGLTextureInfo info;
...@@ -299,12 +300,12 @@ class CanvasResourceProviderRamGpuMemoryBuffer final ...@@ -299,12 +300,12 @@ class CanvasResourceProviderRamGpuMemoryBuffer final
return nullptr; return nullptr;
} }
sk_sp<SkImage> image = GetSkSurface()->makeImageSnapshot(); auto paint_image = MakeImageSnapshot();
if (!image) if (!paint_image)
return nullptr; return nullptr;
DCHECK(!image->isTextureBacked()); DCHECK(!paint_image.GetSkImage()->isTextureBacked());
output_resource->TakeSkImage(std::move(image)); output_resource->TakeSkImage(paint_image.GetSkImage());
return output_resource; return output_resource;
} }
...@@ -353,12 +354,12 @@ class CanvasResourceProviderSharedBitmap : public CanvasResourceProviderBitmap { ...@@ -353,12 +354,12 @@ class CanvasResourceProviderSharedBitmap : public CanvasResourceProviderBitmap {
return nullptr; return nullptr;
} }
sk_sp<SkImage> image = GetSkSurface()->makeImageSnapshot(); auto paint_image = MakeImageSnapshot();
if (!image) if (!paint_image)
return nullptr; return nullptr;
DCHECK(!image->isTextureBacked()); DCHECK(!paint_image.GetSkImage()->isTextureBacked());
output_resource->TakeSkImage(std::move(image)); output_resource->TakeSkImage(paint_image.GetSkImage());
return output_resource; return output_resource;
} }
...@@ -633,15 +634,22 @@ scoped_refptr<StaticBitmapImage> CanvasResourceProvider::Snapshot() { ...@@ -633,15 +634,22 @@ scoped_refptr<StaticBitmapImage> CanvasResourceProvider::Snapshot() {
if (!IsValid()) if (!IsValid())
return nullptr; return nullptr;
auto paint_image = MakeImageSnapshot();
if (paint_image.GetSkImage()->isTextureBacked() && ContextProviderWrapper()) {
return StaticBitmapImage::Create(paint_image.GetSkImage(),
ContextProviderWrapper());
}
return StaticBitmapImage::Create(std::move(paint_image));
}
cc::PaintImage CanvasResourceProvider::MakeImageSnapshot() {
auto sk_image = GetSkSurface()->makeImageSnapshot(); auto sk_image = GetSkSurface()->makeImageSnapshot();
if (!sk_image)
return cc::PaintImage();
auto last_snapshot_sk_image_id = snapshot_sk_image_id_; auto last_snapshot_sk_image_id = snapshot_sk_image_id_;
snapshot_sk_image_id_ = sk_image->uniqueID(); snapshot_sk_image_id_ = sk_image->uniqueID();
if (ContextProviderWrapper()) {
return StaticBitmapImage::Create(std::move(sk_image),
ContextProviderWrapper());
}
// Ensure that a new PaintImage::ContentId is used only when the underlying // Ensure that a new PaintImage::ContentId is used only when the underlying
// SkImage changes. This is necessary to ensure that the same image results // SkImage changes. This is necessary to ensure that the same image results
// in a cache hit in cc's ImageDecodeCache. // in a cache hit in cc's ImageDecodeCache.
...@@ -650,12 +658,10 @@ scoped_refptr<StaticBitmapImage> CanvasResourceProvider::Snapshot() { ...@@ -650,12 +658,10 @@ scoped_refptr<StaticBitmapImage> CanvasResourceProvider::Snapshot() {
snapshot_paint_image_content_id_ = PaintImage::GetNextContentId(); snapshot_paint_image_content_id_ = PaintImage::GetNextContentId();
} }
auto paint_image = return PaintImageBuilder::WithDefault()
PaintImageBuilder::WithDefault() .set_id(snapshot_paint_image_id_)
.set_id(snapshot_paint_image_id_) .set_image(std::move(sk_image), snapshot_paint_image_content_id_)
.set_image(std::move(sk_image), snapshot_paint_image_content_id_) .TakePaintImage();
.TakePaintImage();
return StaticBitmapImage::Create(std::move(paint_image));
} }
gpu::gles2::GLES2Interface* CanvasResourceProvider::ContextGL() const { gpu::gles2::GLES2Interface* CanvasResourceProvider::ContextGL() const {
......
...@@ -164,6 +164,13 @@ class PLATFORM_EXPORT CanvasResourceProvider ...@@ -164,6 +164,13 @@ class PLATFORM_EXPORT CanvasResourceProvider
base::WeakPtr<WebGraphicsContext3DProviderWrapper>, base::WeakPtr<WebGraphicsContext3DProviderWrapper>,
base::WeakPtr<CanvasResourceDispatcher>); base::WeakPtr<CanvasResourceDispatcher>);
// Its important to use this method for generating PaintImage wrapped canvas
// snapshots to get a cache hit from cc's ImageDecodeCache. This method
// ensures that the PaintImage ID for the snapshot, used for keying
// decodes/uploads in the cache is invalidated only when the canvas contents
// change.
cc::PaintImage MakeImageSnapshot();
private: private:
class CanvasImageProvider : public cc::ImageProvider { class CanvasImageProvider : public cc::ImageProvider {
public: public:
......
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