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 {
virtual ~SkiaOutputDevice();
// 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,
const gfx::ColorSpace& color_space,
bool has_alpha,
......
......@@ -327,7 +327,7 @@ void SkiaOutputDeviceBufferQueue::DoFinishSwapBuffers(
FinishSwapBuffers(result, size, latency_info);
}
void SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size,
bool SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......@@ -336,13 +336,14 @@ void SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size,
gl::ColorSpaceUtils::GetGLSurfaceColorSpace(color_space);
if (!gl_surface_->Resize(size, device_scale_factor, surface_color_space,
has_alpha)) {
LOG(FATAL) << "Failed to resize.";
// TODO(vasilyt): Handle the failure.
DLOG(ERROR) << "Failed to resize.";
return false;
}
color_space_ = color_space;
image_size_ = size;
FreeAllSurfaces();
return true;
}
SkSurface* SkiaOutputDeviceBufferQueue::BeginPaint() {
......
......@@ -38,7 +38,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputDeviceBufferQueue final
void PostSubBuffer(const gfx::Rect& rect,
BufferPresentedCallback feedback,
std::vector<ui::LatencyInfo> latency_info) override;
void Reshape(const gfx::Size& size,
bool Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......
......@@ -82,7 +82,7 @@ void SkiaOutputDeviceGL::Initialize(GrContext* gr_context,
SkiaOutputDeviceGL::~SkiaOutputDeviceGL() {}
void SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
bool SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......@@ -93,8 +93,8 @@ void SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
gl::ColorSpaceUtils::GetGLSurfaceColorSpace(color_space);
if (!gl_surface_->Resize(size, device_scale_factor, surface_color_space,
has_alpha)) {
LOG(FATAL) << "Failed to resize.";
// TODO(penghuang): Handle the failure.
DLOG(ERROR) << "Failed to resize.";
return false;
}
SkSurfaceProps surface_props =
SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType);
......@@ -112,6 +112,7 @@ void SkiaOutputDeviceGL::Reshape(const gfx::Size& size,
gr_context_, render_target, origin, color_type,
color_space.ToSkColorSpace(), &surface_props);
DCHECK(sk_surface_);
return true;
}
void SkiaOutputDeviceGL::SwapBuffers(
......
......@@ -53,7 +53,7 @@ class SkiaOutputDeviceGL final : public SkiaOutputDevice {
}
// SkiaOutputDevice implementation:
void Reshape(const gfx::Size& size,
bool Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......
......@@ -36,7 +36,7 @@ SkiaOutputDeviceOffscreen::~SkiaOutputDeviceOffscreen() {
DiscardBackbuffer();
}
void SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size,
bool SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......@@ -47,6 +47,7 @@ void SkiaOutputDeviceOffscreen::Reshape(const gfx::Size& size,
size_ = size;
sk_color_space_ = color_space.ToSkColorSpace();
EnsureBackbuffer();
return true;
}
void SkiaOutputDeviceOffscreen::SwapBuffers(
......
......@@ -25,7 +25,7 @@ class SkiaOutputDeviceOffscreen : public SkiaOutputDevice {
~SkiaOutputDeviceOffscreen() override;
// SkiaOutputDevice implementation:
void Reshape(const gfx::Size& size,
bool Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......
......@@ -41,7 +41,7 @@ SkiaOutputDeviceVulkan::~SkiaOutputDeviceVulkan() {
}
}
void SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size,
bool SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......@@ -65,6 +65,7 @@ void SkiaOutputDeviceVulkan::Reshape(const gfx::Size& size,
sk_surfaces_.resize(vulkan_surface_->swap_chain()->num_images());
sk_color_space_ = std::move(sk_color_space);
}
return true;
}
void SkiaOutputDeviceVulkan::SwapBuffers(
......
......@@ -31,7 +31,7 @@ class SkiaOutputDeviceVulkan final : public SkiaOutputDevice {
~SkiaOutputDeviceVulkan() override;
// SkiaOutputDevice implementation:
void Reshape(const gfx::Size& size,
bool Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......
......@@ -41,16 +41,19 @@ SkiaOutputDeviceX11::~SkiaOutputDeviceX11() {
XFreeGC(display_, gc_);
}
void SkiaOutputDeviceX11::Reshape(const gfx::Size& size,
bool SkiaOutputDeviceX11::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
gfx::OverlayTransform transform) {
SkiaOutputDeviceOffscreen::Reshape(size, device_scale_factor, color_space,
has_alpha, transform);
if (!SkiaOutputDeviceOffscreen::Reshape(size, device_scale_factor,
color_space, has_alpha, transform)) {
return false;
}
auto ii =
SkImageInfo::MakeN32(size.width(), size.height(), kOpaque_SkAlphaType);
pixels_.reserve(ii.computeMinByteSize());
return true;
}
void SkiaOutputDeviceX11::SwapBuffers(
......
......@@ -23,7 +23,7 @@ class SkiaOutputDeviceX11 final : public SkiaOutputDeviceOffscreen {
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback);
~SkiaOutputDeviceX11() override;
void Reshape(const gfx::Size& size,
bool Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
bool has_alpha,
......
......@@ -676,8 +676,11 @@ void SkiaOutputSurfaceImplOnGpu::Reshape(
size_ = size;
color_space_ = color_space;
output_device_->Reshape(size_, device_scale_factor, color_space, has_alpha,
transform);
if (!output_device_->Reshape(size_, device_scale_factor, color_space,
has_alpha, transform)) {
MarkContextLost();
return;
}
if (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