Skip to content

Commit

Permalink
RawDraw: use MSAA for output surface
Browse files Browse the repository at this point in the history
Without MSAA, skia may use slow path for AA. It may regress performance,
so use MSAA for the output surface with RawDraw. To reduce the scope,
this CL only uses MSAA on Linux with SkiaOutputOutputDeviceGL and
SkiaOutputDeviceVulkan.

This CL change SkiaOutputSurfaceImplOnGpu::Reshape() to take
SkSurfaceCharacterization param. It contains the all related surface
infos (size, colorType, colorSpace, sampleCount, etc). And all
SkiaOutputDevice implementations can create SkSurface based on the
given SkSurfaceCharacterization.

Bug: 1301316
Change-Id: I56f4f490e82538303b3c35583b53a11a66c8cbce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3488719
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#983396}
  • Loading branch information
phuang authored and Chromium LUCI CQ committed Mar 21, 2022
1 parent 96ddd5f commit 10e8c5b
Show file tree
Hide file tree
Showing 30 changed files with 319 additions and 234 deletions.
48 changes: 48 additions & 0 deletions components/viz/common/resources/resource_format_utils.cc
Expand Up @@ -624,4 +624,52 @@ WGPUTextureFormat ToWGPUFormat(ResourceFormat format) {
return static_cast<WGPUTextureFormat>(ToDawnFormat(format));
}

size_t AlphaBitsForSkColorType(SkColorType color_type) {
switch (color_type) {
case kAlpha_8_SkColorType:
return 8;
case kRGB_565_SkColorType:
return 0;
case kARGB_4444_SkColorType:
return 4;
case kRGBA_8888_SkColorType:
return 8;
case kRGB_888x_SkColorType:
return 0;
case kBGRA_8888_SkColorType:
return 8;
case kRGBA_1010102_SkColorType:
case kBGRA_1010102_SkColorType:
return 2;
case kRGB_101010x_SkColorType:
case kBGR_101010x_SkColorType:
case kGray_8_SkColorType:
return 0;
case kRGBA_F16Norm_SkColorType:
case kRGBA_F16_SkColorType:
return 16;
case kRGBA_F32_SkColorType:
return 32;
case kR8G8_unorm_SkColorType:
return 0;
case kA16_float_SkColorType:
return 16;
case kR16G16_float_SkColorType:
return 0;
case kA16_unorm_SkColorType:
return 16;
case kR16G16_unorm_SkColorType:
return 0;
case kR16G16B16A16_unorm_SkColorType:
return 16;
case kSRGBA_8888_SkColorType:
return 8;
case kR8_unorm_SkColorType:
return 0;
case kUnknown_SkColorType:
default:
return 0;
}
}

} // namespace viz
3 changes: 3 additions & 0 deletions components/viz/common/resources/resource_format_utils.h
Expand Up @@ -84,6 +84,9 @@ ToWGPUFormat(ResourceFormat format);
VIZ_RESOURCE_FORMAT_EXPORT unsigned int ToMTLPixelFormat(ResourceFormat format);
#endif

VIZ_RESOURCE_FORMAT_EXPORT size_t
AlphaBitsForSkColorType(SkColorType color_type);

} // namespace viz

#endif // COMPONENTS_VIZ_COMMON_RESOURCES_RESOURCE_FORMAT_UTILS_H_
6 changes: 2 additions & 4 deletions components/viz/service/display_embedder/output_presenter.cc
Expand Up @@ -46,7 +46,7 @@ bool OutputPresenter::Image::Initialize(
return true;
}

void OutputPresenter::Image::BeginWriteSkia() {
void OutputPresenter::Image::BeginWriteSkia(int sample_count) {
DCHECK(!scoped_skia_write_access_);
DCHECK(!GetPresentCount());
DCHECK(end_semaphores_.empty());
Expand All @@ -56,10 +56,8 @@ void OutputPresenter::Image::BeginWriteSkia() {

// Buffer queue is internal to GPU proc and handles texture initialization,
// so allow uncleared access.
// TODO(vasilyt): Props and MSAA
scoped_skia_write_access_ = skia_representation_->BeginScopedWriteAccess(
/*final_msaa_count=*/1, surface_props, &begin_semaphores,
&end_semaphores_,
sample_count, surface_props, &begin_semaphores, &end_semaphores_,
gpu::SharedImageRepresentation::AllowUnclearedAccess::kYes);
DCHECK(scoped_skia_write_access_);
if (!begin_semaphores.empty()) {
Expand Down
7 changes: 3 additions & 4 deletions components/viz/service/display_embedder/output_presenter.h
Expand Up @@ -47,7 +47,7 @@ class VIZ_SERVICE_EXPORT OutputPresenter {
return skia_representation_.get();
}

void BeginWriteSkia();
void BeginWriteSkia(int sample_count);
SkSurface* sk_surface();
std::vector<GrBackendSemaphore> TakeEndWriteSkiaSemaphores();
void EndWriteSkia(bool force_flush = false);
Expand Down Expand Up @@ -80,10 +80,9 @@ class VIZ_SERVICE_EXPORT OutputPresenter {

virtual void InitializeCapabilities(
OutputSurface::Capabilities* capabilities) = 0;
virtual bool Reshape(const gfx::Size& size,
float device_scale_factor,
virtual bool Reshape(const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
float device_scale_factor,
gfx::OverlayTransform transform) = 0;
virtual std::vector<std::unique_ptr<Image>> AllocateImages(
gfx::ColorSpace color_space,
Expand Down
Expand Up @@ -221,12 +221,12 @@ void OutputPresenterFuchsia::InitializeCapabilities(
kRGBA_8888_SkColorType;
}

bool OutputPresenterFuchsia::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
gfx::OverlayTransform transform) {
frame_size_ = size;
bool OutputPresenterFuchsia::Reshape(
const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
float device_scale_factor,
gfx::OverlayTransform transform) {
frame_size_ = gfx::SkISizeToSize(characterization.dimensions());
return true;
}

Expand Down
Expand Up @@ -37,10 +37,9 @@ class VIZ_SERVICE_EXPORT OutputPresenterFuchsia : public OutputPresenter {

// OutputPresenter implementation:
void InitializeCapabilities(OutputSurface::Capabilities* capabilities) final;
bool Reshape(const gfx::Size& size,
float device_scale_factor,
bool Reshape(const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
float device_scale_factor,
gfx::OverlayTransform transform) final;
std::vector<std::unique_ptr<Image>> AllocateImages(
gfx::ColorSpace color_space,
Expand Down
18 changes: 10 additions & 8 deletions components/viz/service/display_embedder/output_presenter_gl.cc
Expand Up @@ -266,14 +266,16 @@ void OutputPresenterGL::InitializeCapabilities(
kRGBA_F16_SkColorType;
}

bool OutputPresenterGL::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
gfx::OverlayTransform transform) {
image_format_ = GetResourceFormat(format);
return gl_surface_->Resize(size, device_scale_factor, color_space,
gfx::AlphaBitsForBufferFormat(format));
bool OutputPresenterGL::Reshape(
const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
float device_scale_factor,
gfx::OverlayTransform transform) {
gfx::Size size = gfx::SkISizeToSize(characterization.dimensions());
image_format_ = SkColorTypeToResourceFormat(characterization.colorType());
return gl_surface_->Resize(
size, device_scale_factor, color_space,
!!AlphaBitsForSkColorType(characterization.colorType()));
}

std::vector<std::unique_ptr<OutputPresenter::Image>>
Expand Down
5 changes: 2 additions & 3 deletions components/viz/service/display_embedder/output_presenter_gl.h
Expand Up @@ -43,10 +43,9 @@ class VIZ_SERVICE_EXPORT OutputPresenterGL : public OutputPresenter {

// OutputPresenter implementation:
void InitializeCapabilities(OutputSurface::Capabilities* capabilities) final;
bool Reshape(const gfx::Size& size,
float device_scale_factor,
bool Reshape(const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
float device_scale_factor,
gfx::OverlayTransform transform) final;
std::vector<std::unique_ptr<Image>> AllocateImages(
gfx::ColorSpace color_space,
Expand Down
6 changes: 2 additions & 4 deletions components/viz/service/display_embedder/skia_output_device.h
Expand Up @@ -31,7 +31,6 @@ class SequencedTaskRunner;
}

namespace gfx {
class ColorSpace;
class Rect;
class Size;
struct PresentationFeedback;
Expand Down Expand Up @@ -114,10 +113,9 @@ class SkiaOutputDevice {
bool allocate_frame_buffer);

// Changes the size of draw surface and invalidates it's contents.
virtual bool Reshape(const gfx::Size& size,
float device_scale_factor,
virtual bool Reshape(const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
float device_scale_factor,
gfx::OverlayTransform transform) = 0;

// Submit the GrContext and run |callback| after. Note most but not all
Expand Down
Expand Up @@ -24,6 +24,7 @@
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/command_buffer/service/shared_image_factory.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/skia_utils.h"
#include "gpu/config/gpu_finch_features.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
Expand Down Expand Up @@ -227,7 +228,7 @@ void SkiaOutputDeviceBufferQueue::PageFlipComplete(
if (!available_images_.front()->sk_surface()) {
// BeginWriteSkia() may alter GL's state.
context_state_->set_need_context_state_reset(true);
available_images_.front()->BeginWriteSkia();
available_images_.front()->BeginWriteSkia(sample_count_);
}
}
}
Expand Down Expand Up @@ -320,9 +321,9 @@ const gpu::Mailbox SkiaOutputDeviceBufferQueue::GetImageMailboxForColor(
solid_color =
presenter_->AllocateSingleImage(color_space_, gfx::Size(4, 4));
}
solid_color->BeginWriteSkia();
solid_color->BeginWriteSkia(/*sample_count=*/1);
solid_color->sk_surface()->getCanvas()->clear(color);
solid_color->EndWriteSkia(/*force_flush*/ true);
solid_color->EndWriteSkia(/*force_flush=*/true);
}
DCHECK(solid_color);
auto image_mailbox = solid_color->skia_representation()->mailbox();
Expand Down Expand Up @@ -640,13 +641,13 @@ gfx::Size SkiaOutputDeviceBufferQueue::GetSwapBuffersSize() {
}
}

bool SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size,
float device_scale_factor,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
gfx::OverlayTransform transform) {
bool SkiaOutputDeviceBufferQueue::Reshape(
const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
float device_scale_factor,
gfx::OverlayTransform transform) {
DCHECK(pending_overlay_mailboxes_.empty());
if (!presenter_->Reshape(size, device_scale_factor, color_space, format,
if (!presenter_->Reshape(characterization, color_space, device_scale_factor,
transform)) {
LOG(ERROR) << "Failed to resize.";
CheckForLoopFailuresBufferQueue();
Expand All @@ -656,11 +657,12 @@ bool SkiaOutputDeviceBufferQueue::Reshape(const gfx::Size& size,
}

overlay_transform_ = transform;

gfx::Size size = gfx::SkISizeToSize(characterization.dimensions());
if (color_space_ == color_space && image_size_ == size)
return true;
color_space_ = color_space;
image_size_ = size;
sample_count_ = characterization.sampleCount();

bool success = RecreateImages();
if (!success) {
Expand Down Expand Up @@ -738,7 +740,7 @@ SkSurface* SkiaOutputDeviceBufferQueue::BeginPaint(
}

if (!current_image_->sk_surface())
current_image_->BeginWriteSkia();
current_image_->BeginWriteSkia(sample_count_);
*end_semaphores = current_image_->TakeEndWriteSkiaSemaphores();
return current_image_->sk_surface();
}
Expand Down
Expand Up @@ -50,10 +50,9 @@ class VIZ_SERVICE_EXPORT SkiaOutputDeviceBufferQueue : public SkiaOutputDevice {
OutputSurfaceFrame frame) override;
void CommitOverlayPlanes(BufferPresentedCallback feedback,
OutputSurfaceFrame frame) override;
bool Reshape(const gfx::Size& size,
float device_scale_factor,
bool Reshape(const SkSurfaceCharacterization& characterization,
const gfx::ColorSpace& color_space,
gfx::BufferFormat format,
float device_scale_factor,
gfx::OverlayTransform transform) override;
SkSurface* BeginPaint(
bool allocate_frame_buffer,
Expand Down Expand Up @@ -103,6 +102,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputDeviceBufferQueue : public SkiaOutputDevice {
// Format of images
gfx::ColorSpace color_space_;
gfx::Size image_size_;
int sample_count_ = 1;
gfx::OverlayTransform overlay_transform_ = gfx::OVERLAY_TRANSFORM_NONE;

// All allocated images.
Expand Down

0 comments on commit 10e8c5b

Please sign in to comment.