Commit 4ae0208f authored by Khushal's avatar Khushal Committed by Commit Bot

blink/image_bitmap: Use shared images for textures.

Replace the use of texture creation via skia with shared images in
ImageBitmap. The motivation behind this change is to ensure that the
resources created for ImageBitmap can be used by the compositor using a
different backend and to eliminate usage of skia in client code for
OOPR.

This change uses CanvasResourceProvider, instead of SkSurface, to
issue work executed using skia. This both replaces the resources
created with shared images and allows a natural transition to OOPR,
managed internally by CanvasResourceProvider, going forward.

R=kbr@chromium.org

Bug: 962630
Change-Id: Ibd9c9fc0358a2423b73c15c4e05e1926f6ebb640
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948237
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Auto-Submit: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722707}
parent 73b124de
...@@ -42,11 +42,13 @@ ...@@ -42,11 +42,13 @@
#include "third_party/blink/renderer/core/html/media/html_video_element.h" #include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/loader/resource/image_resource_content.h" #include "third_party/blink/renderer/core/loader/resource/image_resource_content.h"
#include "third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h" #include "third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/canvas_resource_provider.h"
#include "third_party/blink/renderer/platform/graphics/color_correction_test_utils.h" #include "third_party/blink/renderer/platform/graphics/color_correction_test_utils.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h" #include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h" #include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_gles2_interface.h" #include "third_party/blink/renderer/platform/graphics/test/fake_gles2_interface.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h" #include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/platform/graphics/test/gpu_test_utils.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h" #include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
...@@ -79,14 +81,10 @@ class ImageBitmapTest : public testing::Test { ...@@ -79,14 +81,10 @@ class ImageBitmapTest : public testing::Test {
ReplaceMemoryCacheForTesting(MakeGarbageCollected<MemoryCache>( ReplaceMemoryCacheForTesting(MakeGarbageCollected<MemoryCache>(
blink::scheduler::GetSingleThreadTaskRunnerForTesting())); blink::scheduler::GetSingleThreadTaskRunnerForTesting()));
auto factory = [](FakeGLES2Interface* gl, bool* gpu_compositing_disabled) test_context_provider_ = viz::TestContextProvider::Create();
-> std::unique_ptr<WebGraphicsContext3DProvider> { InitializeSharedGpuContext(test_context_provider_.get());
*gpu_compositing_disabled = false;
return std::make_unique<FakeWebGraphicsContext3DProvider>(gl, nullptr);
};
SharedGpuContext::SetContextProviderFactoryForTesting(
WTF::BindRepeating(factory, WTF::Unretained(&gl_)));
} }
void TearDown() override { void TearDown() override {
// Garbage collection is required prior to switching out the // Garbage collection is required prior to switching out the
// test's memory cache; image resources are released, evicting // test's memory cache; image resources are released, evicting
...@@ -99,7 +97,7 @@ class ImageBitmapTest : public testing::Test { ...@@ -99,7 +97,7 @@ class ImageBitmapTest : public testing::Test {
} }
protected: protected:
FakeGLES2Interface gl_; scoped_refptr<viz::TestContextProvider> test_context_provider_;
sk_sp<SkImage> image_, image2_; sk_sp<SkImage> image_, image2_;
Persistent<MemoryCache> global_memory_cache_; Persistent<MemoryCache> global_memory_cache_;
}; };
...@@ -257,16 +255,14 @@ static void TestImageBitmapTextureBacked( ...@@ -257,16 +255,14 @@ static void TestImageBitmapTextureBacked(
TEST_F(ImageBitmapTest, AvoidGPUReadback) { TEST_F(ImageBitmapTest, AvoidGPUReadback) {
base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper = base::WeakPtr<WebGraphicsContext3DProviderWrapper> context_provider_wrapper =
SharedGpuContext::ContextProviderWrapper(); SharedGpuContext::ContextProviderWrapper();
GrContext* gr = context_provider_wrapper->ContextProvider()->GetGrContext(); CanvasColorParams color_params;
SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(100, 100); auto resource_provider = CanvasResourceProvider::Create(
IntSize(100, 100),
sk_sp<SkSurface> surface = CanvasResourceProvider::ResourceUsage::kAcceleratedResourceUsage,
SkSurface::MakeRenderTarget(gr, SkBudgeted::kNo, imageInfo); context_provider_wrapper, 0, kLow_SkFilterQuality, color_params,
sk_sp<SkImage> image = surface->makeImageSnapshot(); CanvasResourceProvider::kDefaultPresentationMode, nullptr);
scoped_refptr<StaticBitmapImage> bitmap = resource_provider->Snapshot();
scoped_refptr<AcceleratedStaticBitmapImage> bitmap = ASSERT_TRUE(bitmap->IsTextureBacked());
AcceleratedStaticBitmapImage::CreateFromSkImage(image,
context_provider_wrapper);
ImageBitmap* image_bitmap = ImageBitmap::Create(bitmap); ImageBitmap* image_bitmap = ImageBitmap::Create(bitmap);
EXPECT_TRUE(image_bitmap); EXPECT_TRUE(image_bitmap);
......
...@@ -122,6 +122,9 @@ class PLATFORM_EXPORT AcceleratedStaticBitmapImage final ...@@ -122,6 +122,9 @@ class PLATFORM_EXPORT AcceleratedStaticBitmapImage final
return mailbox_texture_holder_ ? mailbox_texture_holder_->GetSyncToken() return mailbox_texture_holder_ ? mailbox_texture_holder_->GetSyncToken()
: sync_token; : sync_token;
} }
bool IsOriginTopLeft() const final {
return texture_holder()->IsOriginTopLeft();
}
PaintImage PaintImageForCurrentFrame() override; PaintImage PaintImageForCurrentFrame() override;
......
...@@ -49,6 +49,7 @@ class PLATFORM_EXPORT StaticBitmapImage : public Image { ...@@ -49,6 +49,7 @@ class PLATFORM_EXPORT StaticBitmapImage : public Image {
virtual bool HasMailbox() const { return false; } virtual bool HasMailbox() const { return false; }
virtual bool IsValid() const { return true; } virtual bool IsValid() const { return true; }
virtual void Transfer() {} virtual void Transfer() {}
virtual bool IsOriginTopLeft() const { return true; }
// Creates a non-gpu copy of the image, or returns this if image is already // Creates a non-gpu copy of the image, or returns this if image is already
// non-gpu. // non-gpu.
......
...@@ -221,6 +221,8 @@ _CONFIG = [ ...@@ -221,6 +221,8 @@ _CONFIG = [
# cc painting types. # cc painting types.
'cc::PaintCanvas', 'cc::PaintCanvas',
'cc::PaintFlags', 'cc::PaintFlags',
'cc::PaintImage',
'cc::PaintImageBuilder',
'cc::PaintShader', 'cc::PaintShader',
'cc::PaintWorkletInput', 'cc::PaintWorkletInput',
'cc::NodeId', 'cc::NodeId',
......
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