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

SharedImageBackingFactory: Clarify assumptions about GrContextType

The GrContext used by SharedImageBackingFactory can be GL, Vulkan,
Metal, or Dawn. SharedImageBackingFactory had started storing this
as is_vulkan, is_metal, is_dawn, instead of a single switch. Update
this to be a single switch.

R=kylechar
TBR=geofflang

Bug: 894929
Change-Id: I44c6273ce0818244586b87c53f4f15da83e11239
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2292999
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787814}
parent 91a3e37c
...@@ -144,6 +144,21 @@ SharedContextState::SharedContextState( ...@@ -144,6 +144,21 @@ SharedContextState::SharedContextState(
DCHECK(gr_context_); DCHECK(gr_context_);
} }
// Ensure that the context type is consistent with the provided factories.
switch (gr_context_type_) {
case GrContextType::kGL:
break;
case GrContextType::kVulkan:
DCHECK(vk_context_provider_);
break;
case GrContextType::kMetal:
DCHECK(metal_context_provider_);
break;
case GrContextType::kDawn:
DCHECK(dawn_context_provider_);
break;
}
if (base::ThreadTaskRunnerHandle::IsSet()) { if (base::ThreadTaskRunnerHandle::IsSet()) {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "SharedContextState", base::ThreadTaskRunnerHandle::Get()); this, "SharedContextState", base::ThreadTaskRunnerHandle::Get());
......
...@@ -85,13 +85,13 @@ class GPU_GLES2_EXPORT SharedContextState ...@@ -85,13 +85,13 @@ class GPU_GLES2_EXPORT SharedContextState
return gr_context_type_ == GrContextType::kGL; return gr_context_type_ == GrContextType::kGL;
} }
bool GrContextIsVulkan() const { bool GrContextIsVulkan() const {
return vk_context_provider_ && gr_context_type_ == GrContextType::kVulkan; return gr_context_type_ == GrContextType::kVulkan;
} }
bool GrContextIsMetal() const { bool GrContextIsMetal() const {
return metal_context_provider_ && gr_context_type_ == GrContextType::kMetal; return gr_context_type_ == GrContextType::kMetal;
} }
bool GrContextIsDawn() const { bool GrContextIsDawn() const {
return dawn_context_provider_ && gr_context_type_ == GrContextType::kDawn; return gr_context_type_ == GrContextType::kDawn;
} }
bool InitializeGL(const GpuPreferences& gpu_preferences, bool InitializeGL(const GpuPreferences& gpu_preferences,
...@@ -126,6 +126,7 @@ class GPU_GLES2_EXPORT SharedContextState ...@@ -126,6 +126,7 @@ class GPU_GLES2_EXPORT SharedContextState
} }
gl::ProgressReporter* progress_reporter() const { return progress_reporter_; } gl::ProgressReporter* progress_reporter() const { return progress_reporter_; }
GrContext* gr_context() { return gr_context_; } GrContext* gr_context() { return gr_context_; }
GrContextType gr_context_type() const { return gr_context_type_; }
// Handles Skia-reported shader compilation errors. // Handles Skia-reported shader compilation errors.
void compileError(const char* shader, const char* errors) override; void compileError(const char* shader, const char* errors) override;
gles2::FeatureInfo* feature_info() { return feature_info_.get(); } gles2::FeatureInfo* feature_info() { return feature_info_.get(); }
......
...@@ -89,8 +89,8 @@ SharedImageFactory::SharedImageFactory( ...@@ -89,8 +89,8 @@ SharedImageFactory::SharedImageFactory(
shared_image_manager_(shared_image_manager), shared_image_manager_(shared_image_manager),
shared_context_state_(context_state), shared_context_state_(context_state),
memory_tracker_(std::make_unique<MemoryTypeTracker>(memory_tracker)), memory_tracker_(std::make_unique<MemoryTypeTracker>(memory_tracker)),
using_vulkan_(context_state && context_state->GrContextIsVulkan()), gr_context_type_(context_state ? context_state->gr_context_type()
using_skia_dawn_(context_state && context_state->GrContextIsDawn()) { : GrContextType::kGL) {
bool use_gl = gl::GetGLImplementation() != gl::kGLImplementationNone; bool use_gl = gl::GetGLImplementation() != gl::kGLImplementationNone;
if (use_gl) { if (use_gl) {
gl_backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>( gl_backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>(
...@@ -98,25 +98,26 @@ SharedImageFactory::SharedImageFactory( ...@@ -98,25 +98,26 @@ SharedImageFactory::SharedImageFactory(
shared_image_manager->batch_access_manager()); shared_image_manager->batch_access_manager());
} }
// For X11 // TODO(ccameron): This block of code should be changed to a switch on
// |gr_context_type|.
#if defined(USE_X11) && BUILDFLAG(ENABLE_VULKAN) #if defined(USE_X11) && BUILDFLAG(ENABLE_VULKAN)
if (!features::IsUsingOzonePlatform()) { if (!features::IsUsingOzonePlatform()) {
if (using_vulkan_) { if (gr_context_type_ == GrContextType::kVulkan) {
interop_backing_factory_ = interop_backing_factory_ =
std::make_unique<ExternalVkImageFactory>(context_state); std::make_unique<ExternalVkImageFactory>(context_state);
} }
} else if (using_vulkan_) { } else if (gr_context_type_ == GrContextType::kVulkan) {
LOG(ERROR) << "ERROR: using_vulkan_ = true and interop_backing_factory_ is " LOG(ERROR) << "ERROR: gr_context_type_ is GrContextType::kVulkan and "
"not set"; "interop_backing_factory_ is not set";
} }
#elif (defined(OS_FUCHSIA) || defined(OS_WIN)) && BUILDFLAG(ENABLE_VULKAN) #elif (defined(OS_FUCHSIA) || defined(OS_WIN)) && BUILDFLAG(ENABLE_VULKAN)
if (using_vulkan_) { if (gr_context_type_ == GrContextType::kVulkan) {
interop_backing_factory_ = interop_backing_factory_ =
std::make_unique<ExternalVkImageFactory>(context_state); std::make_unique<ExternalVkImageFactory>(context_state);
} }
#elif defined(OS_ANDROID) && BUILDFLAG(ENABLE_VULKAN) #elif defined(OS_ANDROID) && BUILDFLAG(ENABLE_VULKAN)
// For Android // For Android
if (using_vulkan_) { if (gr_context_type_ == GrContextType::kVulkan) {
external_vk_image_factory_ = external_vk_image_factory_ =
std::make_unique<ExternalVkImageFactory>(context_state); std::make_unique<ExternalVkImageFactory>(context_state);
const auto& enabled_extensions = context_state->vk_context_provider() const auto& enabled_extensions = context_state->vk_context_provider()
...@@ -134,21 +135,22 @@ SharedImageFactory::SharedImageFactory( ...@@ -134,21 +135,22 @@ SharedImageFactory::SharedImageFactory(
} }
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
// OSX // OSX
DCHECK(!using_vulkan_); DCHECK(gr_context_type_ == GrContextType::kGL ||
gr_context_type_ == GrContextType::kMetal);
interop_backing_factory_ = interop_backing_factory_ =
std::make_unique<SharedImageBackingFactoryIOSurface>( std::make_unique<SharedImageBackingFactoryIOSurface>(
workarounds, gpu_feature_info, use_gl); workarounds, gpu_feature_info, use_gl);
#elif defined(OS_CHROMEOS) #elif defined(OS_CHROMEOS)
if (context_state && context_state->vk_context_provider()) { if (gr_context_type_ == GrContextType::kVulkan) {
interop_backing_factory_ = interop_backing_factory_ =
std::make_unique<SharedImageBackingFactoryOzone>(context_state); std::make_unique<SharedImageBackingFactoryOzone>(context_state);
} }
#else #else
// Others // Others
if (using_vulkan_) if (gr_context_type_ == GrContextType::kVulkan) {
LOG(ERROR) << "ERROR: using_vulkan_ = true and interop_backing_factory_ is " LOG(ERROR) << "ERROR: gr_context_type_ is GrContextType::kVulkan and "
"not set"; "interop_backing_factory_ is not set";
}
#endif #endif
if (enable_wrapped_sk_image && context_state) { if (enable_wrapped_sk_image && context_state) {
wrapped_sk_image_factory_ = wrapped_sk_image_factory_ =
...@@ -159,7 +161,7 @@ SharedImageFactory::SharedImageFactory( ...@@ -159,7 +161,7 @@ SharedImageFactory::SharedImageFactory(
// For Windows // For Windows
bool use_passthrough = gpu_preferences.use_passthrough_cmd_decoder && bool use_passthrough = gpu_preferences.use_passthrough_cmd_decoder &&
gles2::PassthroughCommandDecoderSupported(); gles2::PassthroughCommandDecoderSupported();
if (use_passthrough && !using_vulkan_) { if (use_passthrough && gr_context_type_ == GrContextType::kGL) {
// Only supported for passthrough command decoder. // Only supported for passthrough command decoder.
interop_backing_factory_ = std::make_unique<SharedImageBackingFactoryD3D>(); interop_backing_factory_ = std::make_unique<SharedImageBackingFactoryD3D>();
} }
...@@ -215,7 +217,7 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox, ...@@ -215,7 +217,7 @@ bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox,
SharedImageBackingFactory* factory = nullptr; SharedImageBackingFactory* factory = nullptr;
if (backing_factory_for_testing_) { if (backing_factory_for_testing_) {
factory = backing_factory_for_testing_; factory = backing_factory_for_testing_;
} else if (!using_vulkan_ && !using_skia_dawn_) { } else if (gr_context_type_ == GrContextType::kGL) {
allow_legacy_mailbox = true; allow_legacy_mailbox = true;
factory = gl_backing_factory_.get(); factory = gl_backing_factory_.get();
} else { } else {
...@@ -397,7 +399,7 @@ bool SharedImageFactory::CanUseWrappedSkImage(uint32_t usage) const { ...@@ -397,7 +399,7 @@ bool SharedImageFactory::CanUseWrappedSkImage(uint32_t usage) const {
SHARED_IMAGE_USAGE_OOP_RASTERIZATION | SHARED_IMAGE_USAGE_OOP_RASTERIZATION |
SHARED_IMAGE_USAGE_DISPLAY; SHARED_IMAGE_USAGE_DISPLAY;
if (using_vulkan_ || using_skia_dawn_) { if (gr_context_type_ != GrContextType::kGL) {
// For SkiaRenderer/Vulkan+Dawn use WrappedSkImage if the usage is only // For SkiaRenderer/Vulkan+Dawn use WrappedSkImage if the usage is only
// raster and/or display. // raster and/or display.
return (usage & kWrappedSkImageUsage) && !(usage & ~kWrappedSkImageUsage); return (usage & kWrappedSkImageUsage) && !(usage & ~kWrappedSkImageUsage);
...@@ -417,7 +419,8 @@ SharedImageBackingFactory* SharedImageFactory::GetFactoryByUsage( ...@@ -417,7 +419,8 @@ SharedImageBackingFactory* SharedImageFactory::GetFactoryByUsage(
return backing_factory_for_testing_; return backing_factory_for_testing_;
bool using_dawn = usage & SHARED_IMAGE_USAGE_WEBGPU; bool using_dawn = usage & SHARED_IMAGE_USAGE_WEBGPU;
bool vulkan_usage = using_vulkan_ && (usage & SHARED_IMAGE_USAGE_DISPLAY); bool vulkan_usage = gr_context_type_ == GrContextType::kVulkan &&
(usage & SHARED_IMAGE_USAGE_DISPLAY);
bool gl_usage = usage & SHARED_IMAGE_USAGE_GLES2; bool gl_usage = usage & SHARED_IMAGE_USAGE_GLES2;
bool share_between_threads = IsSharedBetweenThreads(usage); bool share_between_threads = IsSharedBetweenThreads(usage);
bool share_between_gl_vulkan = gl_usage && vulkan_usage; bool share_between_gl_vulkan = gl_usage && vulkan_usage;
...@@ -460,8 +463,9 @@ SharedImageBackingFactory* SharedImageFactory::GetFactoryByUsage( ...@@ -460,8 +463,9 @@ SharedImageBackingFactory* SharedImageFactory::GetFactoryByUsage(
using_interop_factory |= interop_factory_supports_gmb; using_interop_factory |= interop_factory_supports_gmb;
} }
*allow_legacy_mailbox = *allow_legacy_mailbox = !using_interop_factory &&
!using_interop_factory && !using_vulkan_ && !share_between_threads; gr_context_type_ == GrContextType::kGL &&
!share_between_threads;
if (using_interop_factory) { if (using_interop_factory) {
// TODO(crbug.com/969114): Not all shared image factory implementations // TODO(crbug.com/969114): Not all shared image factory implementations
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "gpu/command_buffer/common/mailbox.h" #include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/service/shared_image_manager.h" #include "gpu/command_buffer/service/shared_image_manager.h"
#include "gpu/command_buffer/service/texture_manager.h" #include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/config/gpu_preferences.h"
#include "gpu/gpu_gles2_export.h" #include "gpu/gpu_gles2_export.h"
#include "gpu/ipc/common/surface_handle.h" #include "gpu/ipc/common/surface_handle.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
...@@ -134,8 +135,11 @@ class GPU_GLES2_EXPORT SharedImageFactory { ...@@ -134,8 +135,11 @@ class GPU_GLES2_EXPORT SharedImageFactory {
SharedImageManager* shared_image_manager_; SharedImageManager* shared_image_manager_;
SharedContextState* shared_context_state_; SharedContextState* shared_context_state_;
std::unique_ptr<MemoryTypeTracker> memory_tracker_; std::unique_ptr<MemoryTypeTracker> memory_tracker_;
const bool using_vulkan_;
const bool using_skia_dawn_; // This is |shared_context_state_|'s context type. Some tests leave
// |shared_context_state_| as nullptr, in which case this is set to a default
/// of kGL.
const GrContextType gr_context_type_;
// The set of SharedImages which have been created (and are being kept alive) // The set of SharedImages which have been created (and are being kept alive)
// by this factory. // by this factory.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/viz/common/resources/resource_format_utils.h" #include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h" #include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/service/feature_info.h" #include "gpu/command_buffer/service/feature_info.h"
...@@ -248,6 +249,14 @@ class WrappedSkImage : public ClearTrackingSharedImageBacking { ...@@ -248,6 +249,14 @@ class WrappedSkImage : public ClearTrackingSharedImageBacking {
tracing_id_ = tex_info.fID; tracing_id_ = tex_info.fID;
break; break;
} }
#if defined(OS_MACOSX)
case GrBackendApi::kMetal: {
GrMtlTextureInfo image_info;
if (backend_texture_.getMtlTextureInfo(&image_info))
tracing_id_ = reinterpret_cast<uint64_t>(image_info.fTexture.get());
break;
}
#endif
case GrBackendApi::kVulkan: { case GrBackendApi::kVulkan: {
GrVkImageInfo image_info; GrVkImageInfo image_info;
if (backend_texture_.getVkImageInfo(&image_info)) if (backend_texture_.getVkImageInfo(&image_info))
......
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