Commit e0ce652f authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Move SharedImageBackingGL functions to appropriate places

This file has gotten jumbled by keeping diffs small. This does nothing
but move code around.

TBR=geofflang

Bug: 1092155
Change-Id: I6951d61ce1ae96cde61cd879c482bd8a20641f80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2251160Reviewed-by: default avatarccameron <ccameron@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780084}
parent 254c7d7c
...@@ -344,22 +344,6 @@ void SharedImageRepresentationGLTexturePassthroughImpl::EndAccess() { ...@@ -344,22 +344,6 @@ void SharedImageRepresentationGLTexturePassthroughImpl::EndAccess() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// SharedImageBackingGLCommon // SharedImageBackingGLCommon
GLenum SharedImageBackingGLTexture::GetGLTarget() const {
return texture_ ? texture_->target() : passthrough_texture_->target();
}
GLenum SharedImageBackingGLImage::GetGLTarget() const {
return texture_ ? texture_->target() : passthrough_texture_->target();
}
GLuint SharedImageBackingGLTexture::GetGLServiceId() const {
return texture_ ? texture_->service_id() : passthrough_texture_->service_id();
}
GLuint SharedImageBackingGLImage::GetGLServiceId() const {
return texture_ ? texture_->service_id() : passthrough_texture_->service_id();
}
// static // static
void SharedImageBackingGLCommon::MakeTextureAndSetParameters( void SharedImageBackingGLCommon::MakeTextureAndSetParameters(
GLenum target, GLenum target,
...@@ -517,17 +501,30 @@ SharedImageBackingGLTexture::~SharedImageBackingGLTexture() { ...@@ -517,17 +501,30 @@ SharedImageBackingGLTexture::~SharedImageBackingGLTexture() {
} }
} }
gfx::Rect SharedImageBackingGLTexture::ClearedRect() const { GLenum SharedImageBackingGLTexture::GetGLTarget() const {
if (IsPassthrough()) { return texture_ ? texture_->target() : passthrough_texture_->target();
// This backing is used exclusively with ANGLE which handles clear tracking }
// internally. Act as though the texture is always cleared.
return gfx::Rect(size()); GLuint SharedImageBackingGLTexture::GetGLServiceId() const {
} else { return texture_ ? texture_->service_id() : passthrough_texture_->service_id();
return texture_->GetLevelClearedRect(texture_->target(), 0); }
void SharedImageBackingGLTexture::OnMemoryDump(
const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) {
const auto client_guid = GetSharedImageGUIDForTracing(mailbox());
if (!IsPassthrough()) {
const auto service_guid =
gl::GetGLTextureServiceGUIDForTracing(texture_->service_id());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
pmd->AddOwnershipEdge(client_guid, service_guid, /* importance */ 2);
texture_->DumpLevelMemory(pmd, client_tracing_id, dump_name);
} }
} }
gfx::Rect SharedImageBackingGLImage::ClearedRect() const { gfx::Rect SharedImageBackingGLTexture::ClearedRect() const {
if (IsPassthrough()) { if (IsPassthrough()) {
// This backing is used exclusively with ANGLE which handles clear tracking // This backing is used exclusively with ANGLE which handles clear tracking
// internally. Act as though the texture is always cleared. // internally. Act as though the texture is always cleared.
...@@ -543,14 +540,6 @@ void SharedImageBackingGLTexture::SetClearedRect( ...@@ -543,14 +540,6 @@ void SharedImageBackingGLTexture::SetClearedRect(
texture_->SetLevelClearedRect(texture_->target(), 0, cleared_rect); texture_->SetLevelClearedRect(texture_->target(), 0, cleared_rect);
} }
void SharedImageBackingGLImage::SetClearedRect(const gfx::Rect& cleared_rect) {
if (!IsPassthrough())
texture_->SetLevelClearedRect(texture_->target(), 0, cleared_rect);
}
void SharedImageBackingGLTexture::Update(
std::unique_ptr<gfx::GpuFence> in_fence) {}
bool SharedImageBackingGLTexture::ProduceLegacyMailbox( bool SharedImageBackingGLTexture::ProduceLegacyMailbox(
MailboxManager* mailbox_manager) { MailboxManager* mailbox_manager) {
if (IsPassthrough()) if (IsPassthrough())
...@@ -560,30 +549,6 @@ bool SharedImageBackingGLTexture::ProduceLegacyMailbox( ...@@ -560,30 +549,6 @@ bool SharedImageBackingGLTexture::ProduceLegacyMailbox(
return true; return true;
} }
bool SharedImageBackingGLImage::ProduceLegacyMailbox(
MailboxManager* mailbox_manager) {
if (IsPassthrough())
mailbox_manager->ProduceTexture(mailbox(), passthrough_texture_.get());
else
mailbox_manager->ProduceTexture(mailbox(), texture_);
return true;
}
void SharedImageBackingGLTexture::OnMemoryDump(
const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) {
const auto client_guid = GetSharedImageGUIDForTracing(mailbox());
if (!IsPassthrough()) {
const auto service_guid =
gl::GetGLTextureServiceGUIDForTracing(texture_->service_id());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
pmd->AddOwnershipEdge(client_guid, service_guid, /* importance */ 2);
texture_->DumpLevelMemory(pmd, client_tracing_id, dump_name);
}
}
std::unique_ptr<SharedImageRepresentationGLTexture> std::unique_ptr<SharedImageRepresentationGLTexture>
SharedImageBackingGLTexture::ProduceGLTexture(SharedImageManager* manager, SharedImageBackingGLTexture::ProduceGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) { MemoryTypeTracker* tracker) {
...@@ -592,14 +557,6 @@ SharedImageBackingGLTexture::ProduceGLTexture(SharedImageManager* manager, ...@@ -592,14 +557,6 @@ SharedImageBackingGLTexture::ProduceGLTexture(SharedImageManager* manager,
manager, this, tracker, texture_); manager, this, tracker, texture_);
} }
std::unique_ptr<SharedImageRepresentationGLTexture>
SharedImageBackingGLImage::ProduceGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) {
DCHECK(texture_);
return std::make_unique<SharedImageRepresentationGLTextureImpl>(
manager, this, tracker, texture_);
}
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough> std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
SharedImageBackingGLTexture::ProduceGLTexturePassthrough( SharedImageBackingGLTexture::ProduceGLTexturePassthrough(
SharedImageManager* manager, SharedImageManager* manager,
...@@ -609,15 +566,6 @@ SharedImageBackingGLTexture::ProduceGLTexturePassthrough( ...@@ -609,15 +566,6 @@ SharedImageBackingGLTexture::ProduceGLTexturePassthrough(
manager, this, tracker, passthrough_texture_); manager, this, tracker, passthrough_texture_);
} }
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
SharedImageBackingGLImage::ProduceGLTexturePassthrough(
SharedImageManager* manager,
MemoryTypeTracker* tracker) {
DCHECK(passthrough_texture_);
return std::make_unique<SharedImageRepresentationGLTexturePassthroughImpl>(
manager, this, tracker, passthrough_texture_);
}
std::unique_ptr<SharedImageRepresentationDawn> std::unique_ptr<SharedImageRepresentationDawn>
SharedImageBackingGLTexture::ProduceDawn(SharedImageManager* manager, SharedImageBackingGLTexture::ProduceDawn(SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
...@@ -631,17 +579,44 @@ SharedImageBackingGLTexture::ProduceDawn(SharedImageManager* manager, ...@@ -631,17 +579,44 @@ SharedImageBackingGLTexture::ProduceDawn(SharedImageManager* manager,
IsPassthrough()); IsPassthrough());
} }
std::unique_ptr<SharedImageRepresentationDawn> std::unique_ptr<SharedImageRepresentationSkia>
SharedImageBackingGLImage::ProduceDawn(SharedImageManager* manager, SharedImageBackingGLTexture::ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
WGPUDevice device) { scoped_refptr<SharedContextState> context_state) {
if (!factory()) { if (!cached_promise_texture_) {
DLOG(ERROR) << "No SharedImageFactory to create a dawn representation."; GrBackendTexture backend_texture;
return nullptr; GetGrBackendTexture(context_state->feature_info(), GetGLTarget(), size(),
GetGLServiceId(), format(), &backend_texture);
cached_promise_texture_ = SkPromiseImageTexture::Make(backend_texture);
} }
return std::make_unique<SharedImageRepresentationSkiaImpl>(
manager, this, std::move(context_state), cached_promise_texture_,
tracker);
}
return ProduceDawnCommon(factory(), manager, tracker, device, this, void SharedImageBackingGLTexture::Update(
IsPassthrough()); std::unique_ptr<gfx::GpuFence> in_fence) {}
void SharedImageBackingGLTexture::InitializeGLTexture(
GLuint service_id,
const SharedImageBackingGLCommon::InitializeGLTextureParams& params) {
SharedImageBackingGLCommon::MakeTextureAndSetParameters(
params.target, service_id, params.framebuffer_attachment_angle,
IsPassthrough() ? &passthrough_texture_ : nullptr,
IsPassthrough() ? nullptr : &texture_);
if (IsPassthrough()) {
passthrough_texture_->SetEstimatedSize(EstimatedSize(format(), size()));
} else {
texture_->SetLevelInfo(params.target, 0, params.internal_format,
size().width(), size().height(), 1, 0, params.format,
params.type,
params.is_cleared ? gfx::Rect(size()) : gfx::Rect());
if (params.swizzle)
texture_->SetCompatibilitySwizzle(params.swizzle);
texture_->SetImmutable(true, params.has_immutable_storage);
}
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -689,6 +664,169 @@ SharedImageBackingGLImage::~SharedImageBackingGLImage() { ...@@ -689,6 +664,169 @@ SharedImageBackingGLImage::~SharedImageBackingGLImage() {
} }
} }
GLenum SharedImageBackingGLImage::GetGLTarget() const {
return texture_ ? texture_->target() : passthrough_texture_->target();
}
GLuint SharedImageBackingGLImage::GetGLServiceId() const {
return texture_ ? texture_->service_id() : passthrough_texture_->service_id();
}
scoped_refptr<gfx::NativePixmap> SharedImageBackingGLImage::GetNativePixmap() {
if (IsPassthrough())
return nullptr;
return image_->GetNativePixmap();
}
void SharedImageBackingGLImage::OnMemoryDump(
const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) {
// Add a |service_guid| which expresses shared ownership between the
// various GPU dumps.
auto client_guid = GetSharedImageGUIDForTracing(mailbox());
auto service_guid = gl::GetGLTextureServiceGUIDForTracing(GetGLServiceId());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
// TODO(piman): coalesce constant with TextureManager::DumpTextureRef.
int importance = 2; // This client always owns the ref.
pmd->AddOwnershipEdge(client_guid, service_guid, importance);
if (IsPassthrough()) {
auto* gl_image = passthrough_texture_->GetLevelImage(GetGLTarget(), 0);
if (gl_image)
gl_image->OnMemoryDump(pmd, client_tracing_id, dump_name);
} else {
// Dump all sub-levels held by the texture. They will appear below the
// main gl/textures/client_X/mailbox_Y dump.
texture_->DumpLevelMemory(pmd, client_tracing_id, dump_name);
}
}
gfx::Rect SharedImageBackingGLImage::ClearedRect() const {
if (IsPassthrough()) {
// This backing is used exclusively with ANGLE which handles clear tracking
// internally. Act as though the texture is always cleared.
return gfx::Rect(size());
} else {
return texture_->GetLevelClearedRect(texture_->target(), 0);
}
}
void SharedImageBackingGLImage::SetClearedRect(const gfx::Rect& cleared_rect) {
if (!IsPassthrough())
texture_->SetLevelClearedRect(texture_->target(), 0, cleared_rect);
}
bool SharedImageBackingGLImage::ProduceLegacyMailbox(
MailboxManager* mailbox_manager) {
if (IsPassthrough())
mailbox_manager->ProduceTexture(mailbox(), passthrough_texture_.get());
else
mailbox_manager->ProduceTexture(mailbox(), texture_);
return true;
}
std::unique_ptr<SharedImageRepresentationGLTexture>
SharedImageBackingGLImage::ProduceGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) {
DCHECK(texture_);
return std::make_unique<SharedImageRepresentationGLTextureImpl>(
manager, this, tracker, texture_);
}
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
SharedImageBackingGLImage::ProduceGLTexturePassthrough(
SharedImageManager* manager,
MemoryTypeTracker* tracker) {
DCHECK(passthrough_texture_);
return std::make_unique<SharedImageRepresentationGLTexturePassthroughImpl>(
manager, this, tracker, passthrough_texture_);
}
std::unique_ptr<SharedImageRepresentationDawn>
SharedImageBackingGLImage::ProduceDawn(SharedImageManager* manager,
MemoryTypeTracker* tracker,
WGPUDevice device) {
if (!factory()) {
DLOG(ERROR) << "No SharedImageFactory to create a dawn representation.";
return nullptr;
}
return ProduceDawnCommon(factory(), manager, tracker, device, this,
IsPassthrough());
}
std::unique_ptr<SharedImageRepresentationSkia>
SharedImageBackingGLImage::ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) {
// Sub-classes will, in the future, produce non-GL-backed a
// SkPromiseImageTexture.
if (!cached_promise_texture_) {
GrBackendTexture backend_texture;
GetGrBackendTexture(context_state->feature_info(), GetGLTarget(), size(),
GetGLServiceId(), format(), &backend_texture);
cached_promise_texture_ = SkPromiseImageTexture::Make(backend_texture);
}
auto result = std::make_unique<SharedImageRepresentationSkiaImpl>(
manager, this, std::move(context_state), cached_promise_texture_,
tracker);
result->SetBeginReadAccessCallback(
base::BindRepeating(&SharedImageBackingGLImage::BeginSkiaReadAccess,
weak_factory_.GetWeakPtr()));
return result;
}
std::unique_ptr<SharedImageRepresentationGLTexture>
SharedImageBackingGLImage::ProduceRGBEmulationGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) {
if (IsPassthrough())
return nullptr;
if (!rgb_emulation_texture_) {
const GLenum target = GetGLTarget();
gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, target);
// Set to false as this code path is only used on Mac.
const bool framebuffer_attachment_angle = false;
SharedImageBackingGLCommon::MakeTextureAndSetParameters(
target, 0 /* service_id */, framebuffer_attachment_angle, nullptr,
&rgb_emulation_texture_);
api->glBindTextureFn(target, rgb_emulation_texture_->service_id());
gles2::Texture::ImageState image_state = gles2::Texture::BOUND;
gl::GLImage* image = texture_->GetLevelImage(target, 0, &image_state);
DCHECK_EQ(image, image_.get());
DCHECK(image->ShouldBindOrCopy() == gl::GLImage::BIND);
const GLenum internal_format = GL_RGB;
if (!image->BindTexImageWithInternalformat(target, internal_format)) {
LOG(ERROR) << "Failed to bind image to rgb texture.";
rgb_emulation_texture_->RemoveLightweightRef(true /* have_context */);
rgb_emulation_texture_ = nullptr;
return nullptr;
}
GLenum format =
gles2::TextureManager::ExtractFormatFromStorageFormat(internal_format);
GLenum type =
gles2::TextureManager::ExtractTypeFromStorageFormat(internal_format);
const gles2::Texture::LevelInfo* info = texture_->GetLevelInfo(target, 0);
rgb_emulation_texture_->SetLevelInfo(target, 0, internal_format,
info->width, info->height, 1, 0,
format, type, info->cleared_rect);
rgb_emulation_texture_->SetLevelImage(target, 0, image, image_state);
rgb_emulation_texture_->SetImmutable(true, false);
}
return std::make_unique<SharedImageRepresentationGLTextureImpl>(
manager, this, tracker, rgb_emulation_texture_);
}
void SharedImageBackingGLImage::Update( void SharedImageBackingGLImage::Update(
std::unique_ptr<gfx::GpuFence> in_fence) { std::unique_ptr<gfx::GpuFence> in_fence) {
const GLenum target = GetGLTarget(); const GLenum target = GetGLTarget();
...@@ -731,32 +869,6 @@ void SharedImageBackingGLImage::Update( ...@@ -731,32 +869,6 @@ void SharedImageBackingGLImage::Update(
texture_->SetLevelImage(target, 0, image, new_state); texture_->SetLevelImage(target, 0, image, new_state);
} }
void SharedImageBackingGLImage::OnMemoryDump(
const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) {
// Add a |service_guid| which expresses shared ownership between the
// various GPU dumps.
auto client_guid = GetSharedImageGUIDForTracing(mailbox());
auto service_guid = gl::GetGLTextureServiceGUIDForTracing(GetGLServiceId());
pmd->CreateSharedGlobalAllocatorDump(service_guid);
// TODO(piman): coalesce constant with TextureManager::DumpTextureRef.
int importance = 2; // This client always owns the ref.
pmd->AddOwnershipEdge(client_guid, service_guid, importance);
if (IsPassthrough()) {
auto* gl_image = passthrough_texture_->GetLevelImage(GetGLTarget(), 0);
if (gl_image)
gl_image->OnMemoryDump(pmd, client_tracing_id, dump_name);
} else {
// Dump all sub-levels held by the texture. They will appear below the
// main gl/textures/client_X/mailbox_Y dump.
texture_->DumpLevelMemory(pmd, client_tracing_id, dump_name);
}
}
void SharedImageBackingGLImage::BeginSkiaReadAccess() { void SharedImageBackingGLImage::BeginSkiaReadAccess() {
if (IsPassthrough()) if (IsPassthrough())
return; return;
...@@ -784,98 +896,66 @@ void SharedImageBackingGLImage::BeginSkiaReadAccess() { ...@@ -784,98 +896,66 @@ void SharedImageBackingGLImage::BeginSkiaReadAccess() {
} }
} }
scoped_refptr<gfx::NativePixmap> SharedImageBackingGLImage::GetNativePixmap() { bool SharedImageBackingGLImage::InitializeGLTexture(
if (IsPassthrough()) const SharedImageBackingGLCommon::InitializeGLTextureParams& params) {
return nullptr;
return image_->GetNativePixmap();
}
std::unique_ptr<SharedImageRepresentationGLTexture>
SharedImageBackingGLImage::ProduceRGBEmulationGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) {
if (IsPassthrough())
return nullptr;
if (!rgb_emulation_texture_) {
const GLenum target = GetGLTarget();
gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, target);
// Set to false as this code path is only used on Mac.
const bool framebuffer_attachment_angle = false;
SharedImageBackingGLCommon::MakeTextureAndSetParameters( SharedImageBackingGLCommon::MakeTextureAndSetParameters(
target, 0 /* service_id */, framebuffer_attachment_angle, nullptr, params.target, 0 /* service_id */, params.framebuffer_attachment_angle,
&rgb_emulation_texture_); IsPassthrough() ? &passthrough_texture_ : nullptr,
api->glBindTextureFn(target, rgb_emulation_texture_->service_id()); IsPassthrough() ? nullptr : &texture_);
gles2::Texture::ImageState image_state = gles2::Texture::BOUND; gl::GLApi* api = gl::g_current_gl_context;
gl::GLImage* image = texture_->GetLevelImage(target, 0, &image_state); ScopedRestoreTexture scoped_restore(api, params.target);
DCHECK_EQ(image, image_.get()); api->glBindTextureFn(params.target, GetGLServiceId());
DCHECK(image->ShouldBindOrCopy() == gl::GLImage::BIND); gles2::Texture::ImageState image_state = gles2::Texture::UNBOUND;
const GLenum internal_format = GL_RGB; if (image_->ShouldBindOrCopy() == gl::GLImage::BIND) {
if (!image->BindTexImageWithInternalformat(target, internal_format)) { bool is_bound = false;
LOG(ERROR) << "Failed to bind image to rgb texture."; if (params.is_rgb_emulation) {
rgb_emulation_texture_->RemoveLightweightRef(true /* have_context */); is_bound = image_->BindTexImageWithInternalformat(params.target, GL_RGB);
rgb_emulation_texture_ = nullptr; } else {
return nullptr; is_bound = image_->BindTexImage(params.target);
} }
GLenum format =
gles2::TextureManager::ExtractFormatFromStorageFormat(internal_format);
GLenum type =
gles2::TextureManager::ExtractTypeFromStorageFormat(internal_format);
const gles2::Texture::LevelInfo* info = texture_->GetLevelInfo(target, 0);
rgb_emulation_texture_->SetLevelInfo(target, 0, internal_format,
info->width, info->height, 1, 0,
format, type, info->cleared_rect);
rgb_emulation_texture_->SetLevelImage(target, 0, image, image_state); if (is_bound) {
rgb_emulation_texture_->SetImmutable(true, false); image_state = gles2::Texture::BOUND;
} else {
LOG(ERROR) << "Failed to bind image to target.";
return false;
}
} else if (IsPassthrough()) {
image_->CopyTexImage(params.target);
image_state = gles2::Texture::COPIED;
} }
return std::make_unique<SharedImageRepresentationGLTextureImpl>( if (IsPassthrough()) {
manager, this, tracker, rgb_emulation_texture_); passthrough_texture_->SetEstimatedSize(EstimatedSize(format(), size()));
} passthrough_texture_->SetLevelImage(params.target, 0, image_.get());
passthrough_texture_->set_is_bind_pending(image_state ==
std::unique_ptr<SharedImageRepresentationSkia> gles2::Texture::UNBOUND);
SharedImageBackingGLTexture::ProduceSkia( } else {
SharedImageManager* manager, texture_->SetLevelInfo(params.target, 0, params.internal_format,
MemoryTypeTracker* tracker, size().width(), size().height(), 1, 0, params.format,
scoped_refptr<SharedContextState> context_state) { params.type,
if (!cached_promise_texture_) { params.is_cleared ? gfx::Rect(size()) : gfx::Rect());
GrBackendTexture backend_texture; texture_->SetLevelImage(params.target, 0, image_.get(), image_state);
GetGrBackendTexture(context_state->feature_info(), GetGLTarget(), size(), if (params.swizzle)
GetGLServiceId(), format(), &backend_texture); texture_->SetCompatibilitySwizzle(params.swizzle);
cached_promise_texture_ = SkPromiseImageTexture::Make(backend_texture); texture_->SetImmutable(true, false /* has_immutable_storage */);
} }
return std::make_unique<SharedImageRepresentationSkiaImpl>( return true;
manager, this, std::move(context_state), cached_promise_texture_,
tracker);
} }
std::unique_ptr<SharedImageRepresentationSkia> void SharedImageBackingGLImage::InitializePixels(GLenum format,
SharedImageBackingGLImage::ProduceSkia( GLenum type,
SharedImageManager* manager, const uint8_t* data) {
MemoryTypeTracker* tracker, const GLenum target = GetGLTarget();
scoped_refptr<SharedContextState> context_state) { gl::GLApi* api = gl::g_current_gl_context;
// Sub-classes will, in the future, produce non-GL-backed a ScopedRestoreTexture scoped_restore(api, target);
// SkPromiseImageTexture. api->glBindTextureFn(target, GetGLServiceId());
if (!cached_promise_texture_) { ScopedResetAndRestoreUnpackState scoped_unpack_state(
GrBackendTexture backend_texture; api, attribs_, true /* uploading_data */);
GetGrBackendTexture(context_state->feature_info(), GetGLTarget(), size(), api->glTexSubImage2DFn(target, 0, 0, 0, size().width(), size().height(),
GetGLServiceId(), format(), &backend_texture); format, type, data);
cached_promise_texture_ = SkPromiseImageTexture::Make(backend_texture);
}
auto result = std::make_unique<SharedImageRepresentationSkiaImpl>(
manager, this, std::move(context_state), cached_promise_texture_,
tracker);
result->SetBeginReadAccessCallback(
base::BindRepeating(&SharedImageBackingGLImage::BeginSkiaReadAccess,
weak_factory_.GetWeakPtr()));
return result;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -1164,75 +1244,6 @@ bool SharedImageBackingFactoryGLTexture::CanImportGpuMemoryBuffer( ...@@ -1164,75 +1244,6 @@ bool SharedImageBackingFactoryGLTexture::CanImportGpuMemoryBuffer(
return true; return true;
} }
void SharedImageBackingGLTexture::InitializeGLTexture(
GLuint service_id,
const SharedImageBackingGLCommon::InitializeGLTextureParams& params) {
SharedImageBackingGLCommon::MakeTextureAndSetParameters(
params.target, service_id, params.framebuffer_attachment_angle,
IsPassthrough() ? &passthrough_texture_ : nullptr,
IsPassthrough() ? nullptr : &texture_);
if (IsPassthrough()) {
passthrough_texture_->SetEstimatedSize(EstimatedSize(format(), size()));
} else {
texture_->SetLevelInfo(params.target, 0, params.internal_format,
size().width(), size().height(), 1, 0, params.format,
params.type,
params.is_cleared ? gfx::Rect(size()) : gfx::Rect());
if (params.swizzle)
texture_->SetCompatibilitySwizzle(params.swizzle);
texture_->SetImmutable(true, params.has_immutable_storage);
}
}
bool SharedImageBackingGLImage::InitializeGLTexture(
const SharedImageBackingGLCommon::InitializeGLTextureParams& params) {
SharedImageBackingGLCommon::MakeTextureAndSetParameters(
params.target, 0 /* service_id */, params.framebuffer_attachment_angle,
IsPassthrough() ? &passthrough_texture_ : nullptr,
IsPassthrough() ? nullptr : &texture_);
gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, params.target);
api->glBindTextureFn(params.target, GetGLServiceId());
gles2::Texture::ImageState image_state = gles2::Texture::UNBOUND;
if (image_->ShouldBindOrCopy() == gl::GLImage::BIND) {
bool is_bound = false;
if (params.is_rgb_emulation) {
is_bound = image_->BindTexImageWithInternalformat(params.target, GL_RGB);
} else {
is_bound = image_->BindTexImage(params.target);
}
if (is_bound) {
image_state = gles2::Texture::BOUND;
} else {
LOG(ERROR) << "Failed to bind image to target.";
return false;
}
} else if (IsPassthrough()) {
image_->CopyTexImage(params.target);
image_state = gles2::Texture::COPIED;
}
if (IsPassthrough()) {
passthrough_texture_->SetEstimatedSize(EstimatedSize(format(), size()));
passthrough_texture_->SetLevelImage(params.target, 0, image_.get());
passthrough_texture_->set_is_bind_pending(image_state ==
gles2::Texture::UNBOUND);
} else {
texture_->SetLevelInfo(params.target, 0, params.internal_format,
size().width(), size().height(), 1, 0, params.format,
params.type,
params.is_cleared ? gfx::Rect(size()) : gfx::Rect());
texture_->SetLevelImage(params.target, 0, image_.get(), image_state);
if (params.swizzle)
texture_->SetCompatibilitySwizzle(params.swizzle);
texture_->SetImmutable(true, false /* has_immutable_storage */);
}
return true;
}
std::unique_ptr<SharedImageBacking> std::unique_ptr<SharedImageBacking>
SharedImageBackingFactoryGLTexture::MakeEglImageBacking( SharedImageBackingFactoryGLTexture::MakeEglImageBacking(
const Mailbox& mailbox, const Mailbox& mailbox,
...@@ -1450,19 +1461,6 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal( ...@@ -1450,19 +1461,6 @@ SharedImageBackingFactoryGLTexture::CreateSharedImageInternal(
} }
} }
void SharedImageBackingGLImage::InitializePixels(GLenum format,
GLenum type,
const uint8_t* data) {
const GLenum target = GetGLTarget();
gl::GLApi* api = gl::g_current_gl_context;
ScopedRestoreTexture scoped_restore(api, target);
api->glBindTextureFn(target, GetGLServiceId());
ScopedResetAndRestoreUnpackState scoped_unpack_state(
api, attribs_, true /* uploading_data */);
api->glTexSubImage2DFn(target, 0, 0, 0, size().width(), size().height(),
format, type, data);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// SharedImageBackingFactoryGLTexture::FormatInfo // SharedImageBackingFactoryGLTexture::FormatInfo
......
...@@ -144,16 +144,10 @@ class SharedImageBackingGLTexture : public SharedImageBacking { ...@@ -144,16 +144,10 @@ class SharedImageBackingGLTexture : public SharedImageBacking {
private: private:
// SharedImageBacking: // SharedImageBacking:
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
void OnMemoryDump(const std::string& dump_name, void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump, base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd, base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override; uint64_t client_tracing_id) override;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
gfx::Rect ClearedRect() const final; gfx::Rect ClearedRect() const final;
void SetClearedRect(const gfx::Rect& cleared_rect) final; void SetClearedRect(const gfx::Rect& cleared_rect) final;
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) final; bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) final;
...@@ -167,6 +161,11 @@ class SharedImageBackingGLTexture : public SharedImageBacking { ...@@ -167,6 +161,11 @@ class SharedImageBackingGLTexture : public SharedImageBacking {
SharedImageManager* manager, SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
WGPUDevice device) final; WGPUDevice device) final;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
bool IsPassthrough() const { return is_passthrough_; } bool IsPassthrough() const { return is_passthrough_; }
...@@ -205,20 +204,11 @@ class SharedImageBackingGLImage : public SharedImageBacking { ...@@ -205,20 +204,11 @@ class SharedImageBackingGLImage : public SharedImageBacking {
private: private:
// SharedImageBacking: // SharedImageBacking:
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override; scoped_refptr<gfx::NativePixmap> GetNativePixmap() override;
void OnMemoryDump(const std::string& dump_name, void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump, base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd, base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override; uint64_t client_tracing_id) override;
scoped_refptr<gfx::NativePixmap> GetNativePixmap() override;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
std::unique_ptr<SharedImageRepresentationGLTexture>
ProduceRGBEmulationGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) override;
gfx::Rect ClearedRect() const final; gfx::Rect ClearedRect() const final;
void SetClearedRect(const gfx::Rect& cleared_rect) final; void SetClearedRect(const gfx::Rect& cleared_rect) final;
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) final; bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) final;
...@@ -232,6 +222,14 @@ class SharedImageBackingGLImage : public SharedImageBacking { ...@@ -232,6 +222,14 @@ class SharedImageBackingGLImage : public SharedImageBacking {
SharedImageManager* manager, SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
WGPUDevice device) final; WGPUDevice device) final;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
std::unique_ptr<SharedImageRepresentationGLTexture>
ProduceRGBEmulationGLTexture(SharedImageManager* manager,
MemoryTypeTracker* tracker) override;
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
void BeginSkiaReadAccess(); void BeginSkiaReadAccess();
bool IsPassthrough() const { return is_passthrough_; } bool IsPassthrough() const { return is_passthrough_; }
......
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