Commit 57ca0503 authored by Jonathan Backer's avatar Jonathan Backer Committed by Commit Bot

SkiaRenderer: Lose context if cannot resize surface

Copies logic from GLRenderer with InProcCommandBuffer:
https://cs.chromium.org/chromium/src/gpu/command_buffer/service/gles2_cmd_decoder.cc?rcl=04fbda1c2420a137a9f85889084a166f8a66b5d9&l=5866

Bug: 1012472
Change-Id: Iaca1be33e548c8987a06729a3571dbb2aed9c04d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1867191Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: Jonathan Backer <backer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707412}
parent c55db0da
...@@ -72,7 +72,7 @@ class SkiaOutputDevice { ...@@ -72,7 +72,7 @@ class SkiaOutputDevice {
virtual ~SkiaOutputDevice(); virtual ~SkiaOutputDevice();
// Changes the size of draw surface and invalidates it's contents. // Changes the size of draw surface and invalidates it's contents.
virtual void Reshape(const gfx::Size& size, virtual bool Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
......
...@@ -327,7 +327,7 @@ void SkiaOutputDeviceBufferQueue::DoFinishSwapBuffers( ...@@ -327,7 +327,7 @@ void SkiaOutputDeviceBufferQueue::DoFinishSwapBuffers(
FinishSwapBuffers(result, size, latency_info); FinishSwapBuffers(result, size, latency_info);
} }
void SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size, bool SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
...@@ -336,13 +336,14 @@ void SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size, ...@@ -336,13 +336,14 @@ void SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size,
gl::ColorSpaceUtils::GetGLSurfaceColorSpace(color_space); gl::ColorSpaceUtils::GetGLSurfaceColorSpace(color_space);
if (!gl_surface_->Resize(size, device_scale_factor, surface_color_space, if (!gl_surface_->Resize(size, device_scale_factor, surface_color_space,
has_alpha)) { has_alpha)) {
LOG(FATAL) << "Failed to resize."; DLOG(ERROR) << "Failed to resize.";
// TODO(vasilyt): Handle the failure. return false;
} }
color_space_ = color_space; color_space_ = color_space;
image_size_ = size; image_size_ = size;
FreeAllSurfaces(); FreeAllSurfaces();
return true;
} }
SkSurface* SkiaOutputDeviceBufferQueue::BeginPaint() { SkSurface* SkiaOutputDeviceBufferQueue::BeginPaint() {
......
...@@ -38,7 +38,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputDeviceBufferQueue final ...@@ -38,7 +38,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputDeviceBufferQueue final
void PostSubBuffer(const gfx::Rect& rect, void PostSubBuffer(const gfx::Rect& rect,
BufferPresentedCallback feedback, BufferPresentedCallback feedback,
std::vector<ui::LatencyInfo> latency_info) override; std::vector<ui::LatencyInfo> latency_info) override;
void Reshape(const gfx::Size& size, bool Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
......
...@@ -82,7 +82,7 @@ void SkiaOutputDeviceGL::Initialize(GrContext* gr_context, ...@@ -82,7 +82,7 @@ void SkiaOutputDeviceGL::Initialize(GrContext* gr_context,
SkiaOutputDeviceGL::~SkiaOutputDeviceGL() {} SkiaOutputDeviceGL::~SkiaOutputDeviceGL() {}
void SkiaOutputDeviceGL::Reshape(const gfx::Size& size, bool SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
...@@ -93,8 +93,8 @@ void SkiaOutputDeviceGL::Reshape(const gfx::Size& size, ...@@ -93,8 +93,8 @@ void SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
gl::ColorSpaceUtils::GetGLSurfaceColorSpace(color_space); gl::ColorSpaceUtils::GetGLSurfaceColorSpace(color_space);
if (!gl_surface_->Resize(size, device_scale_factor, surface_color_space, if (!gl_surface_->Resize(size, device_scale_factor, surface_color_space,
has_alpha)) { has_alpha)) {
LOG(FATAL) << "Failed to resize."; DLOG(ERROR) << "Failed to resize.";
// TODO(penghuang): Handle the failure. return false;
} }
SkSurfaceProps surface_props = SkSurfaceProps surface_props =
SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType);
...@@ -112,6 +112,7 @@ void SkiaOutputDeviceGL::Reshape(const gfx::Size& size, ...@@ -112,6 +112,7 @@ void SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
gr_context_, render_target, origin, color_type, gr_context_, render_target, origin, color_type,
color_space.ToSkColorSpace(), &surface_props); color_space.ToSkColorSpace(), &surface_props);
DCHECK(sk_surface_); DCHECK(sk_surface_);
return true;
} }
void SkiaOutputDeviceGL::SwapBuffers( void SkiaOutputDeviceGL::SwapBuffers(
......
...@@ -53,7 +53,7 @@ class SkiaOutputDeviceGL final : public SkiaOutputDevice { ...@@ -53,7 +53,7 @@ class SkiaOutputDeviceGL final : public SkiaOutputDevice {
} }
// SkiaOutputDevice implementation: // SkiaOutputDevice implementation:
void Reshape(const gfx::Size& size, bool Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
......
...@@ -36,7 +36,7 @@ SkiaOutputDeviceOffscreen::~SkiaOutputDeviceOffscreen() { ...@@ -36,7 +36,7 @@ SkiaOutputDeviceOffscreen::~SkiaOutputDeviceOffscreen() {
DiscardBackbuffer(); DiscardBackbuffer();
} }
void SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size, bool SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
...@@ -47,6 +47,7 @@ void SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size, ...@@ -47,6 +47,7 @@ void SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size,
size_ = size; size_ = size;
sk_color_space_ = color_space.ToSkColorSpace(); sk_color_space_ = color_space.ToSkColorSpace();
EnsureBackbuffer(); EnsureBackbuffer();
return true;
} }
void SkiaOutputDeviceOffscreen::SwapBuffers( void SkiaOutputDeviceOffscreen::SwapBuffers(
......
...@@ -25,7 +25,7 @@ class SkiaOutputDeviceOffscreen : public SkiaOutputDevice { ...@@ -25,7 +25,7 @@ class SkiaOutputDeviceOffscreen : public SkiaOutputDevice {
~SkiaOutputDeviceOffscreen() override; ~SkiaOutputDeviceOffscreen() override;
// SkiaOutputDevice implementation: // SkiaOutputDevice implementation:
void Reshape(const gfx::Size& size, bool Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
......
...@@ -41,7 +41,7 @@ SkiaOutputDeviceVulkan::~SkiaOutputDeviceVulkan() { ...@@ -41,7 +41,7 @@ SkiaOutputDeviceVulkan::~SkiaOutputDeviceVulkan() {
} }
} }
void SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size, bool SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
...@@ -65,6 +65,7 @@ void SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size, ...@@ -65,6 +65,7 @@ void SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size,
sk_surfaces_.resize(vulkan_surface_->swap_chain()->num_images()); sk_surfaces_.resize(vulkan_surface_->swap_chain()->num_images());
sk_color_space_ = std::move(sk_color_space); sk_color_space_ = std::move(sk_color_space);
} }
return true;
} }
void SkiaOutputDeviceVulkan::SwapBuffers( void SkiaOutputDeviceVulkan::SwapBuffers(
......
...@@ -31,7 +31,7 @@ class SkiaOutputDeviceVulkan final : public SkiaOutputDevice { ...@@ -31,7 +31,7 @@ class SkiaOutputDeviceVulkan final : public SkiaOutputDevice {
~SkiaOutputDeviceVulkan() override; ~SkiaOutputDeviceVulkan() override;
// SkiaOutputDevice implementation: // SkiaOutputDevice implementation:
void Reshape(const gfx::Size& size, bool Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
......
...@@ -41,16 +41,19 @@ SkiaOutputDeviceX11::~SkiaOutputDeviceX11() { ...@@ -41,16 +41,19 @@ SkiaOutputDeviceX11::~SkiaOutputDeviceX11() {
XFreeGC(display_, gc_); XFreeGC(display_, gc_);
} }
void SkiaOutputDeviceX11::Reshape(const gfx::Size& size, bool SkiaOutputDeviceX11::Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
gfx::OverlayTransform transform) { gfx::OverlayTransform transform) {
SkiaOutputDeviceOffscreen::Reshape(size, device_scale_factor, color_space, if (!SkiaOutputDeviceOffscreen::Reshape(size, device_scale_factor,
has_alpha, transform); color_space, has_alpha, transform)) {
return false;
}
auto ii = auto ii =
SkImageInfo::MakeN32(size.width(), size.height(), kOpaque_SkAlphaType); SkImageInfo::MakeN32(size.width(), size.height(), kOpaque_SkAlphaType);
pixels_.reserve(ii.computeMinByteSize()); pixels_.reserve(ii.computeMinByteSize());
return true;
} }
void SkiaOutputDeviceX11::SwapBuffers( void SkiaOutputDeviceX11::SwapBuffers(
......
...@@ -23,7 +23,7 @@ class SkiaOutputDeviceX11 final : public SkiaOutputDeviceOffscreen { ...@@ -23,7 +23,7 @@ class SkiaOutputDeviceX11 final : public SkiaOutputDeviceOffscreen {
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback); DidSwapBufferCompleteCallback did_swap_buffer_complete_callback);
~SkiaOutputDeviceX11() override; ~SkiaOutputDeviceX11() override;
void Reshape(const gfx::Size& size, bool Reshape(const gfx::Size& size,
float device_scale_factor, float device_scale_factor,
const gfx::ColorSpace& color_space, const gfx::ColorSpace& color_space,
bool has_alpha, bool has_alpha,
......
...@@ -676,8 +676,11 @@ void SkiaOutputSurfaceImplOnGpu::Reshape( ...@@ -676,8 +676,11 @@ void SkiaOutputSurfaceImplOnGpu::Reshape(
size_ = size; size_ = size;
color_space_ = color_space; color_space_ = color_space;
output_device_->Reshape(size_, device_scale_factor, color_space, has_alpha, if (!output_device_->Reshape(size_, device_scale_factor, color_space,
transform); has_alpha, transform)) {
MarkContextLost();
return;
}
if (characterization) { if (characterization) {
// Start a paint temporarily for getting sk surface characterization. // Start a paint temporarily for getting sk surface characterization.
......
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