Commit 6638504f authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Create TestSharedImageBacking helper header

We had a number of different test SharedImageBackings. Centralize these
in one file.

Bug: 1003686
Change-Id: I09897394248a4aa560dffb84ce96f459db8d6821
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1974605
Commit-Queue: Eric Karl <ericrk@chromium.org>
Reviewed-by: default avatarvikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726980}
parent 0a333461
......@@ -185,6 +185,8 @@ jumbo_static_library("test_support") {
"command_buffer/service/mocks.h",
"command_buffer/service/test_helper.cc",
"command_buffer/service/test_helper.h",
"command_buffer/service/test_shared_image_backing.cc",
"command_buffer/service/test_shared_image_backing.h",
"ipc/raster_in_process_context.cc",
"ipc/raster_in_process_context.h",
"ipc/service/gpu_memory_buffer_factory_test_template.h",
......
......@@ -8,97 +8,37 @@
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/test_shared_image_backing.h"
namespace gpu {
namespace gles2 {
namespace {
class TestSharedImageBackingPassthrough
: public ClearTrackingSharedImageBacking {
public:
class TestSharedImageRepresentationPassthrough
: public SharedImageRepresentationGLTexturePassthrough {
public:
TestSharedImageRepresentationPassthrough(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
scoped_refptr<TexturePassthrough>& texture_passthrough)
: SharedImageRepresentationGLTexturePassthrough(manager,
backing,
tracker),
texture_passthrough_(texture_passthrough) {}
const scoped_refptr<TexturePassthrough>& GetTexturePassthrough() override {
return texture_passthrough_;
}
void set_can_access(bool can_access) { can_access_ = can_access; }
bool BeginAccess(GLenum mode) override { return can_access_; }
private:
const scoped_refptr<TexturePassthrough>& texture_passthrough_;
bool can_access_ = true;
};
TestSharedImageBackingPassthrough(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage)
: ClearTrackingSharedImageBacking(mailbox,
format,
size,
color_space,
usage,
0 /* estimated_size */,
false /* is_thread_safe */) {
GLuint service_id;
glGenTextures(1, &service_id);
glBindTexture(GL_TEXTURE_2D, service_id);
glTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), size.width(),
size.height(), 0, GLDataFormat(format), GLDataType(format),
nullptr /* data */);
texture_passthrough_ =
base::MakeRefCounted<TexturePassthrough>(service_id, GL_TEXTURE_2D);
}
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override {
DCHECK(!in_fence);
}
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) override {
return false;
}
void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override {}
GLuint ServiceID() const { return texture_passthrough_->service_id(); }
protected:
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
ProduceGLTexturePassthrough(SharedImageManager* manager,
MemoryTypeTracker* tracker) override {
return std::make_unique<TestSharedImageRepresentationPassthrough>(
manager, this, tracker, texture_passthrough_);
}
private:
scoped_refptr<TexturePassthrough> texture_passthrough_;
};
std::unique_ptr<TestSharedImageBacking> AllocateTextureAndCreateSharedImage(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) {
GLuint service_id;
glGenTextures(1, &service_id);
glBindTexture(GL_TEXTURE_2D, service_id);
glTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), size.width(),
size.height(), 0, GLDataFormat(format), GLDataType(format),
nullptr /* data */);
return std::make_unique<TestSharedImageBacking>(
mailbox, format, size, color_space, usage, 0 /* estimated_size */,
service_id);
}
} // namespace
TEST_F(GLES2DecoderPassthroughTest, CreateAndTexStorage2DSharedImageCHROMIUM) {
MemoryTypeTracker memory_tracker(nullptr);
Mailbox mailbox = Mailbox::GenerateForSharedImage();
auto backing = std::make_unique<TestSharedImageBackingPassthrough>(
auto backing = AllocateTextureAndCreateSharedImage(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0);
GLuint service_id = backing->ServiceID();
GLuint service_id = backing->service_id();
std::unique_ptr<SharedImageRepresentationFactoryRef> shared_image =
GetSharedImageManager()->Register(std::move(backing), &memory_tracker);
......@@ -160,7 +100,7 @@ TEST_F(GLES2DecoderPassthroughTest,
Mailbox mailbox = Mailbox::GenerateForSharedImage();
std::unique_ptr<SharedImageRepresentationFactoryRef> shared_image =
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBackingPassthrough>(
AllocateTextureAndCreateSharedImage(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0),
&memory_tracker);
......@@ -195,7 +135,7 @@ TEST_F(GLES2DecoderPassthroughTest, BeginEndSharedImageAccessCRHOMIUM) {
Mailbox mailbox = Mailbox::GenerateForSharedImage();
std::unique_ptr<SharedImageRepresentationFactoryRef> shared_image =
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBackingPassthrough>(
AllocateTextureAndCreateSharedImage(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0),
&memory_tracker);
......@@ -267,12 +207,14 @@ TEST_F(GLES2DecoderPassthroughTest,
// Create a shared image.
MemoryTypeTracker memory_tracker(nullptr);
Mailbox mailbox = Mailbox::GenerateForSharedImage();
auto shared_image_backing = AllocateTextureAndCreateSharedImage(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0);
// Set the shared image to fail BeginAccess.
shared_image_backing->set_can_access(false);
std::unique_ptr<SharedImageRepresentationFactoryRef> shared_image =
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBackingPassthrough>(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0),
&memory_tracker);
GetSharedImageManager()->Register(std::move(shared_image_backing),
&memory_tracker);
auto& cmd = *GetImmediateAs<
cmds::CreateAndTexStorage2DSharedImageINTERNALImmediate>();
......@@ -282,14 +224,6 @@ TEST_F(GLES2DecoderPassthroughTest,
// Try to begin access with a shared image representation that fails
// BeginAccess.
auto found =
GetPassthroughResources()->texture_shared_image_map.find(kNewClientId);
ASSERT_TRUE(found !=
GetPassthroughResources()->texture_shared_image_map.end());
static_cast<TestSharedImageBackingPassthrough::
TestSharedImageRepresentationPassthrough*>(
found->second.representation())
->set_can_access(false);
cmds::BeginSharedImageAccessDirectCHROMIUM read_access_cmd;
read_access_cmd.Init(kNewClientId, GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM);
EXPECT_EQ(error::kNoError, ExecuteCmd(read_access_cmd));
......@@ -316,7 +250,7 @@ TEST_F(GLES2DecoderPassthroughTest,
Mailbox mailbox = Mailbox::GenerateForSharedImage();
std::unique_ptr<SharedImageRepresentationFactoryRef> shared_image =
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBackingPassthrough>(
AllocateTextureAndCreateSharedImage(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0),
&memory_tracker);
......
......@@ -25,6 +25,7 @@
#include "gpu/command_buffer/service/service_discardable_manager.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/test_helper.h"
#include "gpu/command_buffer/service/test_shared_image_backing.h"
#include "gpu/config/gpu_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_image_stub.h"
......@@ -3112,93 +3113,6 @@ TEST_P(GLES2DecoderTest, CreateAndConsumeTextureCHROMIUMInvalidTexture) {
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
}
class TestSharedImageBacking : public SharedImageBacking {
public:
class TestSharedImageRepresentation
: public SharedImageRepresentationGLTexture {
public:
TestSharedImageRepresentation(SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
gles2::Texture* texture)
: SharedImageRepresentationGLTexture(manager, backing, tracker),
texture_(texture) {}
gles2::Texture* GetTexture() override { return texture_; }
void set_can_access(bool can_access) { can_access_ = can_access; }
bool BeginAccess(GLenum mode) override { return can_access_; }
private:
gles2::Texture* texture_;
bool can_access_ = true;
};
TestSharedImageBacking(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
MemoryTypeTracker* memory_tracker,
GLuint texture_id)
: SharedImageBacking(mailbox,
format,
size,
color_space,
usage,
0 /* estimated_size */,
false /* is_thread_safe */) {
texture_ = new gles2::Texture(texture_id);
texture_->SetLightweightRef();
texture_->SetTarget(GL_TEXTURE_2D, 1);
texture_->sampler_state_.min_filter = GL_LINEAR;
texture_->sampler_state_.mag_filter = GL_LINEAR;
texture_->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE;
texture_->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE;
texture_->SetLevelInfo(
GL_TEXTURE_2D, 0, GLInternalFormat(format), size.width(), size.height(),
1, 0, GLDataFormat(format), GLDataType(format), gfx::Rect());
texture_->SetImmutable(true, true);
}
~TestSharedImageBacking() override {
texture_->RemoveLightweightRef(have_context());
texture_ = nullptr;
}
gfx::Rect ClearedRect() const override {
return texture_->GetLevelClearedRect(texture_->target(), 0);
}
void SetClearedRect(const gfx::Rect& cleared_rect) override {
texture_->SetLevelClearedRect(texture_->target(), 0, cleared_rect);
}
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override {
DCHECK(!in_fence);
}
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) override {
return false;
}
void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override {}
protected:
std::unique_ptr<SharedImageRepresentationGLTexture> ProduceGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) override {
return std::make_unique<TestSharedImageRepresentation>(manager, this,
tracker, texture_);
}
private:
gles2::Texture* texture_;
};
TEST_P(GLES2DecoderTest, CreateAndTexStorage2DSharedImageCHROMIUM) {
MemoryTypeTracker memory_tracker(memory_tracker_.get());
Mailbox mailbox = Mailbox::GenerateForSharedImage();
......@@ -3206,7 +3120,7 @@ TEST_P(GLES2DecoderTest, CreateAndTexStorage2DSharedImageCHROMIUM) {
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBacking>(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0, &memory_tracker, kNewServiceId),
gfx::ColorSpace(), 0, 0, kNewServiceId),
&memory_tracker);
auto& cmd = *GetImmediateAs<
......@@ -3267,7 +3181,7 @@ TEST_P(GLES2DecoderTest,
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBacking>(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0, &memory_tracker, kNewServiceId),
gfx::ColorSpace(), 0, 0, kNewServiceId),
&memory_tracker);
auto& cmd = *GetImmediateAs<
......@@ -3290,7 +3204,7 @@ TEST_P(GLES2DecoderTest, BeginEndSharedImageAccessCRHOMIUM) {
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBacking>(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0, &memory_tracker, kNewServiceId),
gfx::ColorSpace(), 0, 0, kNewServiceId),
&memory_tracker);
auto& cmd = *GetImmediateAs<
......@@ -3346,12 +3260,14 @@ TEST_P(GLES2DecoderTest, BeginSharedImageAccessDirectCHROMIUMCantBeginAccess) {
// Create a shared image.
MemoryTypeTracker memory_tracker(memory_tracker_.get());
Mailbox mailbox = Mailbox::GenerateForSharedImage();
auto shared_image_backing = std::make_unique<TestSharedImageBacking>(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0, 0, kNewServiceId);
// Set the shared image to fail BeginAccess.
shared_image_backing->set_can_access(false);
std::unique_ptr<SharedImageRepresentationFactoryRef> shared_image =
GetSharedImageManager()->Register(
std::make_unique<TestSharedImageBacking>(
mailbox, viz::ResourceFormat::RGBA_8888, gfx::Size(10, 10),
gfx::ColorSpace(), 0, &memory_tracker, kNewServiceId),
&memory_tracker);
GetSharedImageManager()->Register(std::move(shared_image_backing),
&memory_tracker);
auto& cmd = *GetImmediateAs<
cmds::CreateAndTexStorage2DSharedImageINTERNALImmediate>();
......@@ -3361,12 +3277,6 @@ TEST_P(GLES2DecoderTest, BeginSharedImageAccessDirectCHROMIUMCantBeginAccess) {
// Try to begin access with a shared image representation that fails
// BeginAccess.
auto* texture_ref = group().texture_manager()->GetTexture(kNewClientId);
ASSERT_NE(texture_ref, nullptr);
ASSERT_NE(texture_ref->shared_image(), nullptr);
static_cast<TestSharedImageBacking::TestSharedImageRepresentation*>(
texture_ref->shared_image())
->set_can_access(false);
cmds::BeginSharedImageAccessDirectCHROMIUM read_access_cmd;
read_access_cmd.Init(kNewClientId, GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM);
EXPECT_EQ(error::kNoError, ExecuteCmd(read_access_cmd));
......
......@@ -11,6 +11,7 @@
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/test_shared_image_backing.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/command_buffer/tests/texture_image_factory.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
......@@ -24,53 +25,9 @@
#include "ui/gl/gl_surface.h"
#include "ui/gl/init/gl_factory.h"
using ::testing::Return;
using ::testing::StrictMock;
namespace gpu {
namespace {
class MockSharedImageRepresentationGLTexture
: public SharedImageRepresentationGLTexture {
public:
MockSharedImageRepresentationGLTexture(SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker)
: SharedImageRepresentationGLTexture(manager, backing, tracker) {}
MOCK_METHOD0(GetTexture, gles2::Texture*());
};
class MockSharedImageBacking : public SharedImageBacking {
public:
MockSharedImageBacking(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
size_t estimated_size)
: SharedImageBacking(mailbox,
format,
size,
color_space,
usage,
estimated_size,
false /* is_thread_safe */) {}
MOCK_CONST_METHOD0(ClearedRect, gfx::Rect());
MOCK_METHOD1(SetClearedRect, void(const gfx::Rect&));
MOCK_METHOD1(Update, void(std::unique_ptr<gfx::GpuFence>));
MOCK_METHOD1(ProduceLegacyMailbox, bool(MailboxManager*));
private:
std::unique_ptr<SharedImageRepresentationGLTexture> ProduceGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) {
return std::make_unique<StrictMock<MockSharedImageRepresentationGLTexture>>(
manager, this, tracker);
}
};
TEST(SharedImageManagerTest, BasicRefCounting) {
const size_t kSizeBytes = 1024;
SharedImageManager manager;
......@@ -82,10 +39,10 @@ TEST(SharedImageManagerTest, BasicRefCounting) {
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
auto mock_backing = std::make_unique<StrictMock<MockSharedImageBacking>>(
auto backing = std::make_unique<TestSharedImageBacking>(
mailbox, format, size, color_space, usage, kSizeBytes);
auto factory_ref = manager.Register(std::move(mock_backing), tracker.get());
auto factory_ref = manager.Register(std::move(backing), tracker.get());
EXPECT_EQ(kSizeBytes, tracker->GetMemRepresented());
// Taking/releasing an additional ref/representation with the same tracker
......@@ -119,10 +76,10 @@ TEST(SharedImageManagerTest, TransferRefSameTracker) {
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
auto mock_backing = std::make_unique<StrictMock<MockSharedImageBacking>>(
auto backing = std::make_unique<TestSharedImageBacking>(
mailbox, format, size, color_space, usage, kSizeBytes);
auto factory_ref = manager.Register(std::move(mock_backing), tracker.get());
auto factory_ref = manager.Register(std::move(backing), tracker.get());
EXPECT_EQ(kSizeBytes, tracker->GetMemRepresented());
// Take an additional ref/representation.
......@@ -148,10 +105,10 @@ TEST(SharedImageManagerTest, TransferRefNewTracker) {
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
auto mock_backing = std::make_unique<StrictMock<MockSharedImageBacking>>(
auto backing = std::make_unique<TestSharedImageBacking>(
mailbox, format, size, color_space, usage, kSizeBytes);
auto factory_ref = manager.Register(std::move(mock_backing), tracker.get());
auto factory_ref = manager.Register(std::move(backing), tracker.get());
EXPECT_EQ(kSizeBytes, tracker->GetMemRepresented());
// Take an additional ref/representation with a new tracker. Memory should
......
// 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 "gpu/command_buffer/service/test_shared_image_backing.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "third_party/skia/include/core/SkPromiseImageTexture.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/mock/GrMockTypes.h"
namespace gpu {
namespace {
class TestSharedImageRepresentationGLTexture
: public SharedImageRepresentationGLTexture {
public:
TestSharedImageRepresentationGLTexture(SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
gles2::Texture* texture)
: SharedImageRepresentationGLTexture(manager, backing, tracker),
texture_(texture) {}
gles2::Texture* GetTexture() override { return texture_; }
bool BeginAccess(GLenum mode) override {
return static_cast<TestSharedImageBacking*>(backing())->can_access();
}
private:
gles2::Texture* const texture_;
};
class TestSharedImageRepresentationGLTexturePassthrough
: public SharedImageRepresentationGLTexturePassthrough {
public:
TestSharedImageRepresentationGLTexturePassthrough(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
scoped_refptr<gles2::TexturePassthrough> texture)
: SharedImageRepresentationGLTexturePassthrough(manager,
backing,
tracker),
texture_(std::move(texture)) {}
const scoped_refptr<gles2::TexturePassthrough>& GetTexturePassthrough()
override {
return texture_;
}
bool BeginAccess(GLenum mode) override {
return static_cast<TestSharedImageBacking*>(backing())->can_access();
}
private:
const scoped_refptr<gles2::TexturePassthrough> texture_;
};
} // namespace
TestSharedImageBacking::TestSharedImageBacking(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
size_t estimated_size,
GLuint texture_id)
: SharedImageBacking(mailbox,
format,
size,
color_space,
usage,
estimated_size,
false /* is_thread_safe */),
service_id_(texture_id) {
texture_ = new gles2::Texture(service_id_);
texture_->SetLightweightRef();
texture_->SetTarget(GL_TEXTURE_2D, 1);
texture_->sampler_state_.min_filter = GL_LINEAR;
texture_->sampler_state_.mag_filter = GL_LINEAR;
texture_->sampler_state_.wrap_s = GL_CLAMP_TO_EDGE;
texture_->sampler_state_.wrap_t = GL_CLAMP_TO_EDGE;
texture_->SetLevelInfo(GL_TEXTURE_2D, 0, GLInternalFormat(format),
size.width(), size.height(), 1, 0,
GLDataFormat(format), GLDataType(format), gfx::Rect());
texture_->SetImmutable(true, true);
texture_passthrough_ = base::MakeRefCounted<gles2::TexturePassthrough>(
service_id_, GL_TEXTURE_2D);
}
TestSharedImageBacking::TestSharedImageBacking(
const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
size_t estimated_size)
: TestSharedImageBacking(mailbox,
format,
size,
color_space,
usage,
estimated_size,
203 /* texture_id */) {
// Using a dummy |texture_id|, so lose our context so we don't do anything
// real with it.
OnContextLost();
}
TestSharedImageBacking::~TestSharedImageBacking() {
// Pretend our context is lost to avoid actual cleanup in |texture_| or
// |passthrough_texture_|.
texture_->RemoveLightweightRef(false /* have_context */);
texture_passthrough_->MarkContextLost();
texture_passthrough_.reset();
if (have_context())
glDeleteTextures(1, &service_id_);
}
gfx::Rect TestSharedImageBacking::ClearedRect() const {
return texture_->GetLevelClearedRect(texture_->target(), 0);
}
void TestSharedImageBacking::SetClearedRect(const gfx::Rect& cleared_rect) {
texture_->SetLevelClearedRect(texture_->target(), 0, cleared_rect);
}
bool TestSharedImageBacking::ProduceLegacyMailbox(
MailboxManager* mailbox_manager) {
return false;
}
std::unique_ptr<SharedImageRepresentationGLTexture>
TestSharedImageBacking::ProduceGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) {
return std::make_unique<TestSharedImageRepresentationGLTexture>(
manager, this, tracker, texture_);
}
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
TestSharedImageBacking::ProduceGLTexturePassthrough(
SharedImageManager* manager,
MemoryTypeTracker* tracker) {
return std::make_unique<TestSharedImageRepresentationGLTexturePassthrough>(
manager, this, tracker, texture_passthrough_);
}
} // namespace gpu
// 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 GPU_COMMAND_BUFFER_SERVICE_TEST_SHARED_IMAGE_BACKING_H_
#define GPU_COMMAND_BUFFER_SERVICE_TEST_SHARED_IMAGE_BACKING_H_
#include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/texture_manager.h"
namespace gpu {
// Test implementation of a gles2::Texture backed backing.
class TestSharedImageBacking : public SharedImageBacking {
public:
// Constructor which uses a dummy GL texture ID for the backing.
TestSharedImageBacking(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
size_t estimated_size);
// Constructor which uses a provided GL texture ID for the backing.
TestSharedImageBacking(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage,
size_t estimated_size,
GLuint texture_id);
~TestSharedImageBacking() override;
gfx::Rect ClearedRect() const override;
void SetClearedRect(const gfx::Rect& cleared_rect) override;
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override {}
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) override;
void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override {}
// Helper functions
GLuint service_id() const { return service_id_; }
void set_can_access(bool can_access) { can_access_ = can_access; }
bool can_access() const { return can_access_; }
protected:
std::unique_ptr<SharedImageRepresentationGLTexture> ProduceGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) override;
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
ProduceGLTexturePassthrough(SharedImageManager* manager,
MemoryTypeTracker* tracker) override;
private:
const GLuint service_id_ = 0;
gles2::Texture* texture_ = nullptr;
scoped_refptr<gles2::TexturePassthrough> texture_passthrough_;
bool can_access_ = true;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_TEST_SHARED_IMAGE_BACKING_H_
......@@ -53,6 +53,7 @@ class SharedImageBackingD3D;
class SharedImageVideo;
class StreamTexture;
class SharedImageBackingFactoryD3D;
class TestSharedImageBacking;
namespace gles2 {
class GLStreamTextureImage;
......@@ -448,12 +449,12 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
friend class gpu::SharedImageRepresentationGLTextureIOSurface;
friend class gpu::SharedImageRepresentationSkiaIOSurface;
friend class gpu::StreamTexture;
friend class gpu::TestSharedImageBacking;
friend class AbstractTextureImplOnSharedContext;
friend class TextureDefinition;
friend class TextureManager;
friend class TextureRef;
friend class TextureTestHelper;
friend class TestSharedImageBacking;
FRIEND_TEST_ALL_PREFIXES(TextureMemoryTrackerTest, LightweightRef);
~Texture() override;
......
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