Commit c66a50d5 authored by Jonah Chin's avatar Jonah Chin Committed by Commit Bot

Make mailbox its own component

Mailbox is required in cc/paint for OOP-R canvas. This CL pulls mailbox
out of //gpu and into its own component.

This change also introduces a mailbox based DecodedDrawImage required
for OOPR-Canvas.

This is being done as part of the OOPR-Canvas2D project. For more info
about that project see the tracking bug here: crbug.com/1018894

Bug: 795884, 1031050
Change-Id: Ibf3930df8436a499f9b647b3a2da8cde65fa95be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2239292
Commit-Queue: Jonah Chin <jochin@microsoft.com>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779597}
parent c6e23216
......@@ -107,6 +107,7 @@ cc_component("paint") {
deps = [
"//base",
"//gpu/command_buffer/common:mailbox",
"//ui/gfx/animation",
"//ui/gfx/ipc/color",
]
......
......@@ -17,6 +17,14 @@ DecodedDrawImage::DecodedDrawImage(sk_sp<const SkImage> image,
filter_quality_(filter_quality),
is_budgeted_(is_budgeted) {}
DecodedDrawImage::DecodedDrawImage(const gpu::Mailbox& mailbox,
SkFilterQuality filter_quality)
: mailbox_(mailbox),
src_rect_offset_(SkSize::MakeEmpty()),
scale_adjustment_(SkSize::Make(1.f, 1.f)),
filter_quality_(filter_quality),
is_budgeted_(true) {}
DecodedDrawImage::DecodedDrawImage(
base::Optional<uint32_t> transfer_cache_entry_id,
const SkSize& src_rect_offset,
......
......@@ -10,6 +10,7 @@
#include "base/optional.h"
#include "cc/paint/paint_export.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "third_party/skia/include/core/SkFilterQuality.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkRefCnt.h"
......@@ -29,6 +30,7 @@ class CC_PAINT_EXPORT DecodedDrawImage {
const SkSize& scale_adjustment,
SkFilterQuality filter_quality,
bool is_budgeted);
DecodedDrawImage(const gpu::Mailbox& mailbox, SkFilterQuality filter_quality);
DecodedDrawImage(base::Optional<uint32_t> transfer_cache_entry_id,
const SkSize& src_rect_offset,
const SkSize& scale_adjustment,
......@@ -62,6 +64,7 @@ class CC_PAINT_EXPORT DecodedDrawImage {
private:
sk_sp<const SkImage> image_;
gpu::Mailbox mailbox_;
base::Optional<uint32_t> transfer_cache_entry_id_;
SkSize src_rect_offset_;
SkSize scale_adjustment_;
......
......@@ -118,6 +118,11 @@ const sk_sp<SkImage>& PaintImage::GetRasterSkImage() const {
return cached_sk_image_;
}
gpu::Mailbox PaintImage::GetMailbox() const {
DCHECK(texture_backing_);
return texture_backing_->GetMailbox();
}
PaintImage PaintImage::MakeSubset(const gfx::Rect& subset) const {
DCHECK(!subset.IsEmpty());
......@@ -293,6 +298,14 @@ SkAlphaType PaintImage::GetAlphaType() const {
return kUnknown_SkAlphaType;
}
bool PaintImage::IsTextureBacked() const {
if (texture_backing_)
return true;
if (cached_sk_image_)
return cached_sk_image_->isTextureBacked();
return false;
}
int PaintImage::width() const {
return paint_worklet_input_
? static_cast<int>(paint_worklet_input_->GetSize().width())
......
......@@ -14,6 +14,7 @@
#include "cc/paint/frame_metadata.h"
#include "cc/paint/image_animation_count.h"
#include "cc/paint/paint_export.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkYUVAIndex.h"
#include "third_party/skia/include/core/SkYUVASizeInfo.h"
......@@ -238,6 +239,7 @@ class CC_PAINT_EXPORT PaintImage {
Id stable_id() const { return id_; }
const sk_sp<SkImage>& GetSkImage() const;
gpu::Mailbox GetMailbox() const;
AnimationType animation_type() const { return animation_type_; }
CompletionState completion_state() const { return completion_state_; }
bool is_multipart() const { return is_multipart_; }
......@@ -260,9 +262,7 @@ class CC_PAINT_EXPORT PaintImage {
return paint_worklet_input_ ? false : GetSkImage()->isLazyGenerated();
}
bool IsPaintWorklet() const { return !!paint_worklet_input_; }
bool IsTextureBacked() const {
return paint_worklet_input_ ? false : GetSkImage()->isTextureBacked();
}
bool IsTextureBacked() const;
int width() const;
int height() const;
SkColorSpace* color_space() const {
......
......@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "cc/tiles/image_decode_cache.h"
#include "gpu/command_buffer/common/mailbox.h"
namespace cc {
namespace {
......@@ -57,10 +58,15 @@ ImageProvider::ScopedResult PlaybackImageProvider::GetRasterContent(
DrawImage adjusted_image(draw_image, 1.f, frame_index, target_color_space_);
if (!cache_->UseCacheForDrawImage(adjusted_image)) {
return ScopedResult(
DecodedDrawImage(paint_image.GetRasterSkImage(), SkSize::Make(0, 0),
SkSize::Make(1.f, 1.f), draw_image.filter_quality(),
true /* is_budgeted */));
if (settings_->use_oop_raster) {
return ScopedResult(DecodedDrawImage(paint_image.GetMailbox(),
draw_image.filter_quality()));
} else {
return ScopedResult(
DecodedDrawImage(paint_image.GetRasterSkImage(), SkSize::Make(0, 0),
SkSize::Make(1.f, 1.f), draw_image.filter_quality(),
true /* is_budgeted */));
}
}
auto decoded_draw_image = cache_->GetDecodedImageForDraw(adjusted_image);
......
......@@ -33,6 +33,10 @@ class CC_EXPORT PlaybackImageProvider : public ImageProvider {
// The frame index to use for the given image id. If no index is provided,
// the frame index provided in the PaintImage will be used.
base::flat_map<PaintImage::Id, size_t> image_to_current_frame_index;
// Indicates that the consumer of decoded images is paint serialization
// for OOP raster.
bool use_oop_raster = false;
};
// If no settings are provided, all images are skipped during rasterization.
......
......@@ -73,6 +73,11 @@ component("raster") {
public_deps = [ "//gpu/command_buffer/client:raster_sources" ]
}
component("mailbox") {
defines = [ "IS_GPU_MAILBOX_IMPL" ]
public_deps = [ "//gpu/command_buffer/common:mailbox_sources" ]
}
component("webgpu") {
public_deps = [ "//gpu/command_buffer/client:webgpu_sources" ]
}
......
......@@ -34,6 +34,14 @@ group("raster") {
}
}
group("mailbox") {
if (is_component_build) {
public_deps = [ "//gpu:mailbox" ]
} else {
public_deps = [ ":mailbox_sources" ]
}
}
group("webgpu") {
public_deps = [ ":webgpu_sources" ]
}
......@@ -68,8 +76,6 @@ jumbo_source_set("common_sources") {
"gpu_memory_buffer_support.h",
"id_allocator.cc",
"id_allocator.h",
"mailbox.cc",
"mailbox.h",
"mailbox_holder.cc",
"mailbox_holder.h",
"presentation_feedback_utils.cc",
......@@ -92,6 +98,7 @@ jumbo_source_set("common_sources") {
configs += [ "//gpu:gpu_implementation" ]
public_deps = [
":mailbox",
"//base/util/type_safety",
"//mojo/public/cpp/system",
"//ui/gfx:memory_buffer",
......@@ -105,6 +112,16 @@ jumbo_source_set("common_sources") {
configs += [ "//third_party/khronos:khronos_headers" ]
}
source_set("mailbox_sources") {
visibility = [ "//gpu/*" ]
defines = [ "IS_GPU_MAILBOX_IMPL" ]
sources = [
"mailbox.cc",
"mailbox.h",
]
deps = [ "//base" ]
}
source_set("gles2_sources") {
visibility = [ "//gpu/*" ]
......
......@@ -10,7 +10,7 @@
#include <string>
#include "gpu/gpu_export.h"
#include "base/component_export.h"
// From gl2/gl2ext.h.
#ifndef GL_MAILBOX_SIZE_CHROMIUM
......@@ -26,7 +26,7 @@ namespace gpu {
// name is valid.
// See src/gpu/GLES2/extensions/CHROMIUM/CHROMIUM_texture_mailbox.txt for more
// details.
struct GPU_EXPORT Mailbox {
struct COMPONENT_EXPORT(GPU_MAILBOX) Mailbox {
using Name = int8_t[GL_MAILBOX_SIZE_CHROMIUM];
Mailbox();
......
......@@ -50,7 +50,8 @@ class CanvasResourceProvider::CanvasImageProvider : public cc::ImageProvider {
cc::ImageDecodeCache* cache_f16,
const gfx::ColorSpace& target_color_space,
SkColorType target_color_type,
bool is_hardware_decode_cache);
bool is_hardware_decode_cache,
bool use_oop_raster);
~CanvasImageProvider() override = default;
// cc::ImageProvider implementation.
......@@ -66,7 +67,7 @@ class CanvasResourceProvider::CanvasImageProvider : public cc::ImageProvider {
bool is_hardware_decode_cache_;
bool cleanup_task_pending_ = false;
Vector<ScopedResult> locked_images_;
cc::PlaybackImageProvider playback_image_provider_n32_;
base::Optional<cc::PlaybackImageProvider> playback_image_provider_n32_;
base::Optional<cc::PlaybackImageProvider> playback_image_provider_f16_;
base::WeakPtrFactory<CanvasImageProvider> weak_factory_{this};
......@@ -199,10 +200,10 @@ class CanvasResourceProviderSharedImage : public CanvasResourceProvider {
nullptr /* resource_dispatcher */),
is_accelerated_(is_accelerated),
shared_image_usage_flags_(shared_image_usage_flags),
use_oop_rasterization_(ContextProviderWrapper()
->ContextProvider()
->GetCapabilities()
.supports_oop_raster) {
use_oop_rasterization_(is_accelerated && ContextProviderWrapper()
->ContextProvider()
->GetCapabilities()
.supports_oop_raster) {
resource_ = NewOrRecycledResource();
if (resource_)
EnsureWriteAccess();
......@@ -277,6 +278,8 @@ class CanvasResourceProviderSharedImage : public CanvasResourceProvider {
shared_image_usage_flags_);
}
bool UseOopRasterization() final { return use_oop_rasterization_; }
void NotifyTexParamsModified(const CanvasResource* resource) override {
if (!is_accelerated_ || use_oop_rasterization_)
return;
......@@ -906,17 +909,23 @@ CanvasResourceProvider::CanvasImageProvider::CanvasImageProvider(
cc::ImageDecodeCache* cache_f16,
const gfx::ColorSpace& target_color_space,
SkColorType canvas_color_type,
bool is_hardware_decode_cache)
: is_hardware_decode_cache_(is_hardware_decode_cache),
playback_image_provider_n32_(cache_n32,
target_color_space,
cc::PlaybackImageProvider::Settings()) {
bool is_hardware_decode_cache,
bool use_oop_raster)
: is_hardware_decode_cache_(is_hardware_decode_cache) {
base::Optional<cc::PlaybackImageProvider::Settings> settings =
cc::PlaybackImageProvider::Settings();
settings->use_oop_raster = use_oop_raster;
playback_image_provider_n32_.emplace(cache_n32, target_color_space,
std::move(settings));
// If the image provider may require to decode to half float instead of
// uint8, create a f16 PlaybackImageProvider with the passed cache.
if (canvas_color_type == kRGBA_F16_SkColorType) {
DCHECK(cache_f16);
settings = cc::PlaybackImageProvider::Settings();
settings->use_oop_raster = use_oop_raster;
playback_image_provider_f16_.emplace(cache_f16, target_color_space,
cc::PlaybackImageProvider::Settings());
std::move(settings));
}
}
......@@ -935,7 +944,7 @@ CanvasResourceProvider::CanvasImageProvider::GetRasterContent(
playback_image_provider_f16_->GetRasterContent(draw_image);
} else {
scoped_decoded_image =
playback_image_provider_n32_.GetRasterContent(draw_image);
playback_image_provider_n32_->GetRasterContent(draw_image);
}
// Holding onto locked images here is a performance optimization for the
......@@ -1054,7 +1063,8 @@ CanvasResourceProvider::GetOrCreateCanvasImageProvider() {
cache_f16 = ImageDecodeCacheF16();
canvas_image_provider_ = std::make_unique<CanvasImageProvider>(
ImageDecodeCacheRGBA8(), cache_f16, gfx::ColorSpace::CreateSRGB(),
color_params_.GetSkColorType(), use_hardware_decode_cache());
color_params_.GetSkColorType(), use_hardware_decode_cache(),
UseOopRasterization());
}
return canvas_image_provider_.get();
}
......@@ -1193,16 +1203,8 @@ bool CanvasResourceProvider::WritePixels(const SkImageInfo& orig_info,
void CanvasResourceProvider::Clear() {
// We don't have an SkCanvas in OOPR mode so we can't do the clear below, plus
// OOPR already clears the canvas in BeginRaster.
if (IsAccelerated()) {
if (!ContextProviderWrapper())
return;
if (ContextProviderWrapper()
->ContextProvider()
->GetCapabilities()
.supports_oop_raster) {
return;
}
if (UseOopRasterization()) {
return;
}
// Clear the background transparent or opaque, as required. This should only
......
......@@ -264,6 +264,7 @@ class PLATFORM_EXPORT CanvasResourceProvider
private:
virtual sk_sp<SkSurface> CreateSkSurface() const = 0;
virtual scoped_refptr<CanvasResource> CreateResource();
virtual bool UseOopRasterization() { return false; }
bool use_hardware_decode_cache() const {
return IsAccelerated() && context_provider_wrapper_;
}
......
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