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

SkiaOutputSurfaceImpl: do not block on Reshape() call

With this CL, SkiaOutputSurfaceImpl will create SkSurfaceCharazation
on viz thread directlly instead of ask gpu thread to create it for us.

But for WebView, we still need to ask GPU thread to get necessary info,
so we can create SkSurfaceCharazation on viz thread.

Bug: 1041949
Change-Id: Id6bb23e63d5191b67b446a8f843ca06c1e63b18d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088343
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748554}
parent a3520fb4
......@@ -34,14 +34,6 @@ SkiaOutputSurfaceDependencyWebView::CreateSequence() {
this->task_queue_, this->gpu_service_->sync_point_manager());
}
bool SkiaOutputSurfaceDependencyWebView::IsUsingVulkan() {
return shared_context_state_ && shared_context_state_->GrContextIsVulkan();
}
bool SkiaOutputSurfaceDependencyWebView::IsUsingDawn() {
return false;
}
gpu::SharedImageManager*
SkiaOutputSurfaceDependencyWebView::GetSharedImageManager() {
return gpu_service_->shared_image_manager();
......@@ -78,7 +70,7 @@ SkiaOutputSurfaceDependencyWebView::GetDawnContextProvider() {
}
const gpu::GpuPreferences&
SkiaOutputSurfaceDependencyWebView::GetGpuPreferences() {
SkiaOutputSurfaceDependencyWebView::GetGpuPreferences() const {
return gpu_service_->gpu_preferences();
}
......
......@@ -26,8 +26,6 @@ class SkiaOutputSurfaceDependencyWebView
~SkiaOutputSurfaceDependencyWebView() override;
std::unique_ptr<gpu::SingleTaskSequence> CreateSequence() override;
bool IsUsingVulkan() override;
bool IsUsingDawn() override;
gpu::SharedImageManager* GetSharedImageManager() override;
gpu::SyncPointManager* GetSyncPointManager() override;
const gpu::GpuDriverBugWorkarounds& GetGpuDriverBugWorkarounds() override;
......@@ -35,7 +33,7 @@ class SkiaOutputSurfaceDependencyWebView
gpu::raster::GrShaderCache* GetGrShaderCache() override;
viz::VulkanContextProvider* GetVulkanContextProvider() override;
viz::DawnContextProvider* GetDawnContextProvider() override;
const gpu::GpuPreferences& GetGpuPreferences() override;
const gpu::GpuPreferences& GetGpuPreferences() const override;
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() override;
gpu::MailboxManager* GetMailboxManager() override;
gpu::ImageFactory* GetGpuImageFactory() override;
......
......@@ -16,6 +16,7 @@
#include "components/viz/common/display/update_vsync_parameters_callback.h"
#include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/gpu/gpu_vsync_callback.h"
#include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/returned_resource.h"
#include "components/viz/service/display/software_output_device.h"
#include "components/viz/service/viz_service_export.h"
......@@ -23,6 +24,7 @@
#include "gpu/command_buffer/common/texture_in_use_response.h"
#include "gpu/ipc/common/surface_handle.h"
#include "gpu/ipc/gpu_task_scheduler_helper.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/overlay_transform.h"
#include "ui/gfx/surface_origin.h"
......@@ -96,6 +98,13 @@ class VIZ_SERVICE_EXPORT OutputSurface {
bool android_surface_control_feature_enabled = false;
// True if the buffer content will be preserved after presenting.
bool preserve_buffer_content = false;
// The SkColorType and GrBackendFormat for non-HDR and HDR.
// TODO(penghuang): remove SkColorType and GrBackendFormat when
// 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.
......
......@@ -99,7 +99,9 @@ class SkiaOutputDeviceBufferQueue::Image {
DCHECK(end_semaphores_.empty());
std::vector<GrBackendSemaphore> begin_semaphores;
SkSurfaceProps surface_props{0, kUnknown_SkPixelGeometry};
// LegacyFontHost will get LCD text and skia figures out what type to use.
SkSurfaceProps surface_props(0 /* flags */,
SkSurfaceProps::kLegacyFontHost_InitType);
// Buffer queue is internal to GPU proc and handles texture initialization,
// so allow uncleared access.
......@@ -265,7 +267,7 @@ SkiaOutputDeviceBufferQueue::SkiaOutputDeviceBufferQueue(
shared_image_usage_(shared_image_usage) {
shared_image_representation_factory_ =
std::make_unique<gpu::SharedImageRepresentationFactory>(
deps->GetSharedImageManager(), memory_tracker);
dependency_->GetSharedImageManager(), memory_tracker);
#if defined(USE_OZONE)
image_format_ = GetResourceFormat(display::DisplaySnapshot::PrimaryFormat());
......@@ -276,6 +278,7 @@ SkiaOutputDeviceBufferQueue::SkiaOutputDeviceBufferQueue(
// are flipped.
DCHECK_EQ(gl_surface_->GetOrigin(), gfx::SurfaceOrigin::kTopLeft);
capabilities_.uses_default_gl_framebuffer = false;
capabilities_.android_surface_control_feature_enabled = true;
capabilities_.supports_post_sub_buffer = gl_surface_->SupportsPostSubBuffer();
capabilities_.supports_commit_overlay_planes =
......@@ -296,6 +299,14 @@ SkiaOutputDeviceBufferQueue::SkiaOutputDeviceBufferQueue(
capabilities_.preserve_buffer_content = true;
// We expect origin of buffers is at top left.
capabilities_.output_surface_origin = gfx::SurfaceOrigin::kTopLeft;
// TODO(penghuang): Use defaultBackendFormat() in shared image implementation
// to make sure backend formant is consistent.
capabilities_.sk_color_type = ResourceFormatToClosestSkColorType(
true /* gpu_compositing */, image_format_);
capabilities_.gr_backend_format =
dependency_->GetSharedContextState()->gr_context()->defaultBackendFormat(
capabilities_.sk_color_type, GrRenderable::kYes);
}
SkiaOutputDeviceBufferQueue::SkiaOutputDeviceBufferQueue(
......
......@@ -43,6 +43,7 @@ SkiaOutputDeviceGL::SkiaOutputDeviceGL(
context_state_(context_state),
gl_surface_(std::move(gl_surface)),
supports_async_swap_(gl_surface_->SupportsAsyncSwap()) {
capabilities_.uses_default_gl_framebuffer = true;
capabilities_.output_surface_origin = gl_surface_->GetOrigin();
capabilities_.supports_post_sub_buffer = gl_surface_->SupportsPostSubBuffer();
if (feature_info->workarounds()
......@@ -90,6 +91,16 @@ SkiaOutputDeviceGL::SkiaOutputDeviceGL(
}
CHECK_GL_ERROR();
supports_alpha_ = alpha_bits > 0;
capabilities_.sk_color_type =
supports_alpha_ ? kRGBA_8888_SkColorType : kRGB_888x_SkColorType;
capabilities_.gr_backend_format =
context_state_->gr_context()->defaultBackendFormat(
capabilities_.sk_color_type, GrRenderable::kYes);
capabilities_.sk_color_type_for_hdr = kRGBA_F16_SkColorType;
capabilities_.gr_backend_format_for_hdr =
context_state_->gr_context()->defaultBackendFormat(
capabilities_.sk_color_type_for_hdr, GrRenderable::kYes);
}
SkiaOutputDeviceGL::~SkiaOutputDeviceGL() {
......@@ -113,20 +124,25 @@ bool SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType);
GrGLFramebufferInfo framebuffer_info;
framebuffer_info.fFBOID = gl_surface_->GetBackingFramebufferObject();
framebuffer_info.fFBOID = 0;
DCHECK_EQ(gl_surface_->GetBackingFramebufferObject(), 0u);
SkColorType color_type;
// TODO(https://crbug.com/1049334): The pixel format should be determined by
// |buffer_format|, not |color_space|, and not |supports_alpha_|.
if (color_space.IsHDR()) {
color_type = capabilities_.sk_color_type_for_hdr;
framebuffer_info.fFormat = GL_RGBA16F;
color_type = kRGBA_F16_SkColorType;
DCHECK_EQ(capabilities_.gr_backend_format_for_hdr.asGLFormat(),
GrGLFormat::kRGBA16F);
} else if (supports_alpha_) {
color_type = capabilities_.sk_color_type;
framebuffer_info.fFormat = GL_RGBA8;
color_type = kRGBA_8888_SkColorType;
DCHECK_EQ(capabilities_.gr_backend_format.asGLFormat(), GrGLFormat::kRGBA8);
} else {
framebuffer_info.fFormat = GL_RGB8_OES;
color_type = kRGB_888x_SkColorType;
color_type = capabilities_.sk_color_type;
framebuffer_info.fFormat = GL_RGB8;
DCHECK_EQ(capabilities_.gr_backend_format.asGLFormat(), GrGLFormat::kRGB8);
}
// 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
......
......@@ -30,8 +30,14 @@ SkiaOutputDeviceOffscreen::SkiaOutputDeviceOffscreen(
did_swap_buffer_complete_callback),
context_state_(context_state),
has_alpha_(has_alpha) {
capabilities_.uses_default_gl_framebuffer = false;
capabilities_.output_surface_origin = origin;
capabilities_.supports_post_sub_buffer = true;
capabilities_.sk_color_type = kSurfaceColorType;
capabilities_.gr_backend_format =
context_state_->gr_context()->defaultBackendFormat(kSurfaceColorType,
GrRenderable::kYes);
}
SkiaOutputDeviceOffscreen::~SkiaOutputDeviceOffscreen() {
......@@ -117,13 +123,16 @@ void SkiaOutputDeviceOffscreen::DiscardBackbuffer() {
SkSurface* SkiaOutputDeviceOffscreen::BeginPaint() {
DCHECK(backend_texture_.isValid());
if (!sk_surface_) {
// LegacyFontHost will get LCD text and skia figures out what type to use.
SkSurfaceProps surface_props(0 /* flags */,
SkSurfaceProps::kLegacyFontHost_InitType);
sk_surface_ = SkSurface::MakeFromBackendTexture(
context_state_->gr_context(), backend_texture_,
capabilities_.output_surface_origin == gfx::SurfaceOrigin::kTopLeft
? kTopLeft_GrSurfaceOrigin
: kBottomLeft_GrSurfaceOrigin,
0 /* sampleCount */, kSurfaceColorType, sk_color_space_,
nullptr /* surfaceProps */);
&surface_props);
}
return sk_surface_.get();
}
......
......@@ -18,6 +18,7 @@
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/vk/GrVkTypes.h"
namespace viz {
......@@ -35,6 +36,7 @@ SkiaOutputDeviceVulkan::SkiaOutputDeviceVulkan(
if (!CreateVulkanSurface()) {
LOG(ERROR) << "Failed to create vulkan surface.";
}
capabilities_.uses_default_gl_framebuffer = false;
capabilities_.max_frames_pending = vulkan_surface_->image_count() - 1;
// Vulkan FIFO swap chain should return vk images in presenting order, so set
// preserve_buffer_content & supports_post_sub_buffer to true to let
......@@ -43,6 +45,14 @@ SkiaOutputDeviceVulkan::SkiaOutputDeviceVulkan(
capabilities_.output_surface_origin = gfx::SurfaceOrigin::kTopLeft;
capabilities_.supports_post_sub_buffer = true;
capabilities_.supports_pre_transform = true;
const auto surface_format = vulkan_surface_->surface_format().format;
DCHECK(surface_format == VK_FORMAT_B8G8R8A8_UNORM ||
surface_format == VK_FORMAT_R8G8B8A8_UNORM);
capabilities_.sk_color_type = surface_format == VK_FORMAT_R8G8B8A8_UNORM
? kRGBA_8888_SkColorType
: kBGRA_8888_SkColorType;
capabilities_.gr_backend_format = GrBackendFormat::MakeVk(surface_format);
}
SkiaOutputDeviceVulkan::~SkiaOutputDeviceVulkan() {
......
......@@ -27,6 +27,10 @@ SkiaOutputDeviceWebView::SkiaOutputDeviceWebView(
std::move(did_swap_buffer_complete_callback)),
context_state_(context_state),
gl_surface_(std::move(gl_surface)) {
// Always set uses_default_gl_framebuffer to true, since
// SkSurfaceCharacterization created for GL fbo0 is compatible with
// SkSurface wrappers non GL fbo0.
capabilities_.uses_default_gl_framebuffer = true;
capabilities_.output_surface_origin = gl_surface_->GetOrigin();
capabilities_.max_frames_pending = gl_surface_->GetBufferCount() - 1;
......@@ -40,6 +44,12 @@ SkiaOutputDeviceWebView::SkiaOutputDeviceWebView(
glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
CHECK_GL_ERROR();
supports_alpha_ = alpha_bits > 0;
capabilities_.sk_color_type =
supports_alpha_ ? kRGBA_8888_SkColorType : kRGB_888x_SkColorType;
capabilities_.gr_backend_format =
context_state_->gr_context()->defaultBackendFormat(
capabilities_.sk_color_type, GrRenderable::kYes);
}
SkiaOutputDeviceWebView::~SkiaOutputDeviceWebView() = default;
......@@ -59,7 +69,6 @@ bool SkiaOutputDeviceWebView::Reshape(const gfx::Size& size,
size_ = size;
color_space_ = color_space;
InitSkiaSurface(gl_surface_->GetBackingFramebufferObject());
return !!sk_surface_;
}
......@@ -98,15 +107,10 @@ void SkiaOutputDeviceWebView::InitSkiaSurface(unsigned int fbo) {
GrGLFramebufferInfo framebuffer_info;
framebuffer_info.fFBOID = fbo;
SkColorType color_type;
if (supports_alpha_) {
framebuffer_info.fFormat = GL_RGBA8;
color_type = kRGBA_8888_SkColorType;
} else {
framebuffer_info.fFormat = GL_RGB8_OES;
color_type = kRGB_888x_SkColorType;
}
framebuffer_info.fFormat = supports_alpha_ ? GL_RGBA8 : GL_RGB8_OES;
DCHECK_EQ(capabilities_.gr_backend_format.asGLFormat(),
supports_alpha_ ? GrGLFormat::kRGBA8 : GrGLFormat::kRGB8);
SkColorType color_type = capabilities_.sk_color_type;
GrBackendRenderTarget render_target(size_.width(), size_.height(), 0, 8,
framebuffer_info);
......
......@@ -15,6 +15,7 @@
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/service/sequence_id.h"
#include "gpu/config/gpu_preferences.h"
#include "gpu/ipc/common/surface_handle.h"
#include "ui/gl/gl_surface_format.h"
......@@ -36,7 +37,6 @@ class SharedImageManager;
class SingleTaskSequence;
class SyncPointManager;
struct GpuFeatureInfo;
struct GpuPreferences;
namespace raster {
class GrShaderCache;
......@@ -59,10 +59,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceDependency {
public:
virtual ~SkiaOutputSurfaceDependency() = default;
// These are client thread methods. All other methods should be called on
// the GPU thread only.
virtual bool IsUsingVulkan() = 0;
virtual bool IsUsingDawn() = 0;
// Returns a new task execution sequence. Sequences should not outlive the
// task executor.
virtual std::unique_ptr<gpu::SingleTaskSequence> CreateSequence() = 0;
......@@ -77,7 +73,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceDependency {
virtual VulkanContextProvider* GetVulkanContextProvider() = 0;
// May return null.
virtual DawnContextProvider* GetDawnContextProvider() = 0;
virtual const gpu::GpuPreferences& GetGpuPreferences() = 0;
virtual const gpu::GpuPreferences& GetGpuPreferences() const = 0;
virtual const gpu::GpuFeatureInfo& GetGpuFeatureInfo() = 0;
virtual gpu::MailboxManager* GetMailboxManager() = 0;
// May return null.
......@@ -113,6 +109,18 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceDependency {
virtual base::TimeDelta GetGpuBlockedTimeSinceLastSwap() = 0;
virtual bool NeedsSupportForExternalStencil() = 0;
gpu::GrContextType gr_context_type() const {
return GetGpuPreferences().gr_context_type;
}
bool IsUsingVulkan() const {
return gr_context_type() == gpu::GrContextType::kVulkan;
}
bool IsUsingDawn() const {
return gr_context_type() == gpu::GrContextType::kDawn;
}
};
} // namespace viz
......
......@@ -30,14 +30,6 @@ SkiaOutputSurfaceDependencyImpl::CreateSequence() {
gpu_service_impl_->GetGpuScheduler());
}
bool SkiaOutputSurfaceDependencyImpl::IsUsingVulkan() {
return gpu_service_impl_->is_using_vulkan();
}
bool SkiaOutputSurfaceDependencyImpl::IsUsingDawn() {
return gpu_service_impl_->is_using_dawn();
}
gpu::SharedImageManager*
SkiaOutputSurfaceDependencyImpl::GetSharedImageManager() {
return gpu_service_impl_->shared_image_manager();
......@@ -71,8 +63,8 @@ DawnContextProvider* SkiaOutputSurfaceDependencyImpl::GetDawnContextProvider() {
return gpu_service_impl_->dawn_context_provider();
}
const gpu::GpuPreferences&
SkiaOutputSurfaceDependencyImpl::GetGpuPreferences() {
const gpu::GpuPreferences& SkiaOutputSurfaceDependencyImpl::GetGpuPreferences()
const {
return gpu_service_impl_->gpu_preferences();
}
......
......@@ -25,8 +25,6 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceDependencyImpl
~SkiaOutputSurfaceDependencyImpl() override;
std::unique_ptr<gpu::SingleTaskSequence> CreateSequence() override;
bool IsUsingVulkan() override;
bool IsUsingDawn() override;
gpu::SharedImageManager* GetSharedImageManager() override;
gpu::SyncPointManager* GetSyncPointManager() override;
const gpu::GpuDriverBugWorkarounds& GetGpuDriverBugWorkarounds() override;
......@@ -34,7 +32,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceDependencyImpl
gpu::raster::GrShaderCache* GetGrShaderCache() override;
VulkanContextProvider* GetVulkanContextProvider() override;
DawnContextProvider* GetDawnContextProvider() override;
const gpu::GpuPreferences& GetGpuPreferences() override;
const gpu::GpuPreferences& GetGpuPreferences() const override;
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() override;
gpu::MailboxManager* GetMailboxManager() override;
gpu::ImageFactory* GetGpuImageFactory() override;
......
......@@ -210,11 +210,6 @@ void SkiaOutputSurfaceImpl::Reshape(const gfx::Size& size,
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(!size.IsEmpty());
if (reshape_waitable_event_) {
reshape_waitable_event_->Wait();
reshape_waitable_event_.reset();
}
// SetDrawRectangle() will need to be called at the new size.
has_set_draw_rectangle_for_frame_ = false;
......@@ -223,54 +218,22 @@ void SkiaOutputSurfaceImpl::Reshape(const gfx::Size& size,
for (auto& damage : damage_of_buffers_)
damage = gfx::Rect(size);
SkSurfaceCharacterization* characterization = nullptr;
bool need_wait_for_gpu_thread = true;
if (characterization_.isValid()) {
// TODO(vasilyt): We temporary keep old code for linux to not interferee
// with M81. Remove this after.
#if defined(OS_LINUX)
if (color_space != color_space_) {
characterization_ =
characterization_.createColorSpace(color_space.ToSkColorSpace());
}
if (size != size_) {
characterization_ =
characterization_.createResized(size.width(), size.height());
}
need_wait_for_gpu_thread = false;
#else
if (!was_forced && color_space_ == color_space &&
format == reshape_format_) {
characterization_ =
characterization_.createResized(size.width(), size.height());
need_wait_for_gpu_thread = false;
}
#endif
}
color_space_ = color_space;
size_ = size;
reshape_format_ = format;
if (need_wait_for_gpu_thread) {
characterization = &characterization_;
reshape_waitable_event_ = std::make_unique<base::WaitableEvent>(
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
} else {
RecreateRootRecorder();
}
// impl_on_gpu_ is released on the GPU thread by a posted task from
// SkiaOutputSurfaceImpl::dtor. So it is safe to use base::Unretained.
auto task = base::BindOnce(&SkiaOutputSurfaceImplOnGpu::Reshape,
base::Unretained(impl_on_gpu_.get()), size,
device_scale_factor, color_space, format,
use_stencil, pre_transform_, characterization,
reshape_waitable_event_.get());
use_stencil, pre_transform_);
ScheduleGpuTask(std::move(task), {});
color_space_ = color_space;
is_hdr_ = color_space_.IsHDR();
size_ = size;
reshape_format_ = format;
characterization_ = CreateSkSurfaceCharacterization(
size, GetResourceFormat(format), false /* mipmap */,
color_space_.ToSkColorSpace(), true /* is_root_render_pass */);
RecreateRootRecorder();
}
void SkiaOutputSurfaceImpl::SetUpdateVSyncParametersCallback(
......@@ -302,17 +265,6 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintCurrentFrame() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
// Make sure there is no unsubmitted PaintFrame or PaintRenderPass.
DCHECK(!current_paint_);
if (reshape_waitable_event_) {
reshape_waitable_event_->Wait();
reshape_waitable_event_ = nullptr;
if (!characterization_.isValid()) {
DLOG(ERROR) << "Reshape failed.";
return nullptr;
}
RecreateRootRecorder();
}
DCHECK(root_recorder_);
current_paint_.emplace(&root_recorder_.value());
......@@ -325,7 +277,8 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintCurrentFrame() {
SkSurfaceCharacterization characterization = CreateSkSurfaceCharacterization(
gfx::Size(characterization_.width(), characterization_.height()),
BGRA_8888, false /* mipmap */, characterization_.refColorSpace());
BGRA_8888, false /* mipmap */, characterization_.refColorSpace(),
false /* is_root_render_pass */);
overdraw_surface_recorder_.emplace(characterization);
overdraw_canvas_.emplace((overdraw_surface_recorder_->getCanvas()));
......@@ -519,7 +472,8 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
DCHECK(resource_sync_tokens_.empty());
SkSurfaceCharacterization c = CreateSkSurfaceCharacterization(
surface_size, format, mipmap, std::move(color_space));
surface_size, format, mipmap, std::move(color_space),
false /* is_root_render_pass */);
current_paint_.emplace(c, id);
return current_paint_->recorder()->getCanvas();
}
......@@ -724,8 +678,7 @@ bool SkiaOutputSurfaceImpl::Initialize() {
base::ThreadTaskRunnerHandle::Get(), weak_ptr_);
#endif
base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
base::WaitableEvent event;
bool result = false;
auto callback = base::BindOnce(&SkiaOutputSurfaceImpl::InitializeOnGpuThread,
base::Unretained(this), vsync_callback_runner,
......@@ -779,20 +732,53 @@ SkiaOutputSurfaceImpl::CreateSkSurfaceCharacterization(
const gfx::Size& surface_size,
ResourceFormat format,
bool mipmap,
sk_sp<SkColorSpace> color_space) {
sk_sp<SkColorSpace> color_space,
bool is_root_render_pass) {
auto gr_context_thread_safe = impl_on_gpu_->GetGrContextThreadSafeProxy();
auto cache_max_resource_bytes = impl_on_gpu_->max_resource_cache_bytes();
// LegacyFontHost will get LCD text and skia figures out what type to use.
SkSurfaceProps surface_props(0 /*flags */,
SkSurfaceProps::kLegacyFontHost_InitType);
if (is_root_render_pass) {
auto color_type =
is_hdr_ && capabilities_.sk_color_type_for_hdr != kUnknown_SkColorType
? capabilities_.sk_color_type_for_hdr
: capabilities_.sk_color_type;
const auto& backend_format =
is_hdr_ && capabilities_.gr_backend_format_for_hdr.isValid()
? capabilities_.gr_backend_format_for_hdr
: capabilities_.gr_backend_format;
auto surface_origin =
capabilities_.output_surface_origin == gfx::SurfaceOrigin::kBottomLeft
? kBottomLeft_GrSurfaceOrigin
: kTopLeft_GrSurfaceOrigin;
auto image_info = SkImageInfo::Make(
surface_size.width(), surface_size.height(), color_type,
kPremul_SkAlphaType, std::move(color_space));
DCHECK((capabilities_.uses_default_gl_framebuffer &&
dependency_->gr_context_type() == gpu::GrContextType::kGL) ||
!capabilities_.uses_default_gl_framebuffer);
auto characterization = gr_context_thread_safe->createCharacterization(
cache_max_resource_bytes, image_info, backend_format,
0 /* sampleCount */, surface_origin, surface_props, mipmap,
capabilities_.uses_default_gl_framebuffer, false /* isTextureable */,
impl_on_gpu_->GetGpuPreferences().enforce_vulkan_protected_memory
? GrProtected::kYes
: GrProtected::kNo);
DCHECK(characterization.isValid());
return characterization;
}
auto color_type =
ResourceFormatToClosestSkColorType(true /* gpu_compositing */, format);
auto image_info =
SkImageInfo::Make(surface_size.width(), surface_size.height(), color_type,
kPremul_SkAlphaType, std::move(color_space));
auto backend_format = gr_context_thread_safe->defaultBackendFormat(
color_type, GrRenderable::kYes);
DCHECK(backend_format.isValid());
auto image_info =
SkImageInfo::Make(surface_size.width(), surface_size.height(), color_type,
kPremul_SkAlphaType, std::move(color_space));
auto characterization = gr_context_thread_safe->createCharacterization(
cache_max_resource_bytes, image_info, backend_format, 0 /* sampleCount */,
kTopLeft_GrSurfaceOrigin, surface_props, mipmap,
......
......@@ -165,7 +165,8 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
const gfx::Size& surface_size,
ResourceFormat format,
bool mipmap,
sk_sp<SkColorSpace> color_space);
sk_sp<SkColorSpace> color_space,
bool is_root_render_pass);
void DidSwapBuffersComplete(gpu::SwapBuffersCompleteParams params,
const gfx::Size& pixel_size);
void BufferPresented(const gfx::PresentationFeedback& feedback);
......@@ -203,9 +204,9 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
GpuVSyncCallback gpu_vsync_callback_;
bool is_displayed_as_overlay_ = false;
std::unique_ptr<base::WaitableEvent> reshape_waitable_event_;
gfx::Size size_;
gfx::ColorSpace color_space_;
bool is_hdr_ = false;
SkSurfaceCharacterization characterization_;
base::Optional<SkDeferredDisplayListRecorder> root_recorder_;
......
......@@ -10,7 +10,6 @@
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/optional.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h"
......@@ -831,25 +830,16 @@ SkiaOutputSurfaceImplOnGpu::~SkiaOutputSurfaceImplOnGpu() {
sync_point_client_state_->Destroy();
}
void SkiaOutputSurfaceImplOnGpu::Reshape(
const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
bool use_stencil,
gfx::OverlayTransform transform,
SkSurfaceCharacterization* characterization,
base::WaitableEvent* event) {
void SkiaOutputSurfaceImplOnGpu::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
bool use_stencil,
gfx::OverlayTransform transform) {
TRACE_EVENT0("viz", "SkiaOutputSurfaceImplOnGpu::Reshape");
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(gr_context());
base::ScopedClosureRunner scoped_runner;
if (event) {
scoped_runner.ReplaceClosure(
base::BindOnce(&base::WaitableEvent::Signal, base::Unretained(event)));
}
if (!MakeCurrent(!dependency_->IsOffscreen() /* need_fbo0 */))
return;
......@@ -860,14 +850,6 @@ void SkiaOutputSurfaceImplOnGpu::Reshape(
MarkContextLost();
return;
}
if (characterization) {
// Start a paint temporarily for getting sk surface characterization.
scoped_output_device_paint_.emplace(output_device_.get());
output_sk_surface()->characterize(characterization);
DCHECK(characterization->isValid());
scoped_output_device_paint_.reset();
}
}
bool SkiaOutputSurfaceImplOnGpu::FinishPaintCurrentFrame(
......@@ -1611,10 +1593,10 @@ bool SkiaOutputSurfaceImplOnGpu::InitializeForDawn() {
}
bool SkiaOutputSurfaceImplOnGpu::MakeCurrent(bool need_fbo0) {
if (!is_using_vulkan()) {
if (context_state_->context_lost())
return false;
if (context_state_->context_lost())
return false;
if (gpu_preferences_.gr_context_type == gpu::GrContextType::kGL) {
// Only make current with |gl_surface_|, if following operations will use
// fbo0.
if (!context_state_->MakeCurrent(need_fbo0 ? gl_surface_.get() : nullptr)) {
......
......@@ -37,10 +37,6 @@
class SkDeferredDisplayList;
namespace base {
class WaitableEvent;
}
namespace gfx {
class ColorSpace;
}
......@@ -126,9 +122,7 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
bool use_stencil,
gfx::OverlayTransform transform,
SkSurfaceCharacterization* characterization,
base::WaitableEvent* event);
gfx::OverlayTransform transform);
bool FinishPaintCurrentFrame(
std::unique_ptr<SkDeferredDisplayList> ddl,
std::unique_ptr<SkDeferredDisplayList> overdraw_ddl,
......
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