Commit fa4f1bf6 authored by Khushal's avatar Khushal Committed by Commit Bot

canvas2d: Remove unused code from CanvasResourceProvider.

For usages that are now handled by shared images, remove unused provider
types and clean up some of the setup code.

R=fserb@chromium.org

Bug: 900706
Change-Id: Ibc3c3795dc7bd7620378acc2c874f445f136c333
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1753698
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697019}
parent f63f9a85
......@@ -120,5 +120,8 @@ specific_include_rules = {
],
"element_test.cc": [
"+third_party/blink/renderer/core/exported/web_plugin_container_impl.h"
],
"html_canvas_painter_test.cc": [
"+components/viz/test/test_context_provider.h",
]
}
......@@ -8,6 +8,7 @@
#include <utility>
#include "cc/layers/layer.h"
#include "components/viz/test/test_context_provider.h"
#include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h"
......@@ -16,8 +17,7 @@
#include "third_party/blink/renderer/core/paint/paint_controller_paint_test.h"
#include "third_party/blink/renderer/platform/graphics/canvas_2d_layer_bridge.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.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/gpu_test_utils.h"
#include "third_party/blink/renderer/platform/graphics/web_graphics_context_3d_provider_wrapper.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
......@@ -33,14 +33,8 @@ class HTMLCanvasPainterTestForCAP : public PaintControllerPaintTest {
protected:
void SetUp() override {
auto factory = [](FakeGLES2Interface* gl, bool* gpu_compositing_disabled)
-> std::unique_ptr<WebGraphicsContext3DProvider> {
*gpu_compositing_disabled = false;
gl->SetIsContextLost(false);
return std::make_unique<FakeWebGraphicsContext3DProvider>(gl);
};
SharedGpuContext::SetContextProviderFactoryForTesting(
WTF::BindRepeating(factory, WTF::Unretained(&gl_)));
test_context_provider_ = viz::TestContextProvider::Create();
InitializeSharedGpuContext(test_context_provider_.get());
PaintControllerPaintTest::SetUp();
}
......@@ -68,7 +62,7 @@ class HTMLCanvasPainterTestForCAP : public PaintControllerPaintTest {
}
private:
FakeGLES2Interface gl_;
scoped_refptr<viz::TestContextProvider> test_context_provider_;
};
INSTANTIATE_CAP_TEST_SUITE_P(HTMLCanvasPainterTestForCAP);
......
include_rules = [
"+third_party/skia/include",
]
\ No newline at end of file
]
specific_include_rules = {
# Additional allowed includes for tests.
".*_test(_.*)?\.(cc|h)" : [
"+components/viz",
]
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
#include <memory>
#include "build/build_config.h"
#include "components/viz/test/test_context_provider.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
......@@ -35,8 +36,7 @@
#include "third_party/blink/renderer/platform/graphics/graphics_types.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_canvas_resource_host.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/gpu_test_utils.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
......@@ -176,7 +176,7 @@ class CanvasRenderingContext2DTest : public ::testing::Test {
Persistent<ImageData> partial_image_data_;
FakeImageSource opaque_bitmap_;
FakeImageSource alpha_bitmap_;
FakeGLES2Interface gl_;
scoped_refptr<viz::TestContextProvider> test_context_provider_;
StringOrCanvasGradientOrCanvasPattern& OpaqueGradient() {
return wrap_gradients_->opaque_gradient_;
......@@ -201,15 +201,8 @@ void CanvasRenderingContext2DTest::CreateContext(OpacityMode opacity_mode,
}
void CanvasRenderingContext2DTest::SetUp() {
auto factory = [](FakeGLES2Interface* gl, bool* gpu_compositing_disabled)
-> std::unique_ptr<WebGraphicsContext3DProvider> {
*gpu_compositing_disabled = false;
gl->SetIsContextLost(false);
return std::make_unique<FakeWebGraphicsContext3DProvider>(gl);
};
SharedGpuContext::SetContextProviderFactoryForTesting(
WTF::BindRepeating(factory, WTF::Unretained(&gl_)));
test_context_provider_ = viz::TestContextProvider::Create();
InitializeSharedGpuContext(test_context_provider_.get());
allow_accelerated_.reset(
new ScopedAccelerated2dCanvasForTest(AllowsAcceleration()));
web_view_helper_ = std::make_unique<frame_test_helpers::WebViewHelper>();
......
......@@ -1570,6 +1570,8 @@ jumbo_static_library("test_support") {
sources = [
"graphics/gpu/drawing_buffer_test_helpers.h",
"graphics/test/gpu_test_utils.cc",
"graphics/test/gpu_test_utils.h",
"testing/code_cache_loader_mock.cc",
"testing/code_cache_loader_mock.h",
"testing/compositor_test.cc",
......
......@@ -110,16 +110,6 @@ class PLATFORM_EXPORT CanvasResourceProvider
base::WeakPtr<CanvasResourceDispatcher>,
bool is_origin_top_left = true);
static std::unique_ptr<CanvasResourceProvider> CreateForTesting(
const IntSize&,
ResourceProviderType,
base::WeakPtr<WebGraphicsContext3DProviderWrapper>,
unsigned msaa_sample_count,
const CanvasColorParams&,
uint8_t presentation_mode,
base::WeakPtr<CanvasResourceDispatcher>,
bool is_origin_top_left = true);
// Use Snapshot() for capturing a frame that is intended to be displayed via
// the compositor. Cases that are destined to be transferred via a
// TransferableResource should call ProduceCanvasResource() instead.
......@@ -195,6 +185,10 @@ class PLATFORM_EXPORT CanvasResourceProvider
// are modified externally from the provider's SkSurface.
virtual void NotifyTexParamsModified(const CanvasResource* resource) {}
size_t cached_resources_count_for_testing() const {
return canvas_resources_.size();
}
protected:
gpu::gles2::GLES2Interface* ContextGL() const;
GrContext* GetGrContext() const;
......
......@@ -156,16 +156,18 @@ class CanvasResourceProviderTest : public Test {
ScopedTestingPlatformSupport<GpuMemoryBufferTestPlatform> platform_;
};
TEST_F(CanvasResourceProviderTest,
CanvasResourceProviderTextureGpuMemoryBuffer) {
TEST_F(CanvasResourceProviderTest, CanvasResourceProviderAcceleratedOverlay) {
const IntSize kSize(10, 10);
const CanvasColorParams kColorParams(kSRGBCanvasColorSpace,
kRGBA8CanvasPixelFormat, kNonOpaque);
EnsureBufferFormatIsSupported(kColorParams.GetBufferFormat());
EnsureOverlaysSupported();
auto provider = CanvasResourceProvider::CreateForTesting(
kSize, CanvasResourceProvider::kTextureGpuMemoryBuffer,
context_provider_wrapper_, 0 /* msaa_sample_count */, kColorParams,
auto provider = CanvasResourceProvider::Create(
kSize,
CanvasResourceProvider::ResourceUsage::kAcceleratedDirect2DResourceUsage,
context_provider_wrapper_, 0 /* msaa_sample_count */,
kMedium_SkFilterQuality, kColorParams,
CanvasResourceProvider::kAllowImageChromiumPresentationMode,
nullptr /* resource_dispatcher */, true /* is_origin_top_left */);
......@@ -209,12 +211,12 @@ TEST_F(CanvasResourceProviderTest, CanvasResourceProviderTexture) {
EXPECT_FALSE(provider->IsSingleBuffered());
}
TEST_F(CanvasResourceProviderTest,
CanvasResourceProviderBitmapGpuMemoryBuffer) {
TEST_F(CanvasResourceProviderTest, CanvasResourceProviderUnacceleratedOverlay) {
const IntSize kSize(10, 10);
const CanvasColorParams kColorParams(kSRGBCanvasColorSpace,
kRGBA8CanvasPixelFormat, kNonOpaque);
EnsureBufferFormatIsSupported(kColorParams.GetBufferFormat());
EnsureOverlaysSupported();
auto provider = CanvasResourceProvider::Create(
kSize,
......@@ -238,15 +240,19 @@ TEST_F(CanvasResourceProviderTest,
EXPECT_FALSE(provider->IsSingleBuffered());
}
TEST_F(CanvasResourceProviderTest, CanvasResourceProviderSharedImage) {
TEST_F(CanvasResourceProviderTest,
CanvasResourceProviderSharedImageResourceRecycling) {
const IntSize kSize(10, 10);
const CanvasColorParams kColorParams(kSRGBCanvasColorSpace,
kRGBA8CanvasPixelFormat, kNonOpaque);
EnsureBufferFormatIsSupported(kColorParams.GetBufferFormat());
auto provider = CanvasResourceProvider::CreateForTesting(
kSize, CanvasResourceProvider::kSharedImage, context_provider_wrapper_,
0 /* msaa_sample_count */, kColorParams,
auto provider = CanvasResourceProvider::Create(
kSize,
CanvasResourceProvider::ResourceUsage::
kAcceleratedCompositedResourceUsage,
context_provider_wrapper_, 0 /* msaa_sample_count */,
kMedium_SkFilterQuality, kColorParams,
CanvasResourceProvider::kAllowImageChromiumPresentationMode,
nullptr /* resource_dispatcher */, true /* is_origin_top_left */);
......@@ -295,9 +301,12 @@ TEST_F(CanvasResourceProviderTest,
kRGBA8CanvasPixelFormat, kNonOpaque);
EnsureBufferFormatIsSupported(kColorParams.GetBufferFormat());
auto provider = CanvasResourceProvider::CreateForTesting(
kSize, CanvasResourceProvider::kSharedImage, context_provider_wrapper_,
0 /* msaa_sample_count */, kColorParams,
auto provider = CanvasResourceProvider::Create(
kSize,
CanvasResourceProvider::ResourceUsage::
kAcceleratedCompositedResourceUsage,
context_provider_wrapper_, 0 /* msaa_sample_count */,
kMedium_SkFilterQuality, kColorParams,
CanvasResourceProvider::kAllowImageChromiumPresentationMode,
nullptr /* resource_dispatcher */, true /* is_origin_top_left */);
ASSERT_TRUE(provider->IsValid());
......@@ -336,9 +345,12 @@ TEST_F(CanvasResourceProviderTest,
kRGBA8CanvasPixelFormat, kNonOpaque);
EnsureBufferFormatIsSupported(kColorParams.GetBufferFormat());
auto provider = CanvasResourceProvider::CreateForTesting(
kSize, CanvasResourceProvider::kSharedImage, context_provider_wrapper_,
0 /* msaa_sample_count */, kColorParams,
auto provider = CanvasResourceProvider::Create(
kSize,
CanvasResourceProvider::ResourceUsage::
kAcceleratedCompositedResourceUsage,
context_provider_wrapper_, 0 /* msaa_sample_count */,
kMedium_SkFilterQuality, kColorParams,
CanvasResourceProvider::kAllowImageChromiumPresentationMode,
nullptr /* resource_dispatcher */, true /* is_origin_top_left */);
ASSERT_TRUE(provider->IsValid());
......@@ -473,7 +485,7 @@ TEST_F(CanvasResourceProviderTest,
ExternalCanvasResource::Create(
mailbox, kSize, GL_TEXTURE_2D, kColorParams,
SharedGpuContext::ContextProviderWrapper(), provider->CreateWeakPtr(),
kNone_SkFilterQuality);
kMedium_SkFilterQuality);
// NewOrRecycledResource() would return nullptr before an ImportResource().
EXPECT_TRUE(provider->ImportResource(resource));
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "base/test/null_task_runner.h"
#include "components/viz/test/test_gles2_interface.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -15,6 +16,7 @@
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.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/gpu_test_utils.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/khronos/GLES2/gl2ext.h"
......@@ -71,9 +73,6 @@ class MailboxMockGLES2Interface : public TestGLES2Interface {
MOCK_METHOD1(GenUnverifiedSyncTokenCHROMIUM, void(GLbyte*));
};
class MailboxSharedGpuContextTest
: public SharedGpuContextTestBase<MailboxMockGLES2Interface> {};
// Test fixure that simulate a graphics context creation failure, when using gpu
// compositing.
class BadSharedGpuContextTest : public Test {
......@@ -210,13 +209,18 @@ TEST_F(SoftwareCompositingTest, CompositingMode) {
EXPECT_FALSE(SharedGpuContext::IsGpuCompositingEnabled());
}
class FakeMailboxGenerator {
STACK_ALLOCATED();
class MailboxSharedGpuContextTest : public Test {
public:
void ProduceTexture(GLuint texture, GLbyte* name) { *name = counter_++; }
void SetUp() override {
task_runner_ = base::MakeRefCounted<base::NullTaskRunner>();
handle_ = std::make_unique<base::ThreadTaskRunnerHandle>(task_runner_);
context_ = viz::TestContextProvider::Create();
InitializeSharedGpuContext(context_.get());
}
GLbyte counter_ = 1;
scoped_refptr<viz::TestContextProvider> context_;
scoped_refptr<base::NullTaskRunner> task_runner_;
std::unique_ptr<base::ThreadTaskRunnerHandle> handle_;
};
TEST_F(MailboxSharedGpuContextTest, MailboxCaching) {
......@@ -231,104 +235,25 @@ TEST_F(MailboxSharedGpuContextTest, MailboxCaching) {
CanvasResourceProvider::kDefaultPresentationMode,
nullptr // canvas_resource_dispatcher
);
ASSERT_TRUE(resource_provider->IsAccelerated());
EXPECT_TRUE(resource_provider && resource_provider->IsValid());
scoped_refptr<StaticBitmapImage> image = resource_provider->Snapshot();
testing::Mock::VerifyAndClearExpectations(&gl_);
FakeMailboxGenerator mailboxGenerator;
gpu::Mailbox mailbox;
GLenum texture_target;
mailbox.name[0] = 0;
EXPECT_CALL(gl_, ProduceTextureDirectCHROMIUM(_, mailbox.name))
.Times(1)
.WillOnce(testing::Invoke(&mailboxGenerator,
&FakeMailboxGenerator::ProduceTexture));
SharedGpuContext::ContextProviderWrapper()->Utils()->GetMailboxForSkImage(
mailbox, texture_target, image->PaintImageForCurrentFrame().GetSkImage(),
GL_NEAREST);
EXPECT_EQ(mailbox.name[0], 1);
testing::Mock::VerifyAndClearExpectations(&gl_);
EXPECT_CALL(gl_, ProduceTextureDirectCHROMIUM(_, mailbox.name))
.Times(0); // ProduceTextureDirectCHROMIUM must not be called!
mailbox.name[0] = 0;
SharedGpuContext::ContextProviderWrapper()->Utils()->GetMailboxForSkImage(
mailbox, texture_target, image->PaintImageForCurrentFrame().GetSkImage(),
GL_NEAREST);
EXPECT_EQ(mailbox.name[0], 1);
testing::Mock::VerifyAndClearExpectations(&gl_);
}
TEST_F(MailboxSharedGpuContextTest, MailboxCacheSurvivesSkiaRecycling) {
IntSize size(10, 10);
std::unique_ptr<CanvasResourceProvider> resource_provider =
CanvasResourceProvider::Create(
size,
CanvasResourceProvider::ResourceUsage::kAcceleratedResourceUsage,
SharedGpuContext::ContextProviderWrapper(),
0, // msaa_sample_count
kLow_SkFilterQuality, CanvasColorParams(),
CanvasResourceProvider::kDefaultPresentationMode,
nullptr // canvas_resource_dispatcher
);
EXPECT_TRUE(resource_provider && resource_provider->IsValid());
scoped_refptr<StaticBitmapImage> image = resource_provider->Snapshot();
testing::Mock::VerifyAndClearExpectations(&gl_);
FakeMailboxGenerator mailboxGenerator;
gpu::Mailbox mailbox;
GLenum texture_target;
mailbox.name[0] = 0;
EXPECT_CALL(gl_, ProduceTextureDirectCHROMIUM(_, mailbox.name))
.Times(1)
.WillOnce(testing::Invoke(&mailboxGenerator,
&FakeMailboxGenerator::ProduceTexture));
GLenum texture_target = GL_TEXTURE_2D;
gpu::Mailbox mailbox[3];
// Creating the SkImage representation from the shared image mailbox registers
// the same mailbox mapping to this SkImage with the cache. This ensures we
// don't recreate a non-shared image mailbox if going from SkImage to mailbox.
mailbox[0] = image->GetMailbox();
SharedGpuContext::ContextProviderWrapper()->Utils()->GetMailboxForSkImage(
mailbox, texture_target, image->PaintImageForCurrentFrame().GetSkImage(),
GL_NEAREST);
EXPECT_EQ(mailbox.name[0], 1);
testing::Mock::VerifyAndClearExpectations(&gl_);
// Destroy image and surface to return texture to recleable resource pool
image = nullptr;
resource_provider = nullptr;
testing::Mock::VerifyAndClearExpectations(&gl_);
// Re-creating surface should recycle the old GrTexture inside skia
resource_provider = CanvasResourceProvider::Create(
size, CanvasResourceProvider::ResourceUsage::kAcceleratedResourceUsage,
SharedGpuContext::ContextProviderWrapper(),
0, // msaa_sample_count
kLow_SkFilterQuality, CanvasColorParams(),
CanvasResourceProvider::kDefaultPresentationMode,
nullptr // canvas_resource_dispatcher
);
mailbox[1], texture_target,
image->PaintImageForCurrentFrame().GetSkImage(), GL_NEAREST);
EXPECT_EQ(mailbox[0], mailbox[1]);
EXPECT_TRUE(resource_provider && resource_provider->IsValid());
image = resource_provider->Snapshot();
testing::Mock::VerifyAndClearExpectations(&gl_);
EXPECT_CALL(gl_, ProduceTextureDirectCHROMIUM(_, mailbox.name))
.Times(0); // ProduceTextureDirectCHROMIUM must not be called!
mailbox.name[0] = 0;
SharedGpuContext::ContextProviderWrapper()->Utils()->GetMailboxForSkImage(
mailbox, texture_target, image->PaintImageForCurrentFrame().GetSkImage(),
GL_NEAREST);
EXPECT_EQ(mailbox.name[0], 1);
testing::Mock::VerifyAndClearExpectations(&gl_);
mailbox[2], texture_target,
image->PaintImageForCurrentFrame().GetSkImage(), GL_NEAREST);
EXPECT_EQ(mailbox[1], mailbox[2]);
}
} // unnamed namespace
......
......@@ -154,9 +154,8 @@ void MailboxTextureHolder::Sync(MailboxSyncMode mode) {
void MailboxTextureHolder::InitCommon() {
DCHECK(!thread_id_);
Thread* thread = Thread::Current();
thread_id_ = thread->ThreadId();
texture_thread_task_runner_ = thread->GetTaskRunner();
thread_id_ = base::PlatformThread::CurrentId();
texture_thread_task_runner_ = Thread::Current()->GetTaskRunner();
}
bool MailboxTextureHolder::IsValid() const {
......@@ -169,7 +168,7 @@ bool MailboxTextureHolder::IsValid() const {
}
bool MailboxTextureHolder::IsCrossThread() const {
return thread_id_ != Thread::Current()->ThreadId();
return thread_id_ != base::PlatformThread::CurrentId();
}
MailboxTextureHolder::~MailboxTextureHolder() {
......@@ -177,8 +176,7 @@ MailboxTextureHolder::~MailboxTextureHolder() {
new gpu::SyncToken(mailbox_ref()->sync_token()));
std::unique_ptr<gpu::Mailbox> passed_mailbox(new gpu::Mailbox(mailbox_));
if (texture_thread_task_runner_ &&
thread_id_ != Thread::Current()->ThreadId()) {
if (texture_thread_task_runner_ && IsCrossThread()) {
PostCrossThreadTask(
*texture_thread_task_runner_, FROM_HERE,
CrossThreadBindOnce(&ReleaseTexture, is_converted_from_skia_texture_,
......
......@@ -72,7 +72,7 @@ class PLATFORM_EXPORT MailboxTextureHolder final : public TextureHolder {
unsigned texture_id_;
bool is_converted_from_skia_texture_;
scoped_refptr<base::SingleThreadTaskRunner> texture_thread_task_runner_;
PlatformThreadId thread_id_;
base::PlatformThreadId thread_id_;
bool did_issue_ordering_barrier_ = false;
SkImageInfo sk_image_info_;
GLenum texture_target_;
......
......@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_FAKE_CANVAS_RESOURCE_HOST_H_
#include "third_party/blink/renderer/platform/graphics/canvas_resource_host.h"
#include "third_party/blink/renderer/platform/graphics/canvas_resource_provider.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_canvas.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
......@@ -45,19 +46,10 @@ class FakeCanvasResourceHost : public CanvasResourceHost {
CanvasResourceProvider::kAllowImageChromiumPresentationMode;
}
std::unique_ptr<CanvasResourceProvider> provider;
if (provider_type_) {
provider = CanvasResourceProvider::CreateForTesting(
size_, *provider_type_, SharedGpuContext::ContextProviderWrapper(), 0,
CanvasColorParams(), presentation_mode, nullptr);
} else {
provider = CanvasResourceProvider::Create(
size_, usage, SharedGpuContext::ContextProviderWrapper(), 0,
kLow_SkFilterQuality, CanvasColorParams(), presentation_mode,
nullptr);
}
ReplaceResourceProvider(std::move(provider));
ReplaceResourceProvider(CanvasResourceProvider::Create(
size_, usage, SharedGpuContext::ContextProviderWrapper(), 0,
kMedium_SkFilterQuality, CanvasColorParams(), presentation_mode,
nullptr));
return ResourceProvider();
}
......@@ -65,12 +57,7 @@ class FakeCanvasResourceHost : public CanvasResourceHost {
return kLow_SkFilterQuality;
}
void set_provider_type(CanvasResourceProvider::ResourceProviderType type) {
provider_type_ = type;
}
private:
base::Optional<CanvasResourceProvider::ResourceProviderType> provider_type_;
IntSize size_;
};
......
// Copyright 2019 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 "third_party/blink/renderer/platform/graphics/test/gpu_test_utils.h"
#include "components/viz/test/test_context_provider.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
#include "third_party/blink/renderer/platform/graphics/test/fake_web_graphics_context_3d_provider.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
void InitializeSharedGpuContext(viz::TestContextProvider* context_provider,
cc::ImageDecodeCache* cache) {
auto factory = [](gpu::gles2::GLES2Interface* gl, GrContext* context,
cc::ImageDecodeCache* cache, bool* gpu_compositing_disabled)
-> std::unique_ptr<WebGraphicsContext3DProvider> {
*gpu_compositing_disabled = false;
return std::make_unique<FakeWebGraphicsContext3DProvider>(gl, cache,
context);
};
context_provider->BindToCurrentThread();
gpu::gles2::GLES2Interface* gl = context_provider->ContextGL();
GrContext* context = context_provider->GrContext();
SharedGpuContext::SetContextProviderFactoryForTesting(
WTF::BindRepeating(factory, WTF::Unretained(gl), WTF::Unretained(context),
WTF::Unretained(cache)));
}
} // namespace blink
// Copyright 2019 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_GPU_TEST_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_GPU_TEST_UTILS_H_
namespace cc {
class ImageDecodeCache;
}
namespace viz {
class TestContextProvider;
}
namespace blink {
void InitializeSharedGpuContext(viz::TestContextProvider* context_provider,
cc::ImageDecodeCache* cache = nullptr);
}
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_TEST_GPU_TEST_UTILS_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