Commit 78ee2cc7 authored by kylechar's avatar kylechar Committed by Commit Bot

Add max_render_target_size plumbing for SkiaRenderer

SurfaceAggregator can enforce a maximum texture size but this was only
plumbed in for GLRenderer. Add this value to OutputSurface::Capabilities
and implement for both GLRenderer, with the value from
gpu::Capabilities, and SkiaRenderer, with the value from GrContext.

Also add an arbitrary limit for SoftwareRenderer. If we get an OOM while
allocating a RenderPass texture it will crash the GPU process, so
placing an upper limit will hopefully reduce OOM crashes.

Bug: 1116745, 1099158
Change-Id: Ie12dedeb2e64ce6b24859adc12a3d73d69c18c0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359152
Commit-Queue: kylechar <kylechar@chromium.org>
Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799149}
parent ad1f2107
......@@ -11,6 +11,7 @@
#include "components/viz/service/display/output_surface_client.h"
#include "components/viz/service/display/output_surface_frame.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "gpu/command_buffer/common/capabilities.h"
namespace android_webview {
......@@ -33,11 +34,13 @@ ParentOutputSurface::ParentOutputSurface(
scoped_refptr<AwGLSurface> gl_surface,
scoped_refptr<AwRenderThreadContextProvider> context_provider)
: viz::OutputSurface(std::move(context_provider)),
gl_surface_(std::move(gl_surface)) {}
ParentOutputSurface::~ParentOutputSurface() {
gl_surface_(std::move(gl_surface)) {
const auto& context_capabilities = context_provider_->ContextCapabilities();
capabilities_.max_render_target_size = context_capabilities.max_texture_size;
}
ParentOutputSurface::~ParentOutputSurface() = default;
void ParentOutputSurface::BindToClient(viz::OutputSurfaceClient* client) {
DCHECK(client);
DCHECK(!client_);
......
......@@ -571,13 +571,8 @@ void Display::InitializeRenderer(bool enable_shared_images) {
aggregator_->set_output_is_secure(output_is_secure_);
aggregator_->SetDisplayColorSpaces(display_color_spaces_);
// Consider adding a softare limit as well.
aggregator_->SetMaximumTextureSize(
(output_surface_ && output_surface_->context_provider())
? output_surface_->context_provider()
->ContextCapabilities()
.max_texture_size
: 0);
aggregator_->SetMaxRenderTargetSize(
output_surface_->capabilities().max_render_target_size);
}
bool Display::IsRootFrameMissing() const {
......
......@@ -108,6 +108,10 @@ class VIZ_SERVICE_EXPORT OutputSurface {
// SwapBuffersCompleteParams::frame_buffer_damage_area for every
// SwapBuffers complete callback.
bool damage_area_from_skia_output_device = false;
// This is the maximum size for RenderPass textures. No maximum size is
// enforced if zero.
int max_render_target_size = 0;
// The SkColorType and GrBackendFormat for non-HDR and HDR.
// TODO(penghuang): remove SkColorType and GrBackendFormat when
// OutputSurface uses the |format| passed to Reshape().
......
......@@ -573,9 +573,11 @@ void SurfaceAggregator::EmitSurfaceContent(
pass_id_remapper_.Remap(source.id, surface_id);
gfx::Rect output_rect = source.output_rect;
if (max_texture_size_ > 0) {
output_rect.set_width(std::min(output_rect.width(), max_texture_size_));
output_rect.set_height(std::min(output_rect.height(), max_texture_size_));
if (max_render_target_size_ > 0) {
output_rect.set_width(
std::min(output_rect.width(), max_render_target_size_));
output_rect.set_height(
std::min(output_rect.height(), max_render_target_size_));
}
copy_pass->SetAll(
remapped_pass_id, output_rect, output_rect,
......@@ -1831,9 +1833,9 @@ void SurfaceAggregator::SetDisplayColorSpaces(
display_color_spaces_ = display_color_spaces;
}
void SurfaceAggregator::SetMaximumTextureSize(int max_texture_size) {
DCHECK_GE(max_texture_size, 0);
max_texture_size_ = max_texture_size;
void SurfaceAggregator::SetMaxRenderTargetSize(int max_size) {
DCHECK_GE(max_size, 0);
max_render_target_size_ = max_size;
}
bool SurfaceAggregator::NotifySurfaceDamageAndCheckForDisplayDamage(
......
......@@ -81,7 +81,7 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
// to the output surface.
void SetDisplayColorSpaces(const gfx::DisplayColorSpaces& color_spaces);
void SetMaximumTextureSize(int max_texture_size);
void SetMaxRenderTargetSize(int max_size);
bool NotifySurfaceDamageAndCheckForDisplayDamage(const SurfaceId& surface_id);
......@@ -331,9 +331,9 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
// between the two will be added. This space must always be valid.
gfx::DisplayColorSpaces display_color_spaces_;
// Maximum texture size which if positive, will limit the size of render
// passes.
int max_texture_size_ = 0;
// Maximum texture size which if larger than zero, will limit the size of
// render passes.
int max_render_target_size_ = 0;
// The id for the final color conversion render pass.
RenderPassId color_conversion_render_pass_id_;
// The id for the optional render pass used to apply the display transform.
......
......@@ -50,6 +50,7 @@ GLOutputSurface::GLOutputSurface(
context_provider->GetGpuFeatureInfo()
.status_values[gpu::GPU_FEATURE_TYPE_ANDROID_SURFACE_CONTROL] ==
gpu::kGpuFeatureStatusEnabled;
capabilities_.max_render_target_size = context_capabilities.max_texture_size;
}
GLOutputSurface::~GLOutputSurface() {
......
......@@ -15,6 +15,7 @@
#include "components/viz/service/display/dc_layer_overlay.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "ui/gfx/gpu_fence.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/latency/latency_tracker.h"
......@@ -54,6 +55,7 @@ SkiaOutputDevice::ScopedPaint::~ScopedPaint() {
}
SkiaOutputDevice::SkiaOutputDevice(
GrContext* gr_context,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: did_swap_buffer_complete_callback_(
......@@ -61,7 +63,10 @@ SkiaOutputDevice::SkiaOutputDevice(
memory_type_tracker_(
std::make_unique<gpu::MemoryTypeTracker>(memory_tracker)),
latency_tracker_(std::make_unique<ui::LatencyTracker>()),
latency_tracker_runner_(CreateLatencyTracerRunner()) {}
latency_tracker_runner_(CreateLatencyTracerRunner()) {
DCHECK(gr_context);
capabilities_.max_render_target_size = gr_context->maxRenderTargetSize();
}
SkiaOutputDevice::~SkiaOutputDevice() {
if (latency_tracker_runner_)
......
......@@ -22,6 +22,7 @@
#include "third_party/skia/src/gpu/GrSemaphore.h"
#include "ui/gfx/swap_result.h"
class GrContext;
class SkSurface;
namespace base {
......@@ -76,6 +77,7 @@ class SkiaOutputDevice {
base::RepeatingCallback<void(gpu::SwapBuffersCompleteParams,
const gfx::Size& pixel_size)>;
SkiaOutputDevice(
GrContext* gr_context,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback);
virtual ~SkiaOutputDevice();
......
......@@ -29,7 +29,9 @@ SkiaOutputDeviceBufferQueue::SkiaOutputDeviceBufferQueue(
SkiaOutputSurfaceDependency* deps,
gpu::MemoryTracker* memory_tracker,
const DidSwapBufferCompleteCallback& did_swap_buffer_complete_callback)
: SkiaOutputDevice(memory_tracker, did_swap_buffer_complete_callback),
: SkiaOutputDevice(deps->GetSharedContextState()->gr_context(),
memory_tracker,
did_swap_buffer_complete_callback),
presenter_(std::move(presenter)),
dependency_(deps) {
capabilities_.uses_default_gl_framebuffer = false;
......
......@@ -4,6 +4,8 @@
#include "components/viz/service/display_embedder/skia_output_device_dawn.h"
#include <utility>
#include "base/check_op.h"
#include "base/notreached.h"
#include "components/viz/common/gpu/dawn_context_provider.h"
......@@ -33,7 +35,9 @@ SkiaOutputDeviceDawn::SkiaOutputDeviceDawn(
gfx::SurfaceOrigin origin,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: SkiaOutputDevice(memory_tracker, did_swap_buffer_complete_callback),
: SkiaOutputDevice(context_provider->GetGrContext(),
memory_tracker,
did_swap_buffer_complete_callback),
context_provider_(context_provider),
child_window_(widget) {
capabilities_.output_surface_origin = origin;
......
......@@ -5,6 +5,9 @@
#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_
#include <memory>
#include <vector>
#include "build/build_config.h"
#include "components/viz/service/display_embedder/skia_output_device.h"
#include "third_party/dawn/src/include/dawn/dawn_wsi.h"
......
......@@ -41,7 +41,8 @@ SkiaOutputDeviceGL::SkiaOutputDeviceGL(
scoped_refptr<gpu::gles2::FeatureInfo> feature_info,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: SkiaOutputDevice(memory_tracker,
: SkiaOutputDevice(context_state->gr_context(),
memory_tracker,
std::move(did_swap_buffer_complete_callback)),
mailbox_manager_(mailbox_manager),
representation_factory_(representation_factory),
......@@ -79,11 +80,12 @@ SkiaOutputDeviceGL::SkiaOutputDeviceGL(
context_state_->MakeCurrent(gl_surface_.get());
}
GrContext* gr_context = context_state_->gr_context();
gl::CurrentGL* current_gl = context_state_->context()->GetCurrentGL();
// Get alpha bits from the default frame buffer.
glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
context_state_->gr_context()->resetContext(kRenderTarget_GrGLBackendState);
gr_context->resetContext(kRenderTarget_GrGLBackendState);
const auto* version = current_gl->Version;
GLint alpha_bits = 0;
if (version->is_desktop_core_profile) {
......@@ -98,13 +100,11 @@ SkiaOutputDeviceGL::SkiaOutputDeviceGL(
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_.gr_backend_format = 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);
capabilities_.gr_backend_format_for_hdr = gr_context->defaultBackendFormat(
capabilities_.sk_color_type_for_hdr, GrRenderable::kYes);
}
SkiaOutputDeviceGL::~SkiaOutputDeviceGL() {
......
......@@ -25,7 +25,9 @@ SkiaOutputDeviceOffscreen::SkiaOutputDeviceOffscreen(
bool has_alpha,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: SkiaOutputDevice(memory_tracker, did_swap_buffer_complete_callback),
: SkiaOutputDevice(context_state->gr_context(),
memory_tracker,
did_swap_buffer_complete_callback),
context_state_(context_state),
has_alpha_(has_alpha) {
capabilities_.uses_default_gl_framebuffer = false;
......
......@@ -46,7 +46,9 @@ SkiaOutputDeviceVulkan::SkiaOutputDeviceVulkan(
gpu::SurfaceHandle surface_handle,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: SkiaOutputDevice(memory_tracker, did_swap_buffer_complete_callback),
: SkiaOutputDevice(context_provider->GetGrContext(),
memory_tracker,
did_swap_buffer_complete_callback),
context_provider_(context_provider),
surface_handle_(surface_handle) {}
......
......@@ -21,7 +21,8 @@ SkiaOutputDeviceWebView::SkiaOutputDeviceWebView(
scoped_refptr<gl::GLSurface> gl_surface,
gpu::MemoryTracker* memory_tracker,
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback)
: SkiaOutputDevice(memory_tracker,
: SkiaOutputDevice(context_state->gr_context(),
memory_tracker,
std::move(did_swap_buffer_complete_callback)),
context_state_(context_state),
gl_surface_(std::move(gl_surface)) {
......
......@@ -26,6 +26,10 @@ SoftwareOutputSurface::SoftwareOutputSurface(
std::unique_ptr<SoftwareOutputDevice> software_device)
: OutputSurface(std::move(software_device)) {
capabilities_.max_frames_pending = software_device_->MaxFramesPending();
// Arbitrary max texture size to help avoid OOM crashes. A 8192*8192 RGBA
// texture will require ~268mb of memory so we probably don't want to allow
// much bigger.
capabilities_.max_render_target_size = 8192;
}
SoftwareOutputSurface::~SoftwareOutputSurface() = default;
......
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