Commit a37811d1 authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

SkiaOutputDevice: use buffer format passed to Reshape

Bug: 1108406
Change-Id: Iaca79e3b6c1d66e421711c46f75a1cb614b7f961
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378745Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802450}
parent 3cd99aa2
...@@ -117,13 +117,9 @@ class VIZ_SERVICE_EXPORT OutputSurface { ...@@ -117,13 +117,9 @@ class VIZ_SERVICE_EXPORT OutputSurface {
// enforced if zero. // enforced if zero.
int max_render_target_size = 0; int max_render_target_size = 0;
// The SkColorType and GrBackendFormat for non-HDR and HDR. // SkColorType for all supported buffer formats.
// TODO(penghuang): remove SkColorType and GrBackendFormat when SkColorType sk_color_types[static_cast<int>(gfx::BufferFormat::LAST) + 1] =
// OutputSurface uses the |format| passed to Reshape(). {};
SkColorType sk_color_type = kUnknown_SkColorType;
GrBackendFormat gr_backend_format;
SkColorType sk_color_type_for_hdr = kUnknown_SkColorType;
GrBackendFormat gr_backend_format_for_hdr;
}; };
// Constructor for skia-based compositing. // Constructor for skia-based compositing.
......
...@@ -188,10 +188,10 @@ void OutputPresenterFuchsia::InitializeCapabilities( ...@@ -188,10 +188,10 @@ void OutputPresenterFuchsia::InitializeCapabilities(
capabilities->supports_post_sub_buffer = false; capabilities->supports_post_sub_buffer = false;
capabilities->supports_commit_overlay_planes = false; capabilities->supports_commit_overlay_planes = false;
capabilities->sk_color_type = kRGBA_8888_SkColorType; capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
capabilities->gr_backend_format = kRGBA_8888_SkColorType;
dependency_->GetSharedContextState()->gr_context()->defaultBackendFormat( capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_8888)] =
capabilities->sk_color_type, GrRenderable::kYes); kRGBA_8888_SkColorType;
} }
bool OutputPresenterFuchsia::Reshape(const gfx::Size& size, bool OutputPresenterFuchsia::Reshape(const gfx::Size& size,
......
...@@ -214,23 +214,6 @@ OutputPresenterGL::OutputPresenterGL(scoped_refptr<gl::GLSurface> gl_surface, ...@@ -214,23 +214,6 @@ OutputPresenterGL::OutputPresenterGL(scoped_refptr<gl::GLSurface> gl_surface,
// GL is origin is at bottom left normally, all Surfaceless implementations // GL is origin is at bottom left normally, all Surfaceless implementations
// are flipped. // are flipped.
DCHECK_EQ(gl_surface_->GetOrigin(), gfx::SurfaceOrigin::kTopLeft); DCHECK_EQ(gl_surface_->GetOrigin(), gfx::SurfaceOrigin::kTopLeft);
// TODO(https://crbug.com/958166): The initial |image_format_| should not be
// used, and the gfx::BufferFormat specified in Reshape should be used
// instead, because it may be updated to reflect changes in the content being
// displayed (e.g, HDR content appearing on-screen).
#if defined(OS_APPLE)
image_format_ = BGRA_8888;
#else
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) {
image_format_ =
GetResourceFormat(display::DisplaySnapshot::PrimaryFormat());
return;
}
#endif
image_format_ = RGBA_8888;
#endif
} }
OutputPresenterGL::~OutputPresenterGL() = default; OutputPresenterGL::~OutputPresenterGL() = default;
...@@ -247,13 +230,28 @@ void OutputPresenterGL::InitializeCapabilities( ...@@ -247,13 +230,28 @@ void OutputPresenterGL::InitializeCapabilities(
// We expect origin of buffers is at top left. // We expect origin of buffers is at top left.
capabilities->output_surface_origin = gfx::SurfaceOrigin::kTopLeft; capabilities->output_surface_origin = gfx::SurfaceOrigin::kTopLeft;
// TODO(penghuang): Use defaultBackendFormat() in shared image implementation // TODO(https://crbug.com/1108406): only add supported formats base on
// to make sure backend format is consistent. // platform, driver, etc.
capabilities->sk_color_type = ResourceFormatToClosestSkColorType( capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::BGR_565)] =
true /* gpu_compositing */, image_format_); kRGB_565_SkColorType;
capabilities->gr_backend_format = capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_4444)] =
dependency_->GetSharedContextState()->gr_context()->defaultBackendFormat( kARGB_4444_SkColorType;
capabilities->sk_color_type, GrRenderable::kYes); capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::RGBX_8888)] =
kRGB_888x_SkColorType;
capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
kRGBA_8888_SkColorType;
capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::BGRX_8888)] =
kBGRA_8888_SkColorType;
capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_8888)] =
kBGRA_8888_SkColorType;
capabilities
->sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_1010102)] =
kBGRA_1010102_SkColorType;
capabilities
->sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_1010102)] =
kRGBA_1010102_SkColorType;
capabilities->sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_F16)] =
kRGBA_F16_SkColorType;
} }
bool OutputPresenterGL::Reshape(const gfx::Size& size, bool OutputPresenterGL::Reshape(const gfx::Size& size,
...@@ -261,6 +259,7 @@ bool OutputPresenterGL::Reshape(const gfx::Size& size, ...@@ -261,6 +259,7 @@ bool OutputPresenterGL::Reshape(const gfx::Size& size,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
gfx::BufferFormat format, gfx::BufferFormat format,
gfx::OverlayTransform transform) { gfx::OverlayTransform transform) {
image_format_ = GetResourceFormat(format);
return gl_surface_->Resize(size, device_scale_factor, color_space, return gl_surface_->Resize(size, device_scale_factor, color_space,
gfx::AlphaBitsForBufferFormat(format)); gfx::AlphaBitsForBufferFormat(format));
} }
......
...@@ -65,7 +65,7 @@ class VIZ_SERVICE_EXPORT OutputPresenterGL : public OutputPresenter { ...@@ -65,7 +65,7 @@ class VIZ_SERVICE_EXPORT OutputPresenterGL : public OutputPresenter {
SkiaOutputSurfaceDependency* dependency_; SkiaOutputSurfaceDependency* dependency_;
const bool supports_async_swap_; const bool supports_async_swap_;
ResourceFormat image_format_; ResourceFormat image_format_ = RGBA_8888;
// Shared Image factories // Shared Image factories
gpu::SharedImageFactory shared_image_factory_; gpu::SharedImageFactory shared_image_factory_;
......
...@@ -120,6 +120,12 @@ void SkiaOutputDevice::ScheduleOverlays( ...@@ -120,6 +120,12 @@ void SkiaOutputDevice::ScheduleOverlays(
void SkiaOutputDevice::EnsureBackbuffer() {} void SkiaOutputDevice::EnsureBackbuffer() {}
void SkiaOutputDevice::DiscardBackbuffer() {} void SkiaOutputDevice::DiscardBackbuffer() {}
void SkiaOutputDevice::SetDrawTimings(base::TimeTicks submitted,
base::TimeTicks started) {
viz_scheduled_draw_ = submitted;
gpu_started_draw_ = started;
}
void SkiaOutputDevice::StartSwapBuffers(BufferPresentedCallback feedback) { void SkiaOutputDevice::StartSwapBuffers(BufferPresentedCallback feedback) {
DCHECK_LT(static_cast<int>(pending_swaps_.size()), DCHECK_LT(static_cast<int>(pending_swaps_.size()),
capabilities_.max_frames_pending); capabilities_.max_frames_pending);
...@@ -158,12 +164,6 @@ void SkiaOutputDevice::FinishSwapBuffers( ...@@ -158,12 +164,6 @@ void SkiaOutputDevice::FinishSwapBuffers(
pending_swaps_.pop(); pending_swaps_.pop();
} }
void SkiaOutputDevice::SetDrawTimings(base::TimeTicks submitted,
base::TimeTicks started) {
viz_scheduled_draw_ = submitted;
gpu_started_draw_ = started;
}
SkiaOutputDevice::SwapInfo::SwapInfo( SkiaOutputDevice::SwapInfo::SwapInfo(
uint64_t swap_id, uint64_t swap_id,
SkiaOutputDevice::BufferPresentedCallback feedback, SkiaOutputDevice::BufferPresentedCallback feedback,
......
...@@ -44,11 +44,10 @@ SkiaOutputDeviceDawn::SkiaOutputDeviceDawn( ...@@ -44,11 +44,10 @@ SkiaOutputDeviceDawn::SkiaOutputDeviceDawn(
capabilities_.uses_default_gl_framebuffer = false; capabilities_.uses_default_gl_framebuffer = false;
capabilities_.supports_post_sub_buffer = false; capabilities_.supports_post_sub_buffer = false;
capabilities_.sk_color_type = kSurfaceColorType; capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
capabilities_.gr_backend_format = kSurfaceColorType;
context_provider_->GetGrContext()->defaultBackendFormat( capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_8888)] =
kSurfaceColorType, GrRenderable::kYes); kSurfaceColorType;
vsync_provider_ = std::make_unique<gl::VSyncProviderWin>(widget); vsync_provider_ = std::make_unique<gl::VSyncProviderWin>(widget);
child_window_.Initialize(); child_window_.Initialize();
} }
......
...@@ -105,15 +105,20 @@ SkiaOutputDeviceGL::SkiaOutputDeviceGL( ...@@ -105,15 +105,20 @@ SkiaOutputDeviceGL::SkiaOutputDeviceGL(
glGetIntegerv(GL_ALPHA_BITS, &alpha_bits); glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
} }
CHECK_GL_ERROR(); CHECK_GL_ERROR();
supports_alpha_ = alpha_bits > 0;
auto color_type =
capabilities_.sk_color_type = (alpha_bits > 0) ? kRGBA_8888_SkColorType : kRGB_888x_SkColorType;
supports_alpha_ ? kRGBA_8888_SkColorType : kRGB_888x_SkColorType; capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
capabilities_.gr_backend_format = gr_context->defaultBackendFormat( color_type;
capabilities_.sk_color_type, GrRenderable::kYes); capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBX_8888)] =
capabilities_.sk_color_type_for_hdr = kRGBA_F16_SkColorType; color_type;
capabilities_.gr_backend_format_for_hdr = gr_context->defaultBackendFormat( capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_8888)] =
capabilities_.sk_color_type_for_hdr, GrRenderable::kYes); color_type;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::BGRX_8888)] =
color_type;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_F16)] =
kRGBA_F16_SkColorType;
} }
SkiaOutputDeviceGL::~SkiaOutputDeviceGL() { SkiaOutputDeviceGL::~SkiaOutputDeviceGL() {
...@@ -140,22 +145,21 @@ bool SkiaOutputDeviceGL::Reshape(const gfx::Size& size, ...@@ -140,22 +145,21 @@ bool SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
framebuffer_info.fFBOID = 0; framebuffer_info.fFBOID = 0;
DCHECK_EQ(gl_surface_->GetBackingFramebufferObject(), 0u); DCHECK_EQ(gl_surface_->GetBackingFramebufferObject(), 0u);
SkColorType color_type; const auto format_index = static_cast<int>(buffer_format);
// TODO(https://crbug.com/1049334): The pixel format should be determined by SkColorType color_type = capabilities_.sk_color_types[format_index];
// |buffer_format|, not |color_space|, and not |supports_alpha_|. switch (color_type) {
if (color_space.IsHDR()) { case kRGBA_8888_SkColorType:
color_type = capabilities_.sk_color_type_for_hdr; framebuffer_info.fFormat = GL_RGBA8;
framebuffer_info.fFormat = GL_RGBA16F; break;
DCHECK_EQ(capabilities_.gr_backend_format_for_hdr.asGLFormat(), case kRGB_888x_SkColorType:
GrGLFormat::kRGBA16F); framebuffer_info.fFormat = GL_RGB8;
} else if (supports_alpha_) { break;
color_type = capabilities_.sk_color_type; case kRGBA_F16_SkColorType:
framebuffer_info.fFormat = GL_RGBA8; framebuffer_info.fFormat = GL_RGBA16F;
DCHECK_EQ(capabilities_.gr_backend_format.asGLFormat(), GrGLFormat::kRGBA8); break;
} else { default:
color_type = capabilities_.sk_color_type; NOTREACHED() << "color_type: " << color_type
framebuffer_info.fFormat = GL_RGB8; << " buffer_format: " << format_index;
DCHECK_EQ(capabilities_.gr_backend_format.asGLFormat(), GrGLFormat::kRGB8);
} }
// TODO(kylechar): We might need to support RGB10A2 for HDR10. HDR10 was only // TODO(kylechar): We might need to support RGB10A2 for HDR10. HDR10 was only
// used with Windows updated RS3 (2017) as a workaround for a DWM bug so it // used with Windows updated RS3 (2017) as a workaround for a DWM bug so it
......
...@@ -81,7 +81,6 @@ class SkiaOutputDeviceGL final : public SkiaOutputDevice { ...@@ -81,7 +81,6 @@ class SkiaOutputDeviceGL final : public SkiaOutputDevice {
sk_sp<SkSurface> sk_surface_; sk_sp<SkSurface> sk_surface_;
bool supports_alpha_ = false;
uint64_t backbuffer_estimated_size_ = 0; uint64_t backbuffer_estimated_size_ = 0;
base::WeakPtrFactory<SkiaOutputDeviceGL> weak_ptr_factory_{this}; base::WeakPtrFactory<SkiaOutputDeviceGL> weak_ptr_factory_{this};
......
...@@ -34,10 +34,16 @@ SkiaOutputDeviceOffscreen::SkiaOutputDeviceOffscreen( ...@@ -34,10 +34,16 @@ SkiaOutputDeviceOffscreen::SkiaOutputDeviceOffscreen(
capabilities_.output_surface_origin = origin; capabilities_.output_surface_origin = origin;
capabilities_.supports_post_sub_buffer = true; capabilities_.supports_post_sub_buffer = true;
capabilities_.sk_color_type = kSurfaceColorType; // TODO(https://crbug.com/1108406): use the right color types base on GPU
capabilities_.gr_backend_format = // capabilities.
context_state_->gr_context()->defaultBackendFormat(kSurfaceColorType, capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
GrRenderable::kYes); kSurfaceColorType;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBX_8888)] =
kSurfaceColorType;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_8888)] =
kSurfaceColorType;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::BGRX_8888)] =
kSurfaceColorType;
} }
SkiaOutputDeviceOffscreen::~SkiaOutputDeviceOffscreen() { SkiaOutputDeviceOffscreen::~SkiaOutputDeviceOffscreen() {
...@@ -53,6 +59,7 @@ bool SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size, ...@@ -53,6 +59,7 @@ bool SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size,
DiscardBackbuffer(); DiscardBackbuffer();
size_ = size; size_ = size;
format_ = format;
sk_color_space_ = color_space.ToSkColorSpace(); sk_color_space_ = color_space.ToSkColorSpace();
EnsureBackbuffer(); EnsureBackbuffer();
return true; return true;
...@@ -82,15 +89,20 @@ void SkiaOutputDeviceOffscreen::EnsureBackbuffer() { ...@@ -82,15 +89,20 @@ void SkiaOutputDeviceOffscreen::EnsureBackbuffer() {
if (size_.IsEmpty()) if (size_.IsEmpty())
return; return;
auto format_index = static_cast<int>(format_);
const auto& sk_color_type = capabilities_.sk_color_types[format_index];
DCHECK(sk_color_type != kUnknown_SkColorType)
<< "SkColorType is invalid for format: " << format_index;
if (has_alpha_) { if (has_alpha_) {
backend_texture_ = context_state_->gr_context()->createBackendTexture( backend_texture_ = context_state_->gr_context()->createBackendTexture(
size_.width(), size_.height(), kSurfaceColorType, GrMipMapped::kNo, size_.width(), size_.height(), sk_color_type, GrMipMapped::kNo,
GrRenderable::kYes); GrRenderable::kYes);
} else { } else {
is_emulated_rgbx_ = true; is_emulated_rgbx_ = true;
// Initialize alpha channel to opaque. // Initialize alpha channel to opaque.
backend_texture_ = context_state_->gr_context()->createBackendTexture( backend_texture_ = context_state_->gr_context()->createBackendTexture(
size_.width(), size_.height(), kSurfaceColorType, SkColors::kBlack, size_.width(), size_.height(), sk_color_type, SkColors::kBlack,
GrMipMapped::kNo, GrRenderable::kYes); GrMipMapped::kNo, GrRenderable::kYes);
} }
DCHECK(backend_texture_.isValid()); DCHECK(backend_texture_.isValid());
......
...@@ -51,6 +51,7 @@ class SkiaOutputDeviceOffscreen : public SkiaOutputDevice { ...@@ -51,6 +51,7 @@ class SkiaOutputDeviceOffscreen : public SkiaOutputDevice {
private: private:
gfx::Size size_; gfx::Size size_;
gfx::BufferFormat format_ = gfx::BufferFormat::RGBA_8888;
uint64_t backbuffer_estimated_size_ = 0; uint64_t backbuffer_estimated_size_ = 0;
sk_sp<SkColorSpace> sk_color_space_; sk_sp<SkColorSpace> sk_color_space_;
......
...@@ -318,10 +318,14 @@ bool SkiaOutputDeviceVulkan::Initialize() { ...@@ -318,10 +318,14 @@ bool SkiaOutputDeviceVulkan::Initialize() {
const auto surface_format = vulkan_surface_->surface_format().format; const auto surface_format = vulkan_surface_->surface_format().format;
DCHECK(surface_format == VK_FORMAT_B8G8R8A8_UNORM || DCHECK(surface_format == VK_FORMAT_B8G8R8A8_UNORM ||
surface_format == VK_FORMAT_R8G8B8A8_UNORM); surface_format == VK_FORMAT_R8G8B8A8_UNORM);
capabilities_.sk_color_type = surface_format == VK_FORMAT_R8G8B8A8_UNORM
? kRGBA_8888_SkColorType auto sk_color_type = surface_format == VK_FORMAT_R8G8B8A8_UNORM
: kBGRA_8888_SkColorType; ? kRGBA_8888_SkColorType
capabilities_.gr_backend_format = GrBackendFormat::MakeVk(surface_format); : kBGRA_8888_SkColorType;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
sk_color_type;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_8888)] =
sk_color_type;
return true; return true;
} }
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
namespace viz { namespace viz {
namespace {
constexpr auto kSurfaceColorType = kRGBA_8888_SkColorType;
}
SkiaOutputDeviceWebView::SkiaOutputDeviceWebView( SkiaOutputDeviceWebView::SkiaOutputDeviceWebView(
gpu::SharedContextState* context_state, gpu::SharedContextState* context_state,
scoped_refptr<gl::GLSurface> gl_surface, scoped_refptr<gl::GLSurface> gl_surface,
...@@ -36,10 +40,10 @@ SkiaOutputDeviceWebView::SkiaOutputDeviceWebView( ...@@ -36,10 +40,10 @@ SkiaOutputDeviceWebView::SkiaOutputDeviceWebView(
DCHECK(context_state_->gr_context()); DCHECK(context_state_->gr_context());
DCHECK(context_state_->context()); DCHECK(context_state_->context());
capabilities_.sk_color_type = kRGBA_8888_SkColorType; capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
capabilities_.gr_backend_format = kSurfaceColorType;
context_state_->gr_context()->defaultBackendFormat( capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::BGRA_8888)] =
capabilities_.sk_color_type, GrRenderable::kYes); kSurfaceColorType;
} }
SkiaOutputDeviceWebView::~SkiaOutputDeviceWebView() = default; SkiaOutputDeviceWebView::~SkiaOutputDeviceWebView() = default;
...@@ -100,8 +104,7 @@ void SkiaOutputDeviceWebView::InitSkiaSurface(unsigned int fbo) { ...@@ -100,8 +104,7 @@ void SkiaOutputDeviceWebView::InitSkiaSurface(unsigned int fbo) {
GrGLFramebufferInfo framebuffer_info; GrGLFramebufferInfo framebuffer_info;
framebuffer_info.fFBOID = fbo; framebuffer_info.fFBOID = fbo;
framebuffer_info.fFormat = GL_RGBA8; framebuffer_info.fFormat = GL_RGBA8;
DCHECK_EQ(capabilities_.gr_backend_format.asGLFormat(), GrGLFormat::kRGBA8); SkColorType color_type = kSurfaceColorType;
SkColorType color_type = capabilities_.sk_color_type;
GrBackendRenderTarget render_target(size_.width(), size_.height(), GrBackendRenderTarget render_target(size_.width(), size_.height(),
/*sampleCnt=*/0, /*sampleCnt=*/0,
......
...@@ -236,9 +236,10 @@ void SkiaOutputSurfaceImpl::Reshape(const gfx::Size& size, ...@@ -236,9 +236,10 @@ void SkiaOutputSurfaceImpl::Reshape(const gfx::Size& size,
color_space_ = color_space; color_space_ = color_space;
is_hdr_ = color_space_.IsHDR(); is_hdr_ = color_space_.IsHDR();
size_ = size; size_ = size;
format_ = format;
characterization_ = CreateSkSurfaceCharacterization( characterization_ = CreateSkSurfaceCharacterization(
size, GetResourceFormat(format), false /* mipmap */, size, format, false /* mipmap */, color_space_.ToSkColorSpace(),
color_space_.ToSkColorSpace(), true /* is_root_render_pass */); true /* is_root_render_pass */);
RecreateRootRecorder(); RecreateRootRecorder();
} }
...@@ -289,8 +290,8 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintCurrentFrame() { ...@@ -289,8 +290,8 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintCurrentFrame() {
nway_canvas_->addCanvas(current_paint_->recorder()->getCanvas()); nway_canvas_->addCanvas(current_paint_->recorder()->getCanvas());
SkSurfaceCharacterization characterization = CreateSkSurfaceCharacterization( SkSurfaceCharacterization characterization = CreateSkSurfaceCharacterization(
gfx::Size(characterization_.width(), characterization_.height()), gfx::Size(characterization_.width(), characterization_.height()), format_,
BGRA_8888, false /* mipmap */, characterization_.refColorSpace(), false /* mipmap */, characterization_.refColorSpace(),
false /* is_root_render_pass */); false /* is_root_render_pass */);
if (characterization.isValid()) { if (characterization.isValid()) {
overdraw_surface_recorder_.emplace(characterization); overdraw_surface_recorder_.emplace(characterization);
...@@ -493,7 +494,7 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass( ...@@ -493,7 +494,7 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
DCHECK(resource_sync_tokens_.empty()); DCHECK(resource_sync_tokens_.empty());
SkSurfaceCharacterization characterization = CreateSkSurfaceCharacterization( SkSurfaceCharacterization characterization = CreateSkSurfaceCharacterization(
surface_size, format, mipmap, std::move(color_space), surface_size, BufferFormat(format), mipmap, std::move(color_space),
false /* is_root_render_pass */); false /* is_root_render_pass */);
if (!characterization.isValid()) if (!characterization.isValid())
return nullptr; return nullptr;
...@@ -779,7 +780,7 @@ void SkiaOutputSurfaceImpl::InitializeOnGpuThread( ...@@ -779,7 +780,7 @@ void SkiaOutputSurfaceImpl::InitializeOnGpuThread(
SkSurfaceCharacterization SkSurfaceCharacterization
SkiaOutputSurfaceImpl::CreateSkSurfaceCharacterization( SkiaOutputSurfaceImpl::CreateSkSurfaceCharacterization(
const gfx::Size& surface_size, const gfx::Size& surface_size,
ResourceFormat format, gfx::BufferFormat format,
bool mipmap, bool mipmap,
sk_sp<SkColorSpace> color_space, sk_sp<SkColorSpace> color_space,
bool is_root_render_pass) { bool is_root_render_pass) {
...@@ -791,15 +792,15 @@ SkiaOutputSurfaceImpl::CreateSkSurfaceCharacterization( ...@@ -791,15 +792,15 @@ SkiaOutputSurfaceImpl::CreateSkSurfaceCharacterization(
SkSurfaceProps surface_props(0 /*flags */, SkSurfaceProps surface_props(0 /*flags */,
SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps::kLegacyFontHost_InitType);
if (is_root_render_pass) { if (is_root_render_pass) {
auto color_type = const auto format_index = static_cast<int>(format);
is_hdr_ && capabilities_.sk_color_type_for_hdr != kUnknown_SkColorType const auto& color_type = capabilities_.sk_color_types[format_index];
? capabilities_.sk_color_type_for_hdr const auto backend_format = gr_context_thread_safe_->defaultBackendFormat(
: capabilities_.sk_color_type; color_type, GrRenderable::kYes);
DCHECK(color_type != kUnknown_SkColorType)
const auto& backend_format = << "SkColorType is invalid for buffer format_index: " << format_index;
is_hdr_ && capabilities_.gr_backend_format_for_hdr.isValid() DCHECK(backend_format.isValid())
? capabilities_.gr_backend_format_for_hdr << "GrBackendFormat is invalid for buffer format_index: "
: capabilities_.gr_backend_format; << format_index;
auto surface_origin = auto surface_origin =
capabilities_.output_surface_origin == gfx::SurfaceOrigin::kBottomLeft capabilities_.output_surface_origin == gfx::SurfaceOrigin::kBottomLeft
? kBottomLeft_GrSurfaceOrigin ? kBottomLeft_GrSurfaceOrigin
...@@ -838,8 +839,9 @@ SkiaOutputSurfaceImpl::CreateSkSurfaceCharacterization( ...@@ -838,8 +839,9 @@ SkiaOutputSurfaceImpl::CreateSkSurfaceCharacterization(
return characterization; return characterization;
} }
auto color_type = auto resource_format = GetResourceFormat(format);
ResourceFormatToClosestSkColorType(true /* gpu_compositing */, format); auto color_type = ResourceFormatToClosestSkColorType(
true /* gpu_compositing */, resource_format);
auto backend_format = gr_context_thread_safe_->defaultBackendFormat( auto backend_format = gr_context_thread_safe_->defaultBackendFormat(
color_type, GrRenderable::kYes); color_type, GrRenderable::kYes);
DCHECK(backend_format.isValid()); DCHECK(backend_format.isValid());
......
...@@ -159,7 +159,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface { ...@@ -159,7 +159,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
bool* result); bool* result);
SkSurfaceCharacterization CreateSkSurfaceCharacterization( SkSurfaceCharacterization CreateSkSurfaceCharacterization(
const gfx::Size& surface_size, const gfx::Size& surface_size,
ResourceFormat format, gfx::BufferFormat format,
bool mipmap, bool mipmap,
sk_sp<SkColorSpace> color_space, sk_sp<SkColorSpace> color_space,
bool is_root_render_pass); bool is_root_render_pass);
...@@ -202,6 +202,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface { ...@@ -202,6 +202,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
gfx::Size size_; gfx::Size size_;
gfx::ColorSpace color_space_; gfx::ColorSpace color_space_;
gfx::BufferFormat format_;
bool is_hdr_ = false; bool is_hdr_ = false;
SkSurfaceCharacterization characterization_; SkSurfaceCharacterization characterization_;
base::Optional<SkDeferredDisplayListRecorder> root_recorder_; base::Optional<SkDeferredDisplayListRecorder> root_recorder_;
......
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