[go: nahoru, domu]

blob: 326c3a386b880b0d1ed18cac710d9e41f1d1881a [file] [log] [blame]
Avi Drissman3f7a9d82022-09-08 20:55:421// Copyright 2014 The Chromium Authors
reveman@chromium.orgb5641b92014-02-15 14:21:582// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
prashant.nb4d4f492016-04-29 12:51:285#include "cc/raster/gpu_raster_buffer_provider.h"
reveman@chromium.orgb5641b92014-02-15 14:21:586
avi02a4d172015-12-21 06:14:367#include <stdint.h>
8
ernstm69fedbd2014-09-18 01:23:419#include <algorithm>
Robert Phillipsdbb0b7d2020-07-29 16:07:4410#include <memory>
Mike Reedf7074ff2019-03-14 14:28:1611#include <utility>
Robert Phillipsdbb0b7d2020-07-29 16:07:4412#include <vector>
ernstm69fedbd2014-09-18 01:23:4113
Peng Huangacb64c02022-02-28 20:36:4414#include "base/bits.h"
Kalvin Leeae3ccb42022-04-28 14:18:2215#include "base/cxx17_backports.h"
Hans Wennborg66d784de2020-06-17 20:23:0316#include "base/logging.h"
Keishi Hattori0e45c022021-11-27 09:25:5217#include "base/memory/raw_ptr.h"
ericrke4027312016-06-30 00:12:4218#include "base/metrics/histogram_macros.h"
Khushal3c3873a2018-11-06 18:14:0119#include "base/rand_util.h"
Alexandr Ilin0443a8f2018-07-20 20:14:5020#include "base/trace_event/process_memory_dump.h"
ssid904ce3b2015-01-27 15:20:1621#include "base/trace_event/trace_event.h"
Yuta Hijikata173c7d62020-11-10 06:21:3722#include "build/chromeos_buildflags.h"
ericrkc7c9e3f2016-07-01 17:30:1623#include "cc/base/histograms.h"
Adrienne Walker436a7752017-08-28 23:33:0924#include "cc/paint/display_item_list.h"
enne5a9630362017-02-24 23:41:0325#include "cc/paint/paint_canvas.h"
Adrienne Walker436a7752017-08-28 23:33:0926#include "cc/paint/paint_recorder.h"
chrishtrac41ff92017-03-17 05:07:3027#include "cc/raster/raster_source.h"
danakj57baa772018-05-29 15:59:1428#include "components/viz/client/client_resource_provider.h"
Maksim Sisov4dc61a12022-03-23 15:09:2629#include "components/viz/common/features.h"
Victor Miura29b7ea3d2017-12-19 20:23:5930#include "components/viz/common/gpu/context_provider.h"
31#include "components/viz/common/gpu/raster_context_provider.h"
danakjaf3170e2018-02-09 17:31:5832#include "gpu/GLES2/gl2extchromium.h"
ericrk7f6a27f2017-01-31 22:34:3233#include "gpu/command_buffer/client/context_support.h"
Victor Miura3a4ad4f82017-12-13 06:03:4534#include "gpu/command_buffer/client/raster_interface.h"
Antoine Labour6283c792018-09-27 16:59:2835#include "gpu/command_buffer/client/shared_image_interface.h"
Antoine Labour6283c792018-09-27 16:59:2836#include "gpu/command_buffer/common/shared_image_trace_utils.h"
37#include "gpu/command_buffer/common/shared_image_usage.h"
Ian Preste598eece2020-10-19 23:31:0238#include "skia/ext/legacy_display_globals.h"
hendrikw04cea972014-09-23 20:50:5339#include "third_party/skia/include/core/SkPictureRecorder.h"
reveman47560ab2014-09-18 19:39:2140#include "third_party/skia/include/core/SkSurface.h"
Peng Huang5f3d4352021-11-23 17:51:2941#include "ui/base/ui_base_features.h"
Adrienne Walker436a7752017-08-28 23:33:0942#include "ui/gfx/geometry/axis_transform2d.h"
Khushal49836ab2018-07-25 02:08:4543#include "url/gurl.h"
reveman@chromium.orgb5641b92014-02-15 14:21:5844
45namespace cc {
vmiura78b69282015-02-14 00:01:1746
danakjaf3170e2018-02-09 17:31:5847// Subclass for InUsePoolResource that holds ownership of a gpu-rastered backing
48// and does cleanup of the backing when destroyed.
49class GpuRasterBufferProvider::GpuRasterBacking
50 : public ResourcePool::GpuBacking {
51 public:
52 ~GpuRasterBacking() override {
Antoine Labour6283c792018-09-27 16:59:2853 if (mailbox.IsZero())
54 return;
55 auto* sii = worker_context_provider->SharedImageInterface();
danakjaf3170e2018-02-09 17:31:5856 if (returned_sync_token.HasData())
Antoine Labour6283c792018-09-27 16:59:2857 sii->DestroySharedImage(returned_sync_token, mailbox);
58 else if (mailbox_sync_token.HasData())
59 sii->DestroySharedImage(mailbox_sync_token, mailbox);
danakjaf3170e2018-02-09 17:31:5860 }
61
Alexandr Ilin0443a8f2018-07-20 20:14:5062 void OnMemoryDump(
63 base::trace_event::ProcessMemoryDump* pmd,
64 const base::trace_event::MemoryAllocatorDumpGuid& buffer_dump_guid,
65 uint64_t tracing_process_id,
66 int importance) const override {
Antoine Labour6283c792018-09-27 16:59:2867 if (mailbox.IsZero())
Alexandr Ilin0443a8f2018-07-20 20:14:5068 return;
69
Antoine Labour6283c792018-09-27 16:59:2870 auto tracing_guid = gpu::GetSharedImageGUIDForTracing(mailbox);
71 pmd->CreateSharedGlobalAllocatorDump(tracing_guid);
72 pmd->AddOwnershipEdge(buffer_dump_guid, tracing_guid, importance);
danakjaf3170e2018-02-09 17:31:5873 }
danakjaf3170e2018-02-09 17:31:5874
Antoine Labour6283c792018-09-27 16:59:2875 // The ContextProvider used to clean up the mailbox
Keishi Hattori0e45c022021-11-27 09:25:5276 raw_ptr<viz::RasterContextProvider> worker_context_provider = nullptr;
danakjaf3170e2018-02-09 17:31:5877};
78
sunnyps5d6ff0d02016-06-28 00:40:1179GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl(
80 GpuRasterBufferProvider* client,
danakjaf3170e2018-02-09 17:31:5881 const ResourcePool::InUsePoolResource& in_use_resource,
82 GpuRasterBacking* backing,
Andres Calderon Jaramillob6b26dc2019-11-25 21:24:0583 bool resource_has_previous_content,
Andres Calderon Jaramillo5057f232019-11-29 23:05:4884 bool depends_on_at_raster_decodes,
85 bool depends_on_hardware_accelerated_jpeg_candidates,
86 bool depends_on_hardware_accelerated_webp_candidates)
sunnyps5d6ff0d02016-06-28 00:40:1187 : client_(client),
danakjaf3170e2018-02-09 17:31:5888 backing_(backing),
89 resource_size_(in_use_resource.size()),
90 resource_format_(in_use_resource.format()),
91 color_space_(in_use_resource.color_space()),
92 resource_has_previous_content_(resource_has_previous_content),
Andres Calderon Jaramillob6b26dc2019-11-25 21:24:0593 depends_on_at_raster_decodes_(depends_on_at_raster_decodes),
Andres Calderon Jaramillo5057f232019-11-29 23:05:4894 depends_on_hardware_accelerated_jpeg_candidates_(
95 depends_on_hardware_accelerated_jpeg_candidates),
96 depends_on_hardware_accelerated_webp_candidates_(
Peng Huang253518e2022-02-09 14:08:3297 depends_on_hardware_accelerated_webp_candidates) {
Yuta Hijikata173c7d62020-11-10 06:21:3798#if BUILDFLAG(IS_CHROMEOS_ASH)
kylechar14f8d7c02022-01-31 21:41:3299 // Only do this in Chrome OS because:
Andres Calderon Jaramillo01d329552019-08-23 17:14:30100 // 1) We will use this timestamp to measure raster scheduling delay and we
101 // only need to collect that data to assess the impact of hardware
kylechar14f8d7c02022-01-31 21:41:32102 // acceleration of image decodes which works only on Chrome OS.
Andres Calderon Jaramillo01d329552019-08-23 17:14:30103 // 2) We use CLOCK_MONOTONIC in that OS to get timestamps, so we can assert
104 // certain assumptions.
kylechar14f8d7c02022-01-31 21:41:32105 creation_time_ = base::TimeTicks::Now();
Andres Calderon Jaramillo01d329552019-08-23 17:14:30106#endif
107}
sunnyps5d6ff0d02016-06-28 00:40:11108
Peng Huang253518e2022-02-09 14:08:32109GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() = default;
sunnyps5d6ff0d02016-06-28 00:40:11110
111void GpuRasterBufferProvider::RasterBufferImpl::Playback(
112 const RasterSource* raster_source,
113 const gfx::Rect& raster_full_rect,
114 const gfx::Rect& raster_dirty_rect,
115 uint64_t new_content_id,
trchen178ac912017-04-04 10:11:10116 const gfx::AxisTransform2d& transform,
Khushal49836ab2018-07-25 02:08:45117 const RasterSource::PlaybackSettings& playback_settings,
118 const GURL& url) {
sunnyps5d6ff0d02016-06-28 00:40:11119 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback");
Peng Huangb79a26452022-02-07 15:53:51120
121 viz::RasterContextProvider::ScopedRasterContextLock scoped_context(
122 client_->worker_context_provider_, url.possibly_invalid_spec().c_str());
123 gpu::raster::RasterInterface* ri =
124 client_->worker_context_provider_->RasterInterface();
125 PlaybackOnWorkerThread(raster_source, raster_full_rect, raster_dirty_rect,
126 new_content_id, transform, playback_settings, url);
Peng Huang253518e2022-02-09 14:08:32127
128 backing_->mailbox_sync_token =
Peng Huangb79a26452022-02-07 15:53:51129 viz::ClientResourceProvider::GenerateSyncTokenHelper(ri);
Peng Huang253518e2022-02-09 14:08:32130 backing_->returned_sync_token = gpu::SyncToken();
sunnyps5d6ff0d02016-06-28 00:40:11131}
132
Francois Dorayaffe0912020-06-30 20:29:21133bool GpuRasterBufferProvider::RasterBufferImpl::
134 SupportsBackgroundThreadPriority() const {
135 return true;
136}
137
prashant.nb4d4f492016-04-29 12:51:28138GpuRasterBufferProvider::GpuRasterBufferProvider(
Xu Xing32549162017-07-17 22:25:43139 viz::ContextProvider* compositor_context_provider,
Victor Miura29b7ea3d2017-12-19 20:23:59140 viz::RasterContextProvider* worker_context_provider,
danakjaf3170e2018-02-09 17:31:58141 bool use_gpu_memory_buffer_resources,
danakja32578c2018-04-25 21:18:36142 viz::ResourceFormat tile_format,
Eric Karl247f09c2018-03-15 02:06:36143 const gfx::Size& max_tile_size,
Eric Karla6ff8862018-04-16 20:21:06144 bool unpremultiply_and_dither_low_bit_depth_tiles,
Chris Blumee4d90f2cf2020-11-20 03:50:57145 RasterQueryQueue* const pending_raster_queries,
Aaron Krajeski6392a86f2019-07-18 13:40:47146 float raster_metric_probability)
danakj0de0c95a2016-05-25 01:42:49147 : compositor_context_provider_(compositor_context_provider),
sunnyps5d6ff0d02016-06-28 00:40:11148 worker_context_provider_(worker_context_provider),
danakjaf3170e2018-02-09 17:31:58149 use_gpu_memory_buffer_resources_(use_gpu_memory_buffer_resources),
danakja32578c2018-04-25 21:18:36150 tile_format_(tile_format),
Eric Karl247f09c2018-03-15 02:06:36151 max_tile_size_(max_tile_size),
Chris Blumee4d90f2cf2020-11-20 03:50:57152 pending_raster_queries_(pending_raster_queries),
Benoit Lize3a2c58f92022-07-05 10:40:44153 raster_metric_probability_(raster_metric_probability),
Peng Huang5017b272021-12-09 17:47:46154 is_using_raw_draw_(features::IsUsingRawDraw()) {
Chris Blumee4d90f2cf2020-11-20 03:50:57155 DCHECK(pending_raster_queries);
sunnyps5d6ff0d02016-06-28 00:40:11156 DCHECK(compositor_context_provider);
157 DCHECK(worker_context_provider);
danakj0de0c95a2016-05-25 01:42:49158}
reveman@chromium.orgb5641b92014-02-15 14:21:58159
kylechar14f8d7c02022-01-31 21:41:32160GpuRasterBufferProvider::~GpuRasterBufferProvider() = default;
reveman@chromium.orgb5641b92014-02-15 14:21:58161
prashant.nb4d4f492016-04-29 12:51:28162std::unique_ptr<RasterBuffer> GpuRasterBufferProvider::AcquireBufferForRaster(
danakj4e871d82018-01-18 21:56:57163 const ResourcePool::InUsePoolResource& resource,
danakj510822aa2015-06-01 20:23:02164 uint64_t resource_content_id,
Andres Calderon Jaramillob6b26dc2019-11-25 21:24:05165 uint64_t previous_content_id,
Andres Calderon Jaramillo5057f232019-11-29 23:05:48166 bool depends_on_at_raster_decodes,
167 bool depends_on_hardware_accelerated_jpeg_candidates,
168 bool depends_on_hardware_accelerated_webp_candidates) {
danakjaf3170e2018-02-09 17:31:58169 if (!resource.gpu_backing()) {
170 auto backing = std::make_unique<GpuRasterBacking>();
Antoine Labour6283c792018-09-27 16:59:28171 backing->worker_context_provider = worker_context_provider_;
Jonathan Backere29d0232018-10-01 21:59:15172 backing->InitOverlayCandidateAndTextureTarget(
173 resource.format(), compositor_context_provider_->ContextCapabilities(),
174 use_gpu_memory_buffer_resources_);
Peng Huanga2a92fe2022-02-08 22:41:30175 backing->is_using_raw_draw =
176 !backing->overlay_candidate && is_using_raw_draw_;
danakjaf3170e2018-02-09 17:31:58177 resource.set_gpu_backing(std::move(backing));
178 }
179 GpuRasterBacking* backing =
180 static_cast<GpuRasterBacking*>(resource.gpu_backing());
sunnyps5d6ff0d02016-06-28 00:40:11181 bool resource_has_previous_content =
182 resource_content_id && resource_content_id == previous_content_id;
Andres Calderon Jaramillo5057f232019-11-29 23:05:48183 return std::make_unique<RasterBufferImpl>(
184 this, resource, backing, resource_has_previous_content,
185 depends_on_at_raster_decodes,
186 depends_on_hardware_accelerated_jpeg_candidates,
187 depends_on_hardware_accelerated_webp_candidates);
reveman@chromium.orgb5641b92014-02-15 14:21:58188}
189
Sunny Sachanandani5f5419e22017-05-12 20:35:30190void GpuRasterBufferProvider::Flush() {
Victor Miuraff6488612017-12-21 04:16:15191 compositor_context_provider_->ContextSupport()->FlushPendingWork();
Sunny Sachanandani5f5419e22017-05-12 20:35:30192}
193
danakja32578c2018-04-25 21:18:36194viz::ResourceFormat GpuRasterBufferProvider::GetResourceFormat() const {
195 return tile_format_;
prashant.nb4d4f492016-04-29 12:51:28196}
197
danakja32578c2018-04-25 21:18:36198bool GpuRasterBufferProvider::IsResourcePremultiplied() const {
199 return !ShouldUnpremultiplyAndDitherResource(GetResourceFormat());
Eric Karl247f09c2018-03-15 02:06:36200}
201
ericrk7f6a27f2017-01-31 22:34:32202bool GpuRasterBufferProvider::IsResourceReadyToDraw(
danakj4e871d82018-01-18 21:56:57203 const ResourcePool::InUsePoolResource& resource) const {
danakjaf3170e2018-02-09 17:31:58204 const gpu::SyncToken& sync_token = resource.gpu_backing()->mailbox_sync_token;
205 // This SyncToken() should have been set by calling OrderingBarrier() before
206 // calling this.
207 DCHECK(sync_token.HasData());
ericrk7f6a27f2017-01-31 22:34:32208
sunnyps74996292017-03-15 02:35:48209 // IsSyncTokenSignaled is thread-safe, no need for worker context lock.
210 return worker_context_provider_->ContextSupport()->IsSyncTokenSignaled(
ericrk7f6a27f2017-01-31 22:34:32211 sync_token);
212}
213
Khushalec3ba5dc2019-11-04 22:30:21214bool GpuRasterBufferProvider::CanPartialRasterIntoProvidedResource() const {
215 return true;
216}
217
ericrk7f6a27f2017-01-31 22:34:32218uint64_t GpuRasterBufferProvider::SetReadyToDrawCallback(
danakj4e871d82018-01-18 21:56:57219 const std::vector<const ResourcePool::InUsePoolResource*>& resources,
kylechar4bb144d2019-01-11 20:42:07220 base::OnceClosure callback,
ericrk7f6a27f2017-01-31 22:34:32221 uint64_t pending_callback_id) const {
danakjaf3170e2018-02-09 17:31:58222 gpu::SyncToken latest_sync_token;
223 for (const auto* in_use : resources) {
224 const gpu::SyncToken& sync_token =
225 in_use->gpu_backing()->mailbox_sync_token;
226 if (sync_token.release_count() > latest_sync_token.release_count())
227 latest_sync_token = sync_token;
228 }
229 uint64_t callback_id = latest_sync_token.release_count();
ericrk7f6a27f2017-01-31 22:34:32230 DCHECK_NE(callback_id, 0u);
231
232 // If the callback is different from the one the caller is already waiting on,
sunnyps31c92fe2017-02-10 23:46:55233 // pass the callback through to SignalSyncToken. Otherwise the request is
ericrk7f6a27f2017-01-31 22:34:32234 // redundant.
235 if (callback_id != pending_callback_id) {
danakjaf3170e2018-02-09 17:31:58236 // Use the compositor context because we want this callback on the
237 // compositor thread.
238 compositor_context_provider_->ContextSupport()->SignalSyncToken(
kylechar4bb144d2019-01-11 20:42:07239 latest_sync_token, std::move(callback));
ericrk7f6a27f2017-01-31 22:34:32240 }
241
242 return callback_id;
243}
244
kylechar14f8d7c02022-01-31 21:41:32245void GpuRasterBufferProvider::Shutdown() {}
sunnyps5d6ff0d02016-06-28 00:40:11246
Peng Huangb79a26452022-02-07 15:53:51247void GpuRasterBufferProvider::RasterBufferImpl::PlaybackOnWorkerThread(
sunnyps5d6ff0d02016-06-28 00:40:11248 const RasterSource* raster_source,
249 const gfx::Rect& raster_full_rect,
250 const gfx::Rect& raster_dirty_rect,
251 uint64_t new_content_id,
trchen178ac912017-04-04 10:11:10252 const gfx::AxisTransform2d& transform,
Khushal49836ab2018-07-25 02:08:45253 const RasterSource::PlaybackSettings& playback_settings,
Peng Huangb79a26452022-02-07 15:53:51254 const GURL& url) {
Chris Blumee4d90f2cf2020-11-20 03:50:57255 RasterQuery query;
Andres Calderon Jaramillo5057f232019-11-29 23:05:48256 query.depends_on_hardware_accelerated_jpeg_candidates =
Peng Huangb79a26452022-02-07 15:53:51257 depends_on_hardware_accelerated_jpeg_candidates_;
Andres Calderon Jaramillo5057f232019-11-29 23:05:48258 query.depends_on_hardware_accelerated_webp_candidates =
Peng Huangb79a26452022-02-07 15:53:51259 depends_on_hardware_accelerated_webp_candidates_;
260 PlaybackOnWorkerThreadInternal(raster_source, raster_full_rect,
261 raster_dirty_rect, new_content_id, transform,
262 playback_settings, url, &query);
Khushal5d4e0962018-10-18 18:04:07263
Andres Calderon Jaramillo01d329552019-08-23 17:14:30264 if (query.raster_duration_query_id) {
265 if (query.raster_start_query_id)
Peng Huangb79a26452022-02-07 15:53:51266 query.raster_buffer_creation_time = creation_time_;
Andres Calderon Jaramillo01d329552019-08-23 17:14:30267
Khushal5d4e0962018-10-18 18:04:07268 // Note that it is important to scope the raster context lock to
Chris Blumee4d90f2cf2020-11-20 03:50:57269 // PlaybackOnWorkerThreadInternal and release it before calling this
270 // function to avoid a deadlock in
271 // RasterQueryQueue::CheckRasterFinishedQueries which acquires the raster
272 // context lock while holding a lock used in the function.
Peng Huangb79a26452022-02-07 15:53:51273 client_->pending_raster_queries_->Append(std::move(query));
Khushal5d4e0962018-10-18 18:04:07274 }
Khushal5d4e0962018-10-18 18:04:07275}
276
Peng Huangb79a26452022-02-07 15:53:51277void GpuRasterBufferProvider::RasterBufferImpl::PlaybackOnWorkerThreadInternal(
Khushal5d4e0962018-10-18 18:04:07278 const RasterSource* raster_source,
279 const gfx::Rect& raster_full_rect,
280 const gfx::Rect& raster_dirty_rect,
281 uint64_t new_content_id,
282 const gfx::AxisTransform2d& transform,
283 const RasterSource::PlaybackSettings& playback_settings,
284 const GURL& url,
Chris Blumee4d90f2cf2020-11-20 03:50:57285 RasterQuery* query) {
Peng Huangb79a26452022-02-07 15:53:51286 gpu::raster::RasterInterface* ri =
287 client_->worker_context_provider_->RasterInterface();
Victor Miura3a4ad4f82017-12-13 06:03:45288 DCHECK(ri);
sunnyps5d6ff0d02016-06-28 00:40:11289
Benoit Lize3a2c58f92022-07-05 10:40:44290 const bool measure_raster_metric = client_->metrics_subsampler_.ShouldSample(
291 client_->raster_metric_probability_);
Khushale898b992018-10-19 22:25:16292
Adrienne Walker436a7752017-08-28 23:33:09293 gfx::Rect playback_rect = raster_full_rect;
Peng Huangb79a26452022-02-07 15:53:51294 if (resource_has_previous_content_) {
Adrienne Walker436a7752017-08-28 23:33:09295 playback_rect.Intersect(raster_dirty_rect);
296 }
297 DCHECK(!playback_rect.IsEmpty())
298 << "Why are we rastering a tile that's not dirty?";
299
Khushale898b992018-10-19 22:25:16300 if (measure_raster_metric) {
Yuta Hijikata173c7d62020-11-10 06:21:37301#if BUILDFLAG(IS_CHROMEOS_ASH)
Andres Calderon Jaramillo01d329552019-08-23 17:14:30302 // Use a query to detect when the GPU side is ready to start issuing raster
303 // work to the driver. We will use the resulting timestamp to measure raster
kylechar14f8d7c02022-01-31 21:41:32304 // scheduling delay. We only care about this in Chrome OS because we will
305 // use this timestamp to measure raster scheduling delay and we only need to
306 // collect that data to assess the impact of hardware acceleration of image
307 // decodes which work only in Chrome OS. Furthermore, we don't count raster
308 // work that depends on at-raster image decodes. This is because we want the
309 // delay to always include image decoding and uploading time, and at-raster
310 // decodes should be relatively rare.
Peng Huangb79a26452022-02-07 15:53:51311 if (!depends_on_at_raster_decodes_) {
Andres Calderon Jaramillo01d329552019-08-23 17:14:30312 ri->GenQueriesEXT(1, &query->raster_start_query_id);
313 DCHECK_GT(query->raster_start_query_id, 0u);
314 ri->QueryCounterEXT(query->raster_start_query_id,
315 GL_COMMANDS_ISSUED_TIMESTAMP_CHROMIUM);
316 }
Peng Huangb79a26452022-02-07 15:53:51317#else
318 std::ignore = depends_on_at_raster_decodes_;
Andres Calderon Jaramillo01d329552019-08-23 17:14:30319#endif
Andres Calderon Jaramillob805fa82019-08-24 05:58:19320
321 // Use a query to time the GPU side work for rasterizing this tile.
322 ri->GenQueriesEXT(1, &query->raster_duration_query_id);
323 DCHECK_GT(query->raster_duration_query_id, 0u);
324 ri->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM,
325 query->raster_duration_query_id);
Khushale898b992018-10-19 22:25:16326 }
Khushalcd8fbb772018-10-16 22:46:14327
328 {
Anton Bikineev1b060a72021-05-14 23:15:34329 absl::optional<base::ElapsedTimer> timer;
Khushale898b992018-10-19 22:25:16330 if (measure_raster_metric)
331 timer.emplace();
Peng Huangb79a26452022-02-07 15:53:51332 RasterizeSource(raster_source, raster_full_rect, playback_rect, transform,
333 playback_settings);
Andres Calderon Jaramillo01d329552019-08-23 17:14:30334 if (measure_raster_metric) {
335 query->worker_raster_duration = timer->Elapsed();
336 ri->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
337 }
Adrienne Walker436a7752017-08-28 23:33:09338 }
Peng Huangb79a26452022-02-07 15:53:51339}
sunnyps5d6ff0d02016-06-28 00:40:11340
Peng Huangb79a26452022-02-07 15:53:51341void GpuRasterBufferProvider::RasterBufferImpl::RasterizeSource(
342 const RasterSource* raster_source,
343 const gfx::Rect& raster_full_rect,
344 const gfx::Rect& playback_rect,
345 const gfx::AxisTransform2d& transform,
346 const RasterSource::PlaybackSettings& playback_settings) {
347 gpu::raster::RasterInterface* ri =
348 client_->worker_context_provider_->RasterInterface();
349 bool mailbox_needs_clear = false;
Peng Huang253518e2022-02-09 14:08:32350 if (backing_->mailbox.IsZero()) {
351 DCHECK(!backing_->returned_sync_token.HasData());
Peng Huangb79a26452022-02-07 15:53:51352 auto* sii = client_->worker_context_provider_->SharedImageInterface();
353 uint32_t flags = gpu::SHARED_IMAGE_USAGE_DISPLAY |
354 gpu::SHARED_IMAGE_USAGE_RASTER |
355 gpu::SHARED_IMAGE_USAGE_OOP_RASTERIZATION;
Peng Huang253518e2022-02-09 14:08:32356 if (backing_->overlay_candidate) {
Peng Huangb79a26452022-02-07 15:53:51357 flags |= gpu::SHARED_IMAGE_USAGE_SCANOUT;
Maksim Sisov4dc61a12022-03-23 15:09:26358 if (features::IsDelegatedCompositingEnabled())
359 flags |= gpu::SHARED_IMAGE_USAGE_RASTER_DELEGATED_COMPOSITING;
Peng Huangb79a26452022-02-07 15:53:51360 } else if (client_->is_using_raw_draw_) {
361 flags |= gpu::SHARED_IMAGE_USAGE_RAW_DRAW;
362 }
Peng Huang253518e2022-02-09 14:08:32363 backing_->mailbox =
Peng Huangb79a26452022-02-07 15:53:51364 sii->CreateSharedImage(resource_format_, resource_size_, color_space_,
365 kTopLeft_GrSurfaceOrigin, kPremul_SkAlphaType,
366 flags, gpu::kNullSurfaceHandle);
367 mailbox_needs_clear = true;
368 ri->WaitSyncTokenCHROMIUM(sii->GenUnverifiedSyncToken().GetConstData());
369 } else {
Peng Huang253518e2022-02-09 14:08:32370 ri->WaitSyncTokenCHROMIUM(backing_->returned_sync_token.GetConstData());
Peng Huangb79a26452022-02-07 15:53:51371 }
372
373 // Assume legacy MSAA if sample count is positive.
374 gpu::raster::MsaaMode msaa_mode = playback_settings.msaa_sample_count > 0
375 ? gpu::raster::kMSAA
376 : gpu::raster::kNoMSAA;
Peng Huangacb64c02022-02-28 20:36:44377 // msaa_sample_count should be 1, 2, 4, 8, 16, 32, 64,
378 // and log2(msaa_sample_count) should be [0,6].
379 // If playback_settings.msaa_sample_count <= 0, the MSAA is not used. It is
380 // equivalent to MSAA sample count 1.
381 uint32_t sample_count =
Kalvin Leeae3ccb42022-04-28 14:18:22382 base::clamp(playback_settings.msaa_sample_count, 1, 64);
Peng Huangacb64c02022-02-28 20:36:44383 UMA_HISTOGRAM_CUSTOM_COUNTS("Gpu.Rasterization.Raster.MSAASampleCountLog2",
384 base::bits::Log2Floor(sample_count), 0, 7, 7);
Peng Huangb79a26452022-02-07 15:53:51385 // With Raw Draw, the framebuffer will be the rasterization target. It cannot
386 // support LCD text, so disable LCD text for Raw Draw backings.
387 // TODO(penghuang): remove it when GrSlug can be serialized.
388 bool is_raw_draw_backing =
Peng Huang253518e2022-02-09 14:08:32389 client_->is_using_raw_draw_ && !backing_->overlay_candidate;
Peng Huangb79a26452022-02-07 15:53:51390 bool use_lcd_text = playback_settings.use_lcd_text && !is_raw_draw_backing;
Aaron Krajeskid7d51a52022-05-25 13:29:09391
Peng Huang5ff70dff2022-03-03 19:55:11392 ri->BeginRasterCHROMIUM(
Aaron Krajeskid7d51a52022-05-25 13:29:09393 raster_source->background_color(), mailbox_needs_clear,
Peng Huang5ff70dff2022-03-03 19:55:11394 playback_settings.msaa_sample_count, msaa_mode, use_lcd_text,
395 playback_settings.visible, color_space_, backing_->mailbox.name);
Aaron Krajeskid7d51a52022-05-25 13:29:09396
Peng Huangb79a26452022-02-07 15:53:51397 gfx::Vector2dF recording_to_raster_scale = transform.scale();
398 recording_to_raster_scale.Scale(1 / raster_source->recording_scale_factor());
399 gfx::Size content_size = raster_source->GetContentSize(transform.scale());
400
401 // TODO(enne): could skip the clear on new textures, as the service side has
402 // to do that anyway. resource_has_previous_content implies that the texture
403 // is not new, but the reverse does not hold, so more plumbing is needed.
404 ri->RasterCHROMIUM(
405 raster_source->GetDisplayItemList().get(),
406 playback_settings.image_provider, content_size, raster_full_rect,
407 playback_rect, transform.translation(), recording_to_raster_scale,
408 raster_source->requires_clear(),
409 const_cast<RasterSource*>(raster_source)->max_op_size_hint());
Peng Huangd11f24a2022-02-18 01:52:37410 UMA_HISTOGRAM_COUNTS_1000(
411 "Gpu.Rasterization.Raster.NumPaintOps",
412 raster_source->GetDisplayItemList()->num_paint_ops());
Peng Huang2248ef62022-02-22 16:18:25413 UMA_HISTOGRAM_COUNTS_100(
Yotam Hacohen29bd2b22022-06-10 18:25:45414 "Gpu.Rasterization.Raster.NumSlowPathsUpToMinForMSAA",
415 raster_source->GetDisplayItemList()->num_slow_paths_up_to_min_for_MSAA());
Peng Huangb79a26452022-02-07 15:53:51416 ri->EndRasterCHROMIUM();
417
418 // TODO(ericrk): Handle unpremultiply+dither for 4444 cases.
419 // https://crbug.com/789153
sunnyps5d6ff0d02016-06-28 00:40:11420}
prashant.nb4d4f492016-04-29 12:51:28421
Eric Karla6ff8862018-04-16 20:21:06422bool GpuRasterBufferProvider::ShouldUnpremultiplyAndDitherResource(
423 viz::ResourceFormat format) const {
Khushal8a168082020-11-21 01:29:34424 // TODO(crbug.com/1151490): Re-enable for OOPR.
425 return false;
Eric Karla6ff8862018-04-16 20:21:06426}
427
reveman@chromium.orgb5641b92014-02-15 14:21:58428} // namespace cc