Avi Drissman | 05dfbc82 | 2022-09-13 21:25:34 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 2 | // 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 11 | #include <string> |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 12 | #include <utility> |
Jonathan Backer | 6307cee9 | 2018-04-25 19:53:43 | [diff] [blame] | 13 | #include <vector> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 14 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 15 | #include "base/atomic_sequence_num.h" |
Peng Huang | cb204209 | 2018-12-04 13:42:34 | [diff] [blame] | 16 | #include "base/containers/flat_map.h" |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 17 | #include "base/debug/crash_logging.h" |
Avi Drissman | 93a273dd | 2023-01-11 00:38:27 | [diff] [blame] | 18 | #include "base/functional/bind.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 19 | #include "base/logging.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 20 | #include "base/memory/raw_ptr.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 21 | #include "base/memory/ref_counted.h" |
| 22 | #include "base/memory/weak_ptr.h" |
Scott Violet | 86dc643d | 2023-04-07 17:57:24 | [diff] [blame] | 23 | #include "base/metrics/histogram_functions.h" |
Nathan Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 24 | #include "base/numerics/checked_math.h" |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 25 | #include "base/time/time.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 26 | #include "base/trace_event/trace_event.h" |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 27 | #include "build/build_config.h" |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 28 | #include "cc/paint/paint_cache.h" |
Xianzhu Wang | e6d732e9 | 2022-12-08 17:27:52 | [diff] [blame] | 29 | #include "cc/paint/paint_op.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 30 | #include "cc/paint/paint_op_buffer.h" |
Lei Zhang | d35969c7 | 2021-05-20 20:58:33 | [diff] [blame] | 31 | #include "cc/paint/transfer_cache_deserialize_helper.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 32 | #include "cc/paint/transfer_cache_entry.h" |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 33 | #include "components/viz/common/resources/resource_format_utils.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 34 | #include "gpu/command_buffer/common/capabilities.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 35 | #include "gpu/command_buffer/common/command_buffer_id.h" |
| 36 | #include "gpu/command_buffer/common/constants.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 37 | #include "gpu/command_buffer/common/context_result.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 38 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 39 | #include "gpu/command_buffer/common/mailbox.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 40 | #include "gpu/command_buffer/common/raster_cmd_format.h" |
| 41 | #include "gpu/command_buffer/common/raster_cmd_ids.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 42 | #include "gpu/command_buffer/common/sync_token.h" |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 43 | #include "gpu/command_buffer/service/command_buffer_service.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/context_state.h" |
Saifuddin Hitawala | a4eb464 | 2023-01-18 23:52:24 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/copy_shared_image_helper.h" |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 46 | #include "gpu/command_buffer/service/decoder_client.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 47 | #include "gpu/command_buffer/service/error_state.h" |
| 48 | #include "gpu/command_buffer/service/feature_info.h" |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 49 | #include "gpu/command_buffer/service/gl_utils.h" |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 50 | #include "gpu/command_buffer/service/gpu_tracer.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 51 | #include "gpu/command_buffer/service/logger.h" |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 52 | #include "gpu/command_buffer/service/mailbox_manager.h" |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 53 | #include "gpu/command_buffer/service/query_manager.h" |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 54 | #include "gpu/command_buffer/service/raster_cmd_validation.h" |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/service_font_manager.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/service_transfer_cache.h" |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/service_utils.h" |
Peng Huang | 8294a5a7f | 2019-01-23 18:56:26 | [diff] [blame] | 58 | #include "gpu/command_buffer/service/shared_context_state.h" |
Saifuddin Hitawala | 81cbd38 | 2022-07-20 19:14:53 | [diff] [blame] | 59 | #include "gpu/command_buffer/service/shared_image/shared_image_factory.h" |
Saifuddin Hitawala | 796463f | 2022-12-02 16:34:10 | [diff] [blame] | 60 | #include "gpu/command_buffer/service/shared_image/shared_image_format_utils.h" |
Saifuddin Hitawala | 81cbd38 | 2022-07-20 19:14:53 | [diff] [blame] | 61 | #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 Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 63 | #include "gpu/command_buffer/service/skia_utils.h" |
Vikas Soni | ca02287b | 2022-01-18 20:17:35 | [diff] [blame] | 64 | #include "gpu/config/gpu_finch_features.h" |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 65 | #include "gpu/vulkan/buildflags.h" |
Ian Prest | e598eece | 2020-10-19 23:31:02 | [diff] [blame] | 66 | #include "skia/ext/legacy_display_globals.h" |
Christopher Cameron | d18b932 | 2021-08-24 21:12:55 | [diff] [blame] | 67 | #include "skia/ext/rgba_to_yuva.h" |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 68 | #include "third_party/libyuv/include/libyuv/planar_functions.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 69 | #include "third_party/skia/include/core/SkCanvas.h" |
Kevin Lubick | 040667a | 2022-04-07 13:49:03 | [diff] [blame] | 70 | #include "third_party/skia/include/core/SkColorSpace.h" |
Victor Miura | 6bb4ab5c | 2023-05-10 21:35:12 | [diff] [blame] | 71 | #include "third_party/skia/include/core/SkGraphics.h" |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 72 | #include "third_party/skia/include/core/SkPromiseImageTexture.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 73 | #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 Salomon | c54f44f | 2020-11-11 16:11:06 | [diff] [blame] | 76 | #include "third_party/skia/include/core/SkYUVAInfo.h" |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 77 | #include "third_party/skia/include/gpu/GrBackendSemaphore.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 78 | #include "third_party/skia/include/gpu/GrBackendSurface.h" |
Adlai Holler | c4dea1a9 | 2020-08-04 13:21:55 | [diff] [blame] | 79 | #include "third_party/skia/include/gpu/GrDirectContext.h" |
Brian Salomon | c54f44f | 2020-11-11 16:11:06 | [diff] [blame] | 80 | #include "third_party/skia/include/gpu/GrYUVABackendTextures.h" |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 81 | #include "third_party/skia/include/gpu/graphite/Context.h" |
Peng Huang | 5f3d435 | 2021-11-23 17:51:29 | [diff] [blame] | 82 | #include "ui/base/ui_base_features.h" |
Jonathan Backer | 76dfd50 | 2018-05-03 18:34:31 | [diff] [blame] | 83 | #include "ui/gfx/buffer_format_util.h" |
Xianzhu Wang | 65ef1ad3 | 2021-10-07 03:12:33 | [diff] [blame] | 84 | #include "ui/gfx/geometry/skia_conversions.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 85 | #include "ui/gl/gl_context.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 86 | #include "ui/gl/gl_gl_api_implementation.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 87 | #include "ui/gl/gl_surface.h" |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 88 | #include "ui/gl/gl_version_info.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 89 | |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 90 | #if BUILDFLAG(ENABLE_VULKAN) |
| 91 | #include "components/viz/common/gpu/vulkan_context_provider.h" |
| 92 | #include "gpu/vulkan/vulkan_device_queue.h" |
Jonah Chin | 09d12b7 | 2021-05-11 00:52:08 | [diff] [blame] | 93 | #endif // BUILDFLAG(ENABLE_VULKAN) |
| 94 | |
Xiaohan Wang | fa22d3e | 2022-01-15 02:02:43 | [diff] [blame] | 95 | #if BUILDFLAG(IS_WIN) |
Saifuddin Hitawala | 81cbd38 | 2022-07-20 19:14:53 | [diff] [blame] | 96 | #include "gpu/command_buffer/service/shared_image/d3d_image_backing_factory.h" |
Xiaohan Wang | fa22d3e | 2022-01-15 02:02:43 | [diff] [blame] | 97 | #endif // BUILDFLAG(IS_WIN) |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 98 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 99 | // Local versions of the SET_GL_ERROR macros |
| 100 | #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 101 | 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 Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 104 | static_cast<uint32_t>(value), label) |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 105 | #define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 106 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 107 | #define LOCAL_PEEK_GL_ERROR(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 108 | ERRORSTATE_PEEK_GL_ERROR(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 109 | #define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 110 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 111 | #define LOCAL_PERFORMANCE_WARNING(msg) \ |
| 112 | PerformanceWarning(__FILE__, __LINE__, msg) |
| 113 | #define LOCAL_RENDER_WARNING(msg) RenderWarning(__FILE__, __LINE__, msg) |
| 114 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 115 | namespace gpu { |
| 116 | namespace raster { |
| 117 | |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 118 | namespace { |
| 119 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 120 | base::AtomicSequenceNumber g_raster_decoder_id; |
| 121 | |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 122 | // This class prevents any GL errors that occur when it is in scope from |
| 123 | // being reported to the client. |
| 124 | class ScopedGLErrorSuppressor { |
| 125 | public: |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 126 | ScopedGLErrorSuppressor(const char* function_name, |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 127 | 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รถm | dbacdc2 | 2021-09-23 22:11:46 | [diff] [blame] | 131 | |
| 132 | ScopedGLErrorSuppressor(const ScopedGLErrorSuppressor&) = delete; |
| 133 | ScopedGLErrorSuppressor& operator=(const ScopedGLErrorSuppressor&) = delete; |
| 134 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 135 | ~ScopedGLErrorSuppressor() { |
| 136 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
| 137 | } |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 138 | |
| 139 | private: |
| 140 | const char* function_name_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 141 | raw_ptr<gles2::ErrorState> error_state_; |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 142 | }; |
| 143 | |
Corentin Wallez | 5cbffcc | 2020-07-08 10:23:57 | [diff] [blame] | 144 | // Commands that are explicitly listed as OK to occur between |
Adlai Holler | c4dea1a9 | 2020-08-04 13:21:55 | [diff] [blame] | 145 | // BeginRasterCHROMIUM and EndRasterCHROMIUM. They do not invalidate |
| 146 | // GrDirectContext state tracking. |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 147 | bool 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 Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 163 | // 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. |
| 168 | class 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 Telezhnikov | 9837f90 | 2022-08-17 15:03:07 | [diff] [blame] | 175 | gles2::ErrorState* error_state) |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 176 | : 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 Telezhnikov | 9837f90 | 2022-08-17 15:03:07 | [diff] [blame] | 180 | error_state_(error_state) { |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 181 | 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 Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 192 | sk_sp<SkImage> OpenSharedImageForRead(const gpu::Mailbox& mailbox, |
| 193 | Error& error) override { |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 194 | auto it = read_accessors_.find(mailbox); |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 195 | error = Error::kNoError; |
| 196 | if (it != read_accessors_.end()) { |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 197 | return it->second.read_access_sk_image; |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 198 | } |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 199 | |
| 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 Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 208 | error = Error::kUnknownMailbox; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 209 | 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 Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 223 | error = Error::kNoAccess; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 224 | return nullptr; |
| 225 | } |
| 226 | |
| 227 | if (!begin_semaphores.empty()) { |
| 228 | bool result = output_surface_->wait(begin_semaphores.size(), |
Peng Huang | 1c6d058 | 2020-07-31 12:14:11 | [diff] [blame] | 229 | begin_semaphores.data(), |
| 230 | /*deleteSemaphoresAfterWait=*/false); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 231 | DCHECK(result); |
| 232 | } |
| 233 | |
Nathan Zabriskie | c5ed236 | 2020-07-21 05:39:54 | [diff] [blame] | 234 | auto sk_image = |
Saifuddin Hitawala | 5a6785d5 | 2023-04-25 22:23:12 | [diff] [blame] | 235 | scoped_read_access->CreateSkImage(shared_context_state_.get()); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 236 | if (!sk_image) { |
| 237 | ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION, |
| 238 | "SharedImageProviderImpl::OpenSharedImageForRead", |
| 239 | "Couldn't create output SkImage."); |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 240 | error = Error::kSkImageCreationFailed; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 241 | 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 Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 249 | void ApplyEndAccessState() { |
| 250 | for (auto& accessor : read_accessors_) { |
Saifuddin Hitawala | 913ae95 | 2023-04-18 23:26:03 | [diff] [blame] | 251 | accessor.second.scoped_read_access->ApplyBackendSurfaceEndState(); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 255 | private: |
Pรขris | 7704a8e | 2022-09-01 09:49:20 | [diff] [blame] | 256 | raw_ptr<SharedImageRepresentationFactory, DanglingUntriaged> |
| 257 | shared_image_factory_; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 258 | scoped_refptr<SharedContextState> shared_context_state_; |
Pรขris | 7704a8e | 2022-09-01 09:49:20 | [diff] [blame] | 259 | raw_ptr<SkSurface, DanglingUntriaged> output_surface_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 260 | raw_ptr<std::vector<GrBackendSemaphore>> end_semaphores_; |
| 261 | raw_ptr<gles2::ErrorState> error_state_; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 262 | |
| 263 | struct SharedImageReadAccess { |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 264 | std::unique_ptr<SkiaImageRepresentation> shared_image_skia; |
| 265 | std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess> |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 266 | scoped_read_access; |
| 267 | sk_sp<SkImage> read_access_sk_image; |
| 268 | }; |
| 269 | base::flat_map<gpu::Mailbox, SharedImageReadAccess> read_accessors_; |
| 270 | }; |
| 271 | |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 272 | class 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 Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 285 | 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 295 | 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 Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 321 | } |
| 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 Huang | 63ef887 | 2021-06-17 22:31:20 | [diff] [blame] | 333 | if (did_finish || finished_) { |
| 334 | const base::TimeDelta elapsed = base::TimeTicks::Now() - *begin_time_; |
| 335 | MarkAsCompleted(elapsed.InMicroseconds()); |
| 336 | begin_time_.reset(); |
| 337 | } |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 338 | } |
| 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 | |
| 363 | class 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 375 | (shared_context_state_->gr_context() || |
| 376 | shared_context_state_->graphite_context())) { |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 377 | 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 Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 392 | } // namespace |
| 393 | |
Jonathan Backer | 5ac08a7 | 2018-06-27 16:15:35 | [diff] [blame] | 394 | // RasterDecoderImpl uses two separate state trackers (gpu::gles2::ContextState |
Adlai Holler | c4dea1a9 | 2020-08-04 13:21:55 | [diff] [blame] | 395 | // 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 Backer | 5ac08a7 | 2018-06-27 16:15:35 | [diff] [blame] | 397 | // state. We guard against that by resetting. But resetting is expensive, so we |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 398 | // avoid it as much as possible. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 399 | class RasterDecoderImpl final : public RasterDecoder, |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 400 | public gles2::ErrorStateClient, |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 401 | public ServiceFontManager::Client, |
| 402 | public SharedContextState::ContextLostObserver { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 403 | public: |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 404 | RasterDecoderImpl(DecoderClient* client, |
| 405 | CommandBufferServiceBase* command_buffer_service, |
| 406 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 407 | const GpuFeatureInfo& gpu_feature_info, |
| 408 | const GpuPreferences& gpu_preferences, |
| 409 | MemoryTracker* memory_tracker, |
| 410 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 411 | scoped_refptr<SharedContextState> shared_context_state, |
| 412 | bool is_privileged); |
Peter Bostrรถm | dbacdc2 | 2021-09-23 22:11:46 | [diff] [blame] | 413 | |
| 414 | RasterDecoderImpl(const RasterDecoderImpl&) = delete; |
| 415 | RasterDecoderImpl& operator=(const RasterDecoderImpl&) = delete; |
| 416 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 417 | ~RasterDecoderImpl() override; |
| 418 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 419 | gles2::GLES2Util* GetGLES2Util() override { return &util_; } |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 420 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 421 | // DecoderContext implementation. |
| 422 | base::WeakPtr<DecoderContext> AsWeakPtr() override; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 423 | ContextResult Initialize( |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 424 | 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 429 | void Destroy(bool have_context) override; |
| 430 | bool MakeCurrent() override; |
| 431 | gl::GLContext* GetGLContext() override; |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 432 | gl::GLSurface* GetGLSurface() override; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 433 | const gles2::FeatureInfo* GetFeatureInfo() const override { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 434 | return feature_info(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 435 | } |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 436 | Capabilities GetCapabilities() override; |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 437 | const gles2::ContextState* GetContextState() override; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 438 | |
| 439 | // TODO(penghuang): Remove unused context state related methods. |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 440 | void RestoreGlobalState() const override; |
| 441 | void ClearAllAttributes() const override; |
| 442 | void RestoreAllAttributes() const override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 443 | 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 Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 453 | void RestoreTextureState(unsigned service_id) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 454 | void RestoreTextureUnitBindings(unsigned unit) const override; |
| 455 | void RestoreVertexAttribArray(unsigned index) override; |
| 456 | void RestoreAllExternalTextureBindingsIfNeeded() override; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 457 | QueryManager* GetQueryManager() override; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 458 | |
Geoff Lang | 85287e1 | 2018-05-22 17:26:40 | [diff] [blame] | 459 | void SetQueryCallback(unsigned int query_client_id, |
| 460 | base::OnceClosure callback) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 461 | 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 Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 469 | 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 478 | 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 Blundell | ddd83e0 | 2022-11-30 13:40:16 | [diff] [blame] | 490 | |
Dave Tapuska | c03874f | 2023-02-01 21:53:55 | [diff] [blame] | 491 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) |
Colin Blundell | ddd83e0 | 2022-11-30 13:40:16 | [diff] [blame] | 492 | void AttachImageToTextureWithDecoderBinding(uint32_t client_texture_id, |
| 493 | uint32_t texture_target, |
| 494 | gl::GLImage* image) override; |
Colin Blundell | e2c394e | 2022-12-16 09:26:59 | [diff] [blame] | 495 | #elif !BUILDFLAG(IS_ANDROID) |
Colin Blundell | ddd83e0 | 2022-11-30 13:40:16 | [diff] [blame] | 496 | void AttachImageToTextureWithClientBinding(uint32_t client_texture_id, |
| 497 | uint32_t texture_target, |
| 498 | gl::GLImage* image) override; |
| 499 | #endif |
| 500 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 501 | gles2::ContextGroup* GetContextGroup() override; |
| 502 | gles2::ErrorState* GetErrorState() override; |
Colin Blundell | 9d4fea6 | 2022-12-14 15:26:16 | [diff] [blame] | 503 | #if !BUILDFLAG(IS_ANDROID) |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 504 | 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 Blundell | 9d4fea6 | 2022-12-14 15:26:16 | [diff] [blame] | 513 | #endif |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 514 | 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; |
shrekshao | ad452548 | 2020-03-12 00:30:55 | [diff] [blame] | 530 | 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 Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 537 | 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 Jaramillo | b870ca6 | 2019-01-29 16:33:35 | [diff] [blame] | 548 | int GetRasterDecoderId() const override; |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 549 | int DecoderIdForTest() override; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 550 | ServiceTransferCache* GetTransferCacheForTest() override; |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 551 | void SetUpForRasterCHROMIUMForTest() override; |
Jonathan Backer | c7b8297 | 2018-11-21 19:08:48 | [diff] [blame] | 552 | void SetOOMErrorForTest() override; |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 553 | void DisableFlushWorkaroundForTest() override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 554 | |
| 555 | // ErrorClientState implementation. |
| 556 | void OnContextLostError() override; |
| 557 | void OnOutOfMemoryError() override; |
| 558 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 559 | gles2::Logger* GetLogger() override; |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 560 | |
| 561 | void SetIgnoreCachedStateForTest(bool ignore) override; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 562 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 563 | // ServiceFontManager::Client implementation. |
| 564 | scoped_refptr<Buffer> GetShmBuffer(uint32_t shm_id) override; |
Khushal | 39641b9 | 2019-06-03 21:32:54 | [diff] [blame] | 565 | void ReportProgress() override; |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 566 | |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 567 | // SharedContextState::ContextLostObserver implementation. |
| 568 | void OnContextLost() override; |
| 569 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 570 | private: |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 571 | gles2::ContextState* state() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 572 | if (use_passthrough_) { |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 573 | NOTREACHED(); |
| 574 | return nullptr; |
| 575 | } |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 576 | return shared_context_state_->context_state(); |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 577 | } |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 578 | gl::GLApi* api() const { return api_; } |
Adlai Holler | c4dea1a9 | 2020-08-04 13:21:55 | [diff] [blame] | 579 | GrDirectContext* gr_context() const { |
| 580 | return shared_context_state_->gr_context(); |
| 581 | } |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 582 | skgpu::graphite::Context* graphite_context() const { |
| 583 | return shared_context_state_->graphite_context(); |
| 584 | } |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 585 | skgpu::graphite::Recorder* graphite_recorder() const { |
| 586 | return shared_context_state_->gpu_main_graphite_recorder(); |
| 587 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 588 | ServiceTransferCache* transfer_cache() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 589 | return shared_context_state_->transfer_cache(); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 590 | } |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 591 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 592 | const gles2::FeatureInfo* feature_info() const { |
| 593 | return shared_context_state_->feature_info(); |
| 594 | } |
| 595 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 596 | const gles2::FeatureInfo::FeatureFlags& features() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 597 | return feature_info()->feature_flags(); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 598 | } |
| 599 | |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 600 | const GpuDriverBugWorkarounds& workarounds() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 601 | return feature_info()->workarounds(); |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 602 | } |
| 603 | |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 604 | void FlushToWorkAroundMacCrashes() { |
Scott Violet | 0430768f | 2022-09-29 00:26:58 | [diff] [blame] | 605 | // 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 608 | // The workaround is also not needed for Graphite, which always uses Metal |
| 609 | // drivers (via Dawn). |
| 610 | if (!shared_context_state_->GrContextIsGL()) { |
Christopher Cameron | f787d0b | 2019-05-15 23:52:18 | [diff] [blame] | 611 | return; |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 612 | } |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 613 | // 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 Sagar | 70ac8913 | 2020-04-17 19:48:42 | [diff] [blame] | 617 | TRACE_EVENT0("gpu", "RasterDecoderImpl::FlushToWorkAroundMacCrashes"); |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 618 | if (gr_context()) |
Greg Daniel | a047623 | 2020-05-19 15:13:58 | [diff] [blame] | 619 | gr_context()->flushAndSubmit(); |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 620 | api()->glFlushFn(); |
Khushal | d15c591 | 2019-06-14 17:51:04 | [diff] [blame] | 621 | |
| 622 | // Flushes can be expensive, yield to allow interruption after each flush. |
| 623 | ExitCommandProcessingEarly(); |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 624 | } |
| 625 | #endif |
| 626 | } |
| 627 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 628 | const gl::GLVersionInfo& gl_version_info() { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 629 | return feature_info()->gl_version_info(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 630 | } |
| 631 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 632 | // 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 Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 635 | void ExitCommandProcessingEarly() override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 636 | |
| 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 Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 643 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 644 | void DeleteQueriesEXTHelper(GLsizei n, const volatile GLuint* client_ids); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 645 | void DoFinish(); |
| 646 | void DoFlush(); |
| 647 | void DoGetIntegerv(GLenum pname, GLint* params, GLsizei params_size); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 648 | void DoTraceEndCHROMIUM(); |
Saifuddin Hitawala | 20790cb | 2023-01-31 17:01:12 | [diff] [blame] | 649 | 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 Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 657 | void DoWritePixelsINTERNAL(GLint x_offset, |
| 658 | GLint y_offset, |
Saifuddin Hitawala | 5d26b20 | 2023-04-04 18:41:43 | [diff] [blame] | 659 | GLint plane_index, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 660 | 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 Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 669 | bool DoWritePixelsINTERNALDirectTextureUpload( |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 670 | SkiaImageRepresentation* dest_shared_image, |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 671 | const SkImageInfo& src_info, |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 672 | const int plane_index, |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 673 | const void* pixel_data, |
| 674 | size_t row_bytes); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 675 | void DoReadbackARGBImagePixelsINTERNAL(GLint src_x, |
| 676 | GLint src_y, |
Saifuddin Hitawala | f32b28c | 2023-02-22 23:30:38 | [diff] [blame] | 677 | GLint plane_index, |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 678 | 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 Cameron | a78f1e3c | 2021-08-13 19:13:44 | [diff] [blame] | 699 | |
Brian Salomon | 99bc7fc | 2020-11-20 16:57:31 | [diff] [blame] | 700 | void DoConvertYUVAMailboxesToRGBINTERNAL(GLenum yuv_color_space, |
| 701 | GLenum plane_config, |
| 702 | GLenum subsampling, |
| 703 | const volatile GLbyte* mailboxes); |
Christopher Cameron | 1c9f532 | 2021-08-14 08:21:36 | [diff] [blame] | 704 | void DoConvertRGBAToYUVAMailboxesINTERNAL(GLenum yuv_color_space, |
| 705 | GLenum plane_config, |
| 706 | GLenum subsampling, |
| 707 | const volatile GLbyte* mailboxes); |
Nathan Zabriskie | 366b893 | 2020-04-28 01:07:13 | [diff] [blame] | 708 | |
Jonah Chin | 053aa6c | 2021-01-22 20:26:14 | [diff] [blame] | 709 | void DoLoseContextCHROMIUM(GLenum current, GLenum other); |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 710 | void DoBeginRasterCHROMIUM(GLfloat r, |
| 711 | GLfloat g, |
| 712 | GLfloat b, |
| 713 | GLfloat a, |
Sunny Sachanandani | b461e21 | 2021-03-05 19:22:12 | [diff] [blame] | 714 | GLboolean needs_clear, |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 715 | GLuint msaa_sample_count, |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 716 | MsaaMode msaa_mode, |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 717 | GLboolean can_use_lcd_text, |
Peng Huang | 5ff70dff | 2022-03-03 19:55:11 | [diff] [blame] | 718 | GLboolean visible, |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 719 | const volatile GLbyte* key); |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 720 | void DoRasterCHROMIUM(GLuint raster_shm_id, |
| 721 | GLuint raster_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 722 | GLuint raster_shm_size, |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 723 | GLuint font_shm_id, |
| 724 | GLuint font_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 725 | GLuint font_shm_size); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 726 | void DoEndRasterCHROMIUM(); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 727 | 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 Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 733 | GLuint data_size); |
| 734 | void DoUnlockTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id); |
| 735 | void DoDeleteTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 736 | void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 737 | void DeletePaintCachePathsINTERNALHelper( |
| 738 | GLsizei n, |
| 739 | const volatile GLuint* paint_cache_ids); |
| 740 | void DoClearPaintCacheINTERNAL(); |
Vikas Soni | ca02287b | 2022-01-18 20:17:35 | [diff] [blame] | 741 | |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 742 | 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 Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 760 | void FlushSurface(SkiaImageRepresentation::ScopedWriteAccess* access) { |
Scott Violet | 86dc643d | 2023-04-07 17:57:24 | [diff] [blame] | 761 | static int flush_count = 0; |
| 762 | const base::TimeTicks start = base::TimeTicks::Now(); |
Saifuddin Hitawala | 796463f | 2022-12-02 16:34:10 | [diff] [blame] | 763 | int num_planes = access->representation()->format().NumberOfPlanes(); |
Saifuddin Hitawala | 796463f | 2022-12-02 16:34:10 | [diff] [blame] | 764 | for (int plane_index = 0; plane_index < num_planes; plane_index++) { |
| 765 | auto* surface = access->surface(plane_index); |
| 766 | DCHECK(surface); |
Saifuddin Hitawala | e3ef7ae | 2023-04-20 14:22:25 | [diff] [blame] | 767 | surface->flush(); |
Saifuddin Hitawala | 796463f | 2022-12-02 16:34:10 | [diff] [blame] | 768 | } |
Saifuddin Hitawala | e3ef7ae | 2023-04-20 14:22:25 | [diff] [blame] | 769 | access->ApplyBackendSurfaceEndState(); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 770 | |
| 771 | if (graphite_context()) { |
| 772 | GraphiteFlushAndSubmit(); |
| 773 | } |
| 774 | |
Scott Violet | 86dc643d | 2023-04-07 17:57:24 | [diff] [blame] | 775 | 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 Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | void SubmitIfNecessary(std::vector<GrBackendSemaphore> signal_semaphores) { |
Vikas Soni | 79b0871 | 2022-08-25 16:42:30 | [diff] [blame] | 784 | // 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 789 | // NOTE: The Graphite SharedImage representation does not set semaphores, |
| 790 | // and we are not enabling DrDC with Graphite. |
| 791 | CHECK(gr_context()); |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 792 | 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 Huang | 95a63e4b | 2020-07-03 21:28:11 | [diff] [blame] | 801 | } |
| 802 | |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 803 | bool sync_cpu = gpu::ShouldVulkanSyncCpuForSkiaSubmit( |
| 804 | shared_context_state_->vk_context_provider()); |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 805 | |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 806 | // 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 816 | 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 Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 821 | gr_context()->submit(sync_cpu); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 822 | } |
Peng Huang | 95a63e4b | 2020-07-03 21:28:11 | [diff] [blame] | 823 | } |
| 824 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 825 | #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 Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 837 | if (gpu_preferences_.enable_gpu_service_logging_gpu) { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 838 | 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 853 | // 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 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 876 | const int raster_decoder_id_; |
Bo Liu | 335323d | 2021-07-14 21:45:18 | [diff] [blame] | 877 | const bool disable_legacy_mailbox_; |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 878 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 879 | // Number of commands remaining to be processed in DoCommands(). |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 880 | int commands_to_process_ = 0; |
| 881 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 882 | bool gpu_raster_enabled_ = false; |
| 883 | bool use_gpu_raster_ = false; |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 884 | bool use_passthrough_ = false; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 885 | |
| 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 Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 889 | error::Error current_decoder_error_ = error::kNoError; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 890 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 891 | GpuPreferences gpu_preferences_; |
| 892 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 893 | gles2::DebugMarkerManager debug_marker_manager_; |
| 894 | gles2::Logger logger_; |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 895 | std::unique_ptr<gles2::ErrorState> error_state_; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 896 | bool context_lost_ = false; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 897 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 898 | scoped_refptr<SharedContextState> shared_context_state_; |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 899 | std::unique_ptr<Validators> validators_; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 900 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 901 | SharedImageRepresentationFactory shared_image_representation_factory_; |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 902 | std::unique_ptr<RasterQueryManager> query_manager_; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 903 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 904 | gles2::GLES2Util util_; |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 905 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 906 | // An optional behaviour to lose the context when OOM. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 907 | bool lose_context_when_out_of_memory_ = false; |
| 908 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 909 | std::unique_ptr<gles2::GPUTracer> gpu_tracer_; |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 910 | 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 Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 915 | // Raster helpers. |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 916 | scoped_refptr<ServiceFontManager> font_manager_; |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 917 | std::unique_ptr<SkiaImageRepresentation> shared_image_; |
| 918 | std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess> |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 919 | scoped_shared_image_write_; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 920 | |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 921 | std::unique_ptr<RasterImageRepresentation> shared_image_raster_; |
| 922 | std::unique_ptr<RasterImageRepresentation::ScopedWriteAccess> |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 923 | scoped_shared_image_raster_write_; |
| 924 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 925 | raw_ptr<SkSurface> sk_surface_ = nullptr; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 926 | std::unique_ptr<SharedImageProviderImpl> paint_op_shared_image_provider_; |
Khushal Sagar | 4bb1c12 | 2020-05-12 20:17:08 | [diff] [blame] | 927 | |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 928 | sk_sp<SkSurface> sk_surface_for_testing_; |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 929 | std::vector<GrBackendSemaphore> end_semaphores_; |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 930 | std::unique_ptr<cc::ServicePaintCache> paint_cache_; |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 931 | |
Peng Huang | 23b9be7b | 2022-02-19 01:05:41 | [diff] [blame] | 932 | raw_ptr<SkCanvas> raster_canvas_ = nullptr; |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 933 | std::vector<SkDiscardableHandleId> locked_handles_; |
Jonathan Backer | 4fb9f5acb | 2018-05-10 22:19:33 | [diff] [blame] | 934 | |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 935 | // Tracing helpers. |
| 936 | int raster_chromium_id_ = 0; |
| 937 | |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 938 | // Workaround for https://crbug.com/906453 |
| 939 | bool flush_workaround_disabled_for_test_ = false; |
| 940 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 941 | bool in_copy_sub_texture_ = false; |
| 942 | bool reset_texture_state_ = false; |
| 943 | |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 944 | bool is_privileged_ = false; |
| 945 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 946 | const bool is_raw_draw_enabled_; |
| 947 | |
Vikas Soni | ca02287b | 2022-01-18 20:17:35 | [diff] [blame] | 948 | const bool is_drdc_enabled_; |
| 949 | |
Pรขris | b3b3aba2 | 2022-10-10 08:15:20 | [diff] [blame] | 950 | raw_ptr<gl::GLApi, DanglingUntriaged> api_ = nullptr; |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 951 | |
Jeremy Roman | 28926e9 | 2019-07-15 15:42:16 | [diff] [blame] | 952 | base::WeakPtrFactory<DecoderContext> weak_ptr_factory_{this}; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 953 | }; |
| 954 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 955 | constexpr RasterDecoderImpl::CommandInfo RasterDecoderImpl::command_info[] = { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 956 | #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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 962 | }, /* NOLINT */ |
| 963 | RASTER_COMMAND_LIST(RASTER_CMD_OP) |
| 964 | #undef RASTER_CMD_OP |
| 965 | }; |
| 966 | |
| 967 | // static |
| 968 | RasterDecoder* RasterDecoder::Create( |
| 969 | DecoderClient* client, |
| 970 | CommandBufferServiceBase* command_buffer_service, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 971 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 972 | const GpuFeatureInfo& gpu_feature_info, |
| 973 | const GpuPreferences& gpu_preferences, |
| 974 | MemoryTracker* memory_tracker, |
| 975 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 976 | scoped_refptr<SharedContextState> shared_context_state, |
| 977 | bool is_privileged) { |
Vasiliy Telezhnikov | e05f074 | 2022-12-05 20:48:38 | [diff] [blame] | 978 | 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 982 | } |
| 983 | |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 984 | RasterDecoder::RasterDecoder(DecoderClient* client, |
| 985 | CommandBufferServiceBase* command_buffer_service, |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 986 | gles2::Outputter* outputter) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 987 | : CommonDecoder(client, command_buffer_service), outputter_(outputter) {} |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 988 | |
| 989 | RasterDecoder::~RasterDecoder() {} |
| 990 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 991 | bool RasterDecoder::initialized() const { |
| 992 | return initialized_; |
| 993 | } |
| 994 | |
| 995 | TextureBase* RasterDecoder::GetTextureBase(uint32_t client_id) { |
| 996 | return nullptr; |
| 997 | } |
| 998 | |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 999 | void 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 Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1009 | void RasterDecoder::BeginDecoding() {} |
| 1010 | |
| 1011 | void RasterDecoder::EndDecoding() {} |
| 1012 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1013 | void RasterDecoder::SetLogCommands(bool log_commands) { |
| 1014 | log_commands_ = log_commands; |
| 1015 | } |
| 1016 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1017 | gles2::Outputter* RasterDecoder::outputter() const { |
| 1018 | return outputter_; |
| 1019 | } |
| 1020 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1021 | base::StringPiece RasterDecoder::GetLogPrefix() { |
| 1022 | return GetLogger()->GetLogPrefix(); |
| 1023 | } |
| 1024 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1025 | RasterDecoderImpl::RasterDecoderImpl( |
| 1026 | DecoderClient* client, |
| 1027 | CommandBufferServiceBase* command_buffer_service, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1028 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1029 | const GpuFeatureInfo& gpu_feature_info, |
| 1030 | const GpuPreferences& gpu_preferences, |
| 1031 | MemoryTracker* memory_tracker, |
| 1032 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 1033 | scoped_refptr<SharedContextState> shared_context_state, |
| 1034 | bool is_privileged) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1035 | : RasterDecoder(client, command_buffer_service, outputter), |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 1036 | raster_decoder_id_(g_raster_decoder_id.GetNext() + 1), |
Bo Liu | 335323d | 2021-07-14 21:45:18 | [diff] [blame] | 1037 | disable_legacy_mailbox_( |
| 1038 | shared_image_manager && |
| 1039 | shared_image_manager->display_context_on_another_thread()), |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1040 | gpu_raster_enabled_( |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1041 | 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 Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1045 | gpu_preferences_(gpu_preferences), |
Peng Huang | 61eccfe4 | 2018-11-15 22:10:13 | [diff] [blame] | 1046 | logger_(&debug_marker_manager_, |
| 1047 | base::BindRepeating(&DecoderClient::OnConsoleMessage, |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1048 | base::Unretained(client), |
James Darpinian | 104af6f | 2018-12-06 03:24:55 | [diff] [blame] | 1049 | 0), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1050 | gpu_preferences_.disable_gl_error_limit), |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 1051 | error_state_(gles2::ErrorState::Create(this, &logger_)), |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1052 | shared_context_state_(std::move(shared_context_state)), |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 1053 | validators_(new Validators), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1054 | shared_image_representation_factory_(shared_image_manager, |
| 1055 | memory_tracker), |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1056 | gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
Miguel Casas | 510fbfcb | 2018-11-13 23:40:57 | [diff] [blame] | 1057 | TRACE_DISABLED_BY_DEFAULT("gpu.decoder"))), |
Vikas Soni | 2a4039f | 2020-07-22 18:34:20 | [diff] [blame] | 1058 | font_manager_(base::MakeRefCounted<ServiceFontManager>( |
| 1059 | this, |
| 1060 | gpu_preferences_.disable_oopr_debug_crash_dump)), |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 1061 | is_privileged_(is_privileged), |
Vikas Soni | ca02287b | 2022-01-18 20:17:35 | [diff] [blame] | 1062 | is_raw_draw_enabled_(features::IsUsingRawDraw()), |
Vikas Soni | bcb7f9b | 2022-08-25 16:03:17 | [diff] [blame] | 1063 | is_drdc_enabled_(features::IsDrDcEnabled() && |
| 1064 | !feature_info()->workarounds().disable_drdc) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1065 | DCHECK(shared_context_state_); |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1066 | shared_context_state_->AddContextLostObserver(this); |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 1067 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1068 | |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1069 | RasterDecoderImpl::~RasterDecoderImpl() { |
| 1070 | shared_context_state_->RemoveContextLostObserver(this); |
| 1071 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1072 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1073 | base::WeakPtr<DecoderContext> RasterDecoderImpl::AsWeakPtr() { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1074 | return weak_ptr_factory_.GetWeakPtr(); |
| 1075 | } |
| 1076 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1077 | ContextResult RasterDecoderImpl::Initialize( |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1078 | const scoped_refptr<gl::GLSurface>& surface, |
| 1079 | const scoped_refptr<gl::GLContext>& context, |
| 1080 | bool offscreen, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1081 | const gles2::DisallowedFeatures& disallowed_features, |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 1082 | const ContextCreationAttribs& attrib_helper) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1083 | TRACE_EVENT0("gpu", "RasterDecoderImpl::Initialize"); |
Jonathan Backer | 19258679 | 2019-12-18 16:36:33 | [diff] [blame] | 1084 | DCHECK(shared_context_state_->IsCurrent(nullptr)); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1085 | |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 1086 | api_ = gl::g_current_gl_context; |
| 1087 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1088 | set_initialized(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1089 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1090 | if (!offscreen) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1091 | return ContextResult::kFatalFailure; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1092 | } |
| 1093 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1094 | if (gpu_preferences_.enable_gpu_debugging) |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1095 | set_debug(true); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1096 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1097 | if (gpu_preferences_.enable_gpu_command_logging) |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1098 | SetLogCommands(true); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1099 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1100 | DCHECK_EQ(surface.get(), shared_context_state_->surface()); |
| 1101 | DCHECK_EQ(context.get(), shared_context_state_->context()); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1102 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1103 | // Create GPU Tracer for timing values. |
Peter Bostrรถm | 1aa21c14 | 2021-04-03 01:12:03 | [diff] [blame] | 1104 | gpu_tracer_ = std::make_unique<gles2::GPUTracer>( |
| 1105 | this, shared_context_state_->GrContextIsGL()); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1106 | |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1107 | // Save the loseContextWhenOutOfMemory context creation attribute. |
| 1108 | lose_context_when_out_of_memory_ = |
| 1109 | attrib_helper.lose_context_when_out_of_memory; |
| 1110 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1111 | CHECK_GL_ERROR(); |
| 1112 | |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 1113 | query_manager_ = std::make_unique<RasterQueryManager>(shared_context_state_); |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1114 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1115 | if (attrib_helper.enable_oop_rasterization) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1116 | if (!gpu_raster_enabled_) { |
| 1117 | LOG(ERROR) << "ContextResult::kFatalFailure: GPU raster is disabled"; |
Jonathan Backer | 15dbca3 | 2018-06-04 20:39:33 | [diff] [blame] | 1118 | Destroy(true); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1119 | return ContextResult::kFatalFailure; |
| 1120 | } |
| 1121 | |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1122 | DCHECK(gr_context() || graphite_context()); |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1123 | use_gpu_raster_ = true; |
| 1124 | paint_cache_ = std::make_unique<cc::ServicePaintCache>(); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 1125 | } |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1126 | |
| 1127 | return ContextResult::kSuccess; |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1128 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1129 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1130 | void RasterDecoderImpl::Destroy(bool have_context) { |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1131 | if (!initialized()) |
| 1132 | return; |
| 1133 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1134 | DCHECK(!have_context || shared_context_state_->context()->IsCurrent(nullptr)); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1135 | |
Vasiliy Telezhnikov | 91d1881 | 2023-02-02 21:21:26 | [diff] [blame] | 1136 | // 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 Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1144 | if (have_context) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1145 | if (use_gpu_raster_) { |
Andres Calderon Jaramillo | 56d9f1ea | 2019-05-24 19:57:34 | [diff] [blame] | 1146 | transfer_cache()->DeleteAllEntriesForDecoder(raster_decoder_id_); |
| 1147 | } |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1148 | } |
| 1149 | |
Peng Huang | 95a63e4b | 2020-07-03 21:28:11 | [diff] [blame] | 1150 | if (query_manager_) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1151 | query_manager_->Destroy(have_context); |
| 1152 | query_manager_.reset(); |
| 1153 | } |
| 1154 | |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 1155 | font_manager_->Destroy(); |
| 1156 | font_manager_.reset(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1157 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1158 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1159 | // Make this decoder's GL context current. |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1160 | bool RasterDecoderImpl::MakeCurrent() { |
Christopher Cameron | dd7812d | 2019-04-23 03:12:21 | [diff] [blame] | 1161 | if (!shared_context_state_->GrContextIsGL()) |
Jonathan Backer | 7621ec9 | 2018-12-11 00:02:44 | [diff] [blame] | 1162 | return true; |
| 1163 | |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1164 | if (context_lost_) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1165 | LOG(ERROR) << " RasterDecoderImpl: Trying to make lost context current."; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1166 | return false; |
| 1167 | } |
| 1168 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1169 | if (shared_context_state_->context_lost() || |
| 1170 | !shared_context_state_->MakeCurrent(nullptr)) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1171 | LOG(ERROR) << " RasterDecoderImpl: Context lost during MakeCurrent."; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1172 | return false; |
| 1173 | } |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1174 | |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1175 | DCHECK_EQ(api(), gl::g_current_gl_context); |
| 1176 | |
| 1177 | // Rebind textures if the service ids may have changed. |
| 1178 | RestoreAllExternalTextureBindingsIfNeeded(); |
| 1179 | |
Vasiliy Telezhnikov | 751b536 | 2021-09-14 13:35:49 | [diff] [blame] | 1180 | // 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 Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1183 | return true; |
| 1184 | } |
| 1185 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1186 | gl::GLContext* RasterDecoderImpl::GetGLContext() { |
Peng Huang | ad7442f | 2020-02-24 22:22:09 | [diff] [blame] | 1187 | return shared_context_state_->GrContextIsGL() |
| 1188 | ? shared_context_state_->context() |
| 1189 | : nullptr; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1190 | } |
| 1191 | |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 1192 | gl::GLSurface* RasterDecoderImpl::GetGLSurface() { |
Peng Huang | ad7442f | 2020-02-24 22:22:09 | [diff] [blame] | 1193 | return shared_context_state_->GrContextIsGL() |
| 1194 | ? shared_context_state_->surface() |
| 1195 | : nullptr; |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 1196 | } |
| 1197 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1198 | Capabilities RasterDecoderImpl::GetCapabilities() { |
Adrienne Walker | 693f34d | 2019-07-29 22:07:04 | [diff] [blame] | 1199 | // TODO(enne): reconcile this with gles2_cmd_decoder's capability settings. |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1200 | Capabilities caps; |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1201 | caps.gpu_rasterization = use_gpu_raster_; |
| 1202 | caps.supports_oop_raster = use_gpu_raster_; |
Antoine Labour | 0f9bee7 | 2018-11-06 07:35:43 | [diff] [blame] | 1203 | caps.gpu_memory_buffer_formats = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1204 | feature_info()->feature_flags().gpu_memory_buffer_formats; |
Victor Miura | cabdfac | 2018-01-05 02:18:18 | [diff] [blame] | 1205 | caps.texture_target_exception_list = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1206 | gpu_preferences_.texture_target_exception_list; |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 1207 | caps.texture_format_bgra8888 = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1208 | feature_info()->feature_flags().ext_texture_format_bgra8888; |
kylechar | 81ac76d | 2023-02-14 21:43:49 | [diff] [blame] | 1209 | caps.texture_rg = feature_info()->feature_flags().ext_texture_rg; |
Vasiliy Telezhnikov | e05f074 | 2022-12-05 20:48:38 | [diff] [blame] | 1210 | caps.supports_scanout_shared_images = |
| 1211 | SharedImageManager::SupportsScanoutImages(); |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 1212 | // TODO(piman): have a consistent limit in shared image backings. |
| 1213 | // https://crbug.com/960588 |
Sunny Sachanandani | 94760ca | 2023-03-30 00:40:56 | [diff] [blame] | 1214 | if (shared_context_state_->GrContextIsGL()) { |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 1215 | 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 Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 1225 | } else { |
kylechar | 468165b3 | 2020-06-02 22:08:58 | [diff] [blame] | 1226 | // TODO(crbug.com/1090476): Query Dawn for this value once an API exists for |
| 1227 | // capabilities. |
| 1228 | caps.max_texture_size = 8192; |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 1229 | } |
Bo Liu | 1e4cf91 | 2022-06-27 16:38:54 | [diff] [blame] | 1230 | if (feature_info()->workarounds().webgl_or_caps_max_texture_size) { |
Bo Liu | f2f4c6d | 2022-04-28 20:34:45 | [diff] [blame] | 1231 | caps.max_texture_size = |
| 1232 | std::min(caps.max_texture_size, |
Bo Liu | 1e4cf91 | 2022-06-27 16:38:54 | [diff] [blame] | 1233 | feature_info()->workarounds().webgl_or_caps_max_texture_size); |
James Darpinian | 3c42203 | 2019-04-06 00:20:16 | [diff] [blame] | 1234 | caps.max_cube_map_texture_size = |
| 1235 | std::min(caps.max_cube_map_texture_size, |
Bo Liu | 1e4cf91 | 2022-06-27 16:38:54 | [diff] [blame] | 1236 | feature_info()->workarounds().webgl_or_caps_max_texture_size); |
James Darpinian | 3c42203 | 2019-04-06 00:20:16 | [diff] [blame] | 1237 | } |
| 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 Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1245 | } |
| 1246 | caps.sync_query = feature_info()->feature_flags().chromium_sync_query; |
Justin Novosad | 4486ec3 | 2022-07-07 17:45:08 | [diff] [blame] | 1247 | 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 Walker | 693f34d | 2019-07-29 22:07:04 | [diff] [blame] | 1251 | caps.avoid_stencil_buffers = |
| 1252 | feature_info()->workarounds().avoid_stencil_buffers; |
Khushal | 315f2fd | 2018-05-29 03:20:39 | [diff] [blame] | 1253 | |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 1254 | if (gr_context()) { |
Khushal | 315f2fd | 2018-05-29 03:20:39 | [diff] [blame] | 1255 | caps.context_supports_distance_field_text = |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 1256 | gr_context()->supportsDistanceFieldText(); |
Dale Curtis | 816d523 | 2020-07-29 19:31:35 | [diff] [blame] | 1257 | caps.texture_norm16 = |
| 1258 | gr_context()->colorTypeSupportedAsImage(kA16_unorm_SkColorType); |
| 1259 | caps.texture_half_float_linear = |
| 1260 | gr_context()->colorTypeSupportedAsImage(kA16_float_SkColorType); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1261 | } 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 Curtis | 816d523 | 2020-07-29 19:31:35 | [diff] [blame] | 1265 | } 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; |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 1269 | } |
Xiaohan Wang | fa22d3e | 2022-01-15 02:02:43 | [diff] [blame] | 1270 | #if BUILDFLAG(IS_WIN) |
Le Hoang Quyen | f6784d0 | 2022-08-05 21:13:24 | [diff] [blame] | 1271 | caps.shared_image_d3d = |
| 1272 | D3DImageBackingFactory::IsD3DSharedImageSupported(gpu_preferences_); |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 1273 | caps.shared_image_swap_chain = D3DImageBackingFactory::IsSwapChainSupported(); |
Xiaohan Wang | fa22d3e | 2022-01-15 02:02:43 | [diff] [blame] | 1274 | #endif // BUILDFLAG(IS_WIN) |
Bo Liu | 335323d | 2021-07-14 21:45:18 | [diff] [blame] | 1275 | caps.disable_legacy_mailbox = disable_legacy_mailbox_; |
Saifuddin Hitawala | 443437a | 2023-01-25 18:12:14 | [diff] [blame] | 1276 | caps.supports_yuv_rgb_conversion = true; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1277 | return caps; |
| 1278 | } |
| 1279 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 1280 | const gles2::ContextState* RasterDecoderImpl::GetContextState() { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1281 | NOTREACHED(); |
| 1282 | return nullptr; |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 1283 | } |
| 1284 | |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1285 | void RasterDecoderImpl::RestoreGlobalState() const { |
Peng Huang | d7aaf78 | 2019-01-09 22:03:08 | [diff] [blame] | 1286 | // 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 Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1288 | shared_context_state_->set_need_context_state_reset(true); |
| 1289 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1290 | } |
| 1291 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 1292 | void RasterDecoderImpl::ClearAllAttributes() const {} |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1293 | |
| 1294 | void RasterDecoderImpl::RestoreAllAttributes() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1295 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1296 | } |
| 1297 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1298 | void RasterDecoderImpl::RestoreState(const gles2::ContextState* prev_state) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1299 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1300 | } |
| 1301 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1302 | void RasterDecoderImpl::RestoreActiveTexture() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1303 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1304 | } |
| 1305 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1306 | void RasterDecoderImpl::RestoreAllTextureUnitAndSamplerBindings( |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1307 | const gles2::ContextState* prev_state) const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1308 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1309 | } |
| 1310 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1311 | void RasterDecoderImpl::RestoreActiveTextureUnitBinding( |
| 1312 | unsigned int target) const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1313 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1314 | } |
| 1315 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1316 | void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1317 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1318 | } |
| 1319 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1320 | void RasterDecoderImpl::RestoreBufferBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1321 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1322 | } |
| 1323 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1324 | void RasterDecoderImpl::RestoreFramebufferBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1325 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1326 | } |
| 1327 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1328 | void RasterDecoderImpl::RestoreRenderbufferBindings() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1329 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1330 | } |
| 1331 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1332 | void RasterDecoderImpl::RestoreProgramBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1333 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1334 | } |
| 1335 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1336 | void RasterDecoderImpl::RestoreTextureState(unsigned service_id) { |
| 1337 | DCHECK(in_copy_sub_texture_); |
| 1338 | reset_texture_state_ = true; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1339 | } |
| 1340 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1341 | void RasterDecoderImpl::RestoreTextureUnitBindings(unsigned unit) const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1342 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1343 | } |
| 1344 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1345 | void RasterDecoderImpl::RestoreVertexAttribArray(unsigned index) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1346 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1347 | } |
| 1348 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1349 | void RasterDecoderImpl::RestoreAllExternalTextureBindingsIfNeeded() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1350 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1351 | } |
| 1352 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1353 | QueryManager* RasterDecoderImpl::GetQueryManager() { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1354 | return query_manager_.get(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1355 | } |
| 1356 | |
Geoff Lang | 85287e1 | 2018-05-22 17:26:40 | [diff] [blame] | 1357 | void 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 Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1369 | gles2::GpuFenceManager* RasterDecoderImpl::GetGpuFenceManager() { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1370 | NOTIMPLEMENTED(); |
| 1371 | return nullptr; |
| 1372 | } |
| 1373 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1374 | bool RasterDecoderImpl::HasPendingQueries() const { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1375 | return query_manager_ && query_manager_->HavePendingQueries(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1376 | } |
| 1377 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1378 | void RasterDecoderImpl::ProcessPendingQueries(bool did_finish) { |
Vasiliy Telezhnikov | 517dd8c | 2022-05-17 15:39:47 | [diff] [blame] | 1379 | if (query_manager_) { |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1380 | if (gr_context()) { |
| 1381 | gr_context()->checkAsyncWorkCompletion(); |
| 1382 | } else if (graphite_context()) { |
| 1383 | graphite_context()->checkAsyncWorkCompletion(); |
| 1384 | } |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1385 | query_manager_->ProcessPendingQueries(did_finish); |
Vasiliy Telezhnikov | 517dd8c | 2022-05-17 15:39:47 | [diff] [blame] | 1386 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1387 | } |
| 1388 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1389 | bool RasterDecoderImpl::HasMoreIdleWork() const { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1390 | return gpu_tracer_->HasTracesToProcess(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1391 | } |
| 1392 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1393 | void RasterDecoderImpl::PerformIdleWork() { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1394 | gpu_tracer_->ProcessTraces(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1395 | } |
| 1396 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1397 | bool RasterDecoderImpl::HasPollingWork() const { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1398 | return false; |
| 1399 | } |
| 1400 | |
Jonathan Backer | c2b0efa | 2018-03-21 16:58:35 | [diff] [blame] | 1401 | void RasterDecoderImpl::PerformPollingWork() {} |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1402 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1403 | TextureBase* RasterDecoderImpl::GetTextureBase(uint32_t client_id) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1404 | NOTIMPLEMENTED(); |
| 1405 | return nullptr; |
| 1406 | } |
| 1407 | |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 1408 | void 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1420 | bool RasterDecoderImpl::WasContextLost() const { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1421 | return shared_context_state_->context_lost(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1422 | } |
| 1423 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1424 | bool RasterDecoderImpl::WasContextLostByRobustnessExtension() const { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1425 | return shared_context_state_->device_needs_reset(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1426 | } |
| 1427 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1428 | void RasterDecoderImpl::MarkContextLost(error::ContextLostReason reason) { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1429 | shared_context_state_->MarkContextLost(reason); |
| 1430 | } |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1431 | |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1432 | void RasterDecoderImpl::OnContextLost() { |
| 1433 | DCHECK(shared_context_state_->context_lost()); |
| 1434 | command_buffer_service()->SetContextLostReason( |
| 1435 | *shared_context_state_->context_lost_reason()); |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1436 | current_decoder_error_ = error::kLostContext; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1437 | } |
| 1438 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1439 | bool RasterDecoderImpl::CheckResetStatus() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1440 | DCHECK(!WasContextLost()); |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1441 | return shared_context_state_->CheckResetStatus(/*needs_gl=*/false); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1442 | } |
| 1443 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1444 | gles2::Logger* RasterDecoderImpl::GetLogger() { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1445 | return &logger_; |
| 1446 | } |
| 1447 | |
| 1448 | void RasterDecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1449 | if (use_passthrough_) |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 1450 | return; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1451 | state()->SetIgnoreCachedStateForTest(ignore); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1452 | } |
| 1453 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1454 | void RasterDecoderImpl::BeginDecoding() { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1455 | gpu_tracer_->BeginDecoding(); |
| 1456 | gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_; |
| 1457 | gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_; |
Khushal | cd8fbb77 | 2018-10-16 22:46:14 | [diff] [blame] | 1458 | query_manager_->BeginProcessingCommands(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1459 | } |
| 1460 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1461 | void RasterDecoderImpl::EndDecoding() { |
| 1462 | gpu_tracer_->EndDecoding(); |
Khushal | cd8fbb77 | 2018-10-16 22:46:14 | [diff] [blame] | 1463 | query_manager_->EndProcessingCommands(); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1464 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1465 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1466 | const char* RasterDecoderImpl::GetCommandName(unsigned int command_id) const { |
| 1467 | if (command_id >= kFirstRasterCommand && command_id < kNumCommands) { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1468 | return raster::GetCommandName(static_cast<CommandId>(command_id)); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1469 | } |
| 1470 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 1471 | } |
| 1472 | |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1473 | template <bool DebugImpl> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1474 | error::Error RasterDecoderImpl::DoCommandsImpl(unsigned int num_commands, |
| 1475 | const volatile void* buffer, |
| 1476 | int num_entries, |
| 1477 | int* entries_processed) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1478 | 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 Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1484 | CommandId command = static_cast<CommandId>(0); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1485 | |
| 1486 | while (process_pos < num_entries && result == error::kNoError && |
| 1487 | commands_to_process_--) { |
| 1488 | const unsigned int size = cmd_data->value_header.size; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1489 | command = static_cast<CommandId>(cmd_data->value_header.command); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1490 | |
| 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 Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1501 | if (DebugImpl && log_commands()) { |
| 1502 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" |
| 1503 | << "cmd: " << GetCommandName(command); |
| 1504 | } |
| 1505 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1506 | const unsigned int arg_count = size - 1; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1507 | unsigned int command_index = command - kFirstRasterCommand; |
Daniel Cheng | adafb3a | 2022-02-28 07:38:22 | [diff] [blame] | 1508 | if (command_index < std::size(command_info)) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1509 | const CommandInfo& info = command_info[command_index]; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1510 | 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 Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1521 | 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 Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1524 | 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 Casas | 510fbfcb | 2018-11-13 23:40:57 | [diff] [blame] | 1528 | gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu.decoder"), |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1529 | GetCommandName(command), gles2::kTraceDecoder); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1533 | uint32_t immediate_data_size = (arg_count - info_arg_count) * |
| 1534 | sizeof(CommandBufferEntry); // NOLINT |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1535 | result = (this->*info.cmd_handler)(immediate_data_size, cmd_data); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1536 | |
| 1537 | if (DebugImpl && doing_gpu_trace) |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1538 | gpu_tracer_->End(gles2::kTraceDecoder); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1539 | |
Kramer Ge | e6c7469 | 2020-02-07 21:07:31 | [diff] [blame] | 1540 | if (DebugImpl && shared_context_state_->GrContextIsGL() && debug() && |
| 1541 | !WasContextLost()) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1542 | GLenum error; |
| 1543 | while ((error = api()->glGetErrorFn()) != GL_NO_ERROR) { |
| 1544 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1545 | << "GL ERROR: " << gles2::GLES2Util::GetStringEnum(error) |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1546 | << " : " << GetCommandName(command); |
| 1547 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1548 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1549 | } |
| 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 Cameron | 02e3149a | 2019-01-25 19:52:23 | [diff] [blame] | 1567 | |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 1568 | // 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 Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | *entries_processed = process_pos; |
| 1575 | |
| 1576 | if (error::IsError(result)) { |
| 1577 | LOG(ERROR) << "Error: " << result << " for Command " |
| 1578 | << GetCommandName(command); |
| 1579 | } |
| 1580 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1581 | if (use_gpu_raster_) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1582 | client()->ScheduleGrContextCleanup(); |
Khushal | 7324ec4 | 2018-07-10 20:01:45 | [diff] [blame] | 1583 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1584 | return result; |
| 1585 | } |
| 1586 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1587 | error::Error RasterDecoderImpl::DoCommands(unsigned int num_commands, |
| 1588 | const volatile void* buffer, |
| 1589 | int num_entries, |
| 1590 | int* entries_processed) { |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1591 | 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 Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1598 | } |
| 1599 | |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1600 | void RasterDecoderImpl::ExitCommandProcessingEarly() { |
| 1601 | commands_to_process_ = 0; |
| 1602 | } |
| 1603 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1604 | base::StringPiece RasterDecoderImpl::GetLogPrefix() { |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1605 | return logger_.GetLogPrefix(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1606 | } |
| 1607 | |
Dave Tapuska | c03874f | 2023-02-01 21:53:55 | [diff] [blame] | 1608 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) |
Colin Blundell | ddd83e0 | 2022-11-30 13:40:16 | [diff] [blame] | 1609 | void RasterDecoderImpl::AttachImageToTextureWithDecoderBinding( |
| 1610 | uint32_t client_texture_id, |
| 1611 | uint32_t texture_target, |
| 1612 | gl::GLImage* image) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1613 | NOTIMPLEMENTED(); |
| 1614 | } |
Colin Blundell | e2c394e | 2022-12-16 09:26:59 | [diff] [blame] | 1615 | #elif !BUILDFLAG(IS_ANDROID) |
Colin Blundell | ddd83e0 | 2022-11-30 13:40:16 | [diff] [blame] | 1616 | void RasterDecoderImpl::AttachImageToTextureWithClientBinding( |
| 1617 | uint32_t client_texture_id, |
| 1618 | uint32_t texture_target, |
| 1619 | gl::GLImage* image) { |
| 1620 | NOTIMPLEMENTED(); |
| 1621 | } |
| 1622 | #endif |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1623 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1624 | gles2::ContextGroup* RasterDecoderImpl::GetContextGroup() { |
Antoine Labour | 914f3af | 2019-02-14 20:24:13 | [diff] [blame] | 1625 | return nullptr; |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1626 | } |
| 1627 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1628 | gles2::ErrorState* RasterDecoderImpl::GetErrorState() { |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 1629 | return error_state_.get(); |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1630 | } |
| 1631 | |
Colin Blundell | 9d4fea6 | 2022-12-14 15:26:16 | [diff] [blame] | 1632 | #if !BUILDFLAG(IS_ANDROID) |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1633 | std::unique_ptr<gles2::AbstractTexture> |
| 1634 | RasterDecoderImpl::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.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 1642 | return nullptr; |
| 1643 | } |
Colin Blundell | 9d4fea6 | 2022-12-14 15:26:16 | [diff] [blame] | 1644 | #endif |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 1645 | |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1646 | bool RasterDecoderImpl::IsCompressedTextureFormat(unsigned format) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1647 | return feature_info()->validators()->compressed_texture_format.IsValid( |
| 1648 | format); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | bool 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 Telezhnikov | 1b818d6 | 2022-08-24 17:19:42 | [diff] [blame] | 1660 | NOTREACHED(); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1661 | return true; |
| 1662 | } |
| 1663 | |
| 1664 | bool RasterDecoderImpl::ClearCompressedTextureLevel(gles2::Texture* texture, |
| 1665 | unsigned target, |
| 1666 | int level, |
| 1667 | unsigned format, |
| 1668 | int width, |
| 1669 | int height) { |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 1670 | NOTREACHED(); |
| 1671 | return false; |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1672 | } |
| 1673 | |
shrekshao | ad452548 | 2020-03-12 00:30:55 | [diff] [blame] | 1674 | bool 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 Jaramillo | b870ca6 | 2019-01-29 16:33:35 | [diff] [blame] | 1685 | int RasterDecoderImpl::GetRasterDecoderId() const { |
| 1686 | return raster_decoder_id_; |
| 1687 | } |
| 1688 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 1689 | int RasterDecoderImpl::DecoderIdForTest() { |
| 1690 | return raster_decoder_id_; |
| 1691 | } |
| 1692 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1693 | ServiceTransferCache* RasterDecoderImpl::GetTransferCacheForTest() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1694 | return shared_context_state_->transfer_cache(); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1695 | } |
| 1696 | |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 1697 | void 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 Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 1700 | auto info = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType, |
| 1701 | SkColorSpace::MakeSRGB()); |
Ian Prest | e598eece | 2020-10-19 23:31:02 | [diff] [blame] | 1702 | SkSurfaceProps props = skia::LegacyDisplayGlobals::GetSkSurfaceProps(); |
Kevin Lubick | 671644d | 2023-05-12 16:32:00 | [diff] [blame^] | 1703 | sk_surface_for_testing_ = SkSurfaces::Raster(info, &props); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 1704 | sk_surface_ = sk_surface_for_testing_.get(); |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 1705 | raster_canvas_ = sk_surface_->getCanvas(); |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 1706 | } |
| 1707 | |
Jonathan Backer | c7b8297 | 2018-11-21 19:08:48 | [diff] [blame] | 1708 | void RasterDecoderImpl::SetOOMErrorForTest() { |
| 1709 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "SetOOMErrorForTest", |
| 1710 | "synthetic out of memory"); |
| 1711 | } |
| 1712 | |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 1713 | void RasterDecoderImpl::DisableFlushWorkaroundForTest() { |
| 1714 | flush_workaround_disabled_for_test_ = true; |
| 1715 | } |
| 1716 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1717 | void RasterDecoderImpl::OnContextLostError() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1718 | if (!WasContextLost()) { |
| 1719 | // Need to lose current context before broadcasting! |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1720 | shared_context_state_->CheckResetStatus(/*needs_gl=*/false); |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1721 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1722 | } |
| 1723 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1724 | void RasterDecoderImpl::OnOutOfMemoryError() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1725 | if (lose_context_when_out_of_memory_ && !WasContextLost()) { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1726 | if (!shared_context_state_->CheckResetStatus(/*needs_gl=*/false)) { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1727 | MarkContextLost(error::kOutOfMemory); |
| 1728 | } |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1729 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1730 | } |
| 1731 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1732 | error::Error RasterDecoderImpl::HandleBeginQueryEXT( |
| 1733 | uint32_t immediate_data_size, |
| 1734 | const volatile void* cmd_data) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1735 | 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 Backer | 80b27029 | 2018-12-13 19:13:55 | [diff] [blame] | 1744 | break; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1745 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
Jonathan Backer | 80b27029 | 2018-12-13 19:13:55 | [diff] [blame] | 1746 | 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 Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1751 | 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 Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1769 | scoped_refptr<Buffer> buffer = GetSharedMemoryBuffer(sync_shm_id); |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1770 | 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1799 | return error::kNoError; |
| 1800 | } |
| 1801 | |
| 1802 | error::Error RasterDecoderImpl::HandleEndQueryEXT( |
| 1803 | uint32_t immediate_data_size, |
| 1804 | const volatile void* cmd_data) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1805 | 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 Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1818 | return error::kNoError; |
| 1819 | } |
| 1820 | |
Andres Calderon Jaramillo | 21e9815 | 2019-08-22 01:38:04 | [diff] [blame] | 1821 | error::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 Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1870 | void RasterDecoderImpl::DoFinish() { |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1871 | if (gr_context()) { |
| 1872 | gr_context()->flushAndSubmit(/*syncCpu=*/true); |
| 1873 | } else if (graphite_context()) { |
| 1874 | GraphiteFlushAndSubmit(skgpu::graphite::SyncToCpu::kYes); |
Peng Huang | 63ef887 | 2021-06-17 22:31:20 | [diff] [blame] | 1875 | } |
| 1876 | ProcessPendingQueries(/*did_finish=*/true); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | void RasterDecoderImpl::DoFlush() { |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1880 | if (gr_context()) { |
| 1881 | gr_context()->flushAndSubmit(/*syncCpu=*/false); |
| 1882 | } else if (graphite_context()) { |
| 1883 | GraphiteFlushAndSubmit(); |
Peng Huang | 63ef887 | 2021-06-17 22:31:20 | [diff] [blame] | 1884 | } |
| 1885 | ProcessPendingQueries(/*did_finish=*/false); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1886 | } |
| 1887 | |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1888 | bool 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 | |
| 1899 | void 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 Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1908 | error::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 Backer | ff2ac0f | 2018-07-18 15:53:47 | [diff] [blame] | 1915 | 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 Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1919 | 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 Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1930 | if (!gpu_tracer_->Begin(category_name, trace_name, gles2::kTraceCHROMIUM)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1931 | 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 | |
| 1938 | void RasterDecoderImpl::DoTraceEndCHROMIUM() { |
| 1939 | debug_marker_manager_.PopGroup(); |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1940 | if (!gpu_tracer_->End(gles2::kTraceCHROMIUM)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1941 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glTraceEndCHROMIUM", |
| 1942 | "no trace begin found"); |
| 1943 | return; |
| 1944 | } |
| 1945 | } |
| 1946 | |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1947 | error::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 || |
Khushal | da1fb833 | 2018-10-26 19:26:22 | [diff] [blame] | 1955 | url_bucket->size() > kMaxStrLen) { |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1956 | return error::kInvalidArguments; |
| 1957 | } |
| 1958 | |
Khushal | da1fb833 | 2018-10-26 19:26:22 | [diff] [blame] | 1959 | size_t size = url_bucket->size(); |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1960 | 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 Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1965 | client()->SetActiveURL(std::move(url)); |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1966 | return error::kNoError; |
| 1967 | } |
| 1968 | |
Saifuddin Hitawala | 20790cb | 2023-01-31 17:01:12 | [diff] [blame] | 1969 | void RasterDecoderImpl::DoCopySharedImageINTERNAL( |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1970 | GLint xoffset, |
| 1971 | GLint yoffset, |
| 1972 | GLint x, |
| 1973 | GLint y, |
| 1974 | GLsizei width, |
| 1975 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1976 | GLboolean unpack_flip_y, |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1977 | const volatile GLbyte* mailboxes) { |
Saifuddin Hitawala | c457bbd | 2023-02-07 21:19:24 | [diff] [blame] | 1978 | 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 Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1986 | } |
Nathan Zabriskie | 67a4fbc | 2021-01-07 19:39:10 | [diff] [blame] | 1987 | } |
| 1988 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 1989 | void RasterDecoderImpl::DoWritePixelsINTERNAL(GLint x_offset, |
| 1990 | GLint y_offset, |
Saifuddin Hitawala | 5d26b20 | 2023-04-04 18:41:43 | [diff] [blame] | 1991 | GLint plane_index, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 1992 | 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 Novosad | 129aa3ea4 | 2021-12-10 20:06:31 | [diff] [blame] | 2001 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoWritePixelsINTERNAL"); |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2002 | if (src_sk_color_type < 0 || src_sk_color_type > kLastEnum_SkColorType) { |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2003 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "WritePixels", |
| 2004 | "src_sk_color_type must be a valid SkColorType"); |
| 2005 | return; |
| 2006 | } |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2007 | if (src_sk_alpha_type < 0 || src_sk_alpha_type > kLastEnum_SkAlphaType) { |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2008 | 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 Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2025 | 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 Hitawala | b0bdad9 | 2022-11-23 23:07:24 | [diff] [blame] | 2032 | if (SkColorTypeBytesPerPixel( |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2033 | viz::ToClosestSkColorType(true, dest_format, plane_index)) != |
Nathan Zabriskie | 108c1828 | 2020-05-28 16:45:07 | [diff] [blame] | 2034 | 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 Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2041 | // 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 Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2045 | // 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 Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2052 | void* color_space_bytes = |
| 2053 | GetSharedMemoryAs<void*>(shm_id, shm_offset, pixels_offset); |
Nathan Zabriskie | a0f955c3 | 2020-04-16 21:29:10 | [diff] [blame] | 2054 | if (!color_space_bytes) { |
| 2055 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 2056 | "Failed to retrieve serialized SkColorSpace."); |
| 2057 | return; |
| 2058 | } |
| 2059 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2060 | 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 Zabriskie | ee59b5e | 2020-06-10 06:15:47 | [diff] [blame] | 2072 | 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 Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2079 | 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2097 | // 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 Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2101 | x_offset == 0 && y_offset == 0 && |
Justin Novosad | 4fb0c0e4 | 2022-02-08 16:10:27 | [diff] [blame] | 2102 | (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 Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2107 | DoWritePixelsINTERNALDirectTextureUpload(dest_shared_image.get(), |
| 2108 | src_info, plane_index, |
| 2109 | pixel_data, row_bytes)) { |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2110 | return; |
| 2111 | } |
| 2112 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2113 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2114 | std::vector<GrBackendSemaphore> end_semaphores; |
| 2115 | |
| 2116 | // Allow uncleared access, as we manually handle clear tracking. |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 2117 | std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess> |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2118 | 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 Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2127 | auto* surface = dest_scoped_access->surface(plane_index); |
| 2128 | DCHECK(surface); |
| 2129 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2130 | if (!begin_semaphores.empty()) { |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2131 | bool result = |
| 2132 | surface->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2133 | /*deleteSemaphoresAfterWait=*/false); |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2134 | 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 Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2141 | auto* canvas = surface->getCanvas(); |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2142 | 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 Hitawala | e3ef7ae | 2023-04-20 14:22:25 | [diff] [blame] | 2149 | surface->flush(); |
| 2150 | dest_scoped_access->ApplyBackendSurfaceEndState(); |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 2151 | SubmitIfNecessary(std::move(end_semaphores)); |
| 2152 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2153 | 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 Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2159 | bool RasterDecoderImpl::DoWritePixelsINTERNALDirectTextureUpload( |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 2160 | SkiaImageRepresentation* dest_shared_image, |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2161 | const SkImageInfo& src_info, |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2162 | const int plane_index, |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2163 | 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 Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 2169 | std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess> |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2170 | 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2178 | // 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 Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2183 | DCHECK(result); |
| 2184 | } |
| 2185 | |
| 2186 | SkPixmap pixmap(src_info, pixel_data, row_bytes); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2187 | 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 Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2207 | |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 2208 | SubmitIfNecessary(std::move(end_semaphores)); |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2209 | 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 Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2216 | void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL( |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2217 | GLint src_x, |
| 2218 | GLint src_y, |
Saifuddin Hitawala | f32b28c | 2023-02-22 23:30:38 | [diff] [blame] | 2219 | GLint plane_index, |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2220 | 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 Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2227 | GLuint color_space_offset, |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2228 | GLuint pixels_offset, |
| 2229 | const volatile GLbyte* mailbox) { |
Justin Novosad | 129aa3ea4 | 2021-12-10 20:06:31 | [diff] [blame] | 2230 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL"); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2231 | 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 Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2254 | viz::SharedImageFormat source_format = source_shared_image->format(); |
| 2255 | |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2256 | // 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 Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2265 | sk_sp<SkColorSpace> dst_color_space; |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2266 | if (color_space_size) { |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2267 | // For multiplanar formats readback is per plane, and destination color |
Saifuddin Hitawala | 6c8b833 | 2023-03-03 18:21:30 | [diff] [blame] | 2268 | // space must be nullptr to avoid unexpected color conversions. |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2269 | 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 Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2274 | void* color_space_bytes = GetSharedMemoryAs<void*>( |
| 2275 | shm_id, shm_offset + color_space_offset, color_space_size); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2276 | 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 Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2282 | SkColorSpace::Deserialize(color_space_bytes, color_space_size); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2283 | 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 Chin | 76a78002 | 2020-08-13 20:45:26 | [diff] [blame] | 2301 | 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 Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2309 | void* pixel_address = |
Jonah Chin | 76a78002 | 2020-08-13 20:45:26 | [diff] [blame] | 2310 | GetSharedMemoryAs<void*>(shm_id, shm_offset + pixels_offset, byte_size); |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2311 | if (!pixel_address) { |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2312 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2313 | "Failed to retrieve memory for readPixels output"); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2314 | return; |
| 2315 | } |
| 2316 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2317 | typedef cmds::ReadbackARGBImagePixelsINTERNALImmediate::Result Result; |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2318 | 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 Chin | f16050a | 2021-02-24 03:27:44 | [diff] [blame] | 2324 | } |
| 2325 | |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2326 | if (!source_format.IsValidPlaneIndex(plane_index)) { |
| 2327 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
| 2328 | "Invalid plane_index"); |
| 2329 | return; |
| 2330 | } |
| 2331 | |
Saifuddin Hitawala | 6c8b833 | 2023-03-03 18:21:30 | [diff] [blame] | 2332 | 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 Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2341 | } else { |
Saifuddin Hitawala | 6c8b833 | 2023-03-03 18:21:30 | [diff] [blame] | 2342 | *result = 1; |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2343 | } |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2344 | } |
| 2345 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2346 | namespace { |
| 2347 | struct YUVReadbackResult { |
| 2348 | std::unique_ptr<const SkImage::AsyncReadResult> async_result; |
Vasiliy Telezhnikov | 081df1e | 2023-01-16 15:41:34 | [diff] [blame] | 2349 | bool finished = false; |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2350 | }; |
| 2351 | |
| 2352 | void 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 Telezhnikov | 081df1e | 2023-01-16 15:41:34 | [diff] [blame] | 2357 | context->finished = true; |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2358 | } |
| 2359 | } // namespace |
| 2360 | |
| 2361 | void 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 Novosad | 129aa3ea4 | 2021-12-10 20:06:31 | [diff] [blame] | 2373 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoReadbackYUVImagePixelsINTERNAL"); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2374 | 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 Telezhnikov | f3f0ffd | 2021-06-22 14:19:18 | [diff] [blame] | 2380 | 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 Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2397 | 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 Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2410 | std::vector<GrBackendSemaphore> end_semaphores; |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2411 | |
| 2412 | // We don't use |end_semaphores| here because we're going to sync with |
| 2413 | // with the CPU later regardless. |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 2414 | std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess> |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2415 | source_scoped_access = source_shared_image->BeginScopedReadAccess( |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2416 | &begin_semaphores, &end_semaphores); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2417 | |
| 2418 | if (!begin_semaphores.empty()) { |
Saifuddin Hitawala | d902766 | 2023-05-12 14:50:10 | [diff] [blame] | 2419 | CHECK(gr_context()); |
| 2420 | bool result = |
| 2421 | gr_context()->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2422 | /*deleteSemaphoresAfterWait=*/false); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2423 | 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 Hitawala | 5a6785d5 | 2023-04-25 22:23:12 | [diff] [blame] | 2433 | source_scoped_access->CreateSkImage(shared_context_state_.get()); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2434 | 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 Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 2450 | // 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 Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2471 | 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 Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 2477 | 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 Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2492 | 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 Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 2498 | 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 Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2510 | 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 Hitawala | 913ae95 | 2023-04-18 23:26:03 | [diff] [blame] | 2529 | source_scoped_access->ApplyBackendSurfaceEndState(); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2530 | if (!end_semaphores.empty()) { |
Saifuddin Hitawala | d902766 | 2023-05-12 14:50:10 | [diff] [blame] | 2531 | CHECK(gr_context()); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2532 | 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 Hitawala | d902766 | 2023-05-12 14:50:10 | [diff] [blame] | 2538 | gr_context()->flush(flush_info); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2539 | } |
| 2540 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2541 | // 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 Hitawala | d902766 | 2023-05-12 14:50:10 | [diff] [blame] | 2544 | DoFinish(); |
Vasiliy Telezhnikov | 081df1e | 2023-01-16 15:41:34 | [diff] [blame] | 2545 | |
| 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 Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2549 | 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 Salomon | 99bc7fc | 2020-11-20 16:57:31 | [diff] [blame] | 2567 | void RasterDecoderImpl::DoConvertYUVAMailboxesToRGBINTERNAL( |
Nathan Zabriskie | 366b893 | 2020-04-28 01:07:13 | [diff] [blame] | 2568 | GLenum planes_yuv_color_space, |
Brian Salomon | 99bc7fc | 2020-11-20 16:57:31 | [diff] [blame] | 2569 | GLenum plane_config, |
| 2570 | GLenum subsampling, |
Christopher Cameron | 7b588da | 2022-08-05 23:38:17 | [diff] [blame] | 2571 | const volatile GLbyte* bytes_in) { |
Saifuddin Hitawala | a4eb464 | 2023-01-18 23:52:24 | [diff] [blame] | 2572 | CopySharedImageHelper helper(&shared_image_representation_factory_, |
Saifuddin Hitawala | a0b9d83 | 2023-01-23 23:53:41 | [diff] [blame] | 2573 | 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 Zabriskie | 366b893 | 2020-04-28 01:07:13 | [diff] [blame] | 2581 | } |
| 2582 | |
Christopher Cameron | 1c9f532 | 2021-08-14 08:21:36 | [diff] [blame] | 2583 | void RasterDecoderImpl::DoConvertRGBAToYUVAMailboxesINTERNAL( |
| 2584 | GLenum yuv_color_space, |
| 2585 | GLenum plane_config, |
| 2586 | GLenum subsampling, |
| 2587 | const volatile GLbyte* mailboxes_in) { |
Saifuddin Hitawala | a4eb464 | 2023-01-18 23:52:24 | [diff] [blame] | 2588 | CopySharedImageHelper helper(&shared_image_representation_factory_, |
Saifuddin Hitawala | a0b9d83 | 2023-01-23 23:53:41 | [diff] [blame] | 2589 | 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 Cameron | 1c9f532 | 2021-08-14 08:21:36 | [diff] [blame] | 2597 | } |
| 2598 | |
Jonah Chin | 053aa6c | 2021-01-22 20:26:14 | [diff] [blame] | 2599 | void RasterDecoderImpl::DoLoseContextCHROMIUM(GLenum current, GLenum other) { |
| 2600 | MarkContextLost(gles2::GetContextLostReasonFromResetStatus(current)); |
| 2601 | } |
| 2602 | |
Nathan Zabriskie | 366b893 | 2020-04-28 01:07:13 | [diff] [blame] | 2603 | namespace { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2604 | |
| 2605 | // Helper to read client data from transfer cache. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2606 | class TransferCacheDeserializeHelperImpl final |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2607 | : public cc::TransferCacheDeserializeHelper { |
| 2608 | public: |
| 2609 | explicit TransferCacheDeserializeHelperImpl( |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2610 | int raster_decoder_id, |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2611 | ServiceTransferCache* transfer_cache) |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2612 | : raster_decoder_id_(raster_decoder_id), transfer_cache_(transfer_cache) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2613 | DCHECK(transfer_cache_); |
| 2614 | } |
Peter Bostrรถm | dbacdc2 | 2021-09-23 22:11:46 | [diff] [blame] | 2615 | |
| 2616 | TransferCacheDeserializeHelperImpl( |
| 2617 | const TransferCacheDeserializeHelperImpl&) = delete; |
| 2618 | TransferCacheDeserializeHelperImpl& operator=( |
| 2619 | const TransferCacheDeserializeHelperImpl&) = delete; |
| 2620 | |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2621 | ~TransferCacheDeserializeHelperImpl() override = default; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2622 | |
Adrienne Walker | 90b79a2 | 2018-05-08 21:40:42 | [diff] [blame] | 2623 | void CreateLocalEntry( |
| 2624 | uint32_t id, |
| 2625 | std::unique_ptr<cc::ServiceTransferCacheEntry> entry) override { |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2626 | auto type = entry->Type(); |
| 2627 | transfer_cache_->CreateLocalEntry( |
| 2628 | ServiceTransferCache::EntryKey(raster_decoder_id_, type, id), |
| 2629 | std::move(entry)); |
Adrienne Walker | 90b79a2 | 2018-05-08 21:40:42 | [diff] [blame] | 2630 | } |
| 2631 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2632 | private: |
| 2633 | cc::ServiceTransferCacheEntry* GetEntryInternal( |
| 2634 | cc::TransferCacheEntryType entry_type, |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2635 | uint32_t entry_id) override { |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2636 | return transfer_cache_->GetEntry(ServiceTransferCache::EntryKey( |
| 2637 | raster_decoder_id_, entry_type, entry_id)); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2638 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2639 | |
| 2640 | const int raster_decoder_id_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 2641 | const raw_ptr<ServiceTransferCache> transfer_cache_; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2642 | }; |
| 2643 | |
| 2644 | } // namespace |
| 2645 | |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2646 | void RasterDecoderImpl::DeletePaintCachePathsINTERNALHelper( |
| 2647 | GLsizei n, |
| 2648 | const volatile GLuint* paint_cache_ids) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2649 | if (!use_gpu_raster_) { |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2650 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 2651 | "glDeletePaintCacheEntriesINTERNAL", |
| 2652 | "No chromium raster support"); |
| 2653 | return; |
| 2654 | } |
| 2655 | |
Khushal | cb653fb | 2018-11-15 08:56:28 | [diff] [blame] | 2656 | paint_cache_->Purge(cc::PaintCacheDataType::kPath, n, paint_cache_ids); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | void RasterDecoderImpl::DoClearPaintCacheINTERNAL() { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2660 | if (!use_gpu_raster_) { |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2661 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glClearPaintCacheINTERNAL", |
| 2662 | "No chromium raster support"); |
| 2663 | return; |
| 2664 | } |
| 2665 | |
| 2666 | paint_cache_->PurgeAll(); |
| 2667 | } |
| 2668 | |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2669 | void RasterDecoderImpl::DoBeginRasterCHROMIUM(GLfloat r, |
| 2670 | GLfloat g, |
| 2671 | GLfloat b, |
| 2672 | GLfloat a, |
Sunny Sachanandani | b461e21 | 2021-03-05 19:22:12 | [diff] [blame] | 2673 | GLboolean needs_clear, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2674 | GLuint msaa_sample_count, |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2675 | MsaaMode msaa_mode, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2676 | GLboolean can_use_lcd_text, |
Peng Huang | 5ff70dff | 2022-03-03 19:55:11 | [diff] [blame] | 2677 | GLboolean visible, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2678 | const volatile GLbyte* key) { |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 2679 | // Workaround for https://crbug.com/906453: Flush before BeginRaster (the |
| 2680 | // commands between BeginRaster and EndRaster will not flush). |
| 2681 | FlushToWorkAroundMacCrashes(); |
| 2682 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2683 | if (!use_gpu_raster_) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2684 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2685 | "No chromium raster support"); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2686 | return; |
| 2687 | } |
| 2688 | if (sk_surface_) { |
| 2689 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2690 | "BeginRasterCHROMIUM without EndRasterCHROMIUM"); |
| 2691 | return; |
| 2692 | } |
| 2693 | |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 2694 | 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 Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2699 | |
| 2700 | DCHECK(!shared_image_); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2701 | 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 Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 2717 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glBeginRasterCHROMIUM", |
| 2718 | "passed invalid mailbox."); |
| 2719 | return; |
| 2720 | } |
| 2721 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2722 | if (!needs_clear && !shared_image->IsCleared()) { |
Sunny Sachanandani | bb3dfad | 2021-06-04 19:04:22 | [diff] [blame] | 2723 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2724 | "SharedImage not cleared before use."); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2725 | shared_image_raster_.reset(); |
Sunny Sachanandani | 8f8b4eae | 2021-06-07 19:14:16 | [diff] [blame] | 2726 | shared_image_.reset(); |
Sunny Sachanandani | bb3dfad | 2021-06-04 19:04:22 | [diff] [blame] | 2727 | return; |
| 2728 | } |
| 2729 | |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 2730 | DCHECK(locked_handles_.empty()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2731 | DCHECK(!raster_canvas_); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2732 | |
Saifuddin Hitawala | b0bdad9 | 2022-11-23 23:07:24 | [diff] [blame] | 2733 | SkColorType sk_color_type = viz::ToClosestSkColorType( |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2734 | /*gpu_compositing=*/true, shared_image->format()); |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2735 | |
| 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 Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2743 | break; |
| 2744 | case kMSAA: |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2745 | // 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 Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2752 | // 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 Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2754 | if (gr_context() && |
| 2755 | final_msaa_count > |
| 2756 | gr_context()->maxSurfaceSampleCountForColorType(sk_color_type)) { |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2757 | final_msaa_count = 0; |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2758 | } |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2759 | flags = 0; |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2760 | break; |
| 2761 | case kDMSAA: |
| 2762 | final_msaa_count = 1; |
| 2763 | flags = SkSurfaceProps::kDynamicMSAA_Flag; |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2764 | break; |
| 2765 | } |
| 2766 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2767 | // Use unknown pixel geometry to disable LCD text. |
| 2768 | SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 2769 | if (can_use_lcd_text) { |
Ian Prest | e598eece | 2020-10-19 23:31:02 | [diff] [blame] | 2770 | surface_props = skia::LegacyDisplayGlobals::GetSkSurfaceProps(flags); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2771 | } |
| 2772 | |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2773 | SkColor4f sk_color_4f = {r, g, b, a}; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2774 | if (shared_image_raster_) { |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2775 | absl::optional<SkColor4f> clear_color; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2776 | if (needs_clear) |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2777 | clear_color.emplace(sk_color_4f); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2778 | scoped_shared_image_raster_write_ = |
| 2779 | shared_image_raster_->BeginScopedWriteAccess( |
Peng Huang | 5ff70dff | 2022-03-03 19:55:11 | [diff] [blame] | 2780 | shared_context_state_, final_msaa_count, surface_props, clear_color, |
| 2781 | visible); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2782 | 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 Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2795 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2796 | DCHECK(end_semaphores_.empty()); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2797 | DCHECK(!scoped_shared_image_write_); |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2798 | // Allow uncleared access, as raster specifically handles uncleared images |
| 2799 | // by clearing them before writing. |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2800 | scoped_shared_image_write_ = shared_image_->BeginScopedWriteAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 2801 | final_msaa_count, surface_props, &begin_semaphores, &end_semaphores_, |
| 2802 | SharedImageRepresentation::AllowUnclearedAccess::kYes); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2803 | 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 Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2810 | sk_surface_ = scoped_shared_image_write_->surface(); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2811 | |
| 2812 | if (!begin_semaphores.empty()) { |
| 2813 | bool result = |
Peng Huang | 1c6d058 | 2020-07-31 12:14:11 | [diff] [blame] | 2814 | sk_surface_->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2815 | /*deleteSemaphoresAfterWait=*/false); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2816 | DCHECK(result); |
| 2817 | } |
| 2818 | |
Peng Huang | 23b9be7b | 2022-02-19 01:05:41 | [diff] [blame] | 2819 | raster_canvas_ = sk_surface_->getCanvas(); |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2820 | |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 2821 | paint_op_shared_image_provider_ = std::make_unique<SharedImageProviderImpl>( |
| 2822 | &shared_image_representation_factory_, shared_context_state_, sk_surface_, |
Vasiliy Telezhnikov | 9837f90 | 2022-08-17 15:03:07 | [diff] [blame] | 2823 | &end_semaphores_, error_state_.get()); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 2824 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2825 | // All or nothing clearing, as no way to validate the client's input on what |
Sunny Sachanandani | b461e21 | 2021-03-05 19:22:12 | [diff] [blame] | 2826 | // 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 Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2834 | raster_canvas_->drawColor(sk_color_4f, SkBlendMode::kSrc); |
Sunny Sachanandani | b461e21 | 2021-03-05 19:22:12 | [diff] [blame] | 2835 | shared_image_->SetCleared(); |
| 2836 | } |
| 2837 | DCHECK(shared_image_->IsCleared()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2838 | } |
| 2839 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2840 | scoped_refptr<Buffer> RasterDecoderImpl::GetShmBuffer(uint32_t shm_id) { |
| 2841 | return GetSharedMemoryBuffer(shm_id); |
| 2842 | } |
| 2843 | |
Khushal | 39641b9 | 2019-06-03 21:32:54 | [diff] [blame] | 2844 | void RasterDecoderImpl::ReportProgress() { |
| 2845 | if (shared_context_state_->progress_reporter()) |
| 2846 | shared_context_state_->progress_reporter()->ReportProgress(); |
| 2847 | } |
| 2848 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2849 | void RasterDecoderImpl::DoRasterCHROMIUM(GLuint raster_shm_id, |
| 2850 | GLuint raster_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 2851 | GLuint raster_shm_size, |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2852 | GLuint font_shm_id, |
| 2853 | GLuint font_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 2854 | GLuint font_shm_size) { |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 2855 | TRACE_EVENT1("gpu", "RasterDecoderImpl::DoRasterCHROMIUM", "raster_id", |
| 2856 | ++raster_chromium_id_); |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2857 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2858 | if (!use_gpu_raster_) { |
| 2859 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 2860 | "No chromium raster support"); |
| 2861 | return; |
| 2862 | } |
| 2863 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2864 | if (!sk_surface_ && !scoped_shared_image_raster_write_) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2865 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 2866 | "RasterCHROMIUM without BeginRasterCHROMIUM"); |
| 2867 | return; |
| 2868 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2869 | DCHECK(transfer_cache()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2870 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2871 | 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 | |
Khushal | db6ea3c | 2018-05-31 00:53:09 | [diff] [blame] | 2881 | std::vector<SkDiscardableHandleId> new_locked_handles; |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 2882 | if (!font_manager_->Deserialize(font_buffer_memory, font_shm_size, |
| 2883 | &new_locked_handles)) { |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2884 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 2885 | "Invalid font buffer."); |
| 2886 | return; |
| 2887 | } |
Khushal | db6ea3c | 2018-05-31 00:53:09 | [diff] [blame] | 2888 | locked_handles_.insert(locked_handles_.end(), new_locked_handles.begin(), |
| 2889 | new_locked_handles.end()); |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2890 | } |
| 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 Huang | a8bda89 | 2022-05-06 17:15:59 | [diff] [blame] | 2900 | 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 Krajeski | d55f4900 | 2020-12-09 17:27:51 | [diff] [blame] | 2906 | cc::PlaybackParams playback_params(nullptr, SkM44()); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2907 | TransferCacheDeserializeHelperImpl impl(raster_decoder_id_, transfer_cache()); |
Adrienne Walker | 5a4952e | 2019-01-07 21:16:29 | [diff] [blame] | 2908 | cc::PaintOp::DeserializeOptions options( |
| 2909 | &impl, paint_cache_.get(), font_manager_->strike_client(), |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 2910 | shared_context_state_->scratch_deserialization_buffer(), is_privileged_, |
| 2911 | paint_op_shared_image_provider_.get()); |
Vikas Soni | 2a4039f | 2020-07-22 18:34:20 | [diff] [blame] | 2912 | options.crash_dump_on_failure = |
| 2913 | !gpu_preferences_.disable_oopr_debug_crash_dump; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2914 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2915 | 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 Wang | a0711d7 | 2023-02-08 22:54:26 | [diff] [blame] | 2922 | alignas(cc::PaintOpBuffer::kPaintOpAlign) char |
| 2923 | data[cc::kLargestPaintOpAlignedSize]; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2924 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2925 | size_t paint_buffer_size = raster_shm_size; |
Adrienne Walker | d8a5646 | 2019-03-16 03:11:47 | [diff] [blame] | 2926 | gl::ScopedProgressReporter report_progress( |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2927 | shared_context_state_->progress_reporter()); |
Khushal | a415686 | 2018-06-08 22:46:02 | [diff] [blame] | 2928 | while (paint_buffer_size > 0) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2929 | size_t skip = 0; |
Xianzhu Wang | a0711d7 | 2023-02-08 22:54:26 | [diff] [blame] | 2930 | cc::PaintOp* deserialized_op = |
| 2931 | cc::PaintOp::Deserialize(paint_buffer_memory, paint_buffer_size, data, |
| 2932 | std::size(data), &skip, options); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2933 | if (!deserialized_op) { |
Adrienne Walker | e62484a | 2018-11-27 18:41:30 | [diff] [blame] | 2934 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 2935 | "RasterCHROMIUM: serialization failure"); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2936 | return; |
| 2937 | } |
| 2938 | |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 2939 | deserialized_op->Raster(raster_canvas_, playback_params); |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 2940 | deserialized_op->DestroyThis(); |
| 2941 | |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 2942 | paint_buffer_size -= skip; |
| 2943 | paint_buffer_memory += skip; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | void RasterDecoderImpl::DoEndRasterCHROMIUM() { |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2948 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM"); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2949 | if (!sk_surface_ && !scoped_shared_image_raster_write_) { |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 2950 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glEndRasterCHROMIUM", |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2951 | "EndRasterCHROMIUM without BeginRasterCHROMIUM"); |
| 2952 | return; |
| 2953 | } |
| 2954 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2955 | 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 Huang | 410ae6b2 | 2022-04-15 03:31:01 | [diff] [blame] | 2959 | font_manager->Unlock(handles); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2960 | }, |
| 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 Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 2968 | raster_canvas_ = nullptr; |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2969 | |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2970 | { |
Peng Huang | d960843 | 2019-07-29 15:56:36 | [diff] [blame] | 2971 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM::Flush"); |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2972 | // 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 Walker | d8a5646 | 2019-03-16 03:11:47 | [diff] [blame] | 2975 | gl::ScopedProgressReporter report_progress( |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2976 | shared_context_state_->progress_reporter()); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2977 | |
| 2978 | // scoped_shared_image_write_ can be nullptr if sk_surface_ was set by |
| 2979 | // SetUpForRasterCHROMIUMForTest. |
| 2980 | if (scoped_shared_image_write_) { |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 2981 | 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 Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2985 | paint_op_shared_image_provider_->ApplyEndAccessState(); |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 2986 | SubmitIfNecessary(std::move(end_semaphores_)); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2987 | end_semaphores_.clear(); |
| 2988 | } else { |
| 2989 | DCHECK(end_semaphores_.empty()); |
| 2990 | } |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2991 | } |
| 2992 | |
Kramer Ge | ddcac353 | 2019-12-12 23:33:10 | [diff] [blame] | 2993 | shared_context_state_->UpdateSkiaOwnedMemorySize(); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2994 | sk_surface_ = nullptr; |
Peng Huang | b63db21 | 2020-06-01 14:37:39 | [diff] [blame] | 2995 | scoped_shared_image_write_.reset(); |
| 2996 | shared_image_.reset(); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 2997 | paint_op_shared_image_provider_.reset(); |
| 2998 | |
Peng Huang | b63db21 | 2020-06-01 14:37:39 | [diff] [blame] | 2999 | // Test only path for SetUpForRasterCHROMIUMForTest. |
| 3000 | sk_surface_for_testing_.reset(); |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 3001 | |
| 3002 | // Unlock all font handles. This needs to be deferred until |
Greg Daniel | 18362e9d | 2019-04-15 19:54:50 | [diff] [blame] | 3003 | // SkSurface::flush since that flushes batched Gr operations |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3004 | // in skia that access the glyph data. |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 3005 | if (!font_manager_->Unlock(locked_handles_)) { |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 3006 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 3007 | "Invalid font discardable handle."); |
| 3008 | } |
| 3009 | locked_handles_.clear(); |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 3010 | |
Victor Miura | 6bb4ab5c | 2023-05-10 21:35:12 | [diff] [blame] | 3011 | // We just unlocked a bunch of handles. Give a call to skia to |
| 3012 | // attempt to purge any unlocked handles. |
| 3013 | SkGraphics::PurgePinnedFontCache(); |
| 3014 | |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 3015 | // We just flushed a tile's worth of GPU work from the SkSurface in |
Khushal Sagar | b3f5329 | 2019-06-05 04:24:23 | [diff] [blame] | 3016 | // flush above. Yield to the Scheduler to allow pre-emption before |
| 3017 | // processing more commands. |
| 3018 | ExitCommandProcessingEarly(); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3019 | } |
| 3020 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3021 | void 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) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3029 | if (!use_gpu_raster_) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3030 | 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 Hitawala | d902766 | 2023-05-12 14:50:10 | [diff] [blame] | 3035 | CHECK(gr_context() || graphite_recorder()); |
| 3036 | CHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3037 | |
| 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 Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3042 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3043 | "Attempt to use OOP transfer cache with an invalid " |
| 3044 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3045 | return; |
| 3046 | } |
| 3047 | |
Khushal | c11f57b | 2020-03-20 16:56:15 | [diff] [blame] | 3048 | 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 Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3054 | 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 Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3072 | // If the entry is going to use skia during deserialization, make sure we |
| 3073 | // mark the context state dirty. |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3074 | bool use_gpu = cc::ServiceTransferCacheEntry::UsesGpuContext(entry_type); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3075 | if (!transfer_cache()->CreateLockedEntry( |
| 3076 | ServiceTransferCache::EntryKey(raster_decoder_id_, entry_type, |
| 3077 | entry_id), |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3078 | handle, use_gpu ? gr_context() : nullptr, |
| 3079 | use_gpu ? graphite_recorder() : nullptr, |
| 3080 | base::make_span(data_memory, data_size))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3081 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3082 | "Failure to deserialize transfer cache entry."); |
| 3083 | return; |
| 3084 | } |
Khushal Sagar | b3f5329 | 2019-06-05 04:24:23 | [diff] [blame] | 3085 | |
| 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 Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3089 | if (use_gpu) { |
Khushal Sagar | b3f5329 | 2019-06-05 04:24:23 | [diff] [blame] | 3090 | ExitCommandProcessingEarly(); |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3091 | } |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | void RasterDecoderImpl::DoUnlockTransferCacheEntryINTERNAL( |
| 3095 | GLuint raw_entry_type, |
| 3096 | GLuint entry_id) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3097 | if (!use_gpu_raster_) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3098 | 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 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3103 | DCHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3104 | cc::TransferCacheEntryType entry_type; |
| 3105 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 3106 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3107 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 3108 | "Attempt to use OOP transfer cache with an invalid " |
| 3109 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3110 | return; |
| 3111 | } |
| 3112 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3113 | if (!transfer_cache()->UnlockEntry(ServiceTransferCache::EntryKey( |
| 3114 | raster_decoder_id_, entry_type, entry_id))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3115 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 3116 | "Attempt to unlock an invalid ID"); |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | void RasterDecoderImpl::DoDeleteTransferCacheEntryINTERNAL( |
| 3121 | GLuint raw_entry_type, |
| 3122 | GLuint entry_id) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3123 | if (!use_gpu_raster_) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3124 | 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 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3129 | DCHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3130 | cc::TransferCacheEntryType entry_type; |
| 3131 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 3132 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3133 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 3134 | "Attempt to use OOP transfer cache with an invalid " |
| 3135 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3136 | return; |
| 3137 | } |
| 3138 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3139 | if (!transfer_cache()->DeleteEntry(ServiceTransferCache::EntryKey( |
| 3140 | raster_decoder_id_, entry_type, entry_id))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3141 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 3142 | "Attempt to delete an invalid ID"); |
| 3143 | } |
| 3144 | } |
| 3145 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 3146 | void RasterDecoderImpl::RestoreStateForAttrib(GLuint attrib_index, |
| 3147 | bool restore_array_binding) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 3148 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 3149 | } |
| 3150 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 3151 | // 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 Hijikata | 7471d26f | 2020-10-23 03:27:42 | [diff] [blame] | 3154 | #include "build/chromeos_buildflags.h" |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 3155 | #include "gpu/command_buffer/service/raster_decoder_autogen.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 3156 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 3157 | } // namespace raster |
| 3158 | } // namespace gpu |