Skip to content

Commit

Permalink
Skip draws in SkiaRenderer and RasterDecoder for tests
Browse files Browse the repository at this point in the history
Bug: 331688266
Change-Id: Iff2c0344bb93d18ddaf5bfe814ce8e39f8edd1ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5460163
Commit-Queue: Sunny Sachanandani <sunnyps@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1288419}
  • Loading branch information
phuang authored and Chromium LUCI CQ committed Apr 16, 2024
1 parent fce3416 commit 38a6280
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
Expand Up @@ -159,32 +159,48 @@ GetOrCreateGraphiteCacheController(skgpu::graphite::Recorder* recorder) {
} // namespace

SkiaOutputSurfaceImpl::ScopedPaint::ScopedPaint(
GrDeferredDisplayListRecorder* root_ddl_recorder)
: ddl_recorder_(root_ddl_recorder), canvas_(ddl_recorder_->getCanvas()) {}
GrDeferredDisplayListRecorder* root_ddl_recorder,
bool skip_draw_for_tests)
: ddl_recorder_(root_ddl_recorder), canvas_(ddl_recorder_->getCanvas()) {
Initialize(skip_draw_for_tests);
}

SkiaOutputSurfaceImpl::ScopedPaint::ScopedPaint(
const GrSurfaceCharacterization& characterization,
const gpu::Mailbox& mailbox)
const gpu::Mailbox& mailbox,
bool skip_draw_for_tests)
: mailbox_(mailbox) {
ddl_recorder_storage_.emplace(characterization);
ddl_recorder_ = &ddl_recorder_storage_.value();
canvas_ = ddl_recorder_->getCanvas();
Initialize(skip_draw_for_tests);
}

SkiaOutputSurfaceImpl::ScopedPaint::ScopedPaint(
skgpu::graphite::Recorder* recorder,
const SkImageInfo& image_info,
skgpu::graphite::TextureInfo texture_info,
const gpu::Mailbox& mailbox)
const gpu::Mailbox& mailbox,
bool skip_draw_for_tests)
: graphite_recorder_(recorder), mailbox_(mailbox) {
CHECK(graphite_recorder_);
canvas_ = graphite_recorder_->makeDeferredCanvas(image_info, texture_info);
Initialize(skip_draw_for_tests);
}

SkiaOutputSurfaceImpl::ScopedPaint::~ScopedPaint() {
CHECK(!canvas_);
}

void SkiaOutputSurfaceImpl::ScopedPaint::Initialize(bool skip_draw_for_tests) {
if (canvas_ && skip_draw_for_tests) {
auto image_info = canvas_->imageInfo();
no_draw_canvas_ = std::make_unique<SkNoDrawCanvas>(image_info.width(),
image_info.height());
canvas_ = no_draw_canvas_.get();
}
}

sk_sp<GrDeferredDisplayList> SkiaOutputSurfaceImpl::ScopedPaint::DetachDDL() {
canvas_ = nullptr;
return ddl_recorder_->detach();
Expand Down Expand Up @@ -284,7 +300,9 @@ SkiaOutputSurfaceImpl::SkiaOutputSurfaceImpl(
display_compositor_controller_(display_controller),
gpu_task_scheduler_(display_compositor_controller_->gpu_task_scheduler()),
is_using_raw_draw_(features::IsUsingRawDraw()),
is_raw_draw_using_msaa_(features::IsRawDrawUsingMSAA()) {
is_raw_draw_using_msaa_(features::IsRawDrawUsingMSAA()),
skip_draw_for_tests_(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGLDrawingForTests)) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (is_using_raw_draw_) {
auto* manager = dependency_->GetSharedImageManager();
Expand Down Expand Up @@ -460,10 +478,11 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintCurrentFrame() {
/*supports_multiplanar_rendering=*/false,
/*supports_multiplanar_copy=*/false);
CHECK(texture_info.isValid());
current_paint_.emplace(graphite_recorder_, image_info, texture_info);
current_paint_.emplace(graphite_recorder_, image_info, texture_info,
gpu::Mailbox(), skip_draw_for_tests_);
} else {
reset_ddl_recorder_on_swap_ = true;
current_paint_.emplace(&root_ddl_recorder_.value());
current_paint_.emplace(&root_ddl_recorder_.value(), skip_draw_for_tests_);
}
return current_paint_->canvas();
}
Expand Down Expand Up @@ -854,7 +873,7 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
return nullptr;
}
current_paint_.emplace(graphite_recorder_, image_info, texture_info,
mailbox);
mailbox, skip_draw_for_tests_);
} else {
GrSurfaceCharacterization characterization =
CreateGrSurfaceCharacterizationRenderPass(
Expand All @@ -864,7 +883,7 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
DLOG(ERROR) << "BeginPaintRenderPass: invalid GrSurfaceCharacterization";
return nullptr;
}
current_paint_.emplace(characterization, mailbox);
current_paint_.emplace(characterization, mailbox, skip_draw_for_tests_);
}

// We are going to overwrite the render pass when it is not for overlay, so we
Expand Down
16 changes: 13 additions & 3 deletions components/viz/service/display_embedder/skia_output_surface_impl.h
Expand Up @@ -36,6 +36,8 @@
#include "third_party/skia/include/private/chromium/GrSurfaceCharacterization.h"
#include "ui/gfx/presentation_feedback.h"

class SkNoDrawCanvas;

namespace gfx {
namespace mojom {
class DelegatedInkPointRenderer;
Expand Down Expand Up @@ -304,15 +306,18 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
class ScopedPaint {
public:
// Ganesh root surface
explicit ScopedPaint(GrDeferredDisplayListRecorder* root_ddl_recorder);
ScopedPaint(GrDeferredDisplayListRecorder* root_ddl_recorder,
bool skip_draw_for_tests);
// Ganesh render pass (root or non-root)
ScopedPaint(const GrSurfaceCharacterization& characterization,
const gpu::Mailbox& mailbox);
const gpu::Mailbox& mailbox,
bool skip_draw_for_tests);
// Graphite (root or non-root)
ScopedPaint(skgpu::graphite::Recorder* recorder,
const SkImageInfo& image_info,
skgpu::graphite::TextureInfo texture_info,
const gpu::Mailbox& mailbox = gpu::Mailbox());
const gpu::Mailbox& mailbox = gpu::Mailbox(),
bool skip_draw_for_tests = false);
~ScopedPaint();

// SkCanvas for the current paint, retrieved from the DDL recorder for
Expand All @@ -329,13 +334,17 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
std::unique_ptr<skgpu::graphite::Recording> SnapRecording();

private:
void Initialize(bool skip_draw_for_tests);

// This is the DDL recorder being used for current paint when using Ganesh.
raw_ptr<GrDeferredDisplayListRecorder> ddl_recorder_ = nullptr;
// If we need new recorder for this Paint (i.e. it's not root render pass),
// it's stored here
std::optional<GrDeferredDisplayListRecorder> ddl_recorder_storage_;
// Graphite recorder used for current paint.
raw_ptr<skgpu::graphite::Recorder> graphite_recorder_ = nullptr;
// No draw canvas for tests.
std::unique_ptr<SkNoDrawCanvas> no_draw_canvas_;
// SkCanvas for the current paint, retrieved from the DDL recorder for
// Ganesh, or from the Graphite recorder.
raw_ptr<SkCanvas> canvas_ = nullptr;
Expand Down Expand Up @@ -468,6 +477,7 @@ class VIZ_SERVICE_EXPORT SkiaOutputSurfaceImpl : public SkiaOutputSurface {
representation_factory_;
// The refresh interval from presentation feedback.
base::TimeDelta refresh_interval_;
bool skip_draw_for_tests_;

base::WeakPtr<SkiaOutputSurfaceImpl> weak_ptr_;
base::WeakPtrFactory<SkiaOutputSurfaceImpl> weak_ptr_factory_{this};
Expand Down
14 changes: 13 additions & 1 deletion gpu/command_buffer/service/raster_decoder.cc
Expand Up @@ -13,6 +13,7 @@
#include <vector>

#include "base/atomic_sequence_num.h"
#include "base/command_line.h"
#include "base/containers/flat_map.h"
#include "base/debug/crash_logging.h"
#include "base/functional/bind.h"
Expand Down Expand Up @@ -83,6 +84,7 @@
#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
#include "third_party/skia/include/gpu/graphite/Context.h"
#include "third_party/skia/include/private/chromium/GrPromiseImageTexture.h"
#include "third_party/skia/include/utils/SkNoDrawCanvas.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/geometry/skia_conversions.h"
Expand Down Expand Up @@ -889,6 +891,7 @@ class RasterDecoderImpl final : public RasterDecoder,
std::vector<GrBackendSemaphore> end_semaphores_;
std::unique_ptr<cc::ServicePaintCache> paint_cache_;

std::unique_ptr<SkNoDrawCanvas> no_draw_canvas_;
raw_ptr<SkCanvas> raster_canvas_ = nullptr;
std::vector<SkDiscardableHandleId> locked_handles_;

Expand Down Expand Up @@ -1015,6 +1018,10 @@ RasterDecoderImpl::RasterDecoderImpl(
is_raw_draw_enabled_(features::IsUsingRawDraw()) {
DCHECK(shared_context_state_);
shared_context_state_->AddContextLostObserver(this);
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
if (cmdline->HasSwitch(switches::kDisableGLDrawingForTests)) {
no_draw_canvas_ = std::make_unique<SkNoDrawCanvas>(0, 0);
}
}

RasterDecoderImpl::~RasterDecoderImpl() {
Expand Down Expand Up @@ -2977,7 +2984,12 @@ void RasterDecoderImpl::DoBeginRasterCHROMIUM(GLfloat r,
DCHECK(result);
}

raster_canvas_ = sk_surface_->getCanvas();
if (no_draw_canvas_) {
no_draw_canvas_->resetCanvas(sk_surface_->width(), sk_surface_->height());
raster_canvas_ = no_draw_canvas_.get();
} else {
raster_canvas_ = sk_surface_->getCanvas();
}

paint_op_shared_image_provider_ = std::make_unique<SharedImageProviderImpl>(
&shared_image_representation_factory_, shared_context_state_, sk_surface_,
Expand Down

0 comments on commit 38a6280

Please sign in to comment.