blob: 7fa39d8135b556e074b11149a4f8c5979df17e15 [file] [log] [blame]
Avi Drissman05dfbc822022-09-13 21:25:341// Copyright 2017 The Chromium Authors
Jonathan Backer7f90dfb662017-12-18 16:52:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "gpu/command_buffer/service/raster_decoder.h"
6
Jonathan Backer7471b2782018-01-25 18:14:197#include <stdint.h>
8
Jonathan Backer0cd1c4322018-04-17 16:57:109#include <algorithm>
10#include <memory>
Jonathan Backer7471b2782018-01-25 18:14:1911#include <string>
Antoine Labourb9f903b2019-02-04 18:06:5712#include <utility>
Jonathan Backer6307cee92018-04-25 19:53:4313#include <vector>
Jonathan Backer7471b2782018-01-25 18:14:1914
Khushal996e9912018-07-13 08:31:0015#include "base/atomic_sequence_num.h"
Peng Huangcb2042092018-12-04 13:42:3416#include "base/containers/flat_map.h"
Christopher Camerond5698f682018-12-11 00:59:2017#include "base/debug/crash_logging.h"
Avi Drissman93a273dd2023-01-11 00:38:2718#include "base/functional/bind.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0419#include "base/logging.h"
Keishi Hattori0e45c022021-11-27 09:25:5220#include "base/memory/raw_ptr.h"
Jonathan Backer7471b2782018-01-25 18:14:1921#include "base/memory/ref_counted.h"
22#include "base/memory/weak_ptr.h"
Scott Violet86dc643d2023-04-07 17:57:2423#include "base/metrics/histogram_functions.h"
Nathan Zabriskie49128932021-07-08 20:00:3124#include "base/numerics/checked_math.h"
Peng Huang7bb7db4b2021-06-16 15:30:0225#include "base/time/time.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0426#include "base/trace_event/trace_event.h"
Jonathan Backer10821a82018-04-04 23:56:0327#include "build/build_config.h"
Khushal33205a72018-11-08 10:12:2928#include "cc/paint/paint_cache.h"
Xianzhu Wange6d732e92022-12-08 17:27:5229#include "cc/paint/paint_op.h"
Jonathan Backer0cd1c4322018-04-17 16:57:1030#include "cc/paint/paint_op_buffer.h"
Lei Zhangd35969c72021-05-20 20:58:3331#include "cc/paint/transfer_cache_deserialize_helper.h"
Jonathan Backer0cd1c4322018-04-17 16:57:1032#include "cc/paint/transfer_cache_entry.h"
Jonathan Backera07c4a9e2018-03-21 15:13:1633#include "components/viz/common/resources/resource_format_utils.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0434#include "gpu/command_buffer/common/capabilities.h"
Jonathan Backer7471b2782018-01-25 18:14:1935#include "gpu/command_buffer/common/command_buffer_id.h"
36#include "gpu/command_buffer/common/constants.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0437#include "gpu/command_buffer/common/context_result.h"
Jonathan Backer7471b2782018-01-25 18:14:1938#include "gpu/command_buffer/common/debug_marker_manager.h"
Jonathan Backera07c4a9e2018-03-21 15:13:1639#include "gpu/command_buffer/common/mailbox.h"
Jonathan Backer7471b2782018-01-25 18:14:1940#include "gpu/command_buffer/common/raster_cmd_format.h"
41#include "gpu/command_buffer/common/raster_cmd_ids.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0442#include "gpu/command_buffer/common/sync_token.h"
Jonathan Backer4f9ee5fb2018-04-25 14:03:3843#include "gpu/command_buffer/service/command_buffer_service.h"
Jonathan Backer7471b2782018-01-25 18:14:1944#include "gpu/command_buffer/service/context_state.h"
Saifuddin Hitawalaa4eb4642023-01-18 23:52:2445#include "gpu/command_buffer/service/copy_shared_image_helper.h"
Jonathan Backer1d807a42018-01-08 20:45:5446#include "gpu/command_buffer/service/decoder_client.h"
Jonathan Backer7471b2782018-01-25 18:14:1947#include "gpu/command_buffer/service/error_state.h"
48#include "gpu/command_buffer/service/feature_info.h"
Jonathan Backerc26060e2018-03-29 15:06:2949#include "gpu/command_buffer/service/gl_utils.h"
Jonathan Backere26739c2018-05-15 13:27:0750#include "gpu/command_buffer/service/gpu_tracer.h"
Jonathan Backer7471b2782018-01-25 18:14:1951#include "gpu/command_buffer/service/logger.h"
Jonathan Backera07c4a9e2018-03-21 15:13:1652#include "gpu/command_buffer/service/mailbox_manager.h"
Jonathan Backer016bd97e2018-03-14 15:26:3953#include "gpu/command_buffer/service/query_manager.h"
Jonathan Backer9267bf1ec2018-03-06 19:56:5054#include "gpu/command_buffer/service/raster_cmd_validation.h"
Khushala8d50642018-05-03 01:29:0655#include "gpu/command_buffer/service/service_font_manager.h"
Jonathan Backer0cd1c4322018-04-17 16:57:1056#include "gpu/command_buffer/service/service_transfer_cache.h"
Antoine Labour10dddca12019-02-19 19:09:2657#include "gpu/command_buffer/service/service_utils.h"
Peng Huang8294a5a7f2019-01-23 18:56:2658#include "gpu/command_buffer/service/shared_context_state.h"
Saifuddin Hitawala81cbd382022-07-20 19:14:5359#include "gpu/command_buffer/service/shared_image/shared_image_factory.h"
Saifuddin Hitawala796463f2022-12-02 16:34:1060#include "gpu/command_buffer/service/shared_image/shared_image_format_utils.h"
Saifuddin Hitawala81cbd382022-07-20 19:14:5361#include "gpu/command_buffer/service/shared_image/shared_image_representation.h"
62#include "gpu/command_buffer/service/shared_image/wrapped_sk_image_backing_factory.h"
Jonathan Backera1f3d7c2018-10-16 14:46:3263#include "gpu/command_buffer/service/skia_utils.h"
Vikas Sonica02287b2022-01-18 20:17:3564#include "gpu/config/gpu_finch_features.h"
Peng Huang3c13b502019-05-08 01:40:0065#include "gpu/vulkan/buildflags.h"
Ian Preste598eece2020-10-19 23:31:0266#include "skia/ext/legacy_display_globals.h"
Christopher Camerond18b9322021-08-24 21:12:5567#include "skia/ext/rgba_to_yuva.h"
Nathan Zabriskief5f270e2021-04-30 20:53:0668#include "third_party/libyuv/include/libyuv/planar_functions.h"
Jonathan Backere19973e82018-04-18 20:08:0969#include "third_party/skia/include/core/SkCanvas.h"
Kevin Lubick040667a2022-04-07 13:49:0370#include "third_party/skia/include/core/SkColorSpace.h"
Victor Miura6bb4ab5c2023-05-10 21:35:1271#include "third_party/skia/include/core/SkGraphics.h"
Peng Huanga8b0e422019-07-16 17:48:5772#include "third_party/skia/include/core/SkPromiseImageTexture.h"
Jonathan Backere19973e82018-04-18 20:08:0973#include "third_party/skia/include/core/SkSurface.h"
74#include "third_party/skia/include/core/SkSurfaceProps.h"
75#include "third_party/skia/include/core/SkTypeface.h"
Brian Salomonc54f44f2020-11-11 16:11:0676#include "third_party/skia/include/core/SkYUVAInfo.h"
Peng Huang5f9118b02019-04-24 20:18:2177#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
Jonathan Backere19973e82018-04-18 20:08:0978#include "third_party/skia/include/gpu/GrBackendSurface.h"
Adlai Hollerc4dea1a92020-08-04 13:21:5579#include "third_party/skia/include/gpu/GrDirectContext.h"
Brian Salomonc54f44f2020-11-11 16:11:0680#include "third_party/skia/include/gpu/GrYUVABackendTextures.h"
Colin Blundelld7b7b472023-05-12 07:38:1281#include "third_party/skia/include/gpu/graphite/Context.h"
Peng Huang5f3d4352021-11-23 17:51:2982#include "ui/base/ui_base_features.h"
Jonathan Backer76dfd502018-05-03 18:34:3183#include "ui/gfx/buffer_format_util.h"
Xianzhu Wang65ef1ad32021-10-07 03:12:3384#include "ui/gfx/geometry/skia_conversions.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0485#include "ui/gl/gl_context.h"
Jonathan Backere19973e82018-04-18 20:08:0986#include "ui/gl/gl_gl_api_implementation.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0487#include "ui/gl/gl_surface.h"
Jonathan Backera4568da12018-01-31 16:25:0488#include "ui/gl/gl_version_info.h"
Jonathan Backer7f90dfb662017-12-18 16:52:0489
Peng Huang3c13b502019-05-08 01:40:0090#if BUILDFLAG(ENABLE_VULKAN)
91#include "components/viz/common/gpu/vulkan_context_provider.h"
92#include "gpu/vulkan/vulkan_device_queue.h"
Jonah Chin09d12b72021-05-11 00:52:0893#endif // BUILDFLAG(ENABLE_VULKAN)
94
Xiaohan Wangfa22d3e2022-01-15 02:02:4395#if BUILDFLAG(IS_WIN)
Saifuddin Hitawala81cbd382022-07-20 19:14:5396#include "gpu/command_buffer/service/shared_image/d3d_image_backing_factory.h"
Xiaohan Wangfa22d3e2022-01-15 02:02:4397#endif // BUILDFLAG(IS_WIN)
Peng Huang3c13b502019-05-08 01:40:0098
Jonathan Backer7f90dfb662017-12-18 16:52:0499// Local versions of the SET_GL_ERROR macros
100#define LOCAL_SET_GL_ERROR(error, function_name, msg) \
Peng Huang66a7a3762018-12-07 20:05:38101 ERRORSTATE_SET_GL_ERROR(error_state_.get(), error, function_name, msg)
102#define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \
103 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state_.get(), function_name, \
Jonathan Backer9267bf1ec2018-03-06 19:56:50104 static_cast<uint32_t>(value), label)
Peng Huangb4ed1852018-12-05 03:35:29105#define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \
Peng Huang66a7a3762018-12-07 20:05:38106 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_.get(), function_name)
Jonathan Backer7f90dfb662017-12-18 16:52:04107#define LOCAL_PEEK_GL_ERROR(function_name) \
Peng Huang66a7a3762018-12-07 20:05:38108 ERRORSTATE_PEEK_GL_ERROR(error_state_.get(), function_name)
Jonathan Backer7f90dfb662017-12-18 16:52:04109#define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \
Peng Huang66a7a3762018-12-07 20:05:38110 ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_.get(), function_name)
Jonathan Backer7f90dfb662017-12-18 16:52:04111#define LOCAL_PERFORMANCE_WARNING(msg) \
112 PerformanceWarning(__FILE__, __LINE__, msg)
113#define LOCAL_RENDER_WARNING(msg) RenderWarning(__FILE__, __LINE__, msg)
114
Jonathan Backer7f90dfb662017-12-18 16:52:04115namespace gpu {
116namespace raster {
117
Jonathan Backera07c4a9e2018-03-21 15:13:16118namespace {
119
Khushal996e9912018-07-13 08:31:00120base::AtomicSequenceNumber g_raster_decoder_id;
121
Jonathan Backer1994ff2e2018-03-22 21:24:33122// This class prevents any GL errors that occur when it is in scope from
123// being reported to the client.
124class ScopedGLErrorSuppressor {
125 public:
Daniel Bratellaabc8d68e2018-07-18 19:20:26126 ScopedGLErrorSuppressor(const char* function_name,
Peng Huangc6a76072018-11-27 23:17:31127 gles2::ErrorState* error_state)
128 : function_name_(function_name), error_state_(error_state) {
129 ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_);
130 }
Peter Bostrรถmdbacdc22021-09-23 22:11:46131
132 ScopedGLErrorSuppressor(const ScopedGLErrorSuppressor&) = delete;
133 ScopedGLErrorSuppressor& operator=(const ScopedGLErrorSuppressor&) = delete;
134
Peng Huangc6a76072018-11-27 23:17:31135 ~ScopedGLErrorSuppressor() {
136 ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_);
137 }
Jonathan Backer1994ff2e2018-03-22 21:24:33138
139 private:
140 const char* function_name_;
Keishi Hattori0e45c022021-11-27 09:25:52141 raw_ptr<gles2::ErrorState> error_state_;
Jonathan Backer1994ff2e2018-03-22 21:24:33142};
143
Corentin Wallez5cbffcc2020-07-08 10:23:57144// Commands that are explicitly listed as OK to occur between
Adlai Hollerc4dea1a92020-08-04 13:21:55145// BeginRasterCHROMIUM and EndRasterCHROMIUM. They do not invalidate
146// GrDirectContext state tracking.
Jonathan Backer2231a002018-05-14 19:55:22147bool AllowedBetweenBeginEndRaster(CommandId command) {
148 switch (command) {
149 case kCreateTransferCacheEntryINTERNAL:
150 case kDeleteTransferCacheEntryINTERNAL:
151 case kEndRasterCHROMIUM:
152 case kFinish:
153 case kFlush:
154 case kGetError:
155 case kRasterCHROMIUM:
156 case kUnlockTransferCacheEntryINTERNAL:
157 return true;
158 default:
159 return false;
160 }
161}
162
Nathan Zabriskieffc210692020-07-09 07:36:47163// This class is sent to cc::PaintOpReader during paint op deserialization. When
164// a cc:PaintOp refers to a mailbox-backed cc:PaintImage, this class opens the
165// shared image for read access and returns an SkImage reference.
166// SharedImageProviderImpl maintains read access until it is destroyed
167// which should occur after |end_semaphores| have been flushed to Skia.
168class SharedImageProviderImpl final : public cc::SharedImageProvider {
169 public:
170 SharedImageProviderImpl(
171 SharedImageRepresentationFactory* shared_image_factory,
172 scoped_refptr<SharedContextState> shared_context_state,
173 SkSurface* output_surface,
174 std::vector<GrBackendSemaphore>* end_semaphores,
Vasiliy Telezhnikov9837f902022-08-17 15:03:07175 gles2::ErrorState* error_state)
Nathan Zabriskieffc210692020-07-09 07:36:47176 : shared_image_factory_(shared_image_factory),
177 shared_context_state_(std::move(shared_context_state)),
178 output_surface_(output_surface),
179 end_semaphores_(end_semaphores),
Vasiliy Telezhnikov9837f902022-08-17 15:03:07180 error_state_(error_state) {
Nathan Zabriskieffc210692020-07-09 07:36:47181 DCHECK(shared_image_factory_);
182 DCHECK(shared_context_state_);
183 DCHECK(output_surface_);
184 DCHECK(end_semaphores_);
185 DCHECK(error_state_);
186 }
187 SharedImageProviderImpl(const SharedImageProviderImpl&) = delete;
188 SharedImageProviderImpl& operator=(const SharedImageProviderImpl&) = delete;
189
190 ~SharedImageProviderImpl() override { read_accessors_.clear(); }
191
Justin Novosad30670e62021-09-27 22:30:23192 sk_sp<SkImage> OpenSharedImageForRead(const gpu::Mailbox& mailbox,
193 Error& error) override {
Nathan Zabriskieffc210692020-07-09 07:36:47194 auto it = read_accessors_.find(mailbox);
Justin Novosad30670e62021-09-27 22:30:23195 error = Error::kNoError;
196 if (it != read_accessors_.end()) {
Nathan Zabriskieffc210692020-07-09 07:36:47197 return it->second.read_access_sk_image;
Justin Novosad30670e62021-09-27 22:30:23198 }
Nathan Zabriskieffc210692020-07-09 07:36:47199
200 auto shared_image_skia =
201 shared_image_factory_->ProduceSkia(mailbox, shared_context_state_);
202 if (!shared_image_skia) {
203 ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION,
204 "SharedImageProviderImpl::OpenSharedImageForRead",
205 ("Attempting to operate on unknown mailbox:" +
206 mailbox.ToDebugString())
207 .c_str());
Justin Novosad30670e62021-09-27 22:30:23208 error = Error::kUnknownMailbox;
Nathan Zabriskieffc210692020-07-09 07:36:47209 return nullptr;
210 }
211
212 std::vector<GrBackendSemaphore> begin_semaphores;
213 // |end_semaphores_| is owned by RasterDecoderImpl which will handle sending
214 // them to SkCanvas
215 auto scoped_read_access = shared_image_skia->BeginScopedReadAccess(
216 &begin_semaphores, end_semaphores_);
217 if (!scoped_read_access) {
218 ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION,
219 "SharedImageProviderImpl::OpenSharedImageForRead",
220 ("Couldn't access shared image for mailbox:" +
221 mailbox.ToDebugString())
222 .c_str());
Justin Novosad30670e62021-09-27 22:30:23223 error = Error::kNoAccess;
Nathan Zabriskieffc210692020-07-09 07:36:47224 return nullptr;
225 }
226
227 if (!begin_semaphores.empty()) {
228 bool result = output_surface_->wait(begin_semaphores.size(),
Peng Huang1c6d0582020-07-31 12:14:11229 begin_semaphores.data(),
230 /*deleteSemaphoresAfterWait=*/false);
Nathan Zabriskieffc210692020-07-09 07:36:47231 DCHECK(result);
232 }
233
Nathan Zabriskiec5ed2362020-07-21 05:39:54234 auto sk_image =
Saifuddin Hitawala5a6785d52023-04-25 22:23:12235 scoped_read_access->CreateSkImage(shared_context_state_.get());
Nathan Zabriskieffc210692020-07-09 07:36:47236 if (!sk_image) {
237 ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION,
238 "SharedImageProviderImpl::OpenSharedImageForRead",
239 "Couldn't create output SkImage.");
Justin Novosad30670e62021-09-27 22:30:23240 error = Error::kSkImageCreationFailed;
Nathan Zabriskieffc210692020-07-09 07:36:47241 return nullptr;
242 }
243
244 read_accessors_[mailbox] = {std::move(shared_image_skia),
245 std::move(scoped_read_access), sk_image};
246 return sk_image;
247 }
248
Vasiliy Telezhnikov6414a252022-04-26 04:42:11249 void ApplyEndAccessState() {
250 for (auto& accessor : read_accessors_) {
Saifuddin Hitawala913ae952023-04-18 23:26:03251 accessor.second.scoped_read_access->ApplyBackendSurfaceEndState();
Vasiliy Telezhnikov6414a252022-04-26 04:42:11252 }
253 }
254
Nathan Zabriskieffc210692020-07-09 07:36:47255 private:
Pรขris7704a8e2022-09-01 09:49:20256 raw_ptr<SharedImageRepresentationFactory, DanglingUntriaged>
257 shared_image_factory_;
Nathan Zabriskieffc210692020-07-09 07:36:47258 scoped_refptr<SharedContextState> shared_context_state_;
Pรขris7704a8e2022-09-01 09:49:20259 raw_ptr<SkSurface, DanglingUntriaged> output_surface_;
Keishi Hattori0e45c022021-11-27 09:25:52260 raw_ptr<std::vector<GrBackendSemaphore>> end_semaphores_;
261 raw_ptr<gles2::ErrorState> error_state_;
Nathan Zabriskieffc210692020-07-09 07:36:47262
263 struct SharedImageReadAccess {
Saifuddin Hitawaladaed5972022-07-20 22:01:01264 std::unique_ptr<SkiaImageRepresentation> shared_image_skia;
265 std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess>
Nathan Zabriskieffc210692020-07-09 07:36:47266 scoped_read_access;
267 sk_sp<SkImage> read_access_sk_image;
268 };
269 base::flat_map<gpu::Mailbox, SharedImageReadAccess> read_accessors_;
270};
271
Peng Huang7bb7db4b2021-06-16 15:30:02272class RasterCommandsCompletedQuery : public QueryManager::Query {
273 public:
274 RasterCommandsCompletedQuery(
275 scoped_refptr<SharedContextState> shared_context_state,
276 QueryManager* manager,
277 GLenum target,
278 scoped_refptr<gpu::Buffer> buffer,
279 QuerySync* sync)
280 : Query(manager, target, std::move(buffer), sync),
281 shared_context_state_(std::move(shared_context_state)) {}
282
283 // Overridden from QueryManager::Query:
284 void Begin() override {
Peng Huang7bb7db4b2021-06-16 15:30:02285 MarkAsActive();
286 begin_time_.emplace(base::TimeTicks::Now());
287 }
288
289 void End(base::subtle::Atomic32 submit_count) override {
290 DCHECK(begin_time_);
291
292 AddToPendingQueue(submit_count);
293 finished_ = false;
294
Colin Blundelld7b7b472023-05-12 07:38:12295 if (auto* gr_context = shared_context_state_->gr_context()) {
296 GrFlushInfo info;
297 info.fFinishedProc = RasterCommandsCompletedQuery::FinishedProc;
298 auto weak_ptr = weak_ptr_factory_.GetWeakPtr();
299 info.fFinishedContext =
300 new base::WeakPtr<RasterCommandsCompletedQuery>(weak_ptr);
301 gr_context->flush(info);
302 gr_context->submit();
303 } else {
304 CHECK(shared_context_state_->graphite_context());
305 auto recording =
306 shared_context_state_->gpu_main_graphite_recorder()->snap();
307 if (recording) {
308 skgpu::graphite::InsertRecordingInfo info = {};
309 info.fRecording = recording.get();
310 info.fFinishedProc = [](void* context, skgpu::CallbackResult result) {
311 RasterCommandsCompletedQuery::FinishedProc(context);
312 };
313 info.fFinishedContext = new base::WeakPtr<RasterCommandsCompletedQuery>(
314 weak_ptr_factory_.GetWeakPtr());
315 shared_context_state_->graphite_context()->insertRecording(info);
316 shared_context_state_->graphite_context()->submit();
317 } else {
318 finished_ = true;
319 }
320 }
Peng Huang7bb7db4b2021-06-16 15:30:02321 }
322
323 void QueryCounter(base::subtle::Atomic32 submit_count) override {
324 NOTREACHED();
325 }
326
327 void Pause() override { MarkAsPaused(); }
328
329 void Resume() override { MarkAsActive(); }
330
331 void Process(bool did_finish) override {
332 DCHECK(begin_time_);
Peng Huang63ef8872021-06-17 22:31:20333 if (did_finish || finished_) {
334 const base::TimeDelta elapsed = base::TimeTicks::Now() - *begin_time_;
335 MarkAsCompleted(elapsed.InMicroseconds());
336 begin_time_.reset();
337 }
Peng Huang7bb7db4b2021-06-16 15:30:02338 }
339
340 void Destroy(bool have_context) override {
341 if (!IsDeleted())
342 MarkAsDeleted();
343 }
344
345 protected:
346 ~RasterCommandsCompletedQuery() override = default;
347
348 private:
349 static void FinishedProc(void* context) {
350 auto* weak_ptr =
351 reinterpret_cast<base::WeakPtr<RasterCommandsCompletedQuery>*>(context);
352 if (*weak_ptr)
353 (*weak_ptr)->finished_ = true;
354 delete weak_ptr;
355 }
356
357 const scoped_refptr<SharedContextState> shared_context_state_;
358 absl::optional<base::TimeTicks> begin_time_;
359 bool finished_ = false;
360 base::WeakPtrFactory<RasterCommandsCompletedQuery> weak_ptr_factory_{this};
361};
362
363class RasterQueryManager : public QueryManager {
364 public:
365 explicit RasterQueryManager(
366 scoped_refptr<SharedContextState> shared_context_state)
367 : shared_context_state_(std::move(shared_context_state)) {}
368 ~RasterQueryManager() override = default;
369
370 Query* CreateQuery(GLenum target,
371 GLuint client_id,
372 scoped_refptr<gpu::Buffer> buffer,
373 QuerySync* sync) override {
374 if (target == GL_COMMANDS_COMPLETED_CHROMIUM &&
Colin Blundelld7b7b472023-05-12 07:38:12375 (shared_context_state_->gr_context() ||
376 shared_context_state_->graphite_context())) {
Peng Huang7bb7db4b2021-06-16 15:30:02377 auto query = base::MakeRefCounted<RasterCommandsCompletedQuery>(
378 shared_context_state_, this, target, std::move(buffer), sync);
379 std::pair<QueryMap::iterator, bool> result =
380 queries_.insert(std::make_pair(client_id, query));
381 DCHECK(result.second);
382 return query.get();
383 }
384 return QueryManager::CreateQuery(target, client_id, std::move(buffer),
385 sync);
386 }
387
388 private:
389 const scoped_refptr<SharedContextState> shared_context_state_;
390};
391
Jonathan Backera07c4a9e2018-03-21 15:13:16392} // namespace
393
Jonathan Backer5ac08a72018-06-27 16:15:35394// RasterDecoderImpl uses two separate state trackers (gpu::gles2::ContextState
Adlai Hollerc4dea1a92020-08-04 13:21:55395// and GrDirectContext) that cache the current GL driver state. Each class sees
396// a fraction of the GL calls issued and can easily become inconsistent with GL
Jonathan Backer5ac08a72018-06-27 16:15:35397// state. We guard against that by resetting. But resetting is expensive, so we
Peng Huange89c2a052018-12-04 11:35:11398// avoid it as much as possible.
Jonathan Backer4f9ee5fb2018-04-25 14:03:38399class RasterDecoderImpl final : public RasterDecoder,
Khushala8d50642018-05-03 01:29:06400 public gles2::ErrorStateClient,
Jonathan Backerbaf79d92020-06-01 21:30:30401 public ServiceFontManager::Client,
402 public SharedContextState::ContextLostObserver {
Jonathan Backer7471b2782018-01-25 18:14:19403 public:
Peng Huang20361dad12019-01-23 14:48:10404 RasterDecoderImpl(DecoderClient* client,
405 CommandBufferServiceBase* command_buffer_service,
406 gles2::Outputter* outputter,
Antoine Labour10dddca12019-02-19 19:09:26407 const GpuFeatureInfo& gpu_feature_info,
408 const GpuPreferences& gpu_preferences,
409 MemoryTracker* memory_tracker,
410 SharedImageManager* shared_image_manager,
Malay Keshava154dcb2020-01-18 00:17:55411 scoped_refptr<SharedContextState> shared_context_state,
412 bool is_privileged);
Peter Bostrรถmdbacdc22021-09-23 22:11:46413
414 RasterDecoderImpl(const RasterDecoderImpl&) = delete;
415 RasterDecoderImpl& operator=(const RasterDecoderImpl&) = delete;
416
Jonathan Backer7471b2782018-01-25 18:14:19417 ~RasterDecoderImpl() override;
418
Daniel Bratellaabc8d68e2018-07-18 19:20:26419 gles2::GLES2Util* GetGLES2Util() override { return &util_; }
Jonathan Backera4568da12018-01-31 16:25:04420
Jonathan Backer7471b2782018-01-25 18:14:19421 // DecoderContext implementation.
422 base::WeakPtr<DecoderContext> AsWeakPtr() override;
Jonathan Backer0cd1c4322018-04-17 16:57:10423 ContextResult Initialize(
Jonathan Backer7471b2782018-01-25 18:14:19424 const scoped_refptr<gl::GLSurface>& surface,
425 const scoped_refptr<gl::GLContext>& context,
426 bool offscreen,
427 const gles2::DisallowedFeatures& disallowed_features,
428 const ContextCreationAttribs& attrib_helper) override;
Jonathan Backer7471b2782018-01-25 18:14:19429 void Destroy(bool have_context) override;
430 bool MakeCurrent() override;
431 gl::GLContext* GetGLContext() override;
liberato@chromium.org00c8a6c2018-06-05 02:22:41432 gl::GLSurface* GetGLSurface() override;
Daniel Bratellaabc8d68e2018-07-18 19:20:26433 const gles2::FeatureInfo* GetFeatureInfo() const override {
Antoine Labour10dddca12019-02-19 19:09:26434 return feature_info();
Jonathan Backer34008d882018-03-27 18:57:55435 }
Jonathan Backer7471b2782018-01-25 18:14:19436 Capabilities GetCapabilities() override;
Peng Huangc6a76072018-11-27 23:17:31437 const gles2::ContextState* GetContextState() override;
Peng Huang66a7a3762018-12-07 20:05:38438
439 // TODO(penghuang): Remove unused context state related methods.
Jonathan Backer34008d882018-03-27 18:57:55440 void RestoreGlobalState() const override;
441 void ClearAllAttributes() const override;
442 void RestoreAllAttributes() const override;
Jonathan Backer7471b2782018-01-25 18:14:19443 void RestoreState(const gles2::ContextState* prev_state) override;
444 void RestoreActiveTexture() const override;
445 void RestoreAllTextureUnitAndSamplerBindings(
446 const gles2::ContextState* prev_state) const override;
447 void RestoreActiveTextureUnitBinding(unsigned int target) const override;
448 void RestoreBufferBinding(unsigned int target) override;
449 void RestoreBufferBindings() const override;
450 void RestoreFramebufferBindings() const override;
451 void RestoreRenderbufferBindings() override;
452 void RestoreProgramBindings() const override;
Antoine Labour9ddf6ac2019-01-17 01:59:39453 void RestoreTextureState(unsigned service_id) override;
Jonathan Backer7471b2782018-01-25 18:14:19454 void RestoreTextureUnitBindings(unsigned unit) const override;
455 void RestoreVertexAttribArray(unsigned index) override;
456 void RestoreAllExternalTextureBindingsIfNeeded() override;
Jonathan Backer016bd97e2018-03-14 15:26:39457 QueryManager* GetQueryManager() override;
Peng Huang66a7a3762018-12-07 20:05:38458
Geoff Lang85287e12018-05-22 17:26:40459 void SetQueryCallback(unsigned int query_client_id,
460 base::OnceClosure callback) override;
Jonathan Backer7471b2782018-01-25 18:14:19461 gles2::GpuFenceManager* GetGpuFenceManager() override;
462 bool HasPendingQueries() const override;
463 void ProcessPendingQueries(bool did_finish) override;
464 bool HasMoreIdleWork() const override;
465 void PerformIdleWork() override;
466 bool HasPollingWork() const override;
467 void PerformPollingWork() override;
468 TextureBase* GetTextureBase(uint32_t client_id) override;
Julien Isorcefd6c15f2018-03-15 16:51:17469 void SetLevelInfo(uint32_t client_id,
470 int level,
471 unsigned internal_format,
472 unsigned width,
473 unsigned height,
474 unsigned depth,
475 unsigned format,
476 unsigned type,
477 const gfx::Rect& cleared_rect) override;
Jonathan Backer7471b2782018-01-25 18:14:19478 bool WasContextLost() const override;
479 bool WasContextLostByRobustnessExtension() const override;
480 void MarkContextLost(error::ContextLostReason reason) override;
481 bool CheckResetStatus() override;
482 void BeginDecoding() override;
483 void EndDecoding() override;
484 const char* GetCommandName(unsigned int command_id) const;
485 error::Error DoCommands(unsigned int num_commands,
486 const volatile void* buffer,
487 int num_entries,
488 int* entries_processed) override;
489 base::StringPiece GetLogPrefix() override;
Colin Blundellddd83e02022-11-30 13:40:16490
Dave Tapuskac03874f2023-02-01 21:53:55491#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE)
Colin Blundellddd83e02022-11-30 13:40:16492 void AttachImageToTextureWithDecoderBinding(uint32_t client_texture_id,
493 uint32_t texture_target,
494 gl::GLImage* image) override;
Colin Blundelle2c394e2022-12-16 09:26:59495#elif !BUILDFLAG(IS_ANDROID)
Colin Blundellddd83e02022-11-30 13:40:16496 void AttachImageToTextureWithClientBinding(uint32_t client_texture_id,
497 uint32_t texture_target,
498 gl::GLImage* image) override;
499#endif
500
Jonathan Backer7471b2782018-01-25 18:14:19501 gles2::ContextGroup* GetContextGroup() override;
502 gles2::ErrorState* GetErrorState() override;
Colin Blundell9d4fea62022-12-14 15:26:16503#if !BUILDFLAG(IS_ANDROID)
Daniel Bratellaabc8d68e2018-07-18 19:20:26504 std::unique_ptr<gles2::AbstractTexture> CreateAbstractTexture(
505 GLenum target,
506 GLenum internal_format,
507 GLsizei width,
508 GLsizei height,
509 GLsizei depth,
510 GLint border,
511 GLenum format,
512 GLenum type) override;
Colin Blundell9d4fea62022-12-14 15:26:16513#endif
Jonathan Backerc26060e2018-03-29 15:06:29514 bool IsCompressedTextureFormat(unsigned format) override;
515 bool ClearLevel(gles2::Texture* texture,
516 unsigned target,
517 int level,
518 unsigned format,
519 unsigned type,
520 int xoffset,
521 int yoffset,
522 int width,
523 int height) override;
524 bool ClearCompressedTextureLevel(gles2::Texture* texture,
525 unsigned target,
526 int level,
527 unsigned format,
528 int width,
529 int height) override;
shrekshaoad4525482020-03-12 00:30:55530 bool ClearCompressedTextureLevel3D(gles2::Texture* texture,
531 unsigned target,
532 int level,
533 unsigned format,
534 int width,
535 int height,
536 int depth) override;
Jonathan Backerc26060e2018-03-29 15:06:29537 bool ClearLevel3D(gles2::Texture* texture,
538 unsigned target,
539 int level,
540 unsigned format,
541 unsigned type,
542 int width,
543 int height,
544 int depth) override {
545 NOTIMPLEMENTED();
546 return false;
547 }
Andres Calderon Jaramillob870ca62019-01-29 16:33:35548 int GetRasterDecoderId() const override;
Khushal996e9912018-07-13 08:31:00549 int DecoderIdForTest() override;
Jonathan Backer0cd1c4322018-04-17 16:57:10550 ServiceTransferCache* GetTransferCacheForTest() override;
Khushal15b6abb2018-06-28 00:16:25551 void SetUpForRasterCHROMIUMForTest() override;
Jonathan Backerc7b82972018-11-21 19:08:48552 void SetOOMErrorForTest() override;
Christopher Cameron386e18582019-01-11 20:17:34553 void DisableFlushWorkaroundForTest() override;
Jonathan Backer7471b2782018-01-25 18:14:19554
555 // ErrorClientState implementation.
556 void OnContextLostError() override;
557 void OnOutOfMemoryError() override;
558
Daniel Bratellaabc8d68e2018-07-18 19:20:26559 gles2::Logger* GetLogger() override;
Jonathan Backera4568da12018-01-31 16:25:04560
561 void SetIgnoreCachedStateForTest(bool ignore) override;
Jonathan Backer0cd1c4322018-04-17 16:57:10562
Khushala8d50642018-05-03 01:29:06563 // ServiceFontManager::Client implementation.
564 scoped_refptr<Buffer> GetShmBuffer(uint32_t shm_id) override;
Khushal39641b92019-06-03 21:32:54565 void ReportProgress() override;
Khushala8d50642018-05-03 01:29:06566
Jonathan Backerbaf79d92020-06-01 21:30:30567 // SharedContextState::ContextLostObserver implementation.
568 void OnContextLost() override;
569
Jonathan Backer7471b2782018-01-25 18:14:19570 private:
Peng Huang66a7a3762018-12-07 20:05:38571 gles2::ContextState* state() const {
Antoine Labour10dddca12019-02-19 19:09:26572 if (use_passthrough_) {
Jonathan Backer628d73f82019-01-17 17:34:18573 NOTREACHED();
574 return nullptr;
575 }
Peng Huang20361dad12019-01-23 14:48:10576 return shared_context_state_->context_state();
Peng Huang66a7a3762018-12-07 20:05:38577 }
Jonathan Backer628d73f82019-01-17 17:34:18578 gl::GLApi* api() const { return api_; }
Adlai Hollerc4dea1a92020-08-04 13:21:55579 GrDirectContext* gr_context() const {
580 return shared_context_state_->gr_context();
581 }
Colin Blundelld7b7b472023-05-12 07:38:12582 skgpu::graphite::Context* graphite_context() const {
583 return shared_context_state_->graphite_context();
584 }
Sunny Sachanandani5fcc5722023-05-09 00:50:36585 skgpu::graphite::Recorder* graphite_recorder() const {
586 return shared_context_state_->gpu_main_graphite_recorder();
587 }
Khushal996e9912018-07-13 08:31:00588 ServiceTransferCache* transfer_cache() {
Peng Huang20361dad12019-01-23 14:48:10589 return shared_context_state_->transfer_cache();
Khushal996e9912018-07-13 08:31:00590 }
Jonathan Backer7471b2782018-01-25 18:14:19591
Antoine Labour10dddca12019-02-19 19:09:26592 const gles2::FeatureInfo* feature_info() const {
593 return shared_context_state_->feature_info();
594 }
595
Daniel Bratellaabc8d68e2018-07-18 19:20:26596 const gles2::FeatureInfo::FeatureFlags& features() const {
Antoine Labour10dddca12019-02-19 19:09:26597 return feature_info()->feature_flags();
Jonathan Backer7471b2782018-01-25 18:14:19598 }
599
Jonathan Backer1994ff2e2018-03-22 21:24:33600 const GpuDriverBugWorkarounds& workarounds() const {
Antoine Labour10dddca12019-02-19 19:09:26601 return feature_info()->workarounds();
Jonathan Backer1994ff2e2018-03-22 21:24:33602 }
603
Christopher Cameronbeb5f272019-02-04 22:49:13604 void FlushToWorkAroundMacCrashes() {
Scott Violet0430768f2022-09-29 00:26:58605 // The workaround is not needed for arm based macs (because they don't have
606 // the bug).
607#if BUILDFLAG(IS_MAC) && !defined(ARCH_CPU_ARM64)
Colin Blundelld7b7b472023-05-12 07:38:12608 // The workaround is also not needed for Graphite, which always uses Metal
609 // drivers (via Dawn).
610 if (!shared_context_state_->GrContextIsGL()) {
Christopher Cameronf787d0b2019-05-15 23:52:18611 return;
Colin Blundelld7b7b472023-05-12 07:38:12612 }
Christopher Cameronbeb5f272019-02-04 22:49:13613 // This function does aggressive flushes to work around crashes in the
614 // macOS OpenGL driver.
615 // https://crbug.com/906453
616 if (!flush_workaround_disabled_for_test_) {
Khushal Sagar70ac89132020-04-17 19:48:42617 TRACE_EVENT0("gpu", "RasterDecoderImpl::FlushToWorkAroundMacCrashes");
Christopher Cameronbeb5f272019-02-04 22:49:13618 if (gr_context())
Greg Daniela0476232020-05-19 15:13:58619 gr_context()->flushAndSubmit();
Christopher Cameronbeb5f272019-02-04 22:49:13620 api()->glFlushFn();
Khushald15c5912019-06-14 17:51:04621
622 // Flushes can be expensive, yield to allow interruption after each flush.
623 ExitCommandProcessingEarly();
Christopher Cameronbeb5f272019-02-04 22:49:13624 }
625#endif
626 }
627
Jonathan Backera4568da12018-01-31 16:25:04628 const gl::GLVersionInfo& gl_version_info() {
Antoine Labour10dddca12019-02-19 19:09:26629 return feature_info()->gl_version_info();
Jonathan Backera4568da12018-01-31 16:25:04630 }
631
Jonathan Backer7471b2782018-01-25 18:14:19632 // Set remaining commands to process to 0 to force DoCommands to return
633 // and allow context preemption and GPU watchdog checks in
634 // CommandExecutor().
Corentin Wallez0f412f02019-04-03 22:42:38635 void ExitCommandProcessingEarly() override;
Jonathan Backer7471b2782018-01-25 18:14:19636
637 template <bool DebugImpl>
638 error::Error DoCommandsImpl(unsigned int num_commands,
639 const volatile void* buffer,
640 int num_entries,
641 int* entries_processed);
642
Jonathan Backer016bd97e2018-03-14 15:26:39643 bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids);
644 void DeleteQueriesEXTHelper(GLsizei n, const volatile GLuint* client_ids);
Jonathan Backera4568da12018-01-31 16:25:04645 void DoFinish();
646 void DoFlush();
647 void DoGetIntegerv(GLenum pname, GLint* params, GLsizei params_size);
Jonathan Backere26739c2018-05-15 13:27:07648 void DoTraceEndCHROMIUM();
Saifuddin Hitawala20790cb2023-01-31 17:01:12649 void DoCopySharedImageINTERNAL(GLint xoffset,
650 GLint yoffset,
651 GLint x,
652 GLint y,
653 GLsizei width,
654 GLsizei height,
655 GLboolean unpack_flip_y,
656 const volatile GLbyte* mailboxes);
Nathan Zabriskie31e4dc92020-04-15 23:10:27657 void DoWritePixelsINTERNAL(GLint x_offset,
658 GLint y_offset,
Saifuddin Hitawala5d26b202023-04-04 18:41:43659 GLint plane_index,
Nathan Zabriskie31e4dc92020-04-15 23:10:27660 GLuint src_width,
661 GLuint src_height,
662 GLuint row_bytes,
663 GLuint src_sk_color_type,
664 GLuint src_sk_alpha_type,
665 GLint shm_id,
666 GLuint shm_offset,
667 GLuint shm_size,
668 const volatile GLbyte* mailbox);
Jonah Chin67897ae62020-12-08 21:13:20669 bool DoWritePixelsINTERNALDirectTextureUpload(
Saifuddin Hitawaladaed5972022-07-20 22:01:01670 SkiaImageRepresentation* dest_shared_image,
Jonah Chin67897ae62020-12-08 21:13:20671 const SkImageInfo& src_info,
Saifuddin Hitawalaa5126a702023-04-04 20:16:39672 const int plane_index,
Jonah Chin67897ae62020-12-08 21:13:20673 const void* pixel_data,
674 size_t row_bytes);
Nathan Zabriskief5f270e2021-04-30 20:53:06675 void DoReadbackARGBImagePixelsINTERNAL(GLint src_x,
676 GLint src_y,
Saifuddin Hitawalaf32b28c2023-02-22 23:30:38677 GLint plane_index,
Nathan Zabriskief5f270e2021-04-30 20:53:06678 GLuint dst_width,
679 GLuint dst_height,
680 GLuint row_bytes,
681 GLuint dst_sk_color_type,
682 GLuint dst_sk_alpha_type,
683 GLint shm_id,
684 GLuint shm_offset,
685 GLuint color_space_offset,
686 GLuint pixels_offset,
687 const volatile GLbyte* mailbox);
688 void DoReadbackYUVImagePixelsINTERNAL(GLuint dst_width,
689 GLuint dst_height,
690 GLint shm_id,
691 GLuint shm_offset,
692 GLuint y_offset,
693 GLuint y_stride,
694 GLuint u_offset,
695 GLuint u_stride,
696 GLuint v_offset,
697 GLuint v_stride,
698 const volatile GLbyte* mailbox);
Christopher Camerona78f1e3c2021-08-13 19:13:44699
Brian Salomon99bc7fc2020-11-20 16:57:31700 void DoConvertYUVAMailboxesToRGBINTERNAL(GLenum yuv_color_space,
701 GLenum plane_config,
702 GLenum subsampling,
703 const volatile GLbyte* mailboxes);
Christopher Cameron1c9f5322021-08-14 08:21:36704 void DoConvertRGBAToYUVAMailboxesINTERNAL(GLenum yuv_color_space,
705 GLenum plane_config,
706 GLenum subsampling,
707 const volatile GLbyte* mailboxes);
Nathan Zabriskie366b8932020-04-28 01:07:13708
Jonah Chin053aa6c2021-01-22 20:26:14709 void DoLoseContextCHROMIUM(GLenum current, GLenum other);
Aaron Krajeskid7d51a52022-05-25 13:29:09710 void DoBeginRasterCHROMIUM(GLfloat r,
711 GLfloat g,
712 GLfloat b,
713 GLfloat a,
Sunny Sachanandanib461e212021-03-05 19:22:12714 GLboolean needs_clear,
Jonathan Backer7471b2782018-01-25 18:14:19715 GLuint msaa_sample_count,
Justin Novosad7cc290af2021-07-20 17:13:07716 MsaaMode msaa_mode,
Jonathan Backer7471b2782018-01-25 18:14:19717 GLboolean can_use_lcd_text,
Peng Huang5ff70dff2022-03-03 19:55:11718 GLboolean visible,
Jonathan Backer7e7492522018-07-20 00:23:55719 const volatile GLbyte* key);
Khushala8d50642018-05-03 01:29:06720 void DoRasterCHROMIUM(GLuint raster_shm_id,
721 GLuint raster_shm_offset,
Antoine Labour423fe592019-01-10 22:13:09722 GLuint raster_shm_size,
Khushala8d50642018-05-03 01:29:06723 GLuint font_shm_id,
724 GLuint font_shm_offset,
Antoine Labour423fe592019-01-10 22:13:09725 GLuint font_shm_size);
Jonathan Backere19973e82018-04-18 20:08:09726 void DoEndRasterCHROMIUM();
Jonathan Backer7471b2782018-01-25 18:14:19727 void DoCreateTransferCacheEntryINTERNAL(GLuint entry_type,
728 GLuint entry_id,
729 GLuint handle_shm_id,
730 GLuint handle_shm_offset,
731 GLuint data_shm_id,
732 GLuint data_shm_offset,
Jonathan Backer0cd1c4322018-04-17 16:57:10733 GLuint data_size);
734 void DoUnlockTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id);
735 void DoDeleteTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id);
Jonathan Backer10821a82018-04-04 23:56:03736 void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding);
Khushal33205a72018-11-08 10:12:29737 void DeletePaintCachePathsINTERNALHelper(
738 GLsizei n,
739 const volatile GLuint* paint_cache_ids);
740 void DoClearPaintCacheINTERNAL();
Vikas Sonica02287b2022-01-18 20:17:35741
Colin Blundelld7b7b472023-05-12 07:38:12742 void GraphiteFlushAndSubmitWithRecording(
743 std::unique_ptr<skgpu::graphite::Recording> recording,
744 skgpu::graphite::SyncToCpu sync_to_cpu =
745 skgpu::graphite::SyncToCpu::kNo) {
746 if (recording) {
747 skgpu::graphite::InsertRecordingInfo info = {};
748 info.fRecording = recording.get();
749 graphite_context()->insertRecording(info);
750 }
751 graphite_context()->submit(sync_to_cpu);
752 }
753
754 void GraphiteFlushAndSubmit(skgpu::graphite::SyncToCpu sync_to_cpu =
755 skgpu::graphite::SyncToCpu::kNo) {
756 GraphiteFlushAndSubmitWithRecording(graphite_recorder()->snap(),
757 sync_to_cpu);
758 }
759
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:05760 void FlushSurface(SkiaImageRepresentation::ScopedWriteAccess* access) {
Scott Violet86dc643d2023-04-07 17:57:24761 static int flush_count = 0;
762 const base::TimeTicks start = base::TimeTicks::Now();
Saifuddin Hitawala796463f2022-12-02 16:34:10763 int num_planes = access->representation()->format().NumberOfPlanes();
Saifuddin Hitawala796463f2022-12-02 16:34:10764 for (int plane_index = 0; plane_index < num_planes; plane_index++) {
765 auto* surface = access->surface(plane_index);
766 DCHECK(surface);
Saifuddin Hitawalae3ef7ae2023-04-20 14:22:25767 surface->flush();
Saifuddin Hitawala796463f2022-12-02 16:34:10768 }
Saifuddin Hitawalae3ef7ae2023-04-20 14:22:25769 access->ApplyBackendSurfaceEndState();
Colin Blundelld7b7b472023-05-12 07:38:12770
771 if (graphite_context()) {
772 GraphiteFlushAndSubmit();
773 }
774
Scott Violet86dc643d2023-04-07 17:57:24775 if (flush_count < 100) {
776 ++flush_count;
777 base::UmaHistogramCustomMicrosecondsTimes(
778 "GPU.RasterDecoder.TimeToFlush", base::TimeTicks::Now() - start,
779 base::Microseconds(1), base::Seconds(1), 100);
780 }
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:05781 }
782
783 void SubmitIfNecessary(std::vector<GrBackendSemaphore> signal_semaphores) {
Vikas Soni79b08712022-08-25 16:42:30784 // Note that when DrDc is enabled, we need to call
785 // AddVulkanCleanupTaskForSkiaFlush() on gpu main thread and do skia flush.
786 // This will ensure that vulkan memory allocated on gpu main thread will be
787 // cleaned up.
788 if (!signal_semaphores.empty() || is_drdc_enabled_) {
Colin Blundelld7b7b472023-05-12 07:38:12789 // NOTE: The Graphite SharedImage representation does not set semaphores,
790 // and we are not enabling DrDC with Graphite.
791 CHECK(gr_context());
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:05792 GrFlushInfo flush_info = {
793 .fNumSemaphores = signal_semaphores.size(),
794 .fSignalSemaphores = signal_semaphores.data(),
795 };
796 gpu::AddVulkanCleanupTaskForSkiaFlush(
797 shared_context_state_->vk_context_provider(), &flush_info);
798
799 auto result = gr_context()->flush(flush_info);
800 DCHECK_EQ(result, GrSemaphoresSubmitted::kYes);
Peng Huang95a63e4b2020-07-03 21:28:11801 }
802
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:05803 bool sync_cpu = gpu::ShouldVulkanSyncCpuForSkiaSubmit(
804 shared_context_state_->vk_context_provider());
Jonah Chin67897ae62020-12-08 21:13:20805
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:05806 // If DrDc is enabled, submit the gr_context() to ensure correct ordering
807 // of vulkan commands between raster and display compositor.
808 // TODO(vikassoni): This submit could be happening more often than
809 // intended resulting in perf penalty. Explore ways to reduce it by
810 // trying to issue submit only once per draw call for both gpu main and
811 // drdc thread gr_context. Also add metric to see how often submits are
812 // happening per frame.
813 const bool need_submit =
814 sync_cpu || !signal_semaphores.empty() || is_drdc_enabled_;
815
Colin Blundelld7b7b472023-05-12 07:38:12816 if (need_submit) {
817 // NOTE: Graphite uses Metal (via Dawn), the Graphite SharedImage
818 // representation does not set semaphores, and we are not enabling DrDC
819 // with Graphite.
820 CHECK(gr_context());
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:05821 gr_context()->submit(sync_cpu);
Colin Blundelld7b7b472023-05-12 07:38:12822 }
Peng Huang95a63e4b2020-07-03 21:28:11823 }
824
Jonathan Backera4568da12018-01-31 16:25:04825#if defined(NDEBUG)
826 void LogClientServiceMapping(const char* /* function_name */,
827 GLuint /* client_id */,
828 GLuint /* service_id */) {}
829 template <typename T>
830 void LogClientServiceForInfo(T* /* info */,
831 GLuint /* client_id */,
832 const char* /* function_name */) {}
833#else
834 void LogClientServiceMapping(const char* function_name,
835 GLuint client_id,
836 GLuint service_id) {
Antoine Labour10dddca12019-02-19 19:09:26837 if (gpu_preferences_.enable_gpu_service_logging_gpu) {
Jonathan Backera4568da12018-01-31 16:25:04838 VLOG(1) << "[" << logger_.GetLogPrefix() << "] " << function_name
839 << ": client_id = " << client_id
840 << ", service_id = " << service_id;
841 }
842 }
843 template <typename T>
844 void LogClientServiceForInfo(T* info,
845 GLuint client_id,
846 const char* function_name) {
847 if (info) {
848 LogClientServiceMapping(function_name, client_id, info->service_id());
849 }
850 }
851#endif
852
Jonathan Backer7471b2782018-01-25 18:14:19853// Generate a member function prototype for each command in an automated and
854// typesafe way.
855#define RASTER_CMD_OP(name) \
856 Error Handle##name(uint32_t immediate_data_size, const volatile void* data);
857
858 RASTER_COMMAND_LIST(RASTER_CMD_OP)
859#undef RASTER_CMD_OP
860
861 typedef error::Error (RasterDecoderImpl::*CmdHandler)(
862 uint32_t immediate_data_size,
863 const volatile void* data);
864
865 // A struct to hold info about each command.
866 struct CommandInfo {
867 CmdHandler cmd_handler;
868 uint8_t arg_flags; // How to handle the arguments for this command
869 uint8_t cmd_flags; // How to handle this command
870 uint16_t arg_count; // How many arguments are expected for this command.
871 };
872
873 // A table of CommandInfo for all the commands.
874 static const CommandInfo command_info[kNumCommands - kFirstRasterCommand];
875
Khushal996e9912018-07-13 08:31:00876 const int raster_decoder_id_;
Bo Liu335323d2021-07-14 21:45:18877 const bool disable_legacy_mailbox_;
Khushal996e9912018-07-13 08:31:00878
Jonathan Backer7471b2782018-01-25 18:14:19879 // Number of commands remaining to be processed in DoCommands().
Jonathan Backer0cd1c4322018-04-17 16:57:10880 int commands_to_process_ = 0;
881
kylecharee7338172022-02-02 16:59:10882 bool gpu_raster_enabled_ = false;
883 bool use_gpu_raster_ = false;
Antoine Labour10dddca12019-02-19 19:09:26884 bool use_passthrough_ = false;
Jonathan Backer7471b2782018-01-25 18:14:19885
886 // The current decoder error communicates the decoder error through command
887 // processing functions that do not return the error value. Should be set
888 // only if not returning an error.
Jonathan Backer0cd1c4322018-04-17 16:57:10889 error::Error current_decoder_error_ = error::kNoError;
Jonathan Backer7471b2782018-01-25 18:14:19890
Antoine Labour10dddca12019-02-19 19:09:26891 GpuPreferences gpu_preferences_;
892
Jonathan Backer7471b2782018-01-25 18:14:19893 gles2::DebugMarkerManager debug_marker_manager_;
894 gles2::Logger logger_;
Peng Huangb4ed1852018-12-05 03:35:29895 std::unique_ptr<gles2::ErrorState> error_state_;
Peng Huang66a7a3762018-12-07 20:05:38896 bool context_lost_ = false;
Jonathan Backer7471b2782018-01-25 18:14:19897
Peng Huang20361dad12019-01-23 14:48:10898 scoped_refptr<SharedContextState> shared_context_state_;
Jonathan Backer9267bf1ec2018-03-06 19:56:50899 std::unique_ptr<Validators> validators_;
Jonathan Backer7471b2782018-01-25 18:14:19900
Antoine Labour10dddca12019-02-19 19:09:26901 SharedImageRepresentationFactory shared_image_representation_factory_;
Peng Huang7bb7db4b2021-06-16 15:30:02902 std::unique_ptr<RasterQueryManager> query_manager_;
Jonathan Backer016bd97e2018-03-14 15:26:39903
Daniel Bratellaabc8d68e2018-07-18 19:20:26904 gles2::GLES2Util util_;
Jonathan Backera4568da12018-01-31 16:25:04905
Antoine Labour10dddca12019-02-19 19:09:26906 // An optional behaviour to lose the context when OOM.
Jonathan Backer4f9ee5fb2018-04-25 14:03:38907 bool lose_context_when_out_of_memory_ = false;
908
Daniel Bratellaabc8d68e2018-07-18 19:20:26909 std::unique_ptr<gles2::GPUTracer> gpu_tracer_;
Jonathan Backere26739c2018-05-15 13:27:07910 const unsigned char* gpu_decoder_category_;
911 static constexpr int gpu_trace_level_ = 2;
912 bool gpu_trace_commands_ = false;
913 bool gpu_debug_commands_ = false;
914
Jonathan Backer0cd1c4322018-04-17 16:57:10915 // Raster helpers.
Khushal3d0b8902018-09-18 03:03:34916 scoped_refptr<ServiceFontManager> font_manager_;
Saifuddin Hitawaladaed5972022-07-20 22:01:01917 std::unique_ptr<SkiaImageRepresentation> shared_image_;
918 std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess>
Peng Huange9b41cd2019-08-12 19:39:47919 scoped_shared_image_write_;
Peng Huangb447da42021-09-22 19:21:26920
Saifuddin Hitawaladaed5972022-07-20 22:01:01921 std::unique_ptr<RasterImageRepresentation> shared_image_raster_;
922 std::unique_ptr<RasterImageRepresentation::ScopedWriteAccess>
Peng Huangb447da42021-09-22 19:21:26923 scoped_shared_image_raster_write_;
924
Keishi Hattori0e45c022021-11-27 09:25:52925 raw_ptr<SkSurface> sk_surface_ = nullptr;
Nathan Zabriskieffc210692020-07-09 07:36:47926 std::unique_ptr<SharedImageProviderImpl> paint_op_shared_image_provider_;
Khushal Sagar4bb1c122020-05-12 20:17:08927
Peng Huange9b41cd2019-08-12 19:39:47928 sk_sp<SkSurface> sk_surface_for_testing_;
Peng Huang5f9118b02019-04-24 20:18:21929 std::vector<GrBackendSemaphore> end_semaphores_;
Khushal33205a72018-11-08 10:12:29930 std::unique_ptr<cc::ServicePaintCache> paint_cache_;
Peng Huang050dee52018-09-05 15:54:08931
Peng Huang23b9be7b2022-02-19 01:05:41932 raw_ptr<SkCanvas> raster_canvas_ = nullptr;
Khushal22204a42018-05-17 23:06:21933 std::vector<SkDiscardableHandleId> locked_handles_;
Jonathan Backer4fb9f5acb2018-05-10 22:19:33934
Khushalf9750702018-06-09 00:42:13935 // Tracing helpers.
936 int raster_chromium_id_ = 0;
937
Christopher Cameron386e18582019-01-11 20:17:34938 // Workaround for https://crbug.com/906453
939 bool flush_workaround_disabled_for_test_ = false;
940
Antoine Labour9ddf6ac2019-01-17 01:59:39941 bool in_copy_sub_texture_ = false;
942 bool reset_texture_state_ = false;
943
Malay Keshava154dcb2020-01-18 00:17:55944 bool is_privileged_ = false;
945
Peng Huangb447da42021-09-22 19:21:26946 const bool is_raw_draw_enabled_;
947
Vikas Sonica02287b2022-01-18 20:17:35948 const bool is_drdc_enabled_;
949
Pรขrisb3b3aba22022-10-10 08:15:20950 raw_ptr<gl::GLApi, DanglingUntriaged> api_ = nullptr;
Jonathan Backer628d73f82019-01-17 17:34:18951
Jeremy Roman28926e92019-07-15 15:42:16952 base::WeakPtrFactory<DecoderContext> weak_ptr_factory_{this};
Jonathan Backer7f90dfb662017-12-18 16:52:04953};
954
Jonathan Backer7471b2782018-01-25 18:14:19955constexpr RasterDecoderImpl::CommandInfo RasterDecoderImpl::command_info[] = {
Peng Huangc6a76072018-11-27 23:17:31956#define RASTER_CMD_OP(name) \
957 { \
958 &RasterDecoderImpl::Handle##name, \
959 cmds::name::kArgFlags, \
960 cmds::name::cmd_flags, \
961 sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \
Jonathan Backer7471b2782018-01-25 18:14:19962 }, /* NOLINT */
963 RASTER_COMMAND_LIST(RASTER_CMD_OP)
964#undef RASTER_CMD_OP
965};
966
967// static
968RasterDecoder* RasterDecoder::Create(
969 DecoderClient* client,
970 CommandBufferServiceBase* command_buffer_service,
Daniel Bratellaabc8d68e2018-07-18 19:20:26971 gles2::Outputter* outputter,
Antoine Labour10dddca12019-02-19 19:09:26972 const GpuFeatureInfo& gpu_feature_info,
973 const GpuPreferences& gpu_preferences,
974 MemoryTracker* memory_tracker,
975 SharedImageManager* shared_image_manager,
Malay Keshava154dcb2020-01-18 00:17:55976 scoped_refptr<SharedContextState> shared_context_state,
977 bool is_privileged) {
Vasiliy Telezhnikove05f0742022-12-05 20:48:38978 return new RasterDecoderImpl(client, command_buffer_service, outputter,
979 gpu_feature_info, gpu_preferences,
980 memory_tracker, shared_image_manager,
981 std::move(shared_context_state), is_privileged);
Jonathan Backer7471b2782018-01-25 18:14:19982}
983
Corentin Wallez0f412f02019-04-03 22:42:38984RasterDecoder::RasterDecoder(DecoderClient* client,
985 CommandBufferServiceBase* command_buffer_service,
Jonathan Backere26739c2018-05-15 13:27:07986 gles2::Outputter* outputter)
Corentin Wallez0f412f02019-04-03 22:42:38987 : CommonDecoder(client, command_buffer_service), outputter_(outputter) {}
Jonathan Backer7471b2782018-01-25 18:14:19988
989RasterDecoder::~RasterDecoder() {}
990
Jonathan Backera4568da12018-01-31 16:25:04991bool RasterDecoder::initialized() const {
992 return initialized_;
993}
994
995TextureBase* RasterDecoder::GetTextureBase(uint32_t client_id) {
996 return nullptr;
997}
998
Julien Isorcefd6c15f2018-03-15 16:51:17999void RasterDecoder::SetLevelInfo(uint32_t client_id,
1000 int level,
1001 unsigned internal_format,
1002 unsigned width,
1003 unsigned height,
1004 unsigned depth,
1005 unsigned format,
1006 unsigned type,
1007 const gfx::Rect& cleared_rect) {}
1008
Jonathan Backera4568da12018-01-31 16:25:041009void RasterDecoder::BeginDecoding() {}
1010
1011void RasterDecoder::EndDecoding() {}
1012
Jonathan Backer0cd1c4322018-04-17 16:57:101013void RasterDecoder::SetLogCommands(bool log_commands) {
1014 log_commands_ = log_commands;
1015}
1016
Jonathan Backere26739c2018-05-15 13:27:071017gles2::Outputter* RasterDecoder::outputter() const {
1018 return outputter_;
1019}
1020
Jonathan Backera4568da12018-01-31 16:25:041021base::StringPiece RasterDecoder::GetLogPrefix() {
1022 return GetLogger()->GetLogPrefix();
1023}
1024
Jonathan Backer7471b2782018-01-25 18:14:191025RasterDecoderImpl::RasterDecoderImpl(
1026 DecoderClient* client,
1027 CommandBufferServiceBase* command_buffer_service,
Daniel Bratellaabc8d68e2018-07-18 19:20:261028 gles2::Outputter* outputter,
Antoine Labour10dddca12019-02-19 19:09:261029 const GpuFeatureInfo& gpu_feature_info,
1030 const GpuPreferences& gpu_preferences,
1031 MemoryTracker* memory_tracker,
1032 SharedImageManager* shared_image_manager,
Malay Keshava154dcb2020-01-18 00:17:551033 scoped_refptr<SharedContextState> shared_context_state,
1034 bool is_privileged)
Corentin Wallez0f412f02019-04-03 22:42:381035 : RasterDecoder(client, command_buffer_service, outputter),
Khushal996e9912018-07-13 08:31:001036 raster_decoder_id_(g_raster_decoder_id.GetNext() + 1),
Bo Liu335323d2021-07-14 21:45:181037 disable_legacy_mailbox_(
1038 shared_image_manager &&
1039 shared_image_manager->display_context_on_another_thread()),
kylecharee7338172022-02-02 16:59:101040 gpu_raster_enabled_(
Antoine Labour10dddca12019-02-19 19:09:261041 gpu_feature_info.status_values[GPU_FEATURE_TYPE_GPU_RASTERIZATION] ==
1042 kGpuFeatureStatusEnabled),
1043 use_passthrough_(gles2::PassthroughCommandDecoderSupported() &&
1044 gpu_preferences.use_passthrough_cmd_decoder),
Antoine Labour10dddca12019-02-19 19:09:261045 gpu_preferences_(gpu_preferences),
Peng Huang61eccfe42018-11-15 22:10:131046 logger_(&debug_marker_manager_,
1047 base::BindRepeating(&DecoderClient::OnConsoleMessage,
Corentin Wallez0f412f02019-04-03 22:42:381048 base::Unretained(client),
James Darpinian104af6f2018-12-06 03:24:551049 0),
Antoine Labour10dddca12019-02-19 19:09:261050 gpu_preferences_.disable_gl_error_limit),
Peng Huangb4ed1852018-12-05 03:35:291051 error_state_(gles2::ErrorState::Create(this, &logger_)),
Peng Huang20361dad12019-01-23 14:48:101052 shared_context_state_(std::move(shared_context_state)),
Jonathan Backer9267bf1ec2018-03-06 19:56:501053 validators_(new Validators),
Antoine Labour10dddca12019-02-19 19:09:261054 shared_image_representation_factory_(shared_image_manager,
1055 memory_tracker),
Jonathan Backere26739c2018-05-15 13:27:071056 gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
Miguel Casas510fbfcb2018-11-13 23:40:571057 TRACE_DISABLED_BY_DEFAULT("gpu.decoder"))),
Vikas Soni2a4039f2020-07-22 18:34:201058 font_manager_(base::MakeRefCounted<ServiceFontManager>(
1059 this,
1060 gpu_preferences_.disable_oopr_debug_crash_dump)),
Peng Huangb447da42021-09-22 19:21:261061 is_privileged_(is_privileged),
Vikas Sonica02287b2022-01-18 20:17:351062 is_raw_draw_enabled_(features::IsUsingRawDraw()),
Vikas Sonibcb7f9b2022-08-25 16:03:171063 is_drdc_enabled_(features::IsDrDcEnabled() &&
1064 !feature_info()->workarounds().disable_drdc) {
Peng Huang20361dad12019-01-23 14:48:101065 DCHECK(shared_context_state_);
Jonathan Backerbaf79d92020-06-01 21:30:301066 shared_context_state_->AddContextLostObserver(this);
Khushalb2c140b2018-07-09 20:21:161067}
Jonathan Backer7f90dfb662017-12-18 16:52:041068
Jonathan Backerbaf79d92020-06-01 21:30:301069RasterDecoderImpl::~RasterDecoderImpl() {
1070 shared_context_state_->RemoveContextLostObserver(this);
1071}
Jonathan Backer7f90dfb662017-12-18 16:52:041072
Jonathan Backer7471b2782018-01-25 18:14:191073base::WeakPtr<DecoderContext> RasterDecoderImpl::AsWeakPtr() {
Jonathan Backer7f90dfb662017-12-18 16:52:041074 return weak_ptr_factory_.GetWeakPtr();
1075}
1076
Jonathan Backer0cd1c4322018-04-17 16:57:101077ContextResult RasterDecoderImpl::Initialize(
Jonathan Backer7f90dfb662017-12-18 16:52:041078 const scoped_refptr<gl::GLSurface>& surface,
1079 const scoped_refptr<gl::GLContext>& context,
1080 bool offscreen,
Daniel Bratellaabc8d68e2018-07-18 19:20:261081 const gles2::DisallowedFeatures& disallowed_features,
Antoine Labourfeab2392017-12-21 20:28:391082 const ContextCreationAttribs& attrib_helper) {
Jonathan Backer7471b2782018-01-25 18:14:191083 TRACE_EVENT0("gpu", "RasterDecoderImpl::Initialize");
Jonathan Backer192586792019-12-18 16:36:331084 DCHECK(shared_context_state_->IsCurrent(nullptr));
Jonathan Backer7f90dfb662017-12-18 16:52:041085
Jonathan Backer628d73f82019-01-17 17:34:181086 api_ = gl::g_current_gl_context;
1087
Jonathan Backera4568da12018-01-31 16:25:041088 set_initialized();
Jonathan Backer7f90dfb662017-12-18 16:52:041089
Jonathan Backer7f90dfb662017-12-18 16:52:041090 if (!offscreen) {
Jonathan Backer0cd1c4322018-04-17 16:57:101091 return ContextResult::kFatalFailure;
Jonathan Backer7f90dfb662017-12-18 16:52:041092 }
1093
Antoine Labour10dddca12019-02-19 19:09:261094 if (gpu_preferences_.enable_gpu_debugging)
Jonathan Backer7471b2782018-01-25 18:14:191095 set_debug(true);
Jonathan Backer7f90dfb662017-12-18 16:52:041096
Antoine Labour10dddca12019-02-19 19:09:261097 if (gpu_preferences_.enable_gpu_command_logging)
Jonathan Backer0cd1c4322018-04-17 16:57:101098 SetLogCommands(true);
Jonathan Backer7f90dfb662017-12-18 16:52:041099
Peng Huang20361dad12019-01-23 14:48:101100 DCHECK_EQ(surface.get(), shared_context_state_->surface());
1101 DCHECK_EQ(context.get(), shared_context_state_->context());
Jonathan Backer7f90dfb662017-12-18 16:52:041102
Jonathan Backere26739c2018-05-15 13:27:071103 // Create GPU Tracer for timing values.
Peter Bostrรถm1aa21c142021-04-03 01:12:031104 gpu_tracer_ = std::make_unique<gles2::GPUTracer>(
1105 this, shared_context_state_->GrContextIsGL());
Jonathan Backere26739c2018-05-15 13:27:071106
Jonathan Backer4f9ee5fb2018-04-25 14:03:381107 // Save the loseContextWhenOutOfMemory context creation attribute.
1108 lose_context_when_out_of_memory_ =
1109 attrib_helper.lose_context_when_out_of_memory;
1110
Jonathan Backer7f90dfb662017-12-18 16:52:041111 CHECK_GL_ERROR();
1112
Peng Huang7bb7db4b2021-06-16 15:30:021113 query_manager_ = std::make_unique<RasterQueryManager>(shared_context_state_);
Jonathan Backer016bd97e2018-03-14 15:26:391114
Jonathan Backer0cd1c4322018-04-17 16:57:101115 if (attrib_helper.enable_oop_rasterization) {
kylecharee7338172022-02-02 16:59:101116 if (!gpu_raster_enabled_) {
1117 LOG(ERROR) << "ContextResult::kFatalFailure: GPU raster is disabled";
Jonathan Backer15dbca32018-06-04 20:39:331118 Destroy(true);
Jonathan Backer0cd1c4322018-04-17 16:57:101119 return ContextResult::kFatalFailure;
1120 }
1121
Colin Blundelld7b7b472023-05-12 07:38:121122 DCHECK(gr_context() || graphite_context());
kylecharee7338172022-02-02 16:59:101123 use_gpu_raster_ = true;
1124 paint_cache_ = std::make_unique<cc::ServicePaintCache>();
Khushal996e9912018-07-13 08:31:001125 }
Jonathan Backer0cd1c4322018-04-17 16:57:101126
1127 return ContextResult::kSuccess;
Jonathan Backer1d807a42018-01-08 20:45:541128}
Jonathan Backer7f90dfb662017-12-18 16:52:041129
Jonathan Backera4568da12018-01-31 16:25:041130void RasterDecoderImpl::Destroy(bool have_context) {
Jonathan Backer10821a82018-04-04 23:56:031131 if (!initialized())
1132 return;
1133
Peng Huang20361dad12019-01-23 14:48:101134 DCHECK(!have_context || shared_context_state_->context()->IsCurrent(nullptr));
Jonathan Backer10821a82018-04-04 23:56:031135
Vasiliy Telezhnikov91d18812023-02-02 21:21:261136 // Client can call BeginRasterChromium and then channel can be closed and
1137 // decoder destroyed. Finish raster first.
1138 // Note: `have_context` is always false for Vulkan, so we don't gate this code
1139 // on it.
1140 if (sk_surface_ || scoped_shared_image_raster_write_) {
1141 DoEndRasterCHROMIUM();
1142 }
1143
Jonathan Backer10821a82018-04-04 23:56:031144 if (have_context) {
kylecharee7338172022-02-02 16:59:101145 if (use_gpu_raster_) {
Andres Calderon Jaramillo56d9f1ea2019-05-24 19:57:341146 transfer_cache()->DeleteAllEntriesForDecoder(raster_decoder_id_);
1147 }
Jonathan Backer10821a82018-04-04 23:56:031148 }
1149
Peng Huang95a63e4b2020-07-03 21:28:111150 if (query_manager_) {
Jonathan Backer016bd97e2018-03-14 15:26:391151 query_manager_->Destroy(have_context);
1152 query_manager_.reset();
1153 }
1154
Khushal3d0b8902018-09-18 03:03:341155 font_manager_->Destroy();
1156 font_manager_.reset();
Jonathan Backera4568da12018-01-31 16:25:041157}
Jonathan Backer7f90dfb662017-12-18 16:52:041158
Jonathan Backer7f90dfb662017-12-18 16:52:041159// Make this decoder's GL context current.
Jonathan Backer7471b2782018-01-25 18:14:191160bool RasterDecoderImpl::MakeCurrent() {
Christopher Camerondd7812d2019-04-23 03:12:211161 if (!shared_context_state_->GrContextIsGL())
Jonathan Backer7621ec92018-12-11 00:02:441162 return true;
1163
Peng Huang66a7a3762018-12-07 20:05:381164 if (context_lost_) {
Jonathan Backer7471b2782018-01-25 18:14:191165 LOG(ERROR) << " RasterDecoderImpl: Trying to make lost context current.";
Jonathan Backer7f90dfb662017-12-18 16:52:041166 return false;
1167 }
1168
Peng Huang20361dad12019-01-23 14:48:101169 if (shared_context_state_->context_lost() ||
1170 !shared_context_state_->MakeCurrent(nullptr)) {
Jonathan Backer7471b2782018-01-25 18:14:191171 LOG(ERROR) << " RasterDecoderImpl: Context lost during MakeCurrent.";
Jonathan Backer7f90dfb662017-12-18 16:52:041172 return false;
1173 }
Peng Huang66a7a3762018-12-07 20:05:381174
Jonathan Backer34008d882018-03-27 18:57:551175 DCHECK_EQ(api(), gl::g_current_gl_context);
1176
1177 // Rebind textures if the service ids may have changed.
1178 RestoreAllExternalTextureBindingsIfNeeded();
1179
Vasiliy Telezhnikov751b5362021-09-14 13:35:491180 // We're going to use skia, so make sure we reset context afterwards.
1181 shared_context_state_->set_need_context_state_reset(true);
1182
Jonathan Backer7f90dfb662017-12-18 16:52:041183 return true;
1184}
1185
Jonathan Backer7471b2782018-01-25 18:14:191186gl::GLContext* RasterDecoderImpl::GetGLContext() {
Peng Huangad7442f2020-02-24 22:22:091187 return shared_context_state_->GrContextIsGL()
1188 ? shared_context_state_->context()
1189 : nullptr;
Jonathan Backer7f90dfb662017-12-18 16:52:041190}
1191
liberato@chromium.org00c8a6c2018-06-05 02:22:411192gl::GLSurface* RasterDecoderImpl::GetGLSurface() {
Peng Huangad7442f2020-02-24 22:22:091193 return shared_context_state_->GrContextIsGL()
1194 ? shared_context_state_->surface()
1195 : nullptr;
liberato@chromium.org00c8a6c2018-06-05 02:22:411196}
1197
Jonathan Backer7471b2782018-01-25 18:14:191198Capabilities RasterDecoderImpl::GetCapabilities() {
Adrienne Walker693f34d2019-07-29 22:07:041199 // TODO(enne): reconcile this with gles2_cmd_decoder's capability settings.
Jonathan Backer0cd1c4322018-04-17 16:57:101200 Capabilities caps;
kylecharee7338172022-02-02 16:59:101201 caps.gpu_rasterization = use_gpu_raster_;
1202 caps.supports_oop_raster = use_gpu_raster_;
Antoine Labour0f9bee72018-11-06 07:35:431203 caps.gpu_memory_buffer_formats =
Antoine Labour10dddca12019-02-19 19:09:261204 feature_info()->feature_flags().gpu_memory_buffer_formats;
Victor Miuracabdfac2018-01-05 02:18:181205 caps.texture_target_exception_list =
Antoine Labour10dddca12019-02-19 19:09:261206 gpu_preferences_.texture_target_exception_list;
Jonathan Backera07c4a9e2018-03-21 15:13:161207 caps.texture_format_bgra8888 =
Antoine Labour10dddca12019-02-19 19:09:261208 feature_info()->feature_flags().ext_texture_format_bgra8888;
kylechar81ac76d2023-02-14 21:43:491209 caps.texture_rg = feature_info()->feature_flags().ext_texture_rg;
Vasiliy Telezhnikove05f0742022-12-05 20:48:381210 caps.supports_scanout_shared_images =
1211 SharedImageManager::SupportsScanoutImages();
Peng Huang3c13b502019-05-08 01:40:001212 // TODO(piman): have a consistent limit in shared image backings.
1213 // https://crbug.com/960588
Sunny Sachanandani94760ca2023-03-30 00:40:561214 if (shared_context_state_->GrContextIsGL()) {
Peng Huang3c13b502019-05-08 01:40:001215 api()->glGetIntegervFn(GL_MAX_TEXTURE_SIZE, &caps.max_texture_size);
1216 } else if (shared_context_state_->GrContextIsVulkan()) {
1217#if BUILDFLAG(ENABLE_VULKAN)
1218 caps.max_texture_size = shared_context_state_->vk_context_provider()
1219 ->GetDeviceQueue()
1220 ->vk_physical_device_properties()
1221 .limits.maxImageDimension2D;
1222#else
1223 NOTREACHED();
1224#endif
Sunny Sachanandanifb74c17f2023-04-10 21:29:171225 } else {
kylechar468165b32020-06-02 22:08:581226 // TODO(crbug.com/1090476): Query Dawn for this value once an API exists for
1227 // capabilities.
1228 caps.max_texture_size = 8192;
Peng Huang3c13b502019-05-08 01:40:001229 }
Bo Liu1e4cf912022-06-27 16:38:541230 if (feature_info()->workarounds().webgl_or_caps_max_texture_size) {
Bo Liuf2f4c6d2022-04-28 20:34:451231 caps.max_texture_size =
1232 std::min(caps.max_texture_size,
Bo Liu1e4cf912022-06-27 16:38:541233 feature_info()->workarounds().webgl_or_caps_max_texture_size);
James Darpinian3c422032019-04-06 00:20:161234 caps.max_cube_map_texture_size =
1235 std::min(caps.max_cube_map_texture_size,
Bo Liu1e4cf912022-06-27 16:38:541236 feature_info()->workarounds().webgl_or_caps_max_texture_size);
James Darpinian3c422032019-04-06 00:20:161237 }
1238 if (feature_info()->workarounds().max_3d_array_texture_size) {
1239 caps.max_3d_texture_size =
1240 std::min(caps.max_3d_texture_size,
1241 feature_info()->workarounds().max_3d_array_texture_size);
1242 caps.max_array_texture_layers =
1243 std::min(caps.max_array_texture_layers,
1244 feature_info()->workarounds().max_3d_array_texture_size);
Antoine Labour10dddca12019-02-19 19:09:261245 }
1246 caps.sync_query = feature_info()->feature_flags().chromium_sync_query;
Justin Novosad4486ec32022-07-07 17:45:081247 caps.msaa_is_slow =
1248 base::FeatureList::IsEnabled(features::kEnableMSAAOnNewIntelGPUs)
1249 ? feature_info()->workarounds().msaa_is_slow_2
1250 : feature_info()->workarounds().msaa_is_slow;
Adrienne Walker693f34d2019-07-29 22:07:041251 caps.avoid_stencil_buffers =
1252 feature_info()->workarounds().avoid_stencil_buffers;
Khushal315f2fd2018-05-29 03:20:391253
Khushalb2c140b2018-07-09 20:21:161254 if (gr_context()) {
Khushal315f2fd2018-05-29 03:20:391255 caps.context_supports_distance_field_text =
Khushalb2c140b2018-07-09 20:21:161256 gr_context()->supportsDistanceFieldText();
Dale Curtis816d5232020-07-29 19:31:351257 caps.texture_norm16 =
1258 gr_context()->colorTypeSupportedAsImage(kA16_unorm_SkColorType);
1259 caps.texture_half_float_linear =
1260 gr_context()->colorTypeSupportedAsImage(kA16_float_SkColorType);
Colin Blundelld7b7b472023-05-12 07:38:121261 } else if (graphite_context()) {
1262 // TODO(b/281151641): Determine if there are checks to be made here.
1263 caps.texture_norm16 = true;
1264 caps.texture_half_float_linear = true;
Dale Curtis816d5232020-07-29 19:31:351265 } else {
1266 caps.texture_norm16 = feature_info()->feature_flags().ext_texture_norm16;
1267 caps.texture_half_float_linear =
1268 feature_info()->feature_flags().enable_texture_half_float_linear;
Khushalf9750702018-06-09 00:42:131269 }
Xiaohan Wangfa22d3e2022-01-15 02:02:431270#if BUILDFLAG(IS_WIN)
Le Hoang Quyenf6784d02022-08-05 21:13:241271 caps.shared_image_d3d =
1272 D3DImageBackingFactory::IsD3DSharedImageSupported(gpu_preferences_);
Saifuddin Hitawaladaed5972022-07-20 22:01:011273 caps.shared_image_swap_chain = D3DImageBackingFactory::IsSwapChainSupported();
Xiaohan Wangfa22d3e2022-01-15 02:02:431274#endif // BUILDFLAG(IS_WIN)
Bo Liu335323d2021-07-14 21:45:181275 caps.disable_legacy_mailbox = disable_legacy_mailbox_;
Saifuddin Hitawala443437a2023-01-25 18:12:141276 caps.supports_yuv_rgb_conversion = true;
Jonathan Backer7f90dfb662017-12-18 16:52:041277 return caps;
1278}
1279
Peng Huangc6a76072018-11-27 23:17:311280const gles2::ContextState* RasterDecoderImpl::GetContextState() {
Peng Huang66a7a3762018-12-07 20:05:381281 NOTREACHED();
1282 return nullptr;
Peng Huangc6a76072018-11-27 23:17:311283}
1284
Jonathan Backer34008d882018-03-27 18:57:551285void RasterDecoderImpl::RestoreGlobalState() const {
Peng Huangd7aaf782019-01-09 22:03:081286 // We mark the context state is dirty instead of restoring global
1287 // state, and the global state will be restored by the next context.
Peng Huang20361dad12019-01-23 14:48:101288 shared_context_state_->set_need_context_state_reset(true);
1289 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer34008d882018-03-27 18:57:551290}
1291
Peng Huangc6a76072018-11-27 23:17:311292void RasterDecoderImpl::ClearAllAttributes() const {}
Jonathan Backer34008d882018-03-27 18:57:551293
1294void RasterDecoderImpl::RestoreAllAttributes() const {
Peng Huang20361dad12019-01-23 14:48:101295 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer34008d882018-03-27 18:57:551296}
1297
Daniel Bratellaabc8d68e2018-07-18 19:20:261298void RasterDecoderImpl::RestoreState(const gles2::ContextState* prev_state) {
Peng Huang20361dad12019-01-23 14:48:101299 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041300}
1301
Jonathan Backer7471b2782018-01-25 18:14:191302void RasterDecoderImpl::RestoreActiveTexture() const {
Peng Huang20361dad12019-01-23 14:48:101303 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041304}
1305
Jonathan Backer7471b2782018-01-25 18:14:191306void RasterDecoderImpl::RestoreAllTextureUnitAndSamplerBindings(
Daniel Bratellaabc8d68e2018-07-18 19:20:261307 const gles2::ContextState* prev_state) const {
Peng Huang20361dad12019-01-23 14:48:101308 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041309}
1310
Jonathan Backer7471b2782018-01-25 18:14:191311void RasterDecoderImpl::RestoreActiveTextureUnitBinding(
1312 unsigned int target) const {
Peng Huang20361dad12019-01-23 14:48:101313 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041314}
1315
Jonathan Backer7471b2782018-01-25 18:14:191316void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) {
Peng Huang20361dad12019-01-23 14:48:101317 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041318}
1319
Jonathan Backer7471b2782018-01-25 18:14:191320void RasterDecoderImpl::RestoreBufferBindings() const {
Peng Huang20361dad12019-01-23 14:48:101321 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041322}
1323
Jonathan Backer7471b2782018-01-25 18:14:191324void RasterDecoderImpl::RestoreFramebufferBindings() const {
Peng Huang20361dad12019-01-23 14:48:101325 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041326}
1327
Jonathan Backer7471b2782018-01-25 18:14:191328void RasterDecoderImpl::RestoreRenderbufferBindings() {
Peng Huang20361dad12019-01-23 14:48:101329 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041330}
1331
Jonathan Backer7471b2782018-01-25 18:14:191332void RasterDecoderImpl::RestoreProgramBindings() const {
Peng Huang20361dad12019-01-23 14:48:101333 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041334}
1335
Antoine Labour9ddf6ac2019-01-17 01:59:391336void RasterDecoderImpl::RestoreTextureState(unsigned service_id) {
1337 DCHECK(in_copy_sub_texture_);
1338 reset_texture_state_ = true;
Jonathan Backer7f90dfb662017-12-18 16:52:041339}
1340
Jonathan Backer7471b2782018-01-25 18:14:191341void RasterDecoderImpl::RestoreTextureUnitBindings(unsigned unit) const {
Peng Huang20361dad12019-01-23 14:48:101342 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041343}
1344
Jonathan Backer7471b2782018-01-25 18:14:191345void RasterDecoderImpl::RestoreVertexAttribArray(unsigned index) {
Peng Huang20361dad12019-01-23 14:48:101346 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041347}
1348
Jonathan Backer7471b2782018-01-25 18:14:191349void RasterDecoderImpl::RestoreAllExternalTextureBindingsIfNeeded() {
Peng Huang20361dad12019-01-23 14:48:101350 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer7f90dfb662017-12-18 16:52:041351}
1352
Jonathan Backer7471b2782018-01-25 18:14:191353QueryManager* RasterDecoderImpl::GetQueryManager() {
Jonathan Backer016bd97e2018-03-14 15:26:391354 return query_manager_.get();
Jonathan Backer7f90dfb662017-12-18 16:52:041355}
1356
Geoff Lang85287e12018-05-22 17:26:401357void RasterDecoderImpl::SetQueryCallback(unsigned int query_client_id,
1358 base::OnceClosure callback) {
1359 QueryManager::Query* query = query_manager_->GetQuery(query_client_id);
1360 if (query) {
1361 query->AddCallback(std::move(callback));
1362 } else {
1363 VLOG(1) << "RasterDecoderImpl::SetQueryCallback: No query with ID "
1364 << query_client_id << ". Running the callback immediately.";
1365 std::move(callback).Run();
1366 }
1367}
1368
Daniel Bratellaabc8d68e2018-07-18 19:20:261369gles2::GpuFenceManager* RasterDecoderImpl::GetGpuFenceManager() {
Jonathan Backer7f90dfb662017-12-18 16:52:041370 NOTIMPLEMENTED();
1371 return nullptr;
1372}
1373
Jonathan Backer7471b2782018-01-25 18:14:191374bool RasterDecoderImpl::HasPendingQueries() const {
Peng Huang66a7a3762018-12-07 20:05:381375 return query_manager_ && query_manager_->HavePendingQueries();
Jonathan Backer7f90dfb662017-12-18 16:52:041376}
1377
Jonathan Backer7471b2782018-01-25 18:14:191378void RasterDecoderImpl::ProcessPendingQueries(bool did_finish) {
Vasiliy Telezhnikov517dd8c2022-05-17 15:39:471379 if (query_manager_) {
Colin Blundelld7b7b472023-05-12 07:38:121380 if (gr_context()) {
1381 gr_context()->checkAsyncWorkCompletion();
1382 } else if (graphite_context()) {
1383 graphite_context()->checkAsyncWorkCompletion();
1384 }
Peng Huang66a7a3762018-12-07 20:05:381385 query_manager_->ProcessPendingQueries(did_finish);
Vasiliy Telezhnikov517dd8c2022-05-17 15:39:471386 }
Jonathan Backer7f90dfb662017-12-18 16:52:041387}
1388
Jonathan Backer7471b2782018-01-25 18:14:191389bool RasterDecoderImpl::HasMoreIdleWork() const {
Jonathan Backere26739c2018-05-15 13:27:071390 return gpu_tracer_->HasTracesToProcess();
Jonathan Backer7f90dfb662017-12-18 16:52:041391}
1392
Jonathan Backer7471b2782018-01-25 18:14:191393void RasterDecoderImpl::PerformIdleWork() {
Jonathan Backere26739c2018-05-15 13:27:071394 gpu_tracer_->ProcessTraces();
Jonathan Backer7f90dfb662017-12-18 16:52:041395}
1396
Jonathan Backer7471b2782018-01-25 18:14:191397bool RasterDecoderImpl::HasPollingWork() const {
Jonathan Backer7f90dfb662017-12-18 16:52:041398 return false;
1399}
1400
Jonathan Backerc2b0efa2018-03-21 16:58:351401void RasterDecoderImpl::PerformPollingWork() {}
Jonathan Backer7f90dfb662017-12-18 16:52:041402
Jonathan Backer7471b2782018-01-25 18:14:191403TextureBase* RasterDecoderImpl::GetTextureBase(uint32_t client_id) {
Jonathan Backer7f90dfb662017-12-18 16:52:041404 NOTIMPLEMENTED();
1405 return nullptr;
1406}
1407
Julien Isorcefd6c15f2018-03-15 16:51:171408void RasterDecoderImpl::SetLevelInfo(uint32_t client_id,
1409 int level,
1410 unsigned internal_format,
1411 unsigned width,
1412 unsigned height,
1413 unsigned depth,
1414 unsigned format,
1415 unsigned type,
1416 const gfx::Rect& cleared_rect) {
1417 NOTIMPLEMENTED();
1418}
1419
Jonathan Backer7471b2782018-01-25 18:14:191420bool RasterDecoderImpl::WasContextLost() const {
Jonathan Backerbaf79d92020-06-01 21:30:301421 return shared_context_state_->context_lost();
Jonathan Backer7f90dfb662017-12-18 16:52:041422}
1423
Jonathan Backer7471b2782018-01-25 18:14:191424bool RasterDecoderImpl::WasContextLostByRobustnessExtension() const {
Jonathan Backerbaf79d92020-06-01 21:30:301425 return shared_context_state_->device_needs_reset();
Jonathan Backer7f90dfb662017-12-18 16:52:041426}
1427
Jonathan Backer7471b2782018-01-25 18:14:191428void RasterDecoderImpl::MarkContextLost(error::ContextLostReason reason) {
Jonathan Backerbaf79d92020-06-01 21:30:301429 shared_context_state_->MarkContextLost(reason);
1430}
Jonathan Backer4f9ee5fb2018-04-25 14:03:381431
Jonathan Backerbaf79d92020-06-01 21:30:301432void RasterDecoderImpl::OnContextLost() {
1433 DCHECK(shared_context_state_->context_lost());
1434 command_buffer_service()->SetContextLostReason(
1435 *shared_context_state_->context_lost_reason());
Jonathan Backer4f9ee5fb2018-04-25 14:03:381436 current_decoder_error_ = error::kLostContext;
Jonathan Backer7f90dfb662017-12-18 16:52:041437}
1438
Jonathan Backer7471b2782018-01-25 18:14:191439bool RasterDecoderImpl::CheckResetStatus() {
Jonathan Backer4f9ee5fb2018-04-25 14:03:381440 DCHECK(!WasContextLost());
Jonathan Backerbaf79d92020-06-01 21:30:301441 return shared_context_state_->CheckResetStatus(/*needs_gl=*/false);
Jonathan Backer7f90dfb662017-12-18 16:52:041442}
1443
Daniel Bratellaabc8d68e2018-07-18 19:20:261444gles2::Logger* RasterDecoderImpl::GetLogger() {
Jonathan Backera4568da12018-01-31 16:25:041445 return &logger_;
1446}
1447
1448void RasterDecoderImpl::SetIgnoreCachedStateForTest(bool ignore) {
Antoine Labour10dddca12019-02-19 19:09:261449 if (use_passthrough_)
Jonathan Backer628d73f82019-01-17 17:34:181450 return;
Peng Huang66a7a3762018-12-07 20:05:381451 state()->SetIgnoreCachedStateForTest(ignore);
Jonathan Backera4568da12018-01-31 16:25:041452}
1453
Jonathan Backer7471b2782018-01-25 18:14:191454void RasterDecoderImpl::BeginDecoding() {
Jonathan Backere26739c2018-05-15 13:27:071455 gpu_tracer_->BeginDecoding();
1456 gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_;
1457 gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_;
Khushalcd8fbb772018-10-16 22:46:141458 query_manager_->BeginProcessingCommands();
Jonathan Backer7f90dfb662017-12-18 16:52:041459}
1460
Jonathan Backere26739c2018-05-15 13:27:071461void RasterDecoderImpl::EndDecoding() {
1462 gpu_tracer_->EndDecoding();
Khushalcd8fbb772018-10-16 22:46:141463 query_manager_->EndProcessingCommands();
Jonathan Backere26739c2018-05-15 13:27:071464}
Jonathan Backer7f90dfb662017-12-18 16:52:041465
Jonathan Backer7471b2782018-01-25 18:14:191466const char* RasterDecoderImpl::GetCommandName(unsigned int command_id) const {
1467 if (command_id >= kFirstRasterCommand && command_id < kNumCommands) {
Jonathan Backera4568da12018-01-31 16:25:041468 return raster::GetCommandName(static_cast<CommandId>(command_id));
Jonathan Backer7f90dfb662017-12-18 16:52:041469 }
1470 return GetCommonCommandName(static_cast<cmd::CommandId>(command_id));
1471}
1472
Jonathan Backer1d807a42018-01-08 20:45:541473template <bool DebugImpl>
Jonathan Backer7471b2782018-01-25 18:14:191474error::Error RasterDecoderImpl::DoCommandsImpl(unsigned int num_commands,
1475 const volatile void* buffer,
1476 int num_entries,
1477 int* entries_processed) {
Jonathan Backer7f90dfb662017-12-18 16:52:041478 DCHECK(entries_processed);
1479 commands_to_process_ = num_commands;
1480 error::Error result = error::kNoError;
1481 const volatile CommandBufferEntry* cmd_data =
1482 static_cast<const volatile CommandBufferEntry*>(buffer);
1483 int process_pos = 0;
Jonathan Backer2231a002018-05-14 19:55:221484 CommandId command = static_cast<CommandId>(0);
Jonathan Backer7f90dfb662017-12-18 16:52:041485
1486 while (process_pos < num_entries && result == error::kNoError &&
1487 commands_to_process_--) {
1488 const unsigned int size = cmd_data->value_header.size;
Jonathan Backer2231a002018-05-14 19:55:221489 command = static_cast<CommandId>(cmd_data->value_header.command);
Jonathan Backer7f90dfb662017-12-18 16:52:041490
1491 if (size == 0) {
1492 result = error::kInvalidSize;
1493 break;
1494 }
1495
1496 if (static_cast<int>(size) + process_pos > num_entries) {
1497 result = error::kOutOfBounds;
1498 break;
1499 }
1500
Jonathan Backer1d807a42018-01-08 20:45:541501 if (DebugImpl && log_commands()) {
1502 LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]"
1503 << "cmd: " << GetCommandName(command);
1504 }
1505
Jonathan Backer7f90dfb662017-12-18 16:52:041506 const unsigned int arg_count = size - 1;
Jonathan Backer7471b2782018-01-25 18:14:191507 unsigned int command_index = command - kFirstRasterCommand;
Daniel Chengadafb3a2022-02-28 07:38:221508 if (command_index < std::size(command_info)) {
Jonathan Backer7f90dfb662017-12-18 16:52:041509 const CommandInfo& info = command_info[command_index];
Jonathan Backer2231a002018-05-14 19:55:221510 if (sk_surface_) {
1511 if (!AllowedBetweenBeginEndRaster(command)) {
1512 LOCAL_SET_GL_ERROR(
1513 GL_INVALID_OPERATION, GetCommandName(command),
1514 "Unexpected command between BeginRasterCHROMIUM and "
1515 "EndRasterCHROMIUM");
1516 process_pos += size;
1517 cmd_data += size;
1518 continue;
1519 }
1520 }
Jonathan Backer7f90dfb662017-12-18 16:52:041521 unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count);
1522 if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) ||
1523 (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) {
Jonathan Backere26739c2018-05-15 13:27:071524 bool doing_gpu_trace = false;
1525 if (DebugImpl && gpu_trace_commands_) {
1526 if (CMD_FLAG_GET_TRACE_LEVEL(info.cmd_flags) <= gpu_trace_level_) {
1527 doing_gpu_trace = true;
Miguel Casas510fbfcb2018-11-13 23:40:571528 gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu.decoder"),
Daniel Bratellaabc8d68e2018-07-18 19:20:261529 GetCommandName(command), gles2::kTraceDecoder);
Jonathan Backere26739c2018-05-15 13:27:071530 }
1531 }
1532
Jonathan Backer7f90dfb662017-12-18 16:52:041533 uint32_t immediate_data_size = (arg_count - info_arg_count) *
1534 sizeof(CommandBufferEntry); // NOLINT
Jonathan Backer7471b2782018-01-25 18:14:191535 result = (this->*info.cmd_handler)(immediate_data_size, cmd_data);
Jonathan Backere26739c2018-05-15 13:27:071536
1537 if (DebugImpl && doing_gpu_trace)
Daniel Bratellaabc8d68e2018-07-18 19:20:261538 gpu_tracer_->End(gles2::kTraceDecoder);
Jonathan Backere26739c2018-05-15 13:27:071539
Kramer Gee6c74692020-02-07 21:07:311540 if (DebugImpl && shared_context_state_->GrContextIsGL() && debug() &&
1541 !WasContextLost()) {
Jonathan Backer7471b2782018-01-25 18:14:191542 GLenum error;
1543 while ((error = api()->glGetErrorFn()) != GL_NO_ERROR) {
1544 LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] "
Daniel Bratellaabc8d68e2018-07-18 19:20:261545 << "GL ERROR: " << gles2::GLES2Util::GetStringEnum(error)
Jonathan Backer7471b2782018-01-25 18:14:191546 << " : " << GetCommandName(command);
1547 LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver");
Jonathan Backer1d807a42018-01-08 20:45:541548 }
Jonathan Backer7f90dfb662017-12-18 16:52:041549 }
1550 } else {
1551 result = error::kInvalidArguments;
1552 }
1553 } else {
1554 result = DoCommonCommand(command, arg_count, cmd_data);
1555 }
1556
1557 if (result == error::kNoError &&
1558 current_decoder_error_ != error::kNoError) {
1559 result = current_decoder_error_;
1560 current_decoder_error_ = error::kNoError;
1561 }
1562
1563 if (result != error::kDeferCommandUntilLater) {
1564 process_pos += size;
1565 cmd_data += size;
1566 }
Christopher Cameron02e3149a2019-01-25 19:52:231567
Christopher Cameronbeb5f272019-02-04 22:49:131568 // Workaround for https://crbug.com/906453: Flush after every command that
1569 // is not between a BeginRaster and EndRaster.
1570 if (!sk_surface_)
1571 FlushToWorkAroundMacCrashes();
Jonathan Backer7f90dfb662017-12-18 16:52:041572 }
1573
1574 *entries_processed = process_pos;
1575
1576 if (error::IsError(result)) {
1577 LOG(ERROR) << "Error: " << result << " for Command "
1578 << GetCommandName(command);
1579 }
1580
kylecharee7338172022-02-02 16:59:101581 if (use_gpu_raster_)
Corentin Wallez0f412f02019-04-03 22:42:381582 client()->ScheduleGrContextCleanup();
Khushal7324ec42018-07-10 20:01:451583
Jonathan Backer7f90dfb662017-12-18 16:52:041584 return result;
1585}
1586
Jonathan Backer7471b2782018-01-25 18:14:191587error::Error RasterDecoderImpl::DoCommands(unsigned int num_commands,
1588 const volatile void* buffer,
1589 int num_entries,
1590 int* entries_processed) {
Jonathan Backer1d807a42018-01-08 20:45:541591 if (gpu_debug_commands_) {
1592 return DoCommandsImpl<true>(num_commands, buffer, num_entries,
1593 entries_processed);
1594 } else {
1595 return DoCommandsImpl<false>(num_commands, buffer, num_entries,
1596 entries_processed);
1597 }
Jonathan Backer7f90dfb662017-12-18 16:52:041598}
1599
Corentin Wallez0f412f02019-04-03 22:42:381600void RasterDecoderImpl::ExitCommandProcessingEarly() {
1601 commands_to_process_ = 0;
1602}
1603
Jonathan Backer7471b2782018-01-25 18:14:191604base::StringPiece RasterDecoderImpl::GetLogPrefix() {
Jonathan Backer1d807a42018-01-08 20:45:541605 return logger_.GetLogPrefix();
Jonathan Backer7f90dfb662017-12-18 16:52:041606}
1607
Dave Tapuskac03874f2023-02-01 21:53:551608#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE)
Colin Blundellddd83e02022-11-30 13:40:161609void RasterDecoderImpl::AttachImageToTextureWithDecoderBinding(
1610 uint32_t client_texture_id,
1611 uint32_t texture_target,
1612 gl::GLImage* image) {
Jonathan Backer7f90dfb662017-12-18 16:52:041613 NOTIMPLEMENTED();
1614}
Colin Blundelle2c394e2022-12-16 09:26:591615#elif !BUILDFLAG(IS_ANDROID)
Colin Blundellddd83e02022-11-30 13:40:161616void RasterDecoderImpl::AttachImageToTextureWithClientBinding(
1617 uint32_t client_texture_id,
1618 uint32_t texture_target,
1619 gl::GLImage* image) {
1620 NOTIMPLEMENTED();
1621}
1622#endif
Jonathan Backer7f90dfb662017-12-18 16:52:041623
Jonathan Backer7471b2782018-01-25 18:14:191624gles2::ContextGroup* RasterDecoderImpl::GetContextGroup() {
Antoine Labour914f3af2019-02-14 20:24:131625 return nullptr;
Jonathan Backer1d807a42018-01-08 20:45:541626}
1627
Jonathan Backer7471b2782018-01-25 18:14:191628gles2::ErrorState* RasterDecoderImpl::GetErrorState() {
Peng Huangb4ed1852018-12-05 03:35:291629 return error_state_.get();
Jonathan Backer1d807a42018-01-08 20:45:541630}
1631
Colin Blundell9d4fea62022-12-14 15:26:161632#if !BUILDFLAG(IS_ANDROID)
Daniel Bratellaabc8d68e2018-07-18 19:20:261633std::unique_ptr<gles2::AbstractTexture>
1634RasterDecoderImpl::CreateAbstractTexture(GLenum target,
1635 GLenum internal_format,
1636 GLsizei width,
1637 GLsizei height,
1638 GLsizei depth,
1639 GLint border,
1640 GLenum format,
1641 GLenum type) {
liberato@chromium.org00c8a6c2018-06-05 02:22:411642 return nullptr;
1643}
Colin Blundell9d4fea62022-12-14 15:26:161644#endif
liberato@chromium.org00c8a6c2018-06-05 02:22:411645
Jonathan Backerc26060e2018-03-29 15:06:291646bool RasterDecoderImpl::IsCompressedTextureFormat(unsigned format) {
Antoine Labour10dddca12019-02-19 19:09:261647 return feature_info()->validators()->compressed_texture_format.IsValid(
1648 format);
Jonathan Backerc26060e2018-03-29 15:06:291649}
1650
1651bool RasterDecoderImpl::ClearLevel(gles2::Texture* texture,
1652 unsigned target,
1653 int level,
1654 unsigned format,
1655 unsigned type,
1656 int xoffset,
1657 int yoffset,
1658 int width,
1659 int height) {
Vasiliy Telezhnikov1b818d62022-08-24 17:19:421660 NOTREACHED();
Jonathan Backerc26060e2018-03-29 15:06:291661 return true;
1662}
1663
1664bool RasterDecoderImpl::ClearCompressedTextureLevel(gles2::Texture* texture,
1665 unsigned target,
1666 int level,
1667 unsigned format,
1668 int width,
1669 int height) {
Peng Huange89c2a052018-12-04 11:35:111670 NOTREACHED();
1671 return false;
Jonathan Backerc26060e2018-03-29 15:06:291672}
1673
shrekshaoad4525482020-03-12 00:30:551674bool RasterDecoderImpl::ClearCompressedTextureLevel3D(gles2::Texture* texture,
1675 unsigned target,
1676 int level,
1677 unsigned format,
1678 int width,
1679 int height,
1680 int depth) {
1681 NOTREACHED();
1682 return false;
1683}
1684
Andres Calderon Jaramillob870ca62019-01-29 16:33:351685int RasterDecoderImpl::GetRasterDecoderId() const {
1686 return raster_decoder_id_;
1687}
1688
Khushal996e9912018-07-13 08:31:001689int RasterDecoderImpl::DecoderIdForTest() {
1690 return raster_decoder_id_;
1691}
1692
Jonathan Backer0cd1c4322018-04-17 16:57:101693ServiceTransferCache* RasterDecoderImpl::GetTransferCacheForTest() {
Peng Huang20361dad12019-01-23 14:48:101694 return shared_context_state_->transfer_cache();
Jonathan Backer0cd1c4322018-04-17 16:57:101695}
1696
Khushal15b6abb2018-06-28 00:16:251697void RasterDecoderImpl::SetUpForRasterCHROMIUMForTest() {
1698 // Some tests use mock GL which doesn't work with skia. Just use a bitmap
1699 // backed surface for OOP raster commands.
Mike Reed421f75d2019-02-25 20:30:031700 auto info = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType,
1701 SkColorSpace::MakeSRGB());
Ian Preste598eece2020-10-19 23:31:021702 SkSurfaceProps props = skia::LegacyDisplayGlobals::GetSkSurfaceProps();
Kevin Lubick671644d2023-05-12 16:32:001703 sk_surface_for_testing_ = SkSurfaces::Raster(info, &props);
Peng Huange9b41cd2019-08-12 19:39:471704 sk_surface_ = sk_surface_for_testing_.get();
Mike Reed421f75d2019-02-25 20:30:031705 raster_canvas_ = sk_surface_->getCanvas();
Khushal15b6abb2018-06-28 00:16:251706}
1707
Jonathan Backerc7b82972018-11-21 19:08:481708void RasterDecoderImpl::SetOOMErrorForTest() {
1709 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "SetOOMErrorForTest",
1710 "synthetic out of memory");
1711}
1712
Christopher Cameron386e18582019-01-11 20:17:341713void RasterDecoderImpl::DisableFlushWorkaroundForTest() {
1714 flush_workaround_disabled_for_test_ = true;
1715}
1716
Jonathan Backer7471b2782018-01-25 18:14:191717void RasterDecoderImpl::OnContextLostError() {
Jonathan Backer4f9ee5fb2018-04-25 14:03:381718 if (!WasContextLost()) {
1719 // Need to lose current context before broadcasting!
Jonathan Backerbaf79d92020-06-01 21:30:301720 shared_context_state_->CheckResetStatus(/*needs_gl=*/false);
Jonathan Backer4f9ee5fb2018-04-25 14:03:381721 }
Jonathan Backer7f90dfb662017-12-18 16:52:041722}
1723
Jonathan Backer7471b2782018-01-25 18:14:191724void RasterDecoderImpl::OnOutOfMemoryError() {
Jonathan Backer4f9ee5fb2018-04-25 14:03:381725 if (lose_context_when_out_of_memory_ && !WasContextLost()) {
Jonathan Backerbaf79d92020-06-01 21:30:301726 if (!shared_context_state_->CheckResetStatus(/*needs_gl=*/false)) {
Jonathan Backer4f9ee5fb2018-04-25 14:03:381727 MarkContextLost(error::kOutOfMemory);
1728 }
Jonathan Backer4f9ee5fb2018-04-25 14:03:381729 }
Jonathan Backer7f90dfb662017-12-18 16:52:041730}
1731
Jonathan Backer7471b2782018-01-25 18:14:191732error::Error RasterDecoderImpl::HandleBeginQueryEXT(
1733 uint32_t immediate_data_size,
1734 const volatile void* cmd_data) {
Jonathan Backer016bd97e2018-03-14 15:26:391735 const volatile raster::cmds::BeginQueryEXT& c =
1736 *static_cast<const volatile raster::cmds::BeginQueryEXT*>(cmd_data);
1737 GLenum target = static_cast<GLenum>(c.target);
1738 GLuint client_id = static_cast<GLuint>(c.id);
1739 int32_t sync_shm_id = static_cast<int32_t>(c.sync_data_shm_id);
1740 uint32_t sync_shm_offset = static_cast<uint32_t>(c.sync_data_shm_offset);
1741
1742 switch (target) {
1743 case GL_COMMANDS_ISSUED_CHROMIUM:
Jonathan Backer80b270292018-12-13 19:13:551744 break;
Jonathan Backer016bd97e2018-03-14 15:26:391745 case GL_COMMANDS_COMPLETED_CHROMIUM:
Jonathan Backer80b270292018-12-13 19:13:551746 if (!features().chromium_sync_query) {
1747 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT",
1748 "not enabled for commands completed queries");
1749 return error::kNoError;
1750 }
Jonathan Backer016bd97e2018-03-14 15:26:391751 break;
1752 default:
1753 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "glBeginQueryEXT",
1754 "unknown query target");
1755 return error::kNoError;
1756 }
1757
1758 if (query_manager_->GetActiveQuery(target)) {
1759 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT",
1760 "query already in progress");
1761 return error::kNoError;
1762 }
1763
1764 if (client_id == 0) {
1765 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0");
1766 return error::kNoError;
1767 }
1768
Jonathan Backer0cd1c4322018-04-17 16:57:101769 scoped_refptr<Buffer> buffer = GetSharedMemoryBuffer(sync_shm_id);
Jonathan Backer016bd97e2018-03-14 15:26:391770 if (!buffer)
1771 return error::kInvalidArguments;
1772 QuerySync* sync = static_cast<QuerySync*>(
1773 buffer->GetDataAddress(sync_shm_offset, sizeof(QuerySync)));
1774 if (!sync)
1775 return error::kOutOfBounds;
1776
1777 QueryManager::Query* query = query_manager_->GetQuery(client_id);
1778 if (!query) {
1779 if (!query_manager_->IsValidQuery(client_id)) {
1780 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT",
1781 "id not made by glGenQueriesEXT");
1782 return error::kNoError;
1783 }
1784
1785 query =
1786 query_manager_->CreateQuery(target, client_id, std::move(buffer), sync);
1787 } else {
1788 if (query->target() != target) {
1789 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT",
1790 "target does not match");
1791 return error::kNoError;
1792 } else if (query->sync() != sync) {
1793 DLOG(ERROR) << "Shared memory used by query not the same as before";
1794 return error::kInvalidArguments;
1795 }
1796 }
1797
1798 query_manager_->BeginQuery(query);
Jonathan Backer7471b2782018-01-25 18:14:191799 return error::kNoError;
1800}
1801
1802error::Error RasterDecoderImpl::HandleEndQueryEXT(
1803 uint32_t immediate_data_size,
1804 const volatile void* cmd_data) {
Jonathan Backer016bd97e2018-03-14 15:26:391805 const volatile raster::cmds::EndQueryEXT& c =
1806 *static_cast<const volatile raster::cmds::EndQueryEXT*>(cmd_data);
1807 GLenum target = static_cast<GLenum>(c.target);
1808 uint32_t submit_count = static_cast<GLuint>(c.submit_count);
1809
1810 QueryManager::Query* query = query_manager_->GetActiveQuery(target);
1811 if (!query) {
1812 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glEndQueryEXT",
1813 "No active query");
1814 return error::kNoError;
1815 }
1816
1817 query_manager_->EndQuery(query, submit_count);
Jonathan Backer7471b2782018-01-25 18:14:191818 return error::kNoError;
1819}
1820
Andres Calderon Jaramillo21e98152019-08-22 01:38:041821error::Error RasterDecoderImpl::HandleQueryCounterEXT(
1822 uint32_t immediate_data_size,
1823 const volatile void* cmd_data) {
1824 const volatile raster::cmds::QueryCounterEXT& c =
1825 *static_cast<const volatile raster::cmds::QueryCounterEXT*>(cmd_data);
1826 GLenum target = static_cast<GLenum>(c.target);
1827 GLuint client_id = static_cast<GLuint>(c.id);
1828 int32_t sync_shm_id = static_cast<int32_t>(c.sync_data_shm_id);
1829 uint32_t sync_shm_offset = static_cast<uint32_t>(c.sync_data_shm_offset);
1830 uint32_t submit_count = static_cast<GLuint>(c.submit_count);
1831
1832 if (target != GL_COMMANDS_ISSUED_TIMESTAMP_CHROMIUM) {
1833 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "glQueryCounterEXT",
1834 "unknown query target");
1835 return error::kNoError;
1836 }
1837
1838 scoped_refptr<Buffer> buffer = GetSharedMemoryBuffer(sync_shm_id);
1839 if (!buffer)
1840 return error::kInvalidArguments;
1841 QuerySync* sync = static_cast<QuerySync*>(
1842 buffer->GetDataAddress(sync_shm_offset, sizeof(QuerySync)));
1843 if (!sync)
1844 return error::kOutOfBounds;
1845
1846 QueryManager::Query* query = query_manager_->GetQuery(client_id);
1847 if (!query) {
1848 if (!query_manager_->IsValidQuery(client_id)) {
1849 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glQueryCounterEXT",
1850 "id not made by glGenQueriesEXT");
1851 return error::kNoError;
1852 }
1853 query =
1854 query_manager_->CreateQuery(target, client_id, std::move(buffer), sync);
1855 } else {
1856 if (query->target() != target) {
1857 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glQueryCounterEXT",
1858 "target does not match");
1859 return error::kNoError;
1860 } else if (query->sync() != sync) {
1861 DLOG(ERROR) << "Shared memory used by query not the same as before";
1862 return error::kInvalidArguments;
1863 }
1864 }
1865 query_manager_->QueryCounter(query, submit_count);
1866
1867 return error::kNoError;
1868}
1869
Jonathan Backera4568da12018-01-31 16:25:041870void RasterDecoderImpl::DoFinish() {
Colin Blundelld7b7b472023-05-12 07:38:121871 if (gr_context()) {
1872 gr_context()->flushAndSubmit(/*syncCpu=*/true);
1873 } else if (graphite_context()) {
1874 GraphiteFlushAndSubmit(skgpu::graphite::SyncToCpu::kYes);
Peng Huang63ef8872021-06-17 22:31:201875 }
1876 ProcessPendingQueries(/*did_finish=*/true);
Jonathan Backera4568da12018-01-31 16:25:041877}
1878
1879void RasterDecoderImpl::DoFlush() {
Colin Blundelld7b7b472023-05-12 07:38:121880 if (gr_context()) {
1881 gr_context()->flushAndSubmit(/*syncCpu=*/false);
1882 } else if (graphite_context()) {
1883 GraphiteFlushAndSubmit();
Peng Huang63ef8872021-06-17 22:31:201884 }
1885 ProcessPendingQueries(/*did_finish=*/false);
Jonathan Backera4568da12018-01-31 16:25:041886}
1887
Jonathan Backer016bd97e2018-03-14 15:26:391888bool RasterDecoderImpl::GenQueriesEXTHelper(GLsizei n,
1889 const GLuint* client_ids) {
1890 for (GLsizei ii = 0; ii < n; ++ii) {
1891 if (query_manager_->IsValidQuery(client_ids[ii])) {
1892 return false;
1893 }
1894 }
1895 query_manager_->GenQueries(n, client_ids);
1896 return true;
1897}
1898
1899void RasterDecoderImpl::DeleteQueriesEXTHelper(
1900 GLsizei n,
1901 const volatile GLuint* client_ids) {
1902 for (GLsizei ii = 0; ii < n; ++ii) {
1903 GLuint client_id = client_ids[ii];
1904 query_manager_->RemoveQuery(client_id);
1905 }
1906}
1907
Jonathan Backere26739c2018-05-15 13:27:071908error::Error RasterDecoderImpl::HandleTraceBeginCHROMIUM(
1909 uint32_t immediate_data_size,
1910 const volatile void* cmd_data) {
1911 const volatile gles2::cmds::TraceBeginCHROMIUM& c =
1912 *static_cast<const volatile gles2::cmds::TraceBeginCHROMIUM*>(cmd_data);
1913 Bucket* category_bucket = GetBucket(c.category_bucket_id);
1914 Bucket* name_bucket = GetBucket(c.name_bucket_id);
Jonathan Backerff2ac0f2018-07-18 15:53:471915 static constexpr size_t kMaxStrLen = 256;
1916 if (!category_bucket || category_bucket->size() == 0 ||
1917 category_bucket->size() > kMaxStrLen || !name_bucket ||
1918 name_bucket->size() == 0 || name_bucket->size() > kMaxStrLen) {
Jonathan Backere26739c2018-05-15 13:27:071919 return error::kInvalidArguments;
1920 }
1921
1922 std::string category_name;
1923 std::string trace_name;
1924 if (!category_bucket->GetAsString(&category_name) ||
1925 !name_bucket->GetAsString(&trace_name)) {
1926 return error::kInvalidArguments;
1927 }
1928
1929 debug_marker_manager_.PushGroup(trace_name);
Daniel Bratellaabc8d68e2018-07-18 19:20:261930 if (!gpu_tracer_->Begin(category_name, trace_name, gles2::kTraceCHROMIUM)) {
Jonathan Backere26739c2018-05-15 13:27:071931 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glTraceBeginCHROMIUM",
1932 "unable to create begin trace");
1933 return error::kNoError;
1934 }
1935 return error::kNoError;
1936}
1937
1938void RasterDecoderImpl::DoTraceEndCHROMIUM() {
1939 debug_marker_manager_.PopGroup();
Daniel Bratellaabc8d68e2018-07-18 19:20:261940 if (!gpu_tracer_->End(gles2::kTraceCHROMIUM)) {
Jonathan Backere26739c2018-05-15 13:27:071941 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glTraceEndCHROMIUM",
1942 "no trace begin found");
1943 return;
1944 }
1945}
1946
Khushal49836ab2018-07-25 02:08:451947error::Error RasterDecoderImpl::HandleSetActiveURLCHROMIUM(
1948 uint32_t immediate_data_size,
1949 const volatile void* cmd_data) {
1950 const volatile cmds::SetActiveURLCHROMIUM& c =
1951 *static_cast<const volatile cmds::SetActiveURLCHROMIUM*>(cmd_data);
1952 Bucket* url_bucket = GetBucket(c.url_bucket_id);
1953 static constexpr size_t kMaxStrLen = 1024;
1954 if (!url_bucket || url_bucket->size() == 0 ||
Khushalda1fb8332018-10-26 19:26:221955 url_bucket->size() > kMaxStrLen) {
Khushal49836ab2018-07-25 02:08:451956 return error::kInvalidArguments;
1957 }
1958
Khushalda1fb8332018-10-26 19:26:221959 size_t size = url_bucket->size();
Khushal49836ab2018-07-25 02:08:451960 const char* url_str = url_bucket->GetDataAs<const char*>(0, size);
1961 if (!url_str)
1962 return error::kInvalidArguments;
1963
1964 GURL url(base::StringPiece(url_str, size));
Corentin Wallez0f412f02019-04-03 22:42:381965 client()->SetActiveURL(std::move(url));
Khushal49836ab2018-07-25 02:08:451966 return error::kNoError;
1967}
1968
Saifuddin Hitawala20790cb2023-01-31 17:01:121969void RasterDecoderImpl::DoCopySharedImageINTERNAL(
Antoine Labour9ddf6ac2019-01-17 01:59:391970 GLint xoffset,
1971 GLint yoffset,
1972 GLint x,
1973 GLint y,
1974 GLsizei width,
1975 GLsizei height,
Nathan Zabriskief1095d7b2019-12-21 00:33:571976 GLboolean unpack_flip_y,
Antoine Labour9ddf6ac2019-01-17 01:59:391977 const volatile GLbyte* mailboxes) {
Saifuddin Hitawalac457bbd2023-02-07 21:19:241978 CopySharedImageHelper helper(&shared_image_representation_factory_,
1979 shared_context_state_.get());
1980 auto result = helper.CopySharedImage(xoffset, yoffset, x, y, width, height,
1981 unpack_flip_y, mailboxes);
1982 if (!result.has_value()) {
1983 LOCAL_SET_GL_ERROR(result.error().gl_error,
1984 result.error().function_name.c_str(),
1985 result.error().msg.c_str());
Antoine Labourb9f903b2019-02-04 18:06:571986 }
Nathan Zabriskie67a4fbc2021-01-07 19:39:101987}
1988
Nathan Zabriskie31e4dc92020-04-15 23:10:271989void RasterDecoderImpl::DoWritePixelsINTERNAL(GLint x_offset,
1990 GLint y_offset,
Saifuddin Hitawala5d26b202023-04-04 18:41:431991 GLint plane_index,
Nathan Zabriskie31e4dc92020-04-15 23:10:271992 GLuint src_width,
1993 GLuint src_height,
1994 GLuint row_bytes,
1995 GLuint src_sk_color_type,
1996 GLuint src_sk_alpha_type,
1997 GLint shm_id,
1998 GLuint shm_offset,
1999 GLuint pixels_offset,
2000 const volatile GLbyte* mailbox) {
Justin Novosad129aa3ea42021-12-10 20:06:312001 TRACE_EVENT0("gpu", "RasterDecoderImpl::DoWritePixelsINTERNAL");
Saifuddin Hitawalaa5126a702023-04-04 20:16:392002 if (src_sk_color_type < 0 || src_sk_color_type > kLastEnum_SkColorType) {
Nathan Zabriskie31e4dc92020-04-15 23:10:272003 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "WritePixels",
2004 "src_sk_color_type must be a valid SkColorType");
2005 return;
2006 }
Saifuddin Hitawalaa5126a702023-04-04 20:16:392007 if (src_sk_alpha_type < 0 || src_sk_alpha_type > kLastEnum_SkAlphaType) {
Nathan Zabriskie31e4dc92020-04-15 23:10:272008 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "WritePixels",
2009 "src_sk_alpha_type must be a valid SkAlphaType");
2010 return;
2011 }
2012
2013 Mailbox dest_mailbox = Mailbox::FromVolatile(
2014 *reinterpret_cast<const volatile Mailbox*>(mailbox));
2015 DLOG_IF(ERROR, !dest_mailbox.Verify())
2016 << "WritePixels was passed an invalid mailbox";
2017 auto dest_shared_image = shared_image_representation_factory_.ProduceSkia(
2018 dest_mailbox, shared_context_state_);
2019 if (!dest_shared_image) {
2020 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2021 "Attempting to write to unknown mailbox.");
2022 return;
2023 }
2024
Saifuddin Hitawalaa5126a702023-04-04 20:16:392025 viz::SharedImageFormat dest_format = dest_shared_image->format();
2026 if (!dest_format.IsValidPlaneIndex(plane_index)) {
2027 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2028 "Invalid plane_index");
2029 return;
2030 }
2031
Saifuddin Hitawalab0bdad92022-11-23 23:07:242032 if (SkColorTypeBytesPerPixel(
Saifuddin Hitawalaa5126a702023-04-04 20:16:392033 viz::ToClosestSkColorType(true, dest_format, plane_index)) !=
Nathan Zabriskie108c18282020-05-28 16:45:072034 SkColorTypeBytesPerPixel(static_cast<SkColorType>(src_sk_color_type))) {
2035 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2036 "Bytes per pixel for src SkColorType and dst "
2037 "SkColorType must be the same.");
2038 return;
2039 }
2040
Nathan Zabriskie31e4dc92020-04-15 23:10:272041 // If present, the color space is serialized into shared memory before the
2042 // pixel data.
2043 sk_sp<SkColorSpace> color_space;
2044 if (pixels_offset > 0) {
Saifuddin Hitawalaa5126a702023-04-04 20:16:392045 // For multiplanar formats write is per plane, and source color
2046 // space must be nullptr to allow letting Skia assume srgb color space.
2047 if (dest_format.is_multi_plane()) {
2048 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2049 "Unexpected color space for multiplanar shared image");
2050 return;
2051 }
Nathan Zabriskie31e4dc92020-04-15 23:10:272052 void* color_space_bytes =
2053 GetSharedMemoryAs<void*>(shm_id, shm_offset, pixels_offset);
Nathan Zabriskiea0f955c32020-04-16 21:29:102054 if (!color_space_bytes) {
2055 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2056 "Failed to retrieve serialized SkColorSpace.");
2057 return;
2058 }
2059
Nathan Zabriskie31e4dc92020-04-15 23:10:272060 color_space = SkColorSpace::Deserialize(color_space_bytes, pixels_offset);
2061 if (!color_space) {
2062 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2063 "Failed to deserialize expected SkColorSpace");
2064 return;
2065 }
2066 }
2067
2068 SkImageInfo src_info = SkImageInfo::Make(
2069 src_width, src_height, static_cast<SkColorType>(src_sk_color_type),
2070 static_cast<SkAlphaType>(src_sk_alpha_type), std::move(color_space));
2071
Nathan Zabriskieee59b5e2020-06-10 06:15:472072 if (row_bytes < src_info.minRowBytes()) {
2073 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glWritePixels",
2074 "row_bytes be >= "
2075 "SkImageInfo::minRowBytes() for source image.");
2076 return;
2077 }
2078
Jonah Chin67897ae62020-12-08 21:13:202079 size_t byte_size = src_info.computeByteSize(row_bytes);
2080 if (byte_size > UINT32_MAX) {
2081 LOCAL_SET_GL_ERROR(
2082 GL_INVALID_VALUE, "glWritePixels",
2083 "Cannot request a memory chunk larger than UINT32_MAX bytes");
2084 return;
2085 }
2086
2087 // The pixels are stored after the serialized SkColorSpace + padding
2088 void* pixel_data =
2089 GetSharedMemoryAs<void*>(shm_id, shm_offset + pixels_offset, byte_size);
2090 if (!pixel_data) {
2091 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2092 "Couldn't retrieve pixel data.");
2093 return;
2094 }
2095
2096 // Try a direct texture upload without using SkSurface.
Colin Blundelld7b7b472023-05-12 07:38:122097 // TODO(crbug.com/1423576): Enable this path for Graphite after fixing
2098 // RGBA/BGRA mismatch.
2099 if (!graphite_context() &&
2100 gfx::Size(src_width, src_height) == dest_shared_image->size() &&
Jonah Chin67897ae62020-12-08 21:13:202101 x_offset == 0 && y_offset == 0 &&
Justin Novosad4fb0c0e42022-02-08 16:10:272102 (src_info.alphaType() == dest_shared_image->alpha_type() ||
2103 src_info.alphaType() == kUnknown_SkAlphaType) &&
2104 SkColorSpace::Equals(
2105 src_info.colorSpace(),
2106 dest_shared_image->color_space().ToSkColorSpace().get()) &&
Saifuddin Hitawalaa5126a702023-04-04 20:16:392107 DoWritePixelsINTERNALDirectTextureUpload(dest_shared_image.get(),
2108 src_info, plane_index,
2109 pixel_data, row_bytes)) {
Jonah Chin67897ae62020-12-08 21:13:202110 return;
2111 }
2112
Nathan Zabriskie31e4dc92020-04-15 23:10:272113 std::vector<GrBackendSemaphore> begin_semaphores;
2114 std::vector<GrBackendSemaphore> end_semaphores;
2115
2116 // Allow uncleared access, as we manually handle clear tracking.
Saifuddin Hitawaladaed5972022-07-20 22:01:012117 std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess>
Nathan Zabriskie31e4dc92020-04-15 23:10:272118 dest_scoped_access = dest_shared_image->BeginScopedWriteAccess(
2119 &begin_semaphores, &end_semaphores,
2120 SharedImageRepresentation::AllowUnclearedAccess::kYes);
2121 if (!dest_scoped_access) {
2122 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glWritePixels",
2123 "Dest shared image is not writable");
2124 return;
2125 }
2126
Saifuddin Hitawalaa5126a702023-04-04 20:16:392127 auto* surface = dest_scoped_access->surface(plane_index);
2128 DCHECK(surface);
2129
Nathan Zabriskie31e4dc92020-04-15 23:10:272130 if (!begin_semaphores.empty()) {
Saifuddin Hitawalaa5126a702023-04-04 20:16:392131 bool result =
2132 surface->wait(begin_semaphores.size(), begin_semaphores.data(),
2133 /*deleteSemaphoresAfterWait=*/false);
Nathan Zabriskie31e4dc92020-04-15 23:10:272134 if (!result) {
2135 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2136 "Unable to obtain write access to dest shared image.");
2137 return;
2138 }
2139 }
2140
Saifuddin Hitawalaa5126a702023-04-04 20:16:392141 auto* canvas = surface->getCanvas();
Nathan Zabriskie31e4dc92020-04-15 23:10:272142 bool written =
2143 canvas->writePixels(src_info, pixel_data, row_bytes, x_offset, y_offset);
2144 if (!written) {
2145 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels",
2146 "Failed to write pixels to SkCanvas");
2147 }
2148
Saifuddin Hitawalae3ef7ae2023-04-20 14:22:252149 surface->flush();
2150 dest_scoped_access->ApplyBackendSurfaceEndState();
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:052151 SubmitIfNecessary(std::move(end_semaphores));
2152
Nathan Zabriskie31e4dc92020-04-15 23:10:272153 if (!dest_shared_image->IsCleared()) {
2154 dest_shared_image->SetClearedRect(
2155 gfx::Rect(x_offset, y_offset, src_width, src_height));
2156 }
2157}
2158
Jonah Chin67897ae62020-12-08 21:13:202159bool RasterDecoderImpl::DoWritePixelsINTERNALDirectTextureUpload(
Saifuddin Hitawaladaed5972022-07-20 22:01:012160 SkiaImageRepresentation* dest_shared_image,
Jonah Chin67897ae62020-12-08 21:13:202161 const SkImageInfo& src_info,
Saifuddin Hitawalaa5126a702023-04-04 20:16:392162 const int plane_index,
Jonah Chin67897ae62020-12-08 21:13:202163 const void* pixel_data,
2164 size_t row_bytes) {
2165 std::vector<GrBackendSemaphore> begin_semaphores;
2166 std::vector<GrBackendSemaphore> end_semaphores;
2167
2168 // Allow uncleared access, as we manually handle clear tracking.
Saifuddin Hitawaladaed5972022-07-20 22:01:012169 std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess>
Jonah Chin67897ae62020-12-08 21:13:202170 dest_scoped_access = dest_shared_image->BeginScopedWriteAccess(
2171 &begin_semaphores, &end_semaphores,
2172 SharedImageRepresentation::AllowUnclearedAccess::kYes,
2173 false /*use_sk_surface*/);
2174 if (!dest_scoped_access) {
2175 return false;
2176 }
2177 if (!begin_semaphores.empty()) {
Colin Blundelld7b7b472023-05-12 07:38:122178 // The Graphite SharedImage representation does not set semaphores.
2179 CHECK(gr_context());
2180 bool result =
2181 gr_context()->wait(begin_semaphores.size(), begin_semaphores.data(),
2182 /*deleteSemaphoresAfterWait=*/false);
Jonah Chin67897ae62020-12-08 21:13:202183 DCHECK(result);
2184 }
2185
2186 SkPixmap pixmap(src_info, pixel_data, row_bytes);
Colin Blundelld7b7b472023-05-12 07:38:122187 bool written = false;
2188 if (gr_context()) {
2189 written = gr_context()->updateBackendTexture(
2190 dest_scoped_access->promise_image_texture(plane_index)
2191 ->backendTexture(),
2192 &pixmap,
2193 /*numLevels=*/1, dest_shared_image->surface_origin(), nullptr, nullptr);
2194 dest_scoped_access->ApplyBackendSurfaceEndState();
2195 } else {
2196 CHECK(graphite_context());
2197 written = graphite_recorder()->updateBackendTexture(
2198 dest_scoped_access->graphite_texture(plane_index), &pixmap,
2199 /*numLevels=*/1);
2200 auto recording = graphite_recorder()->snap();
2201 if (!recording) {
2202 DLOG(ERROR) << "Failed to snap Graphite recording";
2203 return false;
2204 }
2205 GraphiteFlushAndSubmitWithRecording(std::move(recording));
2206 }
Vasiliy Telezhnikov6414a252022-04-26 04:42:112207
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:052208 SubmitIfNecessary(std::move(end_semaphores));
Jonah Chin67897ae62020-12-08 21:13:202209 if (written && !dest_shared_image->IsCleared()) {
2210 dest_shared_image->SetClearedRect(
2211 gfx::Rect(src_info.width(), src_info.height()));
2212 }
2213 return written;
2214}
2215
Nathan Zabriskief5f270e2021-04-30 20:53:062216void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL(
Jonah Chind9d7a732020-07-17 23:32:112217 GLint src_x,
2218 GLint src_y,
Saifuddin Hitawalaf32b28c2023-02-22 23:30:382219 GLint plane_index,
Jonah Chind9d7a732020-07-17 23:32:112220 GLuint dst_width,
2221 GLuint dst_height,
2222 GLuint row_bytes,
2223 GLuint dst_sk_color_type,
2224 GLuint dst_sk_alpha_type,
2225 GLint shm_id,
2226 GLuint shm_offset,
Nathan Zabriskie7febc8702021-04-29 18:52:402227 GLuint color_space_offset,
Jonah Chind9d7a732020-07-17 23:32:112228 GLuint pixels_offset,
2229 const volatile GLbyte* mailbox) {
Justin Novosad129aa3ea42021-12-10 20:06:312230 TRACE_EVENT0("gpu", "RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL");
Jonah Chind9d7a732020-07-17 23:32:112231 if (dst_sk_color_type > kLastEnum_SkColorType) {
2232 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "ReadbackImagePixels",
2233 "dst_sk_color_type must be a valid SkColorType");
2234 return;
2235 }
2236 if (dst_sk_alpha_type > kLastEnum_SkAlphaType) {
2237 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "ReadbackImagePixels",
2238 "dst_sk_alpha_type must be a valid SkAlphaType");
2239 return;
2240 }
2241
2242 Mailbox source_mailbox = Mailbox::FromVolatile(
2243 *reinterpret_cast<const volatile Mailbox*>(mailbox));
2244 DLOG_IF(ERROR, !source_mailbox.Verify())
2245 << "ReadbackImagePixels was passed an invalid mailbox";
2246 auto source_shared_image = shared_image_representation_factory_.ProduceSkia(
2247 source_mailbox, shared_context_state_);
2248 if (!source_shared_image) {
2249 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2250 "Unknown mailbox");
2251 return;
2252 }
2253
Saifuddin Hitawala3db13d02023-02-23 13:27:192254 viz::SharedImageFormat source_format = source_shared_image->format();
2255
Nathan Zabriskie7febc8702021-04-29 18:52:402256 // If present, the color space is serialized into shared memory after the
2257 // result and before the pixel data.
2258 if (color_space_offset > pixels_offset) {
2259 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2260 "|pixels_offset| must be >= |color_space_offset|");
2261 return;
2262 }
2263 unsigned int color_space_size = pixels_offset - color_space_offset;
2264
Jonah Chind9d7a732020-07-17 23:32:112265 sk_sp<SkColorSpace> dst_color_space;
Nathan Zabriskie7febc8702021-04-29 18:52:402266 if (color_space_size) {
Saifuddin Hitawala3db13d02023-02-23 13:27:192267 // For multiplanar formats readback is per plane, and destination color
Saifuddin Hitawala6c8b8332023-03-03 18:21:302268 // space must be nullptr to avoid unexpected color conversions.
Saifuddin Hitawala3db13d02023-02-23 13:27:192269 if (source_format.is_multi_plane()) {
2270 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
2271 "Unexpected color space for multiplanar shared image");
2272 return;
2273 }
Nathan Zabriskie7febc8702021-04-29 18:52:402274 void* color_space_bytes = GetSharedMemoryAs<void*>(
2275 shm_id, shm_offset + color_space_offset, color_space_size);
Jonah Chind9d7a732020-07-17 23:32:112276 if (!color_space_bytes) {
2277 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
2278 "Failed to retrieve serialized SkColorSpace.");
2279 return;
2280 }
2281 dst_color_space =
Nathan Zabriskie7febc8702021-04-29 18:52:402282 SkColorSpace::Deserialize(color_space_bytes, color_space_size);
Jonah Chind9d7a732020-07-17 23:32:112283 if (!dst_color_space) {
2284 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
2285 "Failed to deserialize expected SkColorSpace");
2286 return;
2287 }
2288 }
2289
2290 SkImageInfo dst_info = SkImageInfo::Make(
2291 dst_width, dst_height, static_cast<SkColorType>(dst_sk_color_type),
2292 static_cast<SkAlphaType>(dst_sk_alpha_type), std::move(dst_color_space));
2293
2294 if (row_bytes < dst_info.minRowBytes()) {
2295 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2296 "row_bytes be >= "
2297 "SkImageInfo::minRowBytes() for dest image.");
2298 return;
2299 }
2300
Jonah Chin76a780022020-08-13 20:45:262301 size_t byte_size = dst_info.computeByteSize(row_bytes);
2302 if (byte_size > UINT32_MAX) {
2303 LOCAL_SET_GL_ERROR(
2304 GL_INVALID_VALUE, "glReadbackImagePixels",
2305 "Cannot request a memory chunk larger than UINT32_MAX bytes");
2306 return;
2307 }
2308
Nathan Zabriskie7febc8702021-04-29 18:52:402309 void* pixel_address =
Jonah Chin76a780022020-08-13 20:45:262310 GetSharedMemoryAs<void*>(shm_id, shm_offset + pixels_offset, byte_size);
Nathan Zabriskie7febc8702021-04-29 18:52:402311 if (!pixel_address) {
Jonah Chind9d7a732020-07-17 23:32:112312 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
Nathan Zabriskie7febc8702021-04-29 18:52:402313 "Failed to retrieve memory for readPixels output");
Jonah Chind9d7a732020-07-17 23:32:112314 return;
2315 }
2316
Nathan Zabriskief5f270e2021-04-30 20:53:062317 typedef cmds::ReadbackARGBImagePixelsINTERNALImmediate::Result Result;
Nathan Zabriskie7febc8702021-04-29 18:52:402318 Result* result =
2319 GetSharedMemoryAs<Result*>(shm_id, shm_offset, sizeof(Result));
2320 if (!result) {
2321 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
2322 "Failed to retrieve memory for readPixels result");
2323 return;
Jonah Chinf16050a2021-02-24 03:27:442324 }
2325
Saifuddin Hitawala3db13d02023-02-23 13:27:192326 if (!source_format.IsValidPlaneIndex(plane_index)) {
2327 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
2328 "Invalid plane_index");
2329 return;
2330 }
2331
Saifuddin Hitawala6c8b8332023-03-03 18:21:302332 CopySharedImageHelper helper(&shared_image_representation_factory_,
2333 shared_context_state_.get());
2334 auto helper_result =
2335 helper.ReadPixels(src_x, src_y, plane_index, row_bytes, dst_info,
2336 pixel_address, std::move(source_shared_image));
2337 if (!helper_result.has_value()) {
2338 LOCAL_SET_GL_ERROR(helper_result.error().gl_error,
2339 helper_result.error().function_name.c_str(),
2340 helper_result.error().msg.c_str());
Saifuddin Hitawala3db13d02023-02-23 13:27:192341 } else {
Saifuddin Hitawala6c8b8332023-03-03 18:21:302342 *result = 1;
Saifuddin Hitawala3db13d02023-02-23 13:27:192343 }
Jonah Chind9d7a732020-07-17 23:32:112344}
2345
Nathan Zabriskief5f270e2021-04-30 20:53:062346namespace {
2347struct YUVReadbackResult {
2348 std::unique_ptr<const SkImage::AsyncReadResult> async_result;
Vasiliy Telezhnikov081df1e2023-01-16 15:41:342349 bool finished = false;
Nathan Zabriskief5f270e2021-04-30 20:53:062350};
2351
2352void OnReadYUVImagePixelsDone(
2353 void* raw_ctx,
2354 std::unique_ptr<const SkImage::AsyncReadResult> async_result) {
2355 YUVReadbackResult* context = reinterpret_cast<YUVReadbackResult*>(raw_ctx);
2356 context->async_result = std::move(async_result);
Vasiliy Telezhnikov081df1e2023-01-16 15:41:342357 context->finished = true;
Nathan Zabriskief5f270e2021-04-30 20:53:062358}
2359} // namespace
2360
2361void RasterDecoderImpl::DoReadbackYUVImagePixelsINTERNAL(
2362 GLuint dst_width,
2363 GLuint dst_height,
2364 GLint shm_id,
2365 GLuint shm_offset,
2366 GLuint y_offset,
2367 GLuint y_stride,
2368 GLuint u_offset,
2369 GLuint u_stride,
2370 GLuint v_offset,
2371 GLuint v_stride,
2372 const volatile GLbyte* mailbox) {
Justin Novosad129aa3ea42021-12-10 20:06:312373 TRACE_EVENT0("gpu", "RasterDecoderImpl::DoReadbackYUVImagePixelsINTERNAL");
Nathan Zabriskief5f270e2021-04-30 20:53:062374 if (dst_width % 2 != 0 || dst_height % 2 != 0) {
2375 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2376 "|dst_width| and |dst_height| must be divisible by 2");
2377 return;
2378 }
2379
Vasiliy Telezhnikovf3f0ffd2021-06-22 14:19:182380 if (y_stride < dst_width) {
2381 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2382 "|y_stride| must be >= the width of the y plane.");
2383 return;
2384 }
2385
2386 if (u_stride < ((dst_width + 1) / 2)) {
2387 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2388 "|u_stride| must be >= the width of the u plane.");
2389 return;
2390 }
2391 if (v_stride < ((dst_width + 1) / 2)) {
2392 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2393 "|v_stride| must be >= the width of the u plane.");
2394 return;
2395 }
2396
Nathan Zabriskief5f270e2021-04-30 20:53:062397 Mailbox source_mailbox = Mailbox::FromVolatile(
2398 *reinterpret_cast<const volatile Mailbox*>(mailbox));
2399 DLOG_IF(ERROR, !source_mailbox.Verify())
2400 << "ReadbackImagePixels was passed an invalid mailbox";
2401 auto source_shared_image = shared_image_representation_factory_.ProduceSkia(
2402 source_mailbox, shared_context_state_);
2403 if (!source_shared_image) {
2404 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2405 "Unknown mailbox");
2406 return;
2407 }
2408
2409 std::vector<GrBackendSemaphore> begin_semaphores;
Vasiliy Telezhnikov6414a252022-04-26 04:42:112410 std::vector<GrBackendSemaphore> end_semaphores;
Nathan Zabriskief5f270e2021-04-30 20:53:062411
2412 // We don't use |end_semaphores| here because we're going to sync with
2413 // with the CPU later regardless.
Saifuddin Hitawaladaed5972022-07-20 22:01:012414 std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess>
Nathan Zabriskief5f270e2021-04-30 20:53:062415 source_scoped_access = source_shared_image->BeginScopedReadAccess(
Vasiliy Telezhnikov6414a252022-04-26 04:42:112416 &begin_semaphores, &end_semaphores);
Nathan Zabriskief5f270e2021-04-30 20:53:062417
2418 if (!begin_semaphores.empty()) {
Saifuddin Hitawalad9027662023-05-12 14:50:102419 CHECK(gr_context());
2420 bool result =
2421 gr_context()->wait(begin_semaphores.size(), begin_semaphores.data(),
2422 /*deleteSemaphoresAfterWait=*/false);
Nathan Zabriskief5f270e2021-04-30 20:53:062423 DCHECK(result);
2424 }
2425
2426 if (!source_scoped_access) {
2427 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels",
2428 "Source shared image is not accessible");
2429 return;
2430 }
2431
2432 auto sk_image =
Saifuddin Hitawala5a6785d52023-04-25 22:23:122433 source_scoped_access->CreateSkImage(shared_context_state_.get());
Nathan Zabriskief5f270e2021-04-30 20:53:062434 if (!sk_image) {
2435 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels",
2436 "Couldn't create SkImage for reading.");
2437 return;
2438 }
2439
2440 auto* result = GetSharedMemoryAs<
2441 cmds::ReadbackARGBImagePixelsINTERNALImmediate::Result*>(
2442 shm_id, shm_offset,
2443 sizeof(cmds::ReadbackARGBImagePixelsINTERNALImmediate::Result));
2444 if (!result) {
2445 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2446 "Failed to retrieve memory for readPixels result");
2447 return;
2448 }
2449
Nathan Zabriskie49128932021-07-08 20:00:312450 // Large plane strides or heights could potentially overflow the unsigned int
2451 // parameters of GetSharedMemoryAs() below. We use base::CheckedNumeric to
2452 // prevent using any values that overflowed which could cause us to request
2453 // incorrect shared memory regions.
2454 base::CheckedNumeric<unsigned int> checked_shm_offset(shm_offset);
2455 base::CheckedNumeric<unsigned int> checked_dst_height(dst_height);
2456
2457 base::CheckedNumeric<unsigned int> y_size = checked_dst_height * y_stride;
2458 base::CheckedNumeric<unsigned int> y_plane_offset =
2459 checked_shm_offset + y_offset;
2460 if (!y_size.IsValid() || !y_plane_offset.IsValid()) {
2461 LOCAL_SET_GL_ERROR(
2462 GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2463 "y plane size or offset too large. Both must fit in unsigned int.");
2464 return;
2465 }
2466
2467 // |y_plane_offset| and |y_size| are guaranteed valid by the checks above and
2468 // won't die here. Same with the u and v planes below.
2469 uint8_t* y_out = GetSharedMemoryAs<uint8_t*>(
2470 shm_id, y_plane_offset.ValueOrDie(), y_size.ValueOrDie());
Nathan Zabriskief5f270e2021-04-30 20:53:062471 if (!y_out) {
2472 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2473 "Failed to get memory for y plane output");
2474 return;
2475 }
2476
Nathan Zabriskie49128932021-07-08 20:00:312477 base::CheckedNumeric<unsigned int> checked_uv_plane_height =
2478 (checked_dst_height + 1) / 2;
2479
2480 base::CheckedNumeric<unsigned int> u_size =
2481 checked_uv_plane_height * u_stride;
2482 base::CheckedNumeric<unsigned int> u_plane_offset =
2483 checked_shm_offset + u_offset;
2484 if (!u_size.IsValid() || !u_plane_offset.IsValid()) {
2485 LOCAL_SET_GL_ERROR(
2486 GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2487 "u plane size or offset too large. Both must fit in unsigned int.");
2488 return;
2489 }
2490 uint8_t* u_out = GetSharedMemoryAs<uint8_t*>(
2491 shm_id, u_plane_offset.ValueOrDie(), u_size.ValueOrDie());
Nathan Zabriskief5f270e2021-04-30 20:53:062492 if (!u_out) {
2493 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2494 "Failed to get memory for u plane output");
2495 return;
2496 }
2497
Nathan Zabriskie49128932021-07-08 20:00:312498 base::CheckedNumeric<unsigned int> v_size =
2499 checked_uv_plane_height * v_stride;
2500 base::CheckedNumeric<unsigned int> v_plane_offset =
2501 checked_shm_offset + v_offset;
2502 if (!v_size.IsValid() || !v_plane_offset.IsValid()) {
2503 LOCAL_SET_GL_ERROR(
2504 GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2505 "v plane size or offset too large. Both must fit in unsigned int.");
2506 return;
2507 }
2508 uint8_t* v_out = GetSharedMemoryAs<uint8_t*>(
2509 shm_id, v_plane_offset.ValueOrDie(), v_size.ValueOrDie());
Nathan Zabriskief5f270e2021-04-30 20:53:062510 if (!v_out) {
2511 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2512 "Failed to get memory for v plane output");
2513 return;
2514 }
2515
2516 SkIRect src_rect = SkIRect::MakeSize(sk_image->dimensions());
2517 SkISize dst_size = SkISize::Make(dst_width, dst_height);
2518
2519 // While this function indicates it's asynchronous, the flushAndSubmit()
2520 // call below ensures it completes synchronously. We do this because
2521 // RasterImplementation/Decoder does not currently have a query
2522 // that can handle asynchronous calls.
2523 YUVReadbackResult yuv_result;
2524 sk_image->asyncRescaleAndReadPixelsYUV420(
2525 kJPEG_Full_SkYUVColorSpace, SkColorSpace::MakeSRGB(), src_rect, dst_size,
2526 SkImage::RescaleGamma::kSrc, SkImage::RescaleMode::kRepeatedLinear,
2527 &OnReadYUVImagePixelsDone, &yuv_result);
2528
Saifuddin Hitawala913ae952023-04-18 23:26:032529 source_scoped_access->ApplyBackendSurfaceEndState();
Vasiliy Telezhnikov6414a252022-04-26 04:42:112530 if (!end_semaphores.empty()) {
Saifuddin Hitawalad9027662023-05-12 14:50:102531 CHECK(gr_context());
Vasiliy Telezhnikov6414a252022-04-26 04:42:112532 GrFlushInfo flush_info = {
2533 .fNumSemaphores = end_semaphores.size(),
2534 .fSignalSemaphores = end_semaphores.data(),
2535 };
2536 AddVulkanCleanupTaskForSkiaFlush(
2537 shared_context_state_->vk_context_provider(), &flush_info);
Saifuddin Hitawalad9027662023-05-12 14:50:102538 gr_context()->flush(flush_info);
Vasiliy Telezhnikov6414a252022-04-26 04:42:112539 }
2540
Nathan Zabriskief5f270e2021-04-30 20:53:062541 // TODO(crbug.com/1023262): Eventually we should make this function truly
2542 // asynchronous by removing this flush and implementing a query that can
2543 // signal back to client process.
Saifuddin Hitawalad9027662023-05-12 14:50:102544 DoFinish();
Vasiliy Telezhnikov081df1e2023-01-16 15:41:342545
2546 // The call above will sync up gpu and CPU, resulting in callback being run
2547 // during flushAndSubmit. To prevent UAF make sure it indeed happened.
2548 CHECK(yuv_result.finished);
Nathan Zabriskief5f270e2021-04-30 20:53:062549 if (!yuv_result.async_result) {
2550 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels",
2551 "Failed to read pixels from SkImage");
2552 return;
2553 }
2554
2555 auto& async_result = yuv_result.async_result;
2556 libyuv::I420Copy(static_cast<const uint8_t*>(async_result->data(0)),
2557 async_result->rowBytes(0),
2558 static_cast<const uint8_t*>(async_result->data(1)),
2559 async_result->rowBytes(1),
2560 static_cast<const uint8_t*>(async_result->data(2)),
2561 async_result->rowBytes(2), y_out, y_stride, u_out, u_stride,
2562 v_out, v_stride, dst_width, dst_height);
2563
2564 *result = 1;
2565}
2566
Brian Salomon99bc7fc2020-11-20 16:57:312567void RasterDecoderImpl::DoConvertYUVAMailboxesToRGBINTERNAL(
Nathan Zabriskie366b8932020-04-28 01:07:132568 GLenum planes_yuv_color_space,
Brian Salomon99bc7fc2020-11-20 16:57:312569 GLenum plane_config,
2570 GLenum subsampling,
Christopher Cameron7b588da2022-08-05 23:38:172571 const volatile GLbyte* bytes_in) {
Saifuddin Hitawalaa4eb4642023-01-18 23:52:242572 CopySharedImageHelper helper(&shared_image_representation_factory_,
Saifuddin Hitawalaa0b9d832023-01-23 23:53:412573 shared_context_state_.get());
2574 auto result = helper.ConvertYUVAMailboxesToRGB(
2575 planes_yuv_color_space, plane_config, subsampling, bytes_in);
2576 if (!result.has_value()) {
2577 LOCAL_SET_GL_ERROR(result.error().gl_error,
2578 result.error().function_name.c_str(),
2579 result.error().msg.c_str());
2580 }
Nathan Zabriskie366b8932020-04-28 01:07:132581}
2582
Christopher Cameron1c9f5322021-08-14 08:21:362583void RasterDecoderImpl::DoConvertRGBAToYUVAMailboxesINTERNAL(
2584 GLenum yuv_color_space,
2585 GLenum plane_config,
2586 GLenum subsampling,
2587 const volatile GLbyte* mailboxes_in) {
Saifuddin Hitawalaa4eb4642023-01-18 23:52:242588 CopySharedImageHelper helper(&shared_image_representation_factory_,
Saifuddin Hitawalaa0b9d832023-01-23 23:53:412589 shared_context_state_.get());
2590 auto result = helper.ConvertRGBAToYUVAMailboxes(yuv_color_space, plane_config,
2591 subsampling, mailboxes_in);
2592 if (!result.has_value()) {
2593 LOCAL_SET_GL_ERROR(result.error().gl_error,
2594 result.error().function_name.c_str(),
2595 result.error().msg.c_str());
2596 }
Christopher Cameron1c9f5322021-08-14 08:21:362597}
2598
Jonah Chin053aa6c2021-01-22 20:26:142599void RasterDecoderImpl::DoLoseContextCHROMIUM(GLenum current, GLenum other) {
2600 MarkContextLost(gles2::GetContextLostReasonFromResetStatus(current));
2601}
2602
Nathan Zabriskie366b8932020-04-28 01:07:132603namespace {
Jonathan Backere19973e82018-04-18 20:08:092604
2605// Helper to read client data from transfer cache.
Jonathan Backer4f9ee5fb2018-04-25 14:03:382606class TransferCacheDeserializeHelperImpl final
Jonathan Backere19973e82018-04-18 20:08:092607 : public cc::TransferCacheDeserializeHelper {
2608 public:
2609 explicit TransferCacheDeserializeHelperImpl(
Khushal996e9912018-07-13 08:31:002610 int raster_decoder_id,
Jonathan Backere19973e82018-04-18 20:08:092611 ServiceTransferCache* transfer_cache)
Khushal996e9912018-07-13 08:31:002612 : raster_decoder_id_(raster_decoder_id), transfer_cache_(transfer_cache) {
Jonathan Backere19973e82018-04-18 20:08:092613 DCHECK(transfer_cache_);
2614 }
Peter Bostrรถmdbacdc22021-09-23 22:11:462615
2616 TransferCacheDeserializeHelperImpl(
2617 const TransferCacheDeserializeHelperImpl&) = delete;
2618 TransferCacheDeserializeHelperImpl& operator=(
2619 const TransferCacheDeserializeHelperImpl&) = delete;
2620
Jonathan Backer4f9ee5fb2018-04-25 14:03:382621 ~TransferCacheDeserializeHelperImpl() override = default;
Jonathan Backere19973e82018-04-18 20:08:092622
Adrienne Walker90b79a22018-05-08 21:40:422623 void CreateLocalEntry(
2624 uint32_t id,
2625 std::unique_ptr<cc::ServiceTransferCacheEntry> entry) override {
Khushal996e9912018-07-13 08:31:002626 auto type = entry->Type();
2627 transfer_cache_->CreateLocalEntry(
2628 ServiceTransferCache::EntryKey(raster_decoder_id_, type, id),
2629 std::move(entry));
Adrienne Walker90b79a22018-05-08 21:40:422630 }
2631
Jonathan Backere19973e82018-04-18 20:08:092632 private:
2633 cc::ServiceTransferCacheEntry* GetEntryInternal(
2634 cc::TransferCacheEntryType entry_type,
Jonathan Backer4f9ee5fb2018-04-25 14:03:382635 uint32_t entry_id) override {
Khushal996e9912018-07-13 08:31:002636 return transfer_cache_->GetEntry(ServiceTransferCache::EntryKey(
2637 raster_decoder_id_, entry_type, entry_id));
Jonathan Backere19973e82018-04-18 20:08:092638 }
Khushal996e9912018-07-13 08:31:002639
2640 const int raster_decoder_id_;
Keishi Hattori0e45c022021-11-27 09:25:522641 const raw_ptr<ServiceTransferCache> transfer_cache_;
Jonathan Backere19973e82018-04-18 20:08:092642};
2643
2644} // namespace
2645
Khushal33205a72018-11-08 10:12:292646void RasterDecoderImpl::DeletePaintCachePathsINTERNALHelper(
2647 GLsizei n,
2648 const volatile GLuint* paint_cache_ids) {
kylecharee7338172022-02-02 16:59:102649 if (!use_gpu_raster_) {
Khushal33205a72018-11-08 10:12:292650 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
2651 "glDeletePaintCacheEntriesINTERNAL",
2652 "No chromium raster support");
2653 return;
2654 }
2655
Khushalcb653fb2018-11-15 08:56:282656 paint_cache_->Purge(cc::PaintCacheDataType::kPath, n, paint_cache_ids);
Khushal33205a72018-11-08 10:12:292657}
2658
2659void RasterDecoderImpl::DoClearPaintCacheINTERNAL() {
kylecharee7338172022-02-02 16:59:102660 if (!use_gpu_raster_) {
Khushal33205a72018-11-08 10:12:292661 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glClearPaintCacheINTERNAL",
2662 "No chromium raster support");
2663 return;
2664 }
2665
2666 paint_cache_->PurgeAll();
2667}
2668
Aaron Krajeskid7d51a52022-05-25 13:29:092669void RasterDecoderImpl::DoBeginRasterCHROMIUM(GLfloat r,
2670 GLfloat g,
2671 GLfloat b,
2672 GLfloat a,
Sunny Sachanandanib461e212021-03-05 19:22:122673 GLboolean needs_clear,
Nathan Zabriskie31e4dc92020-04-15 23:10:272674 GLuint msaa_sample_count,
Justin Novosad7cc290af2021-07-20 17:13:072675 MsaaMode msaa_mode,
Nathan Zabriskie31e4dc92020-04-15 23:10:272676 GLboolean can_use_lcd_text,
Peng Huang5ff70dff2022-03-03 19:55:112677 GLboolean visible,
Nathan Zabriskie31e4dc92020-04-15 23:10:272678 const volatile GLbyte* key) {
Christopher Cameronbeb5f272019-02-04 22:49:132679 // Workaround for https://crbug.com/906453: Flush before BeginRaster (the
2680 // commands between BeginRaster and EndRaster will not flush).
2681 FlushToWorkAroundMacCrashes();
2682
kylecharee7338172022-02-02 16:59:102683 if (!use_gpu_raster_) {
Jonathan Backere19973e82018-04-18 20:08:092684 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM",
kylecharee7338172022-02-02 16:59:102685 "No chromium raster support");
Jonathan Backere19973e82018-04-18 20:08:092686 return;
2687 }
2688 if (sk_surface_) {
2689 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM",
2690 "BeginRasterCHROMIUM without EndRasterCHROMIUM");
2691 return;
2692 }
2693
Jonathan Backer7e7492522018-07-20 00:23:552694 Mailbox mailbox =
2695 Mailbox::FromVolatile(*reinterpret_cast<const volatile Mailbox*>(key));
2696 DLOG_IF(ERROR, !mailbox.Verify()) << "BeginRasterCHROMIUM was "
2697 "passed a mailbox that was not "
2698 "generated by ProduceTextureCHROMIUM.";
Eric Karl3750cfa2018-10-25 16:54:172699
2700 DCHECK(!shared_image_);
Peng Huangb447da42021-09-22 19:21:262701 DCHECK(!shared_image_raster_);
2702
2703 SharedImageRepresentation* shared_image = nullptr;
2704 if (is_raw_draw_enabled_) {
2705 shared_image_raster_ =
2706 shared_image_representation_factory_.ProduceRaster(mailbox);
2707 shared_image = shared_image_raster_.get();
2708 }
2709
2710 if (!shared_image) {
2711 shared_image_ = shared_image_representation_factory_.ProduceSkia(
2712 mailbox, shared_context_state_.get());
2713 shared_image = shared_image_.get();
2714 }
2715
2716 if (!shared_image) {
Jonathan Backer7e7492522018-07-20 00:23:552717 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glBeginRasterCHROMIUM",
2718 "passed invalid mailbox.");
2719 return;
2720 }
2721
Peng Huangb447da42021-09-22 19:21:262722 if (!needs_clear && !shared_image->IsCleared()) {
Sunny Sachanandanibb3dfad2021-06-04 19:04:222723 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM",
2724 "SharedImage not cleared before use.");
Peng Huangb447da42021-09-22 19:21:262725 shared_image_raster_.reset();
Sunny Sachanandani8f8b4eae2021-06-07 19:14:162726 shared_image_.reset();
Sunny Sachanandanibb3dfad2021-06-04 19:04:222727 return;
2728 }
2729
Khushal22204a42018-05-17 23:06:212730 DCHECK(locked_handles_.empty());
Jonathan Backere19973e82018-04-18 20:08:092731 DCHECK(!raster_canvas_);
Jonathan Backere19973e82018-04-18 20:08:092732
Saifuddin Hitawalab0bdad92022-11-23 23:07:242733 SkColorType sk_color_type = viz::ToClosestSkColorType(
Peng Huangb447da42021-09-22 19:21:262734 /*gpu_compositing=*/true, shared_image->format());
Justin Novosad7cc290af2021-07-20 17:13:072735
2736 int final_msaa_count;
2737 uint32_t flags;
2738 switch (msaa_mode) {
2739 default:
2740 case kNoMSAA:
2741 final_msaa_count = 0;
2742 flags = 0;
Justin Novosad7cc290af2021-07-20 17:13:072743 break;
2744 case kMSAA:
Colin Blundelld7b7b472023-05-12 07:38:122745 // Graphite operates as in the kDMSAA case below.
2746 if (graphite_context()) {
2747 final_msaa_count = 1;
2748 flags = SkSurfaceProps::kDynamicMSAA_Flag;
2749 break;
2750 }
2751
Justin Novosad7cc290af2021-07-20 17:13:072752 // If we can't match requested MSAA samples, don't use MSAA.
2753 final_msaa_count = std::max(static_cast<int>(msaa_sample_count), 0);
Colin Blundelld7b7b472023-05-12 07:38:122754 if (gr_context() &&
2755 final_msaa_count >
2756 gr_context()->maxSurfaceSampleCountForColorType(sk_color_type)) {
Justin Novosad7cc290af2021-07-20 17:13:072757 final_msaa_count = 0;
Colin Blundelld7b7b472023-05-12 07:38:122758 }
Justin Novosad7cc290af2021-07-20 17:13:072759 flags = 0;
Justin Novosad7cc290af2021-07-20 17:13:072760 break;
2761 case kDMSAA:
2762 final_msaa_count = 1;
2763 flags = SkSurfaceProps::kDynamicMSAA_Flag;
Justin Novosad7cc290af2021-07-20 17:13:072764 break;
2765 }
2766
Jonathan Backere19973e82018-04-18 20:08:092767 // Use unknown pixel geometry to disable LCD text.
2768 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry);
2769 if (can_use_lcd_text) {
Ian Preste598eece2020-10-19 23:31:022770 surface_props = skia::LegacyDisplayGlobals::GetSkSurfaceProps(flags);
Jonathan Backere19973e82018-04-18 20:08:092771 }
2772
Aaron Krajeskid7d51a52022-05-25 13:29:092773 SkColor4f sk_color_4f = {r, g, b, a};
Peng Huangb447da42021-09-22 19:21:262774 if (shared_image_raster_) {
Aaron Krajeskid7d51a52022-05-25 13:29:092775 absl::optional<SkColor4f> clear_color;
Peng Huangb447da42021-09-22 19:21:262776 if (needs_clear)
Aaron Krajeskid7d51a52022-05-25 13:29:092777 clear_color.emplace(sk_color_4f);
Peng Huangb447da42021-09-22 19:21:262778 scoped_shared_image_raster_write_ =
2779 shared_image_raster_->BeginScopedWriteAccess(
Peng Huang5ff70dff2022-03-03 19:55:112780 shared_context_state_, final_msaa_count, surface_props, clear_color,
2781 visible);
Peng Huangb447da42021-09-22 19:21:262782 if (!scoped_shared_image_raster_write_) {
2783 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM",
2784 "failed to create surface");
2785 shared_image_raster_.reset();
2786 return;
2787 }
2788
2789 if (needs_clear)
2790 shared_image_raster_->SetCleared();
2791
2792 return;
2793 }
2794
Peng Huang5f9118b02019-04-24 20:18:212795 std::vector<GrBackendSemaphore> begin_semaphores;
2796 DCHECK(end_semaphores_.empty());
Peng Huange9b41cd2019-08-12 19:39:472797 DCHECK(!scoped_shared_image_write_);
Nathan Zabriskie31e4dc92020-04-15 23:10:272798 // Allow uncleared access, as raster specifically handles uncleared images
2799 // by clearing them before writing.
Eric Karl707c1b92019-12-10 06:50:082800 scoped_shared_image_write_ = shared_image_->BeginScopedWriteAccess(
Eric Karl14bfb992020-01-03 01:32:212801 final_msaa_count, surface_props, &begin_semaphores, &end_semaphores_,
2802 SharedImageRepresentation::AllowUnclearedAccess::kYes);
Eric Karl707c1b92019-12-10 06:50:082803 if (!scoped_shared_image_write_) {
2804 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM",
2805 "failed to create surface");
2806 shared_image_.reset();
2807 return;
2808 }
2809
Peng Huange9b41cd2019-08-12 19:39:472810 sk_surface_ = scoped_shared_image_write_->surface();
Peng Huang5f9118b02019-04-24 20:18:212811
2812 if (!begin_semaphores.empty()) {
2813 bool result =
Peng Huang1c6d0582020-07-31 12:14:112814 sk_surface_->wait(begin_semaphores.size(), begin_semaphores.data(),
2815 /*deleteSemaphoresAfterWait=*/false);
Peng Huang5f9118b02019-04-24 20:18:212816 DCHECK(result);
2817 }
2818
Peng Huang23b9be7b2022-02-19 01:05:412819 raster_canvas_ = sk_surface_->getCanvas();
Peng Huang050dee52018-09-05 15:54:082820
Nathan Zabriskieffc210692020-07-09 07:36:472821 paint_op_shared_image_provider_ = std::make_unique<SharedImageProviderImpl>(
2822 &shared_image_representation_factory_, shared_context_state_, sk_surface_,
Vasiliy Telezhnikov9837f902022-08-17 15:03:072823 &end_semaphores_, error_state_.get());
Nathan Zabriskieffc210692020-07-09 07:36:472824
Jonathan Backere19973e82018-04-18 20:08:092825 // All or nothing clearing, as no way to validate the client's input on what
Sunny Sachanandanib461e212021-03-05 19:22:122826 // is the "used" part of the texture. A separate |needs_clear| flag is needed
2827 // because clear tracking on the shared image cannot be used for this purpose
2828 // with passthrough decoder shared images which are always considered cleared.
2829 //
2830 // TODO(enne): This doesn't handle the case where the background color changes
2831 // and so any extra pixels outside the raster area that get sampled may be
2832 // incorrect.
2833 if (needs_clear) {
Aaron Krajeskid7d51a52022-05-25 13:29:092834 raster_canvas_->drawColor(sk_color_4f, SkBlendMode::kSrc);
Sunny Sachanandanib461e212021-03-05 19:22:122835 shared_image_->SetCleared();
2836 }
2837 DCHECK(shared_image_->IsCleared());
Jonathan Backere19973e82018-04-18 20:08:092838}
2839
Khushala8d50642018-05-03 01:29:062840scoped_refptr<Buffer> RasterDecoderImpl::GetShmBuffer(uint32_t shm_id) {
2841 return GetSharedMemoryBuffer(shm_id);
2842}
2843
Khushal39641b92019-06-03 21:32:542844void RasterDecoderImpl::ReportProgress() {
2845 if (shared_context_state_->progress_reporter())
2846 shared_context_state_->progress_reporter()->ReportProgress();
2847}
2848
Khushala8d50642018-05-03 01:29:062849void RasterDecoderImpl::DoRasterCHROMIUM(GLuint raster_shm_id,
2850 GLuint raster_shm_offset,
Antoine Labour423fe592019-01-10 22:13:092851 GLuint raster_shm_size,
Khushala8d50642018-05-03 01:29:062852 GLuint font_shm_id,
2853 GLuint font_shm_offset,
Antoine Labour423fe592019-01-10 22:13:092854 GLuint font_shm_size) {
Khushalf9750702018-06-09 00:42:132855 TRACE_EVENT1("gpu", "RasterDecoderImpl::DoRasterCHROMIUM", "raster_id",
2856 ++raster_chromium_id_);
Khushala8d50642018-05-03 01:29:062857
kylecharee7338172022-02-02 16:59:102858 if (!use_gpu_raster_) {
2859 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM",
2860 "No chromium raster support");
2861 return;
2862 }
2863
Peng Huangb447da42021-09-22 19:21:262864 if (!sk_surface_ && !scoped_shared_image_raster_write_) {
Jonathan Backere19973e82018-04-18 20:08:092865 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM",
2866 "RasterCHROMIUM without BeginRasterCHROMIUM");
2867 return;
2868 }
Khushal996e9912018-07-13 08:31:002869 DCHECK(transfer_cache());
Jonathan Backere19973e82018-04-18 20:08:092870
Khushala8d50642018-05-03 01:29:062871 if (font_shm_size > 0) {
2872 // Deserialize fonts before raster.
2873 volatile char* font_buffer_memory =
2874 GetSharedMemoryAs<char*>(font_shm_id, font_shm_offset, font_shm_size);
2875 if (!font_buffer_memory) {
2876 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM",
2877 "Can not read font buffer.");
2878 return;
2879 }
2880
Khushaldb6ea3c2018-05-31 00:53:092881 std::vector<SkDiscardableHandleId> new_locked_handles;
Khushal3d0b8902018-09-18 03:03:342882 if (!font_manager_->Deserialize(font_buffer_memory, font_shm_size,
2883 &new_locked_handles)) {
Khushala8d50642018-05-03 01:29:062884 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM",
2885 "Invalid font buffer.");
2886 return;
2887 }
Khushaldb6ea3c2018-05-31 00:53:092888 locked_handles_.insert(locked_handles_.end(), new_locked_handles.begin(),
2889 new_locked_handles.end());
Khushala8d50642018-05-03 01:29:062890 }
2891
2892 char* paint_buffer_memory = GetSharedMemoryAs<char*>(
2893 raster_shm_id, raster_shm_offset, raster_shm_size);
2894 if (!paint_buffer_memory) {
2895 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM",
2896 "Can not read paint buffer.");
2897 return;
2898 }
2899
Peng Huanga8bda892022-05-06 17:15:592900 if (paint_buffer_memory != base::bits::AlignUp(paint_buffer_memory, 16u)) {
2901 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM",
2902 "Buffer is not aligned with 16 bytes.");
2903 return;
2904 }
2905
Aaron Krajeskid55f49002020-12-09 17:27:512906 cc::PlaybackParams playback_params(nullptr, SkM44());
Khushal996e9912018-07-13 08:31:002907 TransferCacheDeserializeHelperImpl impl(raster_decoder_id_, transfer_cache());
Adrienne Walker5a4952e2019-01-07 21:16:292908 cc::PaintOp::DeserializeOptions options(
2909 &impl, paint_cache_.get(), font_manager_->strike_client(),
Nathan Zabriskieffc210692020-07-09 07:36:472910 shared_context_state_->scratch_deserialization_buffer(), is_privileged_,
2911 paint_op_shared_image_provider_.get());
Vikas Soni2a4039f2020-07-22 18:34:202912 options.crash_dump_on_failure =
2913 !gpu_preferences_.disable_oopr_debug_crash_dump;
Jonathan Backere19973e82018-04-18 20:08:092914
Peng Huangb447da42021-09-22 19:21:262915 if (scoped_shared_image_raster_write_) {
2916 auto* paint_op_buffer =
2917 scoped_shared_image_raster_write_->paint_op_buffer();
2918 paint_op_buffer->Deserialize(paint_buffer_memory, raster_shm_size, options);
2919 return;
2920 }
2921
Xianzhu Wanga0711d72023-02-08 22:54:262922 alignas(cc::PaintOpBuffer::kPaintOpAlign) char
2923 data[cc::kLargestPaintOpAlignedSize];
Peng Huangb447da42021-09-22 19:21:262924
Khushala8d50642018-05-03 01:29:062925 size_t paint_buffer_size = raster_shm_size;
Adrienne Walkerd8a56462019-03-16 03:11:472926 gl::ScopedProgressReporter report_progress(
Khushal61977dfc2019-02-22 02:24:292927 shared_context_state_->progress_reporter());
Khushala4156862018-06-08 22:46:022928 while (paint_buffer_size > 0) {
Jonathan Backere19973e82018-04-18 20:08:092929 size_t skip = 0;
Xianzhu Wanga0711d72023-02-08 22:54:262930 cc::PaintOp* deserialized_op =
2931 cc::PaintOp::Deserialize(paint_buffer_memory, paint_buffer_size, data,
2932 std::size(data), &skip, options);
Jonathan Backere19973e82018-04-18 20:08:092933 if (!deserialized_op) {
Adrienne Walkere62484a2018-11-27 18:41:302934 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM",
2935 "RasterCHROMIUM: serialization failure");
Jonathan Backere19973e82018-04-18 20:08:092936 return;
2937 }
2938
Mike Reed421f75d2019-02-25 20:30:032939 deserialized_op->Raster(raster_canvas_, playback_params);
Christopher Camerond5698f682018-12-11 00:59:202940 deserialized_op->DestroyThis();
2941
Christopher Camerond5698f682018-12-11 00:59:202942 paint_buffer_size -= skip;
2943 paint_buffer_memory += skip;
Jonathan Backere19973e82018-04-18 20:08:092944 }
2945}
2946
2947void RasterDecoderImpl::DoEndRasterCHROMIUM() {
Peng Huang050dee52018-09-05 15:54:082948 TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM");
Peng Huangb447da42021-09-22 19:21:262949 if (!sk_surface_ && !scoped_shared_image_raster_write_) {
Jonathan Backera1f3d7c2018-10-16 14:46:322950 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glEndRasterCHROMIUM",
Jonathan Backere19973e82018-04-18 20:08:092951 "EndRasterCHROMIUM without BeginRasterCHROMIUM");
2952 return;
2953 }
2954
Peng Huangb447da42021-09-22 19:21:262955 if (scoped_shared_image_raster_write_) {
2956 scoped_shared_image_raster_write_->set_callback(base::BindOnce(
2957 [](scoped_refptr<ServiceFontManager> font_manager,
2958 std::vector<SkDiscardableHandleId> handles) {
Peng Huang410ae6b22022-04-15 03:31:012959 font_manager->Unlock(handles);
Peng Huangb447da42021-09-22 19:21:262960 },
2961 font_manager_, std::move(locked_handles_)));
2962 scoped_shared_image_raster_write_.reset();
2963 shared_image_raster_.reset();
2964 locked_handles_.clear();
2965 return;
2966 }
2967
Mike Reed421f75d2019-02-25 20:30:032968 raster_canvas_ = nullptr;
Peng Huang050dee52018-09-05 15:54:082969
Khushal61977dfc2019-02-22 02:24:292970 {
Peng Huangd9608432019-07-29 15:56:362971 TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM::Flush");
Khushal61977dfc2019-02-22 02:24:292972 // This is a slow operation since skia will execute the GPU work for the
2973 // complete tile. Make sure the progress reporter is notified to avoid
2974 // hangs.
Adrienne Walkerd8a56462019-03-16 03:11:472975 gl::ScopedProgressReporter report_progress(
Khushal61977dfc2019-02-22 02:24:292976 shared_context_state_->progress_reporter());
Vasiliy Telezhnikov6414a252022-04-26 04:42:112977
2978 // scoped_shared_image_write_ can be nullptr if sk_surface_ was set by
2979 // SetUpForRasterCHROMIUMForTest.
2980 if (scoped_shared_image_write_) {
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:052981 FlushSurface(scoped_shared_image_write_.get());
2982 // Flushing surface will cause vulkan command buffer to be recorded with
2983 // image layout transitions as necessary. Transitioning layout back to
2984 // desired need to be happening after.
Vasiliy Telezhnikov6414a252022-04-26 04:42:112985 paint_op_shared_image_provider_->ApplyEndAccessState();
Vasiliy Telezhnikovf1562c4f2022-08-06 14:02:052986 SubmitIfNecessary(std::move(end_semaphores_));
Vasiliy Telezhnikov6414a252022-04-26 04:42:112987 end_semaphores_.clear();
2988 } else {
2989 DCHECK(end_semaphores_.empty());
2990 }
Khushal61977dfc2019-02-22 02:24:292991 }
2992
Kramer Geddcac3532019-12-12 23:33:102993 shared_context_state_->UpdateSkiaOwnedMemorySize();
Peng Huange9b41cd2019-08-12 19:39:472994 sk_surface_ = nullptr;
Peng Huangb63db212020-06-01 14:37:392995 scoped_shared_image_write_.reset();
2996 shared_image_.reset();
Nathan Zabriskieffc210692020-07-09 07:36:472997 paint_op_shared_image_provider_.reset();
2998
Peng Huangb63db212020-06-01 14:37:392999 // Test only path for SetUpForRasterCHROMIUMForTest.
3000 sk_surface_for_testing_.reset();
Khushal22204a42018-05-17 23:06:213001
3002 // Unlock all font handles. This needs to be deferred until
Greg Daniel18362e9d2019-04-15 19:54:503003 // SkSurface::flush since that flushes batched Gr operations
Peng Huangc6a76072018-11-27 23:17:313004 // in skia that access the glyph data.
Khushal3d0b8902018-09-18 03:03:343005 if (!font_manager_->Unlock(locked_handles_)) {
Khushal22204a42018-05-17 23:06:213006 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM",
3007 "Invalid font discardable handle.");
3008 }
3009 locked_handles_.clear();
Khushal15b6abb2018-06-28 00:16:253010
Victor Miura6bb4ab5c2023-05-10 21:35:123011 // We just unlocked a bunch of handles. Give a call to skia to
3012 // attempt to purge any unlocked handles.
3013 SkGraphics::PurgePinnedFontCache();
3014
Khushal15b6abb2018-06-28 00:16:253015 // We just flushed a tile's worth of GPU work from the SkSurface in
Khushal Sagarb3f53292019-06-05 04:24:233016 // flush above. Yield to the Scheduler to allow pre-emption before
3017 // processing more commands.
3018 ExitCommandProcessingEarly();
Jonathan Backere19973e82018-04-18 20:08:093019}
3020
Jonathan Backer0cd1c4322018-04-17 16:57:103021void RasterDecoderImpl::DoCreateTransferCacheEntryINTERNAL(
3022 GLuint raw_entry_type,
3023 GLuint entry_id,
3024 GLuint handle_shm_id,
3025 GLuint handle_shm_offset,
3026 GLuint data_shm_id,
3027 GLuint data_shm_offset,
3028 GLuint data_size) {
kylecharee7338172022-02-02 16:59:103029 if (!use_gpu_raster_) {
Jonathan Backer0cd1c4322018-04-17 16:57:103030 LOCAL_SET_GL_ERROR(
3031 GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL",
3032 "Attempt to use OOP transfer cache on a context without OOP raster.");
3033 return;
3034 }
Saifuddin Hitawalad9027662023-05-12 14:50:103035 CHECK(gr_context() || graphite_recorder());
3036 CHECK(transfer_cache());
Jonathan Backer0cd1c4322018-04-17 16:57:103037
3038 // Validate the type we are about to create.
3039 cc::TransferCacheEntryType entry_type;
3040 if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type,
3041 &entry_type)) {
Peng Huangc6a76072018-11-27 23:17:313042 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL",
3043 "Attempt to use OOP transfer cache with an invalid "
3044 "cache entry type.");
Jonathan Backer0cd1c4322018-04-17 16:57:103045 return;
3046 }
3047
Khushalc11f57b2020-03-20 16:56:153048 if (entry_type == cc::TransferCacheEntryType::kSkottie && !is_privileged_) {
3049 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL",
3050 "Attempt to use skottie on a non privileged channel");
3051 return;
3052 }
3053
Jonathan Backer0cd1c4322018-04-17 16:57:103054 uint8_t* data_memory =
3055 GetSharedMemoryAs<uint8_t*>(data_shm_id, data_shm_offset, data_size);
3056 if (!data_memory) {
3057 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL",
3058 "Can not read transfer cache entry data.");
3059 return;
3060 }
3061
3062 scoped_refptr<Buffer> handle_buffer = GetSharedMemoryBuffer(handle_shm_id);
3063 if (!DiscardableHandleBase::ValidateParameters(handle_buffer.get(),
3064 handle_shm_offset)) {
3065 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL",
3066 "Invalid shm for discardable handle.");
3067 return;
3068 }
3069 ServiceDiscardableHandle handle(std::move(handle_buffer), handle_shm_offset,
3070 handle_shm_id);
3071
Peng Huangc6a76072018-11-27 23:17:313072 // If the entry is going to use skia during deserialization, make sure we
3073 // mark the context state dirty.
Sunny Sachanandani5fcc5722023-05-09 00:50:363074 bool use_gpu = cc::ServiceTransferCacheEntry::UsesGpuContext(entry_type);
Khushal996e9912018-07-13 08:31:003075 if (!transfer_cache()->CreateLockedEntry(
3076 ServiceTransferCache::EntryKey(raster_decoder_id_, entry_type,
3077 entry_id),
Sunny Sachanandani5fcc5722023-05-09 00:50:363078 handle, use_gpu ? gr_context() : nullptr,
3079 use_gpu ? graphite_recorder() : nullptr,
3080 base::make_span(data_memory, data_size))) {
Jonathan Backer0cd1c4322018-04-17 16:57:103081 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL",
3082 "Failure to deserialize transfer cache entry.");
3083 return;
3084 }
Khushal Sagarb3f53292019-06-05 04:24:233085
3086 // The only entry using the GrContext are image transfer cache entries for
3087 // image uploads. Since this tends to a slow operation, yield to allow the
3088 // decoder to be pre-empted.
Sunny Sachanandani5fcc5722023-05-09 00:50:363089 if (use_gpu) {
Khushal Sagarb3f53292019-06-05 04:24:233090 ExitCommandProcessingEarly();
Sunny Sachanandani5fcc5722023-05-09 00:50:363091 }
Jonathan Backer0cd1c4322018-04-17 16:57:103092}
3093
3094void RasterDecoderImpl::DoUnlockTransferCacheEntryINTERNAL(
3095 GLuint raw_entry_type,
3096 GLuint entry_id) {
kylecharee7338172022-02-02 16:59:103097 if (!use_gpu_raster_) {
Jonathan Backer0cd1c4322018-04-17 16:57:103098 LOCAL_SET_GL_ERROR(
3099 GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL",
3100 "Attempt to use OOP transfer cache on a context without OOP raster.");
3101 return;
3102 }
Khushal996e9912018-07-13 08:31:003103 DCHECK(transfer_cache());
Jonathan Backer0cd1c4322018-04-17 16:57:103104 cc::TransferCacheEntryType entry_type;
3105 if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type,
3106 &entry_type)) {
Peng Huangc6a76072018-11-27 23:17:313107 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL",
3108 "Attempt to use OOP transfer cache with an invalid "
3109 "cache entry type.");
Jonathan Backer0cd1c4322018-04-17 16:57:103110 return;
3111 }
3112
Khushal996e9912018-07-13 08:31:003113 if (!transfer_cache()->UnlockEntry(ServiceTransferCache::EntryKey(
3114 raster_decoder_id_, entry_type, entry_id))) {
Jonathan Backer0cd1c4322018-04-17 16:57:103115 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL",
3116 "Attempt to unlock an invalid ID");
3117 }
3118}
3119
3120void RasterDecoderImpl::DoDeleteTransferCacheEntryINTERNAL(
3121 GLuint raw_entry_type,
3122 GLuint entry_id) {
kylecharee7338172022-02-02 16:59:103123 if (!use_gpu_raster_) {
Jonathan Backer0cd1c4322018-04-17 16:57:103124 LOCAL_SET_GL_ERROR(
3125 GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL",
3126 "Attempt to use OOP transfer cache on a context without OOP raster.");
3127 return;
3128 }
Khushal996e9912018-07-13 08:31:003129 DCHECK(transfer_cache());
Jonathan Backer0cd1c4322018-04-17 16:57:103130 cc::TransferCacheEntryType entry_type;
3131 if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type,
3132 &entry_type)) {
Peng Huangc6a76072018-11-27 23:17:313133 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL",
3134 "Attempt to use OOP transfer cache with an invalid "
3135 "cache entry type.");
Jonathan Backer0cd1c4322018-04-17 16:57:103136 return;
3137 }
3138
Khushal996e9912018-07-13 08:31:003139 if (!transfer_cache()->DeleteEntry(ServiceTransferCache::EntryKey(
3140 raster_decoder_id_, entry_type, entry_id))) {
Jonathan Backer0cd1c4322018-04-17 16:57:103141 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL",
3142 "Attempt to delete an invalid ID");
3143 }
3144}
3145
Jonathan Backer10821a82018-04-04 23:56:033146void RasterDecoderImpl::RestoreStateForAttrib(GLuint attrib_index,
3147 bool restore_array_binding) {
Peng Huang20361dad12019-01-23 14:48:103148 shared_context_state_->PessimisticallyResetGrContext();
Jonathan Backer10821a82018-04-04 23:56:033149}
3150
Jonathan Backer7471b2782018-01-25 18:14:193151// Include the auto-generated part of this file. We split this because it means
3152// we can easily edit the non-auto generated parts right here in this file
3153// instead of having to edit some template or the code generator.
Yuta Hijikata7471d26f2020-10-23 03:27:423154#include "build/chromeos_buildflags.h"
Jonathan Backera4568da12018-01-31 16:25:043155#include "gpu/command_buffer/service/raster_decoder_autogen.h"
Jonathan Backer7471b2782018-01-25 18:14:193156
Jonathan Backer7f90dfb662017-12-18 16:52:043157} // namespace raster
3158} // namespace gpu