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 | |
Arthur Sonzogni | 720f1c95 | 2024-07-25 16:17:51 | [diff] [blame] | 5 | #ifdef UNSAFE_BUFFERS_BUILD |
| 6 | // TODO(crbug.com/40285824): Remove this and convert code to safer constructs. |
| 7 | #pragma allow_unsafe_buffers |
| 8 | #endif |
| 9 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 10 | #include "gpu/command_buffer/service/raster_decoder.h" |
| 11 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 12 | #include <stdint.h> |
| 13 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 14 | #include <algorithm> |
Arthur Sonzogni | 6718b70 | 2025-01-09 10:49:10 | [diff] [blame] | 15 | #include <array> |
Ho Cheung | a4e15c8 | 2024-05-13 15:48:50 | [diff] [blame] | 16 | #include <cstdint> |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 17 | #include <memory> |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 18 | #include <optional> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 19 | #include <string> |
Helmut Januschka | b81e97dc | 2024-04-17 14:57:05 | [diff] [blame] | 20 | #include <string_view> |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 21 | #include <utility> |
Jonathan Backer | 6307cee9 | 2018-04-25 19:53:43 | [diff] [blame] | 22 | #include <vector> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 23 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 24 | #include "base/atomic_sequence_num.h" |
Peng Huang | 38a628064 | 2024-04-16 23:56:55 | [diff] [blame] | 25 | #include "base/command_line.h" |
Peng Huang | cb204209 | 2018-12-04 13:42:34 | [diff] [blame] | 26 | #include "base/containers/flat_map.h" |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 27 | #include "base/debug/crash_logging.h" |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 28 | #include "base/feature_list.h" |
Avi Drissman | 93a273dd | 2023-01-11 00:38:27 | [diff] [blame] | 29 | #include "base/functional/bind.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 30 | #include "base/logging.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 31 | #include "base/memory/raw_ptr.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 32 | #include "base/memory/ref_counted.h" |
| 33 | #include "base/memory/weak_ptr.h" |
Scott Violet | 86dc643d | 2023-04-07 17:57:24 | [diff] [blame] | 34 | #include "base/metrics/histogram_functions.h" |
Daniel Cheng | ee862142 | 2025-06-19 20:27:17 | [diff] [blame] | 35 | #include "base/notimplemented.h" |
Nathan Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 36 | #include "base/numerics/checked_math.h" |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 37 | #include "base/time/time.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 38 | #include "base/trace_event/trace_event.h" |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 39 | #include "build/build_config.h" |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 40 | #include "cc/paint/paint_cache.h" |
Xianzhu Wang | e6d732e9 | 2022-12-08 17:27:52 | [diff] [blame] | 41 | #include "cc/paint/paint_op.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 42 | #include "cc/paint/paint_op_buffer.h" |
Lei Zhang | d35969c7 | 2021-05-20 20:58:33 | [diff] [blame] | 43 | #include "cc/paint/transfer_cache_deserialize_helper.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 44 | #include "cc/paint/transfer_cache_entry.h" |
Colin Blundell | 34f5a45 | 2023-05-24 08:31:58 | [diff] [blame] | 45 | #include "components/viz/common/resources/shared_image_format_utils.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 46 | #include "gpu/command_buffer/common/capabilities.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 47 | #include "gpu/command_buffer/common/command_buffer_id.h" |
| 48 | #include "gpu/command_buffer/common/constants.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 49 | #include "gpu/command_buffer/common/context_result.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 50 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 51 | #include "gpu/command_buffer/common/mailbox.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 52 | #include "gpu/command_buffer/common/raster_cmd_format.h" |
| 53 | #include "gpu/command_buffer/common/raster_cmd_ids.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 54 | #include "gpu/command_buffer/common/sync_token.h" |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/command_buffer_service.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/context_state.h" |
Saifuddin Hitawala | a4eb464 | 2023-01-18 23:52:24 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/copy_shared_image_helper.h" |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 58 | #include "gpu/command_buffer/service/decoder_client.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 59 | #include "gpu/command_buffer/service/error_state.h" |
| 60 | #include "gpu/command_buffer/service/feature_info.h" |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 61 | #include "gpu/command_buffer/service/gl_utils.h" |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 62 | #include "gpu/command_buffer/service/gpu_tracer.h" |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 63 | #include "gpu/command_buffer/service/graphite_shared_context.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 64 | #include "gpu/command_buffer/service/logger.h" |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 65 | #include "gpu/command_buffer/service/query_manager.h" |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 66 | #include "gpu/command_buffer/service/raster_cmd_validation.h" |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 67 | #include "gpu/command_buffer/service/service_font_manager.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 68 | #include "gpu/command_buffer/service/service_transfer_cache.h" |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 69 | #include "gpu/command_buffer/service/service_utils.h" |
Peng Huang | 8294a5a7f | 2019-01-23 18:56:26 | [diff] [blame] | 70 | #include "gpu/command_buffer/service/shared_context_state.h" |
Saifuddin Hitawala | 81cbd38 | 2022-07-20 19:14:53 | [diff] [blame] | 71 | #include "gpu/command_buffer/service/shared_image/shared_image_factory.h" |
Colin Blundell | 415f5cc | 2023-05-23 14:46:40 | [diff] [blame] | 72 | #include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h" |
Saifuddin Hitawala | 81cbd38 | 2022-07-20 19:14:53 | [diff] [blame] | 73 | #include "gpu/command_buffer/service/shared_image/shared_image_representation.h" |
| 74 | #include "gpu/command_buffer/service/shared_image/wrapped_sk_image_backing_factory.h" |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 75 | #include "gpu/command_buffer/service/skia_utils.h" |
Vikas Soni | ca02287b | 2022-01-18 20:17:35 | [diff] [blame] | 76 | #include "gpu/config/gpu_finch_features.h" |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 77 | #include "gpu/vulkan/buildflags.h" |
Ian Prest | e598eece | 2020-10-19 23:31:02 | [diff] [blame] | 78 | #include "skia/ext/legacy_display_globals.h" |
Christopher Cameron | d18b932 | 2021-08-24 21:12:55 | [diff] [blame] | 79 | #include "skia/ext/rgba_to_yuva.h" |
Saifuddin Hitawala | 53b469aa | 2023-07-17 16:27:47 | [diff] [blame] | 80 | #include "third_party/abseil-cpp/absl/cleanup/cleanup.h" |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 81 | #include "third_party/libyuv/include/libyuv/planar_functions.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 82 | #include "third_party/skia/include/core/SkCanvas.h" |
Kevin Lubick | 040667a | 2022-04-07 13:49:03 | [diff] [blame] | 83 | #include "third_party/skia/include/core/SkColorSpace.h" |
Victor Miura | 6bb4ab5c | 2023-05-10 21:35:12 | [diff] [blame] | 84 | #include "third_party/skia/include/core/SkGraphics.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 85 | #include "third_party/skia/include/core/SkSurface.h" |
| 86 | #include "third_party/skia/include/core/SkSurfaceProps.h" |
| 87 | #include "third_party/skia/include/core/SkTypeface.h" |
Brian Salomon | c54f44f | 2020-11-11 16:11:06 | [diff] [blame] | 88 | #include "third_party/skia/include/core/SkYUVAInfo.h" |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 89 | #include "third_party/skia/include/core/SkYUVAPixmaps.h" |
Kaylee Lubick | a077f7923 | 2024-09-04 01:32:55 | [diff] [blame] | 90 | #include "third_party/skia/include/gpu/ganesh/GrBackendSemaphore.h" |
| 91 | #include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h" |
| 92 | #include "third_party/skia/include/gpu/ganesh/GrDirectContext.h" |
| 93 | #include "third_party/skia/include/gpu/ganesh/GrTypes.h" |
| 94 | #include "third_party/skia/include/gpu/ganesh/GrYUVABackendTextures.h" |
Kevin Lubick | 6abb9c6 | 2023-05-30 21:28:22 | [diff] [blame] | 95 | #include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h" |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 96 | #include "third_party/skia/include/gpu/graphite/Context.h" |
Kevin Lubick | 9865bc8 | 2023-06-15 15:48:30 | [diff] [blame] | 97 | #include "third_party/skia/include/private/chromium/GrPromiseImageTexture.h" |
Peng Huang | 38a628064 | 2024-04-16 23:56:55 | [diff] [blame] | 98 | #include "third_party/skia/include/utils/SkNoDrawCanvas.h" |
Peng Huang | 5f3d435 | 2021-11-23 17:51:29 | [diff] [blame] | 99 | #include "ui/base/ui_base_features.h" |
Jonathan Backer | 76dfd50 | 2018-05-03 18:34:31 | [diff] [blame] | 100 | #include "ui/gfx/buffer_format_util.h" |
Xianzhu Wang | 65ef1ad3 | 2021-10-07 03:12:33 | [diff] [blame] | 101 | #include "ui/gfx/geometry/skia_conversions.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 102 | #include "ui/gl/gl_context.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 103 | #include "ui/gl/gl_gl_api_implementation.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 104 | #include "ui/gl/gl_surface.h" |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 105 | #include "ui/gl/gl_version_info.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 106 | |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 107 | #if BUILDFLAG(ENABLE_VULKAN) |
| 108 | #include "components/viz/common/gpu/vulkan_context_provider.h" |
Saifuddin Hitawala | 47abaf36 | 2025-09-09 18:15:58 | [diff] [blame] | 109 | #include "gpu/command_buffer/service/drm_modifiers_filter_vulkan.h" |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 110 | #include "gpu/vulkan/vulkan_device_queue.h" |
Chia-I Wu | ae6d926 | 2023-12-13 01:27:48 | [diff] [blame] | 111 | #include "gpu/vulkan/vulkan_util.h" |
Jonah Chin | 09d12b7 | 2021-05-11 00:52:08 | [diff] [blame] | 112 | #endif // BUILDFLAG(ENABLE_VULKAN) |
| 113 | |
Xiaohan Wang | fa22d3e | 2022-01-15 02:02:43 | [diff] [blame] | 114 | #if BUILDFLAG(IS_WIN) |
Saifuddin Hitawala | 81cbd38 | 2022-07-20 19:14:53 | [diff] [blame] | 115 | #include "gpu/command_buffer/service/shared_image/d3d_image_backing_factory.h" |
Xiaohan Wang | fa22d3e | 2022-01-15 02:02:43 | [diff] [blame] | 116 | #endif // BUILDFLAG(IS_WIN) |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 117 | |
Saifuddin Hitawala | b0c218e | 2023-10-27 17:25:29 | [diff] [blame] | 118 | #if BUILDFLAG(SKIA_USE_DAWN) |
| 119 | #include <dawn/webgpu_cpp.h> |
| 120 | #include "gpu/command_buffer/service/dawn_context_provider.h" |
| 121 | #endif // BUILDFLAG(USE_DAWN) |
| 122 | |
Georg Neis | 24b92cc4 | 2025-02-07 04:11:10 | [diff] [blame] | 123 | #if BUILDFLAG(SKIA_USE_DAWN) && BUILDFLAG(IS_CHROMEOS) |
Kevin Haslett | 0ae5ba1 | 2024-03-21 20:10:44 | [diff] [blame] | 124 | #include "gpu/command_buffer/service/drm_modifiers_filter_dawn.h" |
Georg Neis | 24b92cc4 | 2025-02-07 04:11:10 | [diff] [blame] | 125 | #endif // BUILDFLAG(SKIA_USE_DAWN) && BUILDFLAG(IS_CHROMEOS) |
Kevin Haslett | 0ae5ba1 | 2024-03-21 20:10:44 | [diff] [blame] | 126 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 127 | // Local versions of the SET_GL_ERROR macros |
| 128 | #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 129 | ERRORSTATE_SET_GL_ERROR(error_state_.get(), error, function_name, msg) |
| 130 | #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ |
| 131 | ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state_.get(), function_name, \ |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 132 | static_cast<uint32_t>(value), label) |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 133 | #define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 134 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 135 | #define LOCAL_PEEK_GL_ERROR(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 136 | ERRORSTATE_PEEK_GL_ERROR(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 137 | #define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 138 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 139 | #define LOCAL_PERFORMANCE_WARNING(msg) \ |
| 140 | PerformanceWarning(__FILE__, __LINE__, msg) |
| 141 | #define LOCAL_RENDER_WARNING(msg) RenderWarning(__FILE__, __LINE__, msg) |
| 142 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 143 | namespace gpu { |
| 144 | namespace raster { |
| 145 | |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 146 | namespace { |
| 147 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 148 | base::AtomicSequenceNumber g_raster_decoder_id; |
| 149 | |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 150 | // Controls whether we may yield during rasterization. |
Xiaohan Wang | 732c4f8d5 | 2025-09-09 02:40:43 | [diff] [blame] | 151 | BASE_FEATURE(kGpuYieldRasterization, base::FEATURE_DISABLED_BY_DEFAULT); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 152 | |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 153 | // Controls how many ops are rastered before checking if we should yield. |
| 154 | const base::FeatureParam<int> kGpuYieldRasterizationOpCount( |
| 155 | &kGpuYieldRasterization, |
| 156 | "gpu_yield_rasterization_op_count", |
| 157 | 500); |
| 158 | |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 159 | // This class prevents any GL errors that occur when it is in scope from |
| 160 | // being reported to the client. |
| 161 | class ScopedGLErrorSuppressor { |
| 162 | public: |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 163 | ScopedGLErrorSuppressor(const char* function_name, |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 164 | gles2::ErrorState* error_state) |
| 165 | : function_name_(function_name), error_state_(error_state) { |
| 166 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); |
| 167 | } |
Peter BostrÃļm | dbacdc2 | 2021-09-23 22:11:46 | [diff] [blame] | 168 | |
| 169 | ScopedGLErrorSuppressor(const ScopedGLErrorSuppressor&) = delete; |
| 170 | ScopedGLErrorSuppressor& operator=(const ScopedGLErrorSuppressor&) = delete; |
| 171 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 172 | ~ScopedGLErrorSuppressor() { |
| 173 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
| 174 | } |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 175 | |
| 176 | private: |
| 177 | const char* function_name_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 178 | raw_ptr<gles2::ErrorState> error_state_; |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 179 | }; |
| 180 | |
Corentin Wallez | 5cbffcc | 2020-07-08 10:23:57 | [diff] [blame] | 181 | // Commands that are explicitly listed as OK to occur between |
Adlai Holler | c4dea1a9 | 2020-08-04 13:21:55 | [diff] [blame] | 182 | // BeginRasterCHROMIUM and EndRasterCHROMIUM. They do not invalidate |
| 183 | // GrDirectContext state tracking. |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 184 | bool AllowedBetweenBeginEndRaster(CommandId command) { |
| 185 | switch (command) { |
| 186 | case kCreateTransferCacheEntryINTERNAL: |
| 187 | case kDeleteTransferCacheEntryINTERNAL: |
| 188 | case kEndRasterCHROMIUM: |
| 189 | case kFinish: |
| 190 | case kFlush: |
| 191 | case kGetError: |
| 192 | case kRasterCHROMIUM: |
| 193 | case kUnlockTransferCacheEntryINTERNAL: |
| 194 | return true; |
| 195 | default: |
| 196 | return false; |
| 197 | } |
| 198 | } |
| 199 | |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 200 | // This class is sent to cc::PaintOpReader during paint op deserialization. When |
| 201 | // a cc:PaintOp refers to a mailbox-backed cc:PaintImage, this class opens the |
| 202 | // shared image for read access and returns an SkImage reference. |
| 203 | // SharedImageProviderImpl maintains read access until it is destroyed |
| 204 | // which should occur after |end_semaphores| have been flushed to Skia. |
| 205 | class SharedImageProviderImpl final : public cc::SharedImageProvider { |
| 206 | public: |
| 207 | SharedImageProviderImpl( |
| 208 | SharedImageRepresentationFactory* shared_image_factory, |
| 209 | scoped_refptr<SharedContextState> shared_context_state, |
| 210 | SkSurface* output_surface, |
| 211 | std::vector<GrBackendSemaphore>* end_semaphores, |
Vasiliy Telezhnikov | 9837f90 | 2022-08-17 15:03:07 | [diff] [blame] | 212 | gles2::ErrorState* error_state) |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 213 | : shared_image_factory_(shared_image_factory), |
| 214 | shared_context_state_(std::move(shared_context_state)), |
| 215 | output_surface_(output_surface), |
| 216 | end_semaphores_(end_semaphores), |
Vasiliy Telezhnikov | 9837f90 | 2022-08-17 15:03:07 | [diff] [blame] | 217 | error_state_(error_state) { |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 218 | DCHECK(shared_image_factory_); |
| 219 | DCHECK(shared_context_state_); |
| 220 | DCHECK(output_surface_); |
| 221 | DCHECK(end_semaphores_); |
| 222 | DCHECK(error_state_); |
| 223 | } |
| 224 | SharedImageProviderImpl(const SharedImageProviderImpl&) = delete; |
| 225 | SharedImageProviderImpl& operator=(const SharedImageProviderImpl&) = delete; |
| 226 | |
| 227 | ~SharedImageProviderImpl() override { read_accessors_.clear(); } |
| 228 | |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 229 | sk_sp<SkImage> OpenSharedImageForRead(const gpu::Mailbox& mailbox, |
| 230 | Error& error) override { |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 231 | auto it = read_accessors_.find(mailbox); |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 232 | error = Error::kNoError; |
| 233 | if (it != read_accessors_.end()) { |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 234 | return it->second.read_access_sk_image; |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 235 | } |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 236 | |
| 237 | auto shared_image_skia = |
| 238 | shared_image_factory_->ProduceSkia(mailbox, shared_context_state_); |
| 239 | if (!shared_image_skia) { |
| 240 | ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION, |
| 241 | "SharedImageProviderImpl::OpenSharedImageForRead", |
| 242 | ("Attempting to operate on unknown mailbox:" + |
| 243 | mailbox.ToDebugString()) |
| 244 | .c_str()); |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 245 | error = Error::kUnknownMailbox; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 246 | return nullptr; |
| 247 | } |
| 248 | |
| 249 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 250 | // |end_semaphores_| is owned by RasterDecoderImpl which will handle sending |
| 251 | // them to SkCanvas |
| 252 | auto scoped_read_access = shared_image_skia->BeginScopedReadAccess( |
| 253 | &begin_semaphores, end_semaphores_); |
| 254 | if (!scoped_read_access) { |
| 255 | ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION, |
| 256 | "SharedImageProviderImpl::OpenSharedImageForRead", |
| 257 | ("Couldn't access shared image for mailbox:" + |
| 258 | mailbox.ToDebugString()) |
| 259 | .c_str()); |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 260 | error = Error::kNoAccess; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 261 | return nullptr; |
| 262 | } |
| 263 | |
| 264 | if (!begin_semaphores.empty()) { |
| 265 | bool result = output_surface_->wait(begin_semaphores.size(), |
Peng Huang | 1c6d058 | 2020-07-31 12:14:11 | [diff] [blame] | 266 | begin_semaphores.data(), |
| 267 | /*deleteSemaphoresAfterWait=*/false); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 268 | DCHECK(result); |
| 269 | } |
| 270 | |
Nathan Zabriskie | c5ed236 | 2020-07-21 05:39:54 | [diff] [blame] | 271 | auto sk_image = |
Saifuddin Hitawala | 5a6785d5 | 2023-04-25 22:23:12 | [diff] [blame] | 272 | scoped_read_access->CreateSkImage(shared_context_state_.get()); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 273 | if (!sk_image) { |
| 274 | ERRORSTATE_SET_GL_ERROR(error_state_, GL_INVALID_OPERATION, |
| 275 | "SharedImageProviderImpl::OpenSharedImageForRead", |
| 276 | "Couldn't create output SkImage."); |
Justin Novosad | 30670e6 | 2021-09-27 22:30:23 | [diff] [blame] | 277 | error = Error::kSkImageCreationFailed; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 278 | return nullptr; |
| 279 | } |
| 280 | |
| 281 | read_accessors_[mailbox] = {std::move(shared_image_skia), |
| 282 | std::move(scoped_read_access), sk_image}; |
| 283 | return sk_image; |
| 284 | } |
| 285 | |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 286 | void ApplyEndAccessState() { |
Saifuddin Hitawala | 7065278 | 2024-08-21 14:13:32 | [diff] [blame] | 287 | for (auto& [mailbox, access] : read_accessors_) { |
| 288 | access.scoped_read_access->ApplyBackendSurfaceEndState(); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Saifuddin Hitawala | 7065278 | 2024-08-21 14:13:32 | [diff] [blame] | 292 | bool NeedGraphiteContextSubmit() { |
| 293 | bool need_graphite_submit = false; |
| 294 | for (auto& [mailbox, access] : read_accessors_) { |
| 295 | need_graphite_submit |= |
| 296 | access.scoped_read_access->NeedGraphiteContextSubmit(); |
| 297 | } |
| 298 | return need_graphite_submit; |
| 299 | } |
| 300 | |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 301 | private: |
PÃĸris | 7704a8e | 2022-09-01 09:49:20 | [diff] [blame] | 302 | raw_ptr<SharedImageRepresentationFactory, DanglingUntriaged> |
| 303 | shared_image_factory_; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 304 | scoped_refptr<SharedContextState> shared_context_state_; |
PÃĸris | 7704a8e | 2022-09-01 09:49:20 | [diff] [blame] | 305 | raw_ptr<SkSurface, DanglingUntriaged> output_surface_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 306 | raw_ptr<std::vector<GrBackendSemaphore>> end_semaphores_; |
| 307 | raw_ptr<gles2::ErrorState> error_state_; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 308 | |
| 309 | struct SharedImageReadAccess { |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 310 | std::unique_ptr<SkiaImageRepresentation> shared_image_skia; |
| 311 | std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess> |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 312 | scoped_read_access; |
| 313 | sk_sp<SkImage> read_access_sk_image; |
| 314 | }; |
| 315 | base::flat_map<gpu::Mailbox, SharedImageReadAccess> read_accessors_; |
| 316 | }; |
| 317 | |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 318 | class RasterCommandsCompletedQuery : public QueryManager::Query { |
| 319 | public: |
| 320 | RasterCommandsCompletedQuery( |
| 321 | scoped_refptr<SharedContextState> shared_context_state, |
| 322 | QueryManager* manager, |
| 323 | GLenum target, |
| 324 | scoped_refptr<gpu::Buffer> buffer, |
| 325 | QuerySync* sync) |
| 326 | : Query(manager, target, std::move(buffer), sync), |
| 327 | shared_context_state_(std::move(shared_context_state)) {} |
| 328 | |
| 329 | // Overridden from QueryManager::Query: |
| 330 | void Begin() override { |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 331 | MarkAsActive(); |
| 332 | begin_time_.emplace(base::TimeTicks::Now()); |
| 333 | } |
| 334 | |
| 335 | void End(base::subtle::Atomic32 submit_count) override { |
| 336 | DCHECK(begin_time_); |
| 337 | |
| 338 | AddToPendingQueue(submit_count); |
| 339 | finished_ = false; |
| 340 | |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 341 | if (auto* gr_context = shared_context_state_->gr_context()) { |
| 342 | GrFlushInfo info; |
| 343 | info.fFinishedProc = RasterCommandsCompletedQuery::FinishedProc; |
| 344 | auto weak_ptr = weak_ptr_factory_.GetWeakPtr(); |
| 345 | info.fFinishedContext = |
| 346 | new base::WeakPtr<RasterCommandsCompletedQuery>(weak_ptr); |
| 347 | gr_context->flush(info); |
| 348 | gr_context->submit(); |
| 349 | } else { |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 350 | CHECK(shared_context_state_->graphite_shared_context()); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 351 | auto recording = |
| 352 | shared_context_state_->gpu_main_graphite_recorder()->snap(); |
| 353 | if (recording) { |
| 354 | skgpu::graphite::InsertRecordingInfo info = {}; |
| 355 | info.fRecording = recording.get(); |
| 356 | info.fFinishedProc = [](void* context, skgpu::CallbackResult result) { |
| 357 | RasterCommandsCompletedQuery::FinishedProc(context); |
| 358 | }; |
| 359 | info.fFinishedContext = new base::WeakPtr<RasterCommandsCompletedQuery>( |
| 360 | weak_ptr_factory_.GetWeakPtr()); |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 361 | shared_context_state_->graphite_shared_context()->insertRecording(info); |
Le Hoang Quyen | a3f3304 | 2025-06-07 02:05:34 | [diff] [blame] | 362 | |
Le Hoang Quyen | a3f3304 | 2025-06-07 02:05:34 | [diff] [blame] | 363 | // Canvas typically uses Commands Completed query to implement |
| 364 | // backpressures. We need to flush any delayed commands to make sure the |
| 365 | // query can be completed in finite time. |
| 366 | // Furthermore, some websites use setTimeout() to implement canvas' |
| 367 | // rendering loop. Hence within a vsync interval, a canvas could be |
| 368 | // redrawn multiple times. Flushing here ensures that we send the draw |
| 369 | // commands to GPU earlier, reducing the chance the canvas' rate limiter |
| 370 | // kicks in. |
Le Hoang Quyen | 63c9ca0 | 2025-07-17 15:56:30 | [diff] [blame] | 371 | shared_context_state_->graphite_shared_context() |
| 372 | ->submitAndFlushBackend(); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 373 | } else { |
| 374 | finished_ = true; |
| 375 | } |
| 376 | } |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | void QueryCounter(base::subtle::Atomic32 submit_count) override { |
Peter BostrÃļm | a11556e | 2024-10-31 04:49:10 | [diff] [blame] | 380 | NOTREACHED(); |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void Pause() override { MarkAsPaused(); } |
| 384 | |
| 385 | void Resume() override { MarkAsActive(); } |
| 386 | |
| 387 | void Process(bool did_finish) override { |
| 388 | DCHECK(begin_time_); |
Peng Huang | 63ef887 | 2021-06-17 22:31:20 | [diff] [blame] | 389 | if (did_finish || finished_) { |
| 390 | const base::TimeDelta elapsed = base::TimeTicks::Now() - *begin_time_; |
| 391 | MarkAsCompleted(elapsed.InMicroseconds()); |
| 392 | begin_time_.reset(); |
| 393 | } |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void Destroy(bool have_context) override { |
| 397 | if (!IsDeleted()) |
| 398 | MarkAsDeleted(); |
| 399 | } |
| 400 | |
| 401 | protected: |
| 402 | ~RasterCommandsCompletedQuery() override = default; |
| 403 | |
| 404 | private: |
| 405 | static void FinishedProc(void* context) { |
| 406 | auto* weak_ptr = |
| 407 | reinterpret_cast<base::WeakPtr<RasterCommandsCompletedQuery>*>(context); |
| 408 | if (*weak_ptr) |
| 409 | (*weak_ptr)->finished_ = true; |
| 410 | delete weak_ptr; |
| 411 | } |
| 412 | |
| 413 | const scoped_refptr<SharedContextState> shared_context_state_; |
Arthur Sonzogni | 59ac822 | 2023-11-10 09:46:54 | [diff] [blame] | 414 | std::optional<base::TimeTicks> begin_time_; |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 415 | bool finished_ = false; |
| 416 | base::WeakPtrFactory<RasterCommandsCompletedQuery> weak_ptr_factory_{this}; |
| 417 | }; |
| 418 | |
| 419 | class RasterQueryManager : public QueryManager { |
| 420 | public: |
| 421 | explicit RasterQueryManager( |
| 422 | scoped_refptr<SharedContextState> shared_context_state) |
| 423 | : shared_context_state_(std::move(shared_context_state)) {} |
| 424 | ~RasterQueryManager() override = default; |
| 425 | |
| 426 | Query* CreateQuery(GLenum target, |
| 427 | GLuint client_id, |
| 428 | scoped_refptr<gpu::Buffer> buffer, |
| 429 | QuerySync* sync) override { |
| 430 | if (target == GL_COMMANDS_COMPLETED_CHROMIUM && |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 431 | (shared_context_state_->gr_context() || |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 432 | shared_context_state_->graphite_shared_context())) { |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 433 | auto query = base::MakeRefCounted<RasterCommandsCompletedQuery>( |
| 434 | shared_context_state_, this, target, std::move(buffer), sync); |
| 435 | std::pair<QueryMap::iterator, bool> result = |
| 436 | queries_.insert(std::make_pair(client_id, query)); |
| 437 | DCHECK(result.second); |
| 438 | return query.get(); |
| 439 | } |
| 440 | return QueryManager::CreateQuery(target, client_id, std::move(buffer), |
| 441 | sync); |
| 442 | } |
| 443 | |
| 444 | private: |
| 445 | const scoped_refptr<SharedContextState> shared_context_state_; |
| 446 | }; |
| 447 | |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 448 | SkYUVAPixmapInfo::DataType ToSkYUVADataType(viz::SharedImageFormat format) { |
| 449 | switch (format.channel_format()) { |
| 450 | case viz::SharedImageFormat::ChannelFormat::k8: |
| 451 | return SkYUVAPixmapInfo::DataType::kUnorm8; |
| 452 | case viz::SharedImageFormat::ChannelFormat::k10: |
| 453 | return SkYUVAPixmapInfo::DataType::kUnorm10_Unorm2; |
| 454 | case viz::SharedImageFormat::ChannelFormat::k16: |
| 455 | return SkYUVAPixmapInfo::DataType::kUnorm16; |
| 456 | case viz::SharedImageFormat::ChannelFormat::k16F: |
| 457 | return SkYUVAPixmapInfo::DataType::kFloat16; |
| 458 | } |
Peter BostrÃļm | 01ab59a | 2024-08-15 02:39:49 | [diff] [blame] | 459 | NOTREACHED(); |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 460 | } |
| 461 | |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 462 | } // namespace |
| 463 | |
Jonathan Backer | 5ac08a7 | 2018-06-27 16:15:35 | [diff] [blame] | 464 | // RasterDecoderImpl uses two separate state trackers (gpu::gles2::ContextState |
Adlai Holler | c4dea1a9 | 2020-08-04 13:21:55 | [diff] [blame] | 465 | // and GrDirectContext) that cache the current GL driver state. Each class sees |
| 466 | // 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] | 467 | // state. We guard against that by resetting. But resetting is expensive, so we |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 468 | // avoid it as much as possible. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 469 | class RasterDecoderImpl final : public RasterDecoder, |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 470 | public gles2::ErrorStateClient, |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 471 | public ServiceFontManager::Client, |
| 472 | public SharedContextState::ContextLostObserver { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 473 | public: |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 474 | RasterDecoderImpl(DecoderClient* client, |
| 475 | CommandBufferServiceBase* command_buffer_service, |
| 476 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 477 | const GpuFeatureInfo& gpu_feature_info, |
| 478 | const GpuPreferences& gpu_preferences, |
Maggie Chen | 40af1efa | 2025-06-04 18:19:57 | [diff] [blame] | 479 | scoped_refptr<MemoryTracker> memory_tracker, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 480 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 481 | scoped_refptr<SharedContextState> shared_context_state, |
| 482 | bool is_privileged); |
Peter BostrÃļm | dbacdc2 | 2021-09-23 22:11:46 | [diff] [blame] | 483 | |
| 484 | RasterDecoderImpl(const RasterDecoderImpl&) = delete; |
| 485 | RasterDecoderImpl& operator=(const RasterDecoderImpl&) = delete; |
| 486 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 487 | ~RasterDecoderImpl() override; |
| 488 | |
Vasiliy Telezhnikov | 5816c660 | 2025-09-05 17:32:41 | [diff] [blame] | 489 | // RasterDecoder implementation. |
| 490 | ContextResult Initialize(bool enable_gpu_rasterization, |
| 491 | bool lose_context_when_out_of_memory) override; |
| 492 | int GetRasterDecoderId() const override; |
| 493 | int DecoderIdForTest() override; |
| 494 | ServiceTransferCache* GetTransferCacheForTest() override; |
| 495 | void SetUpForRasterCHROMIUMForTest() override; |
| 496 | void SetOOMErrorForTest() override; |
| 497 | void DisableFlushWorkaroundForTest() override; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 498 | gles2::GLES2Util* GetGLES2Util() override { return &util_; } |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 499 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 500 | // DecoderContext implementation. |
| 501 | base::WeakPtr<DecoderContext> AsWeakPtr() override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 502 | void Destroy(bool have_context) override; |
| 503 | bool MakeCurrent() override; |
| 504 | gl::GLContext* GetGLContext() override; |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 505 | gl::GLSurface* GetGLSurface() override; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 506 | const gles2::FeatureInfo* GetFeatureInfo() const override { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 507 | return feature_info(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 508 | } |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 509 | Capabilities GetCapabilities() override; |
Saifuddin Hitawala | b2da4f0 | 2023-10-04 15:36:46 | [diff] [blame] | 510 | GLCapabilities GetGLCapabilities() override; |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 511 | const gles2::ContextState* GetContextState() override; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 512 | |
| 513 | // TODO(penghuang): Remove unused context state related methods. |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 514 | void RestoreGlobalState() const override; |
| 515 | void ClearAllAttributes() const override; |
| 516 | void RestoreAllAttributes() const override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 517 | void RestoreState(const gles2::ContextState* prev_state) override; |
| 518 | void RestoreActiveTexture() const override; |
| 519 | void RestoreAllTextureUnitAndSamplerBindings( |
| 520 | const gles2::ContextState* prev_state) const override; |
| 521 | void RestoreActiveTextureUnitBinding(unsigned int target) const override; |
| 522 | void RestoreBufferBinding(unsigned int target) override; |
| 523 | void RestoreBufferBindings() const override; |
| 524 | void RestoreFramebufferBindings() const override; |
| 525 | void RestoreRenderbufferBindings() override; |
| 526 | void RestoreProgramBindings() const override; |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 527 | void RestoreTextureState(unsigned service_id) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 528 | void RestoreTextureUnitBindings(unsigned unit) const override; |
| 529 | void RestoreVertexAttribArray(unsigned index) override; |
| 530 | void RestoreAllExternalTextureBindingsIfNeeded() override; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 531 | QueryManager* GetQueryManager() override; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 532 | |
Geoff Lang | 85287e1 | 2018-05-22 17:26:40 | [diff] [blame] | 533 | void SetQueryCallback(unsigned int query_client_id, |
| 534 | base::OnceClosure callback) override; |
Jeffrey Cohen | 11a6cad | 2023-07-10 19:56:18 | [diff] [blame] | 535 | void CancelAllQueries() override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 536 | gles2::GpuFenceManager* GetGpuFenceManager() override; |
| 537 | bool HasPendingQueries() const override; |
| 538 | void ProcessPendingQueries(bool did_finish) override; |
| 539 | bool HasMoreIdleWork() const override; |
| 540 | void PerformIdleWork() override; |
| 541 | bool HasPollingWork() const override; |
| 542 | void PerformPollingWork() override; |
| 543 | TextureBase* GetTextureBase(uint32_t client_id) override; |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 544 | void SetLevelInfo(uint32_t client_id, |
| 545 | int level, |
| 546 | unsigned internal_format, |
| 547 | unsigned width, |
| 548 | unsigned height, |
| 549 | unsigned depth, |
| 550 | unsigned format, |
| 551 | unsigned type, |
| 552 | const gfx::Rect& cleared_rect) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 553 | bool WasContextLost() const override; |
| 554 | bool WasContextLostByRobustnessExtension() const override; |
| 555 | void MarkContextLost(error::ContextLostReason reason) override; |
| 556 | bool CheckResetStatus() override; |
| 557 | void BeginDecoding() override; |
| 558 | void EndDecoding() override; |
| 559 | const char* GetCommandName(unsigned int command_id) const; |
| 560 | error::Error DoCommands(unsigned int num_commands, |
| 561 | const volatile void* buffer, |
| 562 | int num_entries, |
| 563 | int* entries_processed) override; |
Helmut Januschka | b81e97dc | 2024-04-17 14:57:05 | [diff] [blame] | 564 | std::string_view GetLogPrefix() override; |
Colin Blundell | ddd83e0 | 2022-11-30 13:40:16 | [diff] [blame] | 565 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 566 | gles2::ContextGroup* GetContextGroup() override; |
| 567 | gles2::ErrorState* GetErrorState() override; |
Vasiliy Telezhnikov | e4fc4679 | 2024-04-17 19:03:48 | [diff] [blame] | 568 | |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 569 | bool IsCompressedTextureFormat(unsigned format) override; |
| 570 | bool ClearLevel(gles2::Texture* texture, |
| 571 | unsigned target, |
| 572 | int level, |
| 573 | unsigned format, |
| 574 | unsigned type, |
| 575 | int xoffset, |
| 576 | int yoffset, |
| 577 | int width, |
| 578 | int height) override; |
| 579 | bool ClearCompressedTextureLevel(gles2::Texture* texture, |
| 580 | unsigned target, |
| 581 | int level, |
| 582 | unsigned format, |
| 583 | int width, |
| 584 | int height) override; |
shrekshao | ad452548 | 2020-03-12 00:30:55 | [diff] [blame] | 585 | bool ClearCompressedTextureLevel3D(gles2::Texture* texture, |
| 586 | unsigned target, |
| 587 | int level, |
| 588 | unsigned format, |
| 589 | int width, |
| 590 | int height, |
| 591 | int depth) override; |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 592 | bool ClearLevel3D(gles2::Texture* texture, |
| 593 | unsigned target, |
| 594 | int level, |
| 595 | unsigned format, |
| 596 | unsigned type, |
| 597 | int width, |
| 598 | int height, |
| 599 | int depth) override { |
| 600 | NOTIMPLEMENTED(); |
| 601 | return false; |
| 602 | } |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 603 | |
| 604 | // ErrorClientState implementation. |
| 605 | void OnContextLostError() override; |
| 606 | void OnOutOfMemoryError() override; |
| 607 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 608 | gles2::Logger* GetLogger() override; |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 609 | |
| 610 | void SetIgnoreCachedStateForTest(bool ignore) override; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 611 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 612 | // ServiceFontManager::Client implementation. |
| 613 | scoped_refptr<Buffer> GetShmBuffer(uint32_t shm_id) override; |
Khushal | 39641b9 | 2019-06-03 21:32:54 | [diff] [blame] | 614 | void ReportProgress() override; |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 615 | |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 616 | // SharedContextState::ContextLostObserver implementation. |
| 617 | void OnContextLost() override; |
| 618 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 619 | private: |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 620 | gles2::ContextState* state() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 621 | if (use_passthrough_) { |
Peter BostrÃļm | a11556e | 2024-10-31 04:49:10 | [diff] [blame] | 622 | NOTREACHED(); |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 623 | } |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 624 | return shared_context_state_->context_state(); |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 625 | } |
Adlai Holler | c4dea1a9 | 2020-08-04 13:21:55 | [diff] [blame] | 626 | GrDirectContext* gr_context() const { |
| 627 | return shared_context_state_->gr_context(); |
| 628 | } |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 629 | GraphiteSharedContext* graphite_shared_context() const { |
| 630 | return shared_context_state_->graphite_shared_context(); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 631 | } |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 632 | skgpu::graphite::Recorder* graphite_recorder() const { |
| 633 | return shared_context_state_->gpu_main_graphite_recorder(); |
| 634 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 635 | ServiceTransferCache* transfer_cache() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 636 | return shared_context_state_->transfer_cache(); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 637 | } |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 638 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 639 | const gles2::FeatureInfo* feature_info() const { |
| 640 | return shared_context_state_->feature_info(); |
| 641 | } |
| 642 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 643 | const gles2::FeatureInfo::FeatureFlags& features() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 644 | return feature_info()->feature_flags(); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 645 | } |
| 646 | |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 647 | const GpuDriverBugWorkarounds& workarounds() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 648 | return feature_info()->workarounds(); |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 649 | } |
| 650 | |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 651 | void FlushToWorkAroundMacCrashes() { |
Scott Violet | 0430768f | 2022-09-29 00:26:58 | [diff] [blame] | 652 | // The workaround is not needed for arm based macs (because they don't have |
| 653 | // the bug). |
| 654 | #if BUILDFLAG(IS_MAC) && !defined(ARCH_CPU_ARM64) |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 655 | // The workaround is also not needed for Graphite, which always uses Metal |
| 656 | // drivers (via Dawn). |
| 657 | if (!shared_context_state_->GrContextIsGL()) { |
Christopher Cameron | f787d0b | 2019-05-15 23:52:18 | [diff] [blame] | 658 | return; |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 659 | } |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 660 | // This function does aggressive flushes to work around crashes in the |
| 661 | // macOS OpenGL driver. |
| 662 | // https://crbug.com/906453 |
| 663 | if (!flush_workaround_disabled_for_test_) { |
Khushal Sagar | 70ac8913 | 2020-04-17 19:48:42 | [diff] [blame] | 664 | TRACE_EVENT0("gpu", "RasterDecoderImpl::FlushToWorkAroundMacCrashes"); |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 665 | if (gr_context()) |
Kevin Lubick | 3aeaf2b8 | 2023-09-08 18:37:08 | [diff] [blame] | 666 | gr_context()->flushAndSubmit(GrSyncCpu::kNo); |
Sunny Sachanandani | 46df8ac | 2023-09-06 23:18:43 | [diff] [blame] | 667 | |
| 668 | gl::GLApi* const api = gl::g_current_gl_context; |
| 669 | api->glFlushFn(); |
Khushal | d15c591 | 2019-06-14 17:51:04 | [diff] [blame] | 670 | |
| 671 | // Flushes can be expensive, yield to allow interruption after each flush. |
| 672 | ExitCommandProcessingEarly(); |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 673 | } |
| 674 | #endif |
| 675 | } |
| 676 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 677 | const gl::GLVersionInfo& gl_version_info() { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 678 | return feature_info()->gl_version_info(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 679 | } |
| 680 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 681 | // Set remaining commands to process to 0 to force DoCommands to return |
| 682 | // and allow context preemption and GPU watchdog checks in |
| 683 | // CommandExecutor(). |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 684 | void ExitCommandProcessingEarly() override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 685 | |
| 686 | template <bool DebugImpl> |
| 687 | error::Error DoCommandsImpl(unsigned int num_commands, |
| 688 | const volatile void* buffer, |
| 689 | int num_entries, |
| 690 | int* entries_processed); |
| 691 | |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 692 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 693 | void DeleteQueriesEXTHelper(GLsizei n, const volatile GLuint* client_ids); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 694 | void DoFinish(); |
| 695 | void DoFlush(); |
| 696 | void DoGetIntegerv(GLenum pname, GLint* params, GLsizei params_size); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 697 | void DoTraceEndCHROMIUM(); |
Saifuddin Hitawala | 20790cb | 2023-01-31 17:01:12 | [diff] [blame] | 698 | void DoCopySharedImageINTERNAL(GLint xoffset, |
| 699 | GLint yoffset, |
| 700 | GLint x, |
| 701 | GLint y, |
Ilya Nikolaevskiy | 18fd297 | 2025-09-09 17:19:46 | [diff] [blame] | 702 | GLsizei src_width, |
| 703 | GLsizei src_height, |
| 704 | GLsizei dst_width, |
| 705 | GLsizei dst_height, |
Saifuddin Hitawala | 20790cb | 2023-01-31 17:01:12 | [diff] [blame] | 706 | const volatile GLbyte* mailboxes); |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 707 | void DoWritePixelsINTERNAL(GLint x_offset, |
| 708 | GLint y_offset, |
| 709 | GLuint src_width, |
| 710 | GLuint src_height, |
| 711 | GLuint row_bytes, |
| 712 | GLuint src_sk_color_type, |
| 713 | GLuint src_sk_alpha_type, |
| 714 | GLint shm_id, |
| 715 | GLuint shm_offset, |
| 716 | GLuint shm_size, |
| 717 | const volatile GLbyte* mailbox); |
Saifuddin Hitawala | 9d8a52dd | 2023-06-26 20:21:37 | [diff] [blame] | 718 | void DoWritePixelsYUVINTERNAL(GLuint src_width, |
| 719 | GLuint src_height, |
| 720 | GLuint src_row_bytes_plane1, |
| 721 | GLuint src_row_bytes_plane2, |
| 722 | GLuint src_row_bytes_plane3, |
| 723 | GLuint src_row_bytes_plane4, |
| 724 | GLuint src_yuv_plane_config, |
| 725 | GLuint src_yuv_subsampling, |
| 726 | GLuint src_yuv_color_space, |
| 727 | GLint shm_id, |
| 728 | GLuint shm_offset, |
| 729 | GLuint plane2_offset, |
| 730 | GLuint plane3_offset, |
| 731 | GLuint plane4_offset, |
| 732 | const volatile GLbyte* mailbox); |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 733 | bool DoWritePixelsINTERNALDirectTextureUpload( |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 734 | SkiaImageRepresentation* dest_shared_image, |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 735 | const SkImageInfo& src_info, |
| 736 | const void* pixel_data, |
| 737 | size_t row_bytes); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 738 | void DoReadbackARGBImagePixelsINTERNAL(GLint src_x, |
| 739 | GLint src_y, |
Saifuddin Hitawala | f32b28c | 2023-02-22 23:30:38 | [diff] [blame] | 740 | GLint plane_index, |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 741 | GLuint dst_width, |
| 742 | GLuint dst_height, |
| 743 | GLuint row_bytes, |
| 744 | GLuint dst_sk_color_type, |
| 745 | GLuint dst_sk_alpha_type, |
| 746 | GLint shm_id, |
| 747 | GLuint shm_offset, |
| 748 | GLuint color_space_offset, |
| 749 | GLuint pixels_offset, |
| 750 | const volatile GLbyte* mailbox); |
| 751 | void DoReadbackYUVImagePixelsINTERNAL(GLuint dst_width, |
| 752 | GLuint dst_height, |
| 753 | GLint shm_id, |
| 754 | GLuint shm_offset, |
| 755 | GLuint y_offset, |
| 756 | GLuint y_stride, |
| 757 | GLuint u_offset, |
| 758 | GLuint u_stride, |
| 759 | GLuint v_offset, |
| 760 | GLuint v_stride, |
| 761 | const volatile GLbyte* mailbox); |
Christopher Cameron | a78f1e3c | 2021-08-13 19:13:44 | [diff] [blame] | 762 | |
Jonah Chin | 053aa6c | 2021-01-22 20:26:14 | [diff] [blame] | 763 | void DoLoseContextCHROMIUM(GLenum current, GLenum other); |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 764 | void DoBeginRasterCHROMIUM(GLfloat r, |
| 765 | GLfloat g, |
| 766 | GLfloat b, |
| 767 | GLfloat a, |
Sunny Sachanandani | b461e21 | 2021-03-05 19:22:12 | [diff] [blame] | 768 | GLboolean needs_clear, |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 769 | GLuint msaa_sample_count, |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 770 | MsaaMode msaa_mode, |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 771 | GLboolean can_use_lcd_text, |
Peng Huang | 5ff70dff | 2022-03-03 19:55:11 | [diff] [blame] | 772 | GLboolean visible, |
Christopher Cameron | 060d382e7 | 2023-10-04 23:12:42 | [diff] [blame] | 773 | GLfloat hdr_headroom, |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 774 | const volatile GLbyte* key); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 775 | error::Error DoRasterCHROMIUM(GLuint raster_shm_id, |
| 776 | GLuint raster_shm_offset, |
| 777 | GLuint raster_shm_size, |
| 778 | GLuint font_shm_id, |
| 779 | GLuint font_shm_offset, |
| 780 | GLuint font_shm_size); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 781 | void DoEndRasterCHROMIUM(); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 782 | void DoCreateTransferCacheEntryINTERNAL(GLuint entry_type, |
| 783 | GLuint entry_id, |
| 784 | GLuint handle_shm_id, |
| 785 | GLuint handle_shm_offset, |
| 786 | GLuint data_shm_id, |
| 787 | GLuint data_shm_offset, |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 788 | GLuint data_size); |
| 789 | void DoUnlockTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id); |
| 790 | void DoDeleteTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 791 | void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 792 | void DeletePaintCachePathsINTERNALHelper( |
| 793 | GLsizei n, |
| 794 | const volatile GLuint* paint_cache_ids); |
William Liu | 88a553387 | 2025-03-18 19:11:47 | [diff] [blame] | 795 | void DeletePaintCacheEffectsINTERNALHelper( |
| 796 | GLsizei n, |
| 797 | const volatile GLuint* paint_cache_ids); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 798 | void DoClearPaintCacheINTERNAL(); |
Vikas Soni | ca02287b | 2022-01-18 20:17:35 | [diff] [blame] | 799 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 800 | #if defined(NDEBUG) |
| 801 | void LogClientServiceMapping(const char* /* function_name */, |
| 802 | GLuint /* client_id */, |
| 803 | GLuint /* service_id */) {} |
| 804 | template <typename T> |
| 805 | void LogClientServiceForInfo(T* /* info */, |
| 806 | GLuint /* client_id */, |
| 807 | const char* /* function_name */) {} |
| 808 | #else |
| 809 | void LogClientServiceMapping(const char* function_name, |
| 810 | GLuint client_id, |
| 811 | GLuint service_id) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 812 | if (gpu_preferences_.enable_gpu_service_logging_gpu) { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 813 | VLOG(1) << "[" << logger_.GetLogPrefix() << "] " << function_name |
| 814 | << ": client_id = " << client_id |
| 815 | << ", service_id = " << service_id; |
| 816 | } |
| 817 | } |
| 818 | template <typename T> |
| 819 | void LogClientServiceForInfo(T* info, |
| 820 | GLuint client_id, |
| 821 | const char* function_name) { |
| 822 | if (info) { |
| 823 | LogClientServiceMapping(function_name, client_id, info->service_id()); |
| 824 | } |
| 825 | } |
| 826 | #endif |
| 827 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 828 | // Generate a member function prototype for each command in an automated and |
| 829 | // typesafe way. |
| 830 | #define RASTER_CMD_OP(name) \ |
| 831 | Error Handle##name(uint32_t immediate_data_size, const volatile void* data); |
| 832 | |
| 833 | RASTER_COMMAND_LIST(RASTER_CMD_OP) |
| 834 | #undef RASTER_CMD_OP |
| 835 | |
| 836 | typedef error::Error (RasterDecoderImpl::*CmdHandler)( |
| 837 | uint32_t immediate_data_size, |
| 838 | const volatile void* data); |
| 839 | |
| 840 | // A struct to hold info about each command. |
| 841 | struct CommandInfo { |
| 842 | CmdHandler cmd_handler; |
| 843 | uint8_t arg_flags; // How to handle the arguments for this command |
| 844 | uint8_t cmd_flags; // How to handle this command |
| 845 | uint16_t arg_count; // How many arguments are expected for this command. |
| 846 | }; |
| 847 | |
| 848 | // A table of CommandInfo for all the commands. |
| 849 | static const CommandInfo command_info[kNumCommands - kFirstRasterCommand]; |
| 850 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 851 | const int raster_decoder_id_; |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 852 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 853 | // Number of commands remaining to be processed in DoCommands(). |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 854 | int commands_to_process_ = 0; |
| 855 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 856 | bool use_gpu_raster_ = false; |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 857 | bool use_passthrough_ = false; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 858 | |
| 859 | // The current decoder error communicates the decoder error through command |
| 860 | // processing functions that do not return the error value. Should be set |
| 861 | // only if not returning an error. |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 862 | error::Error current_decoder_error_ = error::kNoError; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 863 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 864 | GpuPreferences gpu_preferences_; |
| 865 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 866 | gles2::DebugMarkerManager debug_marker_manager_; |
| 867 | gles2::Logger logger_; |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 868 | std::unique_ptr<gles2::ErrorState> error_state_; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 869 | bool context_lost_ = false; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 870 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 871 | scoped_refptr<SharedContextState> shared_context_state_; |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 872 | std::unique_ptr<Validators> validators_; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 873 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 874 | SharedImageRepresentationFactory shared_image_representation_factory_; |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 875 | std::unique_ptr<RasterQueryManager> query_manager_; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 876 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 877 | gles2::GLES2Util util_; |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 878 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 879 | // An optional behaviour to lose the context when OOM. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 880 | bool lose_context_when_out_of_memory_ = false; |
| 881 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 882 | std::unique_ptr<gles2::GPUTracer> gpu_tracer_; |
Ali Hijazi | f5d8b74 | 2024-05-29 16:10:43 | [diff] [blame] | 883 | raw_ptr<const unsigned char> gpu_decoder_category_; |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 884 | static constexpr int gpu_trace_level_ = 2; |
| 885 | bool gpu_trace_commands_ = false; |
| 886 | bool gpu_debug_commands_ = false; |
| 887 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 888 | // Raster helpers. |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 889 | scoped_refptr<ServiceFontManager> font_manager_; |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 890 | std::unique_ptr<SkiaImageRepresentation> shared_image_; |
| 891 | std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess> |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 892 | scoped_shared_image_write_; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 893 | |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 894 | std::unique_ptr<RasterImageRepresentation> shared_image_raster_; |
| 895 | std::unique_ptr<RasterImageRepresentation::ScopedWriteAccess> |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 896 | scoped_shared_image_raster_write_; |
| 897 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 898 | raw_ptr<SkSurface> sk_surface_ = nullptr; |
Christopher Cameron | 578e3dd | 2023-10-06 09:34:07 | [diff] [blame] | 899 | float sk_surface_hdr_headroom_ = 1.f; |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 900 | std::unique_ptr<SharedImageProviderImpl> paint_op_shared_image_provider_; |
Khushal Sagar | 4bb1c12 | 2020-05-12 20:17:08 | [diff] [blame] | 901 | |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 902 | sk_sp<SkSurface> sk_surface_for_testing_; |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 903 | std::vector<GrBackendSemaphore> end_semaphores_; |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 904 | std::unique_ptr<cc::ServicePaintCache> paint_cache_; |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 905 | |
Peng Huang | 38a628064 | 2024-04-16 23:56:55 | [diff] [blame] | 906 | std::unique_ptr<SkNoDrawCanvas> no_draw_canvas_; |
Peng Huang | 23b9be7b | 2022-02-19 01:05:41 | [diff] [blame] | 907 | raw_ptr<SkCanvas> raster_canvas_ = nullptr; |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 908 | std::vector<SkDiscardableHandleId> locked_handles_; |
Jonathan Backer | 4fb9f5acb | 2018-05-10 22:19:33 | [diff] [blame] | 909 | |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 910 | // Cached value of `kGpuYieldRasterizationOpCount`. This is only set if |
| 911 | // `kGpuYieldRasterization` is enabled. |
| 912 | std::optional<int> check_for_yield_op_count_; |
| 913 | |
| 914 | // If set, indicates rasterization was deferred. The value gives how far into |
| 915 | // the buffer was processed. |
| 916 | std::optional<size_t> deferred_raster_paint_buffer_offset_; |
| 917 | |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 918 | // Tracing helpers. |
| 919 | int raster_chromium_id_ = 0; |
| 920 | |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 921 | // Workaround for https://crbug.com/906453 |
| 922 | bool flush_workaround_disabled_for_test_ = false; |
| 923 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 924 | bool in_copy_sub_texture_ = false; |
| 925 | bool reset_texture_state_ = false; |
| 926 | |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 927 | bool is_privileged_ = false; |
| 928 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 929 | const bool is_raw_draw_enabled_; |
| 930 | |
Jeremy Roman | 28926e9 | 2019-07-15 15:42:16 | [diff] [blame] | 931 | base::WeakPtrFactory<DecoderContext> weak_ptr_factory_{this}; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 932 | }; |
| 933 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 934 | constexpr RasterDecoderImpl::CommandInfo RasterDecoderImpl::command_info[] = { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 935 | #define RASTER_CMD_OP(name) \ |
| 936 | { \ |
| 937 | &RasterDecoderImpl::Handle##name, \ |
| 938 | cmds::name::kArgFlags, \ |
| 939 | cmds::name::cmd_flags, \ |
| 940 | sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 941 | }, /* NOLINT */ |
| 942 | RASTER_COMMAND_LIST(RASTER_CMD_OP) |
| 943 | #undef RASTER_CMD_OP |
| 944 | }; |
| 945 | |
| 946 | // static |
Vasiliy Telezhnikov | 1bb704f | 2025-09-05 17:49:35 | [diff] [blame] | 947 | std::unique_ptr<RasterDecoder> RasterDecoder::Create( |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 948 | DecoderClient* client, |
| 949 | CommandBufferServiceBase* command_buffer_service, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 950 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 951 | const GpuFeatureInfo& gpu_feature_info, |
| 952 | const GpuPreferences& gpu_preferences, |
Maggie Chen | 40af1efa | 2025-06-04 18:19:57 | [diff] [blame] | 953 | scoped_refptr<MemoryTracker> memory_tracker, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 954 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 955 | scoped_refptr<SharedContextState> shared_context_state, |
| 956 | bool is_privileged) { |
Vasiliy Telezhnikov | 1bb704f | 2025-09-05 17:49:35 | [diff] [blame] | 957 | return std::make_unique<RasterDecoderImpl>( |
| 958 | client, command_buffer_service, outputter, gpu_feature_info, |
| 959 | gpu_preferences, std::move(memory_tracker), shared_image_manager, |
| 960 | std::move(shared_context_state), is_privileged); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 961 | } |
| 962 | |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 963 | RasterDecoder::RasterDecoder(DecoderClient* client, |
| 964 | CommandBufferServiceBase* command_buffer_service, |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 965 | gles2::Outputter* outputter) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 966 | : CommonDecoder(client, command_buffer_service), outputter_(outputter) {} |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 967 | |
| 968 | RasterDecoder::~RasterDecoder() {} |
| 969 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 970 | bool RasterDecoder::initialized() const { |
| 971 | return initialized_; |
| 972 | } |
| 973 | |
| 974 | TextureBase* RasterDecoder::GetTextureBase(uint32_t client_id) { |
| 975 | return nullptr; |
| 976 | } |
| 977 | |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 978 | void RasterDecoder::SetLevelInfo(uint32_t client_id, |
| 979 | int level, |
| 980 | unsigned internal_format, |
| 981 | unsigned width, |
| 982 | unsigned height, |
| 983 | unsigned depth, |
| 984 | unsigned format, |
| 985 | unsigned type, |
| 986 | const gfx::Rect& cleared_rect) {} |
| 987 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 988 | void RasterDecoder::BeginDecoding() {} |
| 989 | |
| 990 | void RasterDecoder::EndDecoding() {} |
| 991 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 992 | void RasterDecoder::SetLogCommands(bool log_commands) { |
| 993 | log_commands_ = log_commands; |
| 994 | } |
| 995 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 996 | gles2::Outputter* RasterDecoder::outputter() const { |
| 997 | return outputter_; |
| 998 | } |
| 999 | |
Helmut Januschka | b81e97dc | 2024-04-17 14:57:05 | [diff] [blame] | 1000 | std::string_view RasterDecoder::GetLogPrefix() { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1001 | return GetLogger()->GetLogPrefix(); |
| 1002 | } |
| 1003 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1004 | RasterDecoderImpl::RasterDecoderImpl( |
| 1005 | DecoderClient* client, |
| 1006 | CommandBufferServiceBase* command_buffer_service, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1007 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1008 | const GpuFeatureInfo& gpu_feature_info, |
| 1009 | const GpuPreferences& gpu_preferences, |
Maggie Chen | 40af1efa | 2025-06-04 18:19:57 | [diff] [blame] | 1010 | scoped_refptr<MemoryTracker> memory_tracker, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1011 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame] | 1012 | scoped_refptr<SharedContextState> shared_context_state, |
| 1013 | bool is_privileged) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1014 | : RasterDecoder(client, command_buffer_service, outputter), |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 1015 | raster_decoder_id_(g_raster_decoder_id.GetNext() + 1), |
Zhenyao Mo | ed03688 | 2025-02-05 00:05:04 | [diff] [blame] | 1016 | use_passthrough_(gpu_preferences.use_passthrough_cmd_decoder), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1017 | gpu_preferences_(gpu_preferences), |
Peng Huang | 61eccfe4 | 2018-11-15 22:10:13 | [diff] [blame] | 1018 | logger_(&debug_marker_manager_, |
| 1019 | base::BindRepeating(&DecoderClient::OnConsoleMessage, |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1020 | base::Unretained(client), |
James Darpinian | 104af6f | 2018-12-06 03:24:55 | [diff] [blame] | 1021 | 0), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1022 | gpu_preferences_.disable_gl_error_limit), |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 1023 | error_state_(gles2::ErrorState::Create(this, &logger_)), |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1024 | shared_context_state_(std::move(shared_context_state)), |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 1025 | validators_(new Validators), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1026 | shared_image_representation_factory_(shared_image_manager, |
Maggie Chen | 40af1efa | 2025-06-04 18:19:57 | [diff] [blame] | 1027 | std::move(memory_tracker)), |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1028 | gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
Miguel Casas | 510fbfcb | 2018-11-13 23:40:57 | [diff] [blame] | 1029 | TRACE_DISABLED_BY_DEFAULT("gpu.decoder"))), |
Vikas Soni | 2a4039f | 2020-07-22 18:34:20 | [diff] [blame] | 1030 | font_manager_(base::MakeRefCounted<ServiceFontManager>( |
| 1031 | this, |
| 1032 | gpu_preferences_.disable_oopr_debug_crash_dump)), |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 1033 | is_privileged_(is_privileged), |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 1034 | is_raw_draw_enabled_(features::IsUsingRawDraw()) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1035 | DCHECK(shared_context_state_); |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1036 | shared_context_state_->AddContextLostObserver(this); |
Peng Huang | 38a628064 | 2024-04-16 23:56:55 | [diff] [blame] | 1037 | const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 1038 | if (cmdline->HasSwitch(switches::kDisableGLDrawingForTests)) { |
| 1039 | no_draw_canvas_ = std::make_unique<SkNoDrawCanvas>(0, 0); |
| 1040 | } |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 1041 | if (base::FeatureList::IsEnabled(kGpuYieldRasterization)) { |
| 1042 | check_for_yield_op_count_ = kGpuYieldRasterizationOpCount.Get(); |
| 1043 | } |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 1044 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1045 | |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1046 | RasterDecoderImpl::~RasterDecoderImpl() { |
| 1047 | shared_context_state_->RemoveContextLostObserver(this); |
| 1048 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1049 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1050 | base::WeakPtr<DecoderContext> RasterDecoderImpl::AsWeakPtr() { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1051 | return weak_ptr_factory_.GetWeakPtr(); |
| 1052 | } |
| 1053 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1054 | ContextResult RasterDecoderImpl::Initialize( |
Vasiliy Telezhnikov | 5816c660 | 2025-09-05 17:32:41 | [diff] [blame] | 1055 | bool enable_gpu_rasterization, |
| 1056 | bool lose_context_when_out_of_memory) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1057 | TRACE_EVENT0("gpu", "RasterDecoderImpl::Initialize"); |
Jonathan Backer | 19258679 | 2019-12-18 16:36:33 | [diff] [blame] | 1058 | DCHECK(shared_context_state_->IsCurrent(nullptr)); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1059 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1060 | set_initialized(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1061 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1062 | if (gpu_preferences_.enable_gpu_debugging) |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1063 | set_debug(true); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1064 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1065 | if (gpu_preferences_.enable_gpu_command_logging) |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1066 | SetLogCommands(true); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1067 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1068 | // Create GPU Tracer for timing values. |
Peter BostrÃļm | 1aa21c14 | 2021-04-03 01:12:03 | [diff] [blame] | 1069 | gpu_tracer_ = std::make_unique<gles2::GPUTracer>( |
| 1070 | this, shared_context_state_->GrContextIsGL()); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1071 | |
Vasiliy Telezhnikov | 5816c660 | 2025-09-05 17:32:41 | [diff] [blame] | 1072 | lose_context_when_out_of_memory_ = lose_context_when_out_of_memory; |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1073 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1074 | CHECK_GL_ERROR(); |
| 1075 | |
Peng Huang | 7bb7db4b | 2021-06-16 15:30:02 | [diff] [blame] | 1076 | query_manager_ = std::make_unique<RasterQueryManager>(shared_context_state_); |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1077 | |
Vasiliy Telezhnikov | 5816c660 | 2025-09-05 17:32:41 | [diff] [blame] | 1078 | if (enable_gpu_rasterization) { |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 1079 | DCHECK(gr_context() || graphite_shared_context()); |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1080 | use_gpu_raster_ = true; |
| 1081 | paint_cache_ = std::make_unique<cc::ServicePaintCache>(); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 1082 | } |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1083 | |
| 1084 | return ContextResult::kSuccess; |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1085 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1086 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1087 | void RasterDecoderImpl::Destroy(bool have_context) { |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1088 | if (!initialized()) |
| 1089 | return; |
| 1090 | |
Sunny Sachanandani | e00e86fb | 2024-07-18 14:36:41 | [diff] [blame] | 1091 | DCHECK(!have_context || shared_context_state_->IsCurrent(nullptr)); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1092 | |
Vasiliy Telezhnikov | 91d1881 | 2023-02-02 21:21:26 | [diff] [blame] | 1093 | // Client can call BeginRasterChromium and then channel can be closed and |
| 1094 | // decoder destroyed. Finish raster first. |
| 1095 | // Note: `have_context` is always false for Vulkan, so we don't gate this code |
| 1096 | // on it. |
| 1097 | if (sk_surface_ || scoped_shared_image_raster_write_) { |
| 1098 | DoEndRasterCHROMIUM(); |
| 1099 | } |
| 1100 | |
Geoff Lang | 615cca2 | 2025-04-07 18:03:45 | [diff] [blame] | 1101 | if (have_context && use_gpu_raster_ && transfer_cache()) { |
| 1102 | transfer_cache()->DeleteAllEntriesForDecoder(raster_decoder_id_); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1103 | } |
| 1104 | |
Peng Huang | 95a63e4b | 2020-07-03 21:28:11 | [diff] [blame] | 1105 | if (query_manager_) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1106 | query_manager_->Destroy(have_context); |
| 1107 | query_manager_.reset(); |
| 1108 | } |
| 1109 | |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 1110 | font_manager_->Destroy(); |
| 1111 | font_manager_.reset(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1112 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1113 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1114 | // Make this decoder's GL context current. |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1115 | bool RasterDecoderImpl::MakeCurrent() { |
Christopher Cameron | dd7812d | 2019-04-23 03:12:21 | [diff] [blame] | 1116 | if (!shared_context_state_->GrContextIsGL()) |
Jonathan Backer | 7621ec9 | 2018-12-11 00:02:44 | [diff] [blame] | 1117 | return true; |
| 1118 | |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1119 | if (context_lost_) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1120 | LOG(ERROR) << " RasterDecoderImpl: Trying to make lost context current."; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1121 | return false; |
| 1122 | } |
| 1123 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1124 | if (shared_context_state_->context_lost() || |
| 1125 | !shared_context_state_->MakeCurrent(nullptr)) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1126 | LOG(ERROR) << " RasterDecoderImpl: Context lost during MakeCurrent."; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1127 | return false; |
| 1128 | } |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1129 | |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1130 | // Rebind textures if the service ids may have changed. |
| 1131 | RestoreAllExternalTextureBindingsIfNeeded(); |
| 1132 | |
Vasiliy Telezhnikov | 751b536 | 2021-09-14 13:35:49 | [diff] [blame] | 1133 | // We're going to use skia, so make sure we reset context afterwards. |
| 1134 | shared_context_state_->set_need_context_state_reset(true); |
| 1135 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1136 | return true; |
| 1137 | } |
| 1138 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1139 | gl::GLContext* RasterDecoderImpl::GetGLContext() { |
Peng Huang | ad7442f | 2020-02-24 22:22:09 | [diff] [blame] | 1140 | return shared_context_state_->GrContextIsGL() |
| 1141 | ? shared_context_state_->context() |
| 1142 | : nullptr; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1143 | } |
| 1144 | |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 1145 | gl::GLSurface* RasterDecoderImpl::GetGLSurface() { |
Peng Huang | ad7442f | 2020-02-24 22:22:09 | [diff] [blame] | 1146 | return shared_context_state_->GrContextIsGL() |
| 1147 | ? shared_context_state_->surface() |
| 1148 | : nullptr; |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 1149 | } |
| 1150 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1151 | Capabilities RasterDecoderImpl::GetCapabilities() { |
Adrienne Walker | 693f34d | 2019-07-29 22:07:04 | [diff] [blame] | 1152 | // TODO(enne): reconcile this with gles2_cmd_decoder's capability settings. |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1153 | Capabilities caps; |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1154 | caps.gpu_rasterization = use_gpu_raster_; |
Antoine Labour | 0f9bee7 | 2018-11-06 07:35:43 | [diff] [blame] | 1155 | caps.gpu_memory_buffer_formats = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1156 | feature_info()->feature_flags().gpu_memory_buffer_formats; |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 1157 | caps.texture_format_bgra8888 = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1158 | feature_info()->feature_flags().ext_texture_format_bgra8888; |
kylechar | 81ac76d | 2023-02-14 21:43:49 | [diff] [blame] | 1159 | caps.texture_rg = feature_info()->feature_flags().ext_texture_rg; |
Sunny Sachanandani | e9ea4a9 | 2023-05-25 19:01:25 | [diff] [blame] | 1160 | caps.max_texture_size = shared_context_state_->GetMaxTextureSize(); |
Vikas Soni | d2adcb24 | 2023-05-25 23:38:27 | [diff] [blame] | 1161 | caps.using_vulkan_context = |
| 1162 | shared_context_state_->GrContextIsVulkan() ? true : false; |
| 1163 | |
Saifuddin Hitawala | 9f18748 | 2023-10-11 22:43:09 | [diff] [blame] | 1164 | caps.max_copy_texture_chromium_size = |
| 1165 | feature_info()->workarounds().max_copy_texture_chromium_size; |
| 1166 | caps.texture_format_etc1_npot = |
| 1167 | feature_info()->feature_flags().oes_compressed_etc1_rgb8_texture && |
| 1168 | !feature_info()->workarounds().etc1_power_of_two_only; |
| 1169 | caps.image_ycbcr_420v = |
| 1170 | feature_info()->feature_flags().chromium_image_ycbcr_420v; |
Saifuddin Hitawala | 9f18748 | 2023-10-11 22:43:09 | [diff] [blame] | 1171 | caps.image_ar30 = feature_info()->feature_flags().chromium_image_ar30; |
| 1172 | caps.image_ab30 = feature_info()->feature_flags().chromium_image_ab30; |
| 1173 | caps.image_ycbcr_p010 = |
| 1174 | feature_info()->feature_flags().chromium_image_ycbcr_p010; |
| 1175 | caps.render_buffer_format_bgra8888 = |
| 1176 | feature_info()->feature_flags().ext_render_buffer_format_bgra8888; |
Saifuddin Hitawala | 899d7f9 | 2025-03-20 22:43:18 | [diff] [blame] | 1177 | |
Saifuddin Hitawala | 9f18748 | 2023-10-11 22:43:09 | [diff] [blame] | 1178 | caps.angle_rgbx_internal_format = |
| 1179 | feature_info()->feature_flags().angle_rgbx_internal_format; |
| 1180 | caps.chromium_gpu_fence = feature_info()->feature_flags().chromium_gpu_fence; |
| 1181 | caps.mesa_framebuffer_flip_y = |
| 1182 | feature_info()->feature_flags().mesa_framebuffer_flip_y; |
| 1183 | |
Bo Liu | 1e4cf91 | 2022-06-27 16:38:54 | [diff] [blame] | 1184 | if (feature_info()->workarounds().webgl_or_caps_max_texture_size) { |
Bo Liu | f2f4c6d | 2022-04-28 20:34:45 | [diff] [blame] | 1185 | caps.max_texture_size = |
| 1186 | std::min(caps.max_texture_size, |
Bo Liu | 1e4cf91 | 2022-06-27 16:38:54 | [diff] [blame] | 1187 | feature_info()->workarounds().webgl_or_caps_max_texture_size); |
James Darpinian | 3c42203 | 2019-04-06 00:20:16 | [diff] [blame] | 1188 | } |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1189 | caps.sync_query = feature_info()->feature_flags().chromium_sync_query; |
Justin Novosad | 5730d36 | 2023-07-19 22:05:47 | [diff] [blame] | 1190 | caps.msaa_is_slow = gles2::MSAAIsSlow(feature_info()->workarounds()); |
Adrienne Walker | 693f34d | 2019-07-29 22:07:04 | [diff] [blame] | 1191 | caps.avoid_stencil_buffers = |
| 1192 | feature_info()->workarounds().avoid_stencil_buffers; |
Khushal | 315f2fd | 2018-05-29 03:20:39 | [diff] [blame] | 1193 | |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 1194 | if (gr_context()) { |
Khushal | 315f2fd | 2018-05-29 03:20:39 | [diff] [blame] | 1195 | caps.context_supports_distance_field_text = |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 1196 | gr_context()->supportsDistanceFieldText(); |
Dale Curtis | 816d523 | 2020-07-29 19:31:35 | [diff] [blame] | 1197 | caps.texture_norm16 = |
| 1198 | gr_context()->colorTypeSupportedAsImage(kA16_unorm_SkColorType); |
| 1199 | caps.texture_half_float_linear = |
| 1200 | gr_context()->colorTypeSupportedAsImage(kA16_float_SkColorType); |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 1201 | } else if (graphite_shared_context()) { |
Sunny Sachanandani | f67f495 | 2024-08-16 13:31:34 | [diff] [blame] | 1202 | caps.context_supports_distance_field_text = true; |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1203 | caps.texture_half_float_linear = true; |
Sunny Sachanandani | f67f495 | 2024-08-16 13:31:34 | [diff] [blame] | 1204 | #if BUILDFLAG(SKIA_USE_DAWN) |
| 1205 | if (shared_context_state_->IsGraphiteDawn()) { |
| 1206 | caps.texture_norm16 = |
| 1207 | shared_context_state_->dawn_context_provider()->SupportsFeature( |
| 1208 | wgpu::FeatureName::Unorm16TextureFormats); |
| 1209 | } |
| 1210 | #endif |
| 1211 | #if BUILDFLAG(SKIA_USE_METAL) |
| 1212 | if (shared_context_state_->IsGraphiteMetal()) { |
| 1213 | caps.texture_norm16 = true; |
| 1214 | } |
| 1215 | #endif |
Dale Curtis | 816d523 | 2020-07-29 19:31:35 | [diff] [blame] | 1216 | } else { |
| 1217 | caps.texture_norm16 = feature_info()->feature_flags().ext_texture_norm16; |
| 1218 | caps.texture_half_float_linear = |
| 1219 | feature_info()->feature_flags().enable_texture_half_float_linear; |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 1220 | } |
Saifuddin Hitawala | b0c218e | 2023-10-27 17:25:29 | [diff] [blame] | 1221 | |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 1222 | if (graphite_shared_context()) { |
Saifuddin Hitawala | b0c218e | 2023-10-27 17:25:29 | [diff] [blame] | 1223 | bool supports_multiplanar_rendering = false; |
| 1224 | #if BUILDFLAG(SKIA_USE_DAWN) |
Sunny Sachanandani | f67f495 | 2024-08-16 13:31:34 | [diff] [blame] | 1225 | if (shared_context_state_->IsGraphiteDawn()) { |
| 1226 | supports_multiplanar_rendering = |
| 1227 | shared_context_state_->dawn_context_provider()->SupportsFeature( |
| 1228 | wgpu::FeatureName::MultiPlanarRenderTargets); |
Saifuddin Hitawala | b0c218e | 2023-10-27 17:25:29 | [diff] [blame] | 1229 | } |
| 1230 | #endif |
Vasiliy Telezhnikov | fb8ce25 | 2024-01-02 20:04:18 | [diff] [blame] | 1231 | caps.supports_rgb_to_yuv_conversion = supports_multiplanar_rendering; |
Saifuddin Hitawala | b0c218e | 2023-10-27 17:25:29 | [diff] [blame] | 1232 | caps.supports_yuv_readback = supports_multiplanar_rendering; |
| 1233 | } else { |
Vasiliy Telezhnikov | fb8ce25 | 2024-01-02 20:04:18 | [diff] [blame] | 1234 | caps.supports_rgb_to_yuv_conversion = true; |
Saifuddin Hitawala | b0c218e | 2023-10-27 17:25:29 | [diff] [blame] | 1235 | caps.supports_yuv_readback = true; |
| 1236 | } |
| 1237 | |
Georg Neis | 24b92cc4 | 2025-02-07 04:11:10 | [diff] [blame] | 1238 | #if BUILDFLAG(IS_CHROMEOS) |
Chia-I Wu | ae6d926 | 2023-12-13 01:27:48 | [diff] [blame] | 1239 | if (shared_context_state_->GrContextIsGL()) { |
| 1240 | PopulateDRMCapabilities(&caps, feature_info()); |
| 1241 | } |
| 1242 | #if BUILDFLAG(ENABLE_VULKAN) |
| 1243 | else if (shared_context_state_->GrContextIsVulkan()) { |
| 1244 | auto* device_queue = |
| 1245 | shared_context_state_->vk_context_provider()->GetDeviceQueue(); |
| 1246 | caps.drm_device_id = device_queue->drm_device_id(); |
| 1247 | gpu::PopulateVkDrmFormatsAndModifiers(device_queue, |
| 1248 | caps.drm_formats_and_modifiers); |
| 1249 | } |
| 1250 | #endif // BUILDFLAG(ENABLE_VULKAN) |
Kevin Haslett | 0ae5ba1 | 2024-03-21 20:10:44 | [diff] [blame] | 1251 | #if BUILDFLAG(SKIA_USE_DAWN) |
| 1252 | else if (shared_context_state_->IsGraphiteDawnVulkan()) { |
| 1253 | auto adapter = shared_context_state_->dawn_context_provider() |
| 1254 | ->GetDevice() |
| 1255 | .GetAdapter(); |
| 1256 | gpu::PopulateDawnDrmFormatsAndModifiers(adapter, |
| 1257 | caps.drm_formats_and_modifiers); |
| 1258 | } |
| 1259 | #endif // BUILDFLAG(SKIA_USE_DAWN) |
Chia-I Wu | ae6d926 | 2023-12-13 01:27:48 | [diff] [blame] | 1260 | else { |
Peter BostrÃļm | a11556e | 2024-10-31 04:49:10 | [diff] [blame] | 1261 | NOTREACHED(); |
Chia-I Wu | ae6d926 | 2023-12-13 01:27:48 | [diff] [blame] | 1262 | } |
Georg Neis | 24b92cc4 | 2025-02-07 04:11:10 | [diff] [blame] | 1263 | #endif // BUILDFLAG(IS_CHROMEOS) |
Chia-I Wu | ae6d926 | 2023-12-13 01:27:48 | [diff] [blame] | 1264 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1265 | return caps; |
| 1266 | } |
| 1267 | |
Saifuddin Hitawala | b2da4f0 | 2023-10-04 15:36:46 | [diff] [blame] | 1268 | GLCapabilities RasterDecoderImpl::GetGLCapabilities() { |
| 1269 | return GLCapabilities(); |
| 1270 | } |
| 1271 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 1272 | const gles2::ContextState* RasterDecoderImpl::GetContextState() { |
Peter BostrÃļm | a11556e | 2024-10-31 04:49:10 | [diff] [blame] | 1273 | NOTREACHED(); |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 1274 | } |
| 1275 | |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1276 | void RasterDecoderImpl::RestoreGlobalState() const { |
Peng Huang | d7aaf78 | 2019-01-09 22:03:08 | [diff] [blame] | 1277 | // We mark the context state is dirty instead of restoring global |
| 1278 | // state, and the global state will be restored by the next context. |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1279 | shared_context_state_->set_need_context_state_reset(true); |
| 1280 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1281 | } |
| 1282 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 1283 | void RasterDecoderImpl::ClearAllAttributes() const {} |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1284 | |
| 1285 | void RasterDecoderImpl::RestoreAllAttributes() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1286 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 1287 | } |
| 1288 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1289 | void RasterDecoderImpl::RestoreState(const gles2::ContextState* prev_state) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1290 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1291 | } |
| 1292 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1293 | void RasterDecoderImpl::RestoreActiveTexture() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1294 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1295 | } |
| 1296 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1297 | void RasterDecoderImpl::RestoreAllTextureUnitAndSamplerBindings( |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1298 | const gles2::ContextState* prev_state) const { |
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::RestoreActiveTextureUnitBinding( |
| 1303 | unsigned int target) const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1304 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1305 | } |
| 1306 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1307 | void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) { |
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::RestoreBufferBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1312 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1313 | } |
| 1314 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1315 | void RasterDecoderImpl::RestoreFramebufferBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1316 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1317 | } |
| 1318 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1319 | void RasterDecoderImpl::RestoreRenderbufferBindings() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1320 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1321 | } |
| 1322 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1323 | void RasterDecoderImpl::RestoreProgramBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1324 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1325 | } |
| 1326 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1327 | void RasterDecoderImpl::RestoreTextureState(unsigned service_id) { |
| 1328 | DCHECK(in_copy_sub_texture_); |
| 1329 | reset_texture_state_ = true; |
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::RestoreTextureUnitBindings(unsigned unit) 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 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1336 | void RasterDecoderImpl::RestoreVertexAttribArray(unsigned index) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1337 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1338 | } |
| 1339 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1340 | void RasterDecoderImpl::RestoreAllExternalTextureBindingsIfNeeded() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1341 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1342 | } |
| 1343 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1344 | QueryManager* RasterDecoderImpl::GetQueryManager() { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1345 | return query_manager_.get(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1346 | } |
| 1347 | |
Geoff Lang | 85287e1 | 2018-05-22 17:26:40 | [diff] [blame] | 1348 | void RasterDecoderImpl::SetQueryCallback(unsigned int query_client_id, |
| 1349 | base::OnceClosure callback) { |
| 1350 | QueryManager::Query* query = query_manager_->GetQuery(query_client_id); |
| 1351 | if (query) { |
| 1352 | query->AddCallback(std::move(callback)); |
| 1353 | } else { |
| 1354 | VLOG(1) << "RasterDecoderImpl::SetQueryCallback: No query with ID " |
| 1355 | << query_client_id << ". Running the callback immediately."; |
| 1356 | std::move(callback).Run(); |
| 1357 | } |
| 1358 | } |
| 1359 | |
Jeffrey Cohen | 11a6cad | 2023-07-10 19:56:18 | [diff] [blame] | 1360 | void RasterDecoderImpl::CancelAllQueries() { |
| 1361 | query_manager_->RemoveAllQueries(); |
| 1362 | } |
| 1363 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1364 | gles2::GpuFenceManager* RasterDecoderImpl::GetGpuFenceManager() { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1365 | NOTIMPLEMENTED(); |
| 1366 | return nullptr; |
| 1367 | } |
| 1368 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1369 | bool RasterDecoderImpl::HasPendingQueries() const { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1370 | return query_manager_ && query_manager_->HavePendingQueries(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1371 | } |
| 1372 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1373 | void RasterDecoderImpl::ProcessPendingQueries(bool did_finish) { |
Vasiliy Telezhnikov | 517dd8c | 2022-05-17 15:39:47 | [diff] [blame] | 1374 | if (query_manager_) { |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1375 | if (gr_context()) { |
| 1376 | gr_context()->checkAsyncWorkCompletion(); |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 1377 | } else if (graphite_shared_context()) { |
| 1378 | graphite_shared_context()->checkAsyncWorkCompletion(); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 1379 | } |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1380 | query_manager_->ProcessPendingQueries(did_finish); |
Vasiliy Telezhnikov | 517dd8c | 2022-05-17 15:39:47 | [diff] [blame] | 1381 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1382 | } |
| 1383 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1384 | bool RasterDecoderImpl::HasMoreIdleWork() const { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1385 | return gpu_tracer_->HasTracesToProcess(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1386 | } |
| 1387 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1388 | void RasterDecoderImpl::PerformIdleWork() { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1389 | gpu_tracer_->ProcessTraces(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1390 | } |
| 1391 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1392 | bool RasterDecoderImpl::HasPollingWork() const { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1393 | return false; |
| 1394 | } |
| 1395 | |
Jonathan Backer | c2b0efa | 2018-03-21 16:58:35 | [diff] [blame] | 1396 | void RasterDecoderImpl::PerformPollingWork() {} |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1397 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1398 | TextureBase* RasterDecoderImpl::GetTextureBase(uint32_t client_id) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1399 | NOTIMPLEMENTED(); |
| 1400 | return nullptr; |
| 1401 | } |
| 1402 | |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 1403 | void RasterDecoderImpl::SetLevelInfo(uint32_t client_id, |
| 1404 | int level, |
| 1405 | unsigned internal_format, |
| 1406 | unsigned width, |
| 1407 | unsigned height, |
| 1408 | unsigned depth, |
| 1409 | unsigned format, |
| 1410 | unsigned type, |
| 1411 | const gfx::Rect& cleared_rect) { |
| 1412 | NOTIMPLEMENTED(); |
| 1413 | } |
| 1414 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1415 | bool RasterDecoderImpl::WasContextLost() const { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1416 | return shared_context_state_->context_lost(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1417 | } |
| 1418 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1419 | bool RasterDecoderImpl::WasContextLostByRobustnessExtension() const { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1420 | return shared_context_state_->device_needs_reset(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1421 | } |
| 1422 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1423 | void RasterDecoderImpl::MarkContextLost(error::ContextLostReason reason) { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1424 | shared_context_state_->MarkContextLost(reason); |
| 1425 | } |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1426 | |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1427 | void RasterDecoderImpl::OnContextLost() { |
| 1428 | DCHECK(shared_context_state_->context_lost()); |
| 1429 | command_buffer_service()->SetContextLostReason( |
| 1430 | *shared_context_state_->context_lost_reason()); |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1431 | current_decoder_error_ = error::kLostContext; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1432 | } |
| 1433 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1434 | bool RasterDecoderImpl::CheckResetStatus() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1435 | DCHECK(!WasContextLost()); |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1436 | return shared_context_state_->CheckResetStatus(/*needs_gl=*/false); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1437 | } |
| 1438 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1439 | gles2::Logger* RasterDecoderImpl::GetLogger() { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1440 | return &logger_; |
| 1441 | } |
| 1442 | |
| 1443 | void RasterDecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1444 | if (use_passthrough_) |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 1445 | return; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1446 | state()->SetIgnoreCachedStateForTest(ignore); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1447 | } |
| 1448 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1449 | void RasterDecoderImpl::BeginDecoding() { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1450 | gpu_tracer_->BeginDecoding(); |
| 1451 | gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_; |
| 1452 | gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_; |
Khushal | cd8fbb77 | 2018-10-16 22:46:14 | [diff] [blame] | 1453 | query_manager_->BeginProcessingCommands(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1454 | } |
| 1455 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1456 | void RasterDecoderImpl::EndDecoding() { |
| 1457 | gpu_tracer_->EndDecoding(); |
Khushal | cd8fbb77 | 2018-10-16 22:46:14 | [diff] [blame] | 1458 | query_manager_->EndProcessingCommands(); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1459 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1460 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1461 | const char* RasterDecoderImpl::GetCommandName(unsigned int command_id) const { |
| 1462 | if (command_id >= kFirstRasterCommand && command_id < kNumCommands) { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1463 | return raster::GetCommandName(static_cast<CommandId>(command_id)); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1464 | } |
| 1465 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 1466 | } |
| 1467 | |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1468 | template <bool DebugImpl> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1469 | error::Error RasterDecoderImpl::DoCommandsImpl(unsigned int num_commands, |
| 1470 | const volatile void* buffer, |
| 1471 | int num_entries, |
| 1472 | int* entries_processed) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1473 | DCHECK(entries_processed); |
| 1474 | commands_to_process_ = num_commands; |
| 1475 | error::Error result = error::kNoError; |
| 1476 | const volatile CommandBufferEntry* cmd_data = |
| 1477 | static_cast<const volatile CommandBufferEntry*>(buffer); |
| 1478 | int process_pos = 0; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1479 | CommandId command = static_cast<CommandId>(0); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1480 | |
| 1481 | while (process_pos < num_entries && result == error::kNoError && |
| 1482 | commands_to_process_--) { |
| 1483 | const unsigned int size = cmd_data->value_header.size; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1484 | command = static_cast<CommandId>(cmd_data->value_header.command); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1485 | |
| 1486 | if (size == 0) { |
| 1487 | result = error::kInvalidSize; |
| 1488 | break; |
| 1489 | } |
| 1490 | |
| 1491 | if (static_cast<int>(size) + process_pos > num_entries) { |
| 1492 | result = error::kOutOfBounds; |
| 1493 | break; |
| 1494 | } |
| 1495 | |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1496 | if (DebugImpl && log_commands()) { |
| 1497 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" |
| 1498 | << "cmd: " << GetCommandName(command); |
| 1499 | } |
| 1500 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1501 | const unsigned int arg_count = size - 1; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1502 | unsigned int command_index = command - kFirstRasterCommand; |
Daniel Cheng | adafb3a | 2022-02-28 07:38:22 | [diff] [blame] | 1503 | if (command_index < std::size(command_info)) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1504 | const CommandInfo& info = command_info[command_index]; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1505 | if (sk_surface_) { |
| 1506 | if (!AllowedBetweenBeginEndRaster(command)) { |
| 1507 | LOCAL_SET_GL_ERROR( |
| 1508 | GL_INVALID_OPERATION, GetCommandName(command), |
| 1509 | "Unexpected command between BeginRasterCHROMIUM and " |
| 1510 | "EndRasterCHROMIUM"); |
| 1511 | process_pos += size; |
| 1512 | cmd_data += size; |
| 1513 | continue; |
| 1514 | } |
| 1515 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1516 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 1517 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 1518 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1519 | bool doing_gpu_trace = false; |
| 1520 | if (DebugImpl && gpu_trace_commands_) { |
| 1521 | if (CMD_FLAG_GET_TRACE_LEVEL(info.cmd_flags) <= gpu_trace_level_) { |
| 1522 | doing_gpu_trace = true; |
Miguel Casas | 510fbfcb | 2018-11-13 23:40:57 | [diff] [blame] | 1523 | gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu.decoder"), |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1524 | GetCommandName(command), gles2::kTraceDecoder); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1528 | uint32_t immediate_data_size = (arg_count - info_arg_count) * |
| 1529 | sizeof(CommandBufferEntry); // NOLINT |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1530 | result = (this->*info.cmd_handler)(immediate_data_size, cmd_data); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1531 | |
| 1532 | if (DebugImpl && doing_gpu_trace) |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1533 | gpu_tracer_->End(gles2::kTraceDecoder); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1534 | |
Kramer Ge | e6c7469 | 2020-02-07 21:07:31 | [diff] [blame] | 1535 | if (DebugImpl && shared_context_state_->GrContextIsGL() && debug() && |
| 1536 | !WasContextLost()) { |
Sunny Sachanandani | 46df8ac | 2023-09-06 23:18:43 | [diff] [blame] | 1537 | gl::GLApi* const api = gl::g_current_gl_context; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1538 | GLenum error; |
Sunny Sachanandani | 46df8ac | 2023-09-06 23:18:43 | [diff] [blame] | 1539 | while ((error = api->glGetErrorFn()) != GL_NO_ERROR) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1540 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1541 | << "GL ERROR: " << gles2::GLES2Util::GetStringEnum(error) |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1542 | << " : " << GetCommandName(command); |
| 1543 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1544 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1545 | } |
| 1546 | } else { |
| 1547 | result = error::kInvalidArguments; |
| 1548 | } |
| 1549 | } else { |
| 1550 | result = DoCommonCommand(command, arg_count, cmd_data); |
| 1551 | } |
| 1552 | |
| 1553 | if (result == error::kNoError && |
| 1554 | current_decoder_error_ != error::kNoError) { |
| 1555 | result = current_decoder_error_; |
| 1556 | current_decoder_error_ = error::kNoError; |
| 1557 | } |
| 1558 | |
| 1559 | if (result != error::kDeferCommandUntilLater) { |
| 1560 | process_pos += size; |
| 1561 | cmd_data += size; |
| 1562 | } |
Christopher Cameron | 02e3149a | 2019-01-25 19:52:23 | [diff] [blame] | 1563 | |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 1564 | // Workaround for https://crbug.com/906453: Flush after every command that |
| 1565 | // is not between a BeginRaster and EndRaster. |
| 1566 | if (!sk_surface_) |
| 1567 | FlushToWorkAroundMacCrashes(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | *entries_processed = process_pos; |
| 1571 | |
| 1572 | if (error::IsError(result)) { |
| 1573 | LOG(ERROR) << "Error: " << result << " for Command " |
| 1574 | << GetCommandName(command); |
| 1575 | } |
| 1576 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 1577 | if (use_gpu_raster_) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1578 | client()->ScheduleGrContextCleanup(); |
Khushal | 7324ec4 | 2018-07-10 20:01:45 | [diff] [blame] | 1579 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1580 | return result; |
| 1581 | } |
| 1582 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1583 | error::Error RasterDecoderImpl::DoCommands(unsigned int num_commands, |
| 1584 | const volatile void* buffer, |
| 1585 | int num_entries, |
| 1586 | int* entries_processed) { |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1587 | if (gpu_debug_commands_) { |
| 1588 | return DoCommandsImpl<true>(num_commands, buffer, num_entries, |
| 1589 | entries_processed); |
| 1590 | } else { |
| 1591 | return DoCommandsImpl<false>(num_commands, buffer, num_entries, |
| 1592 | entries_processed); |
| 1593 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1594 | } |
| 1595 | |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1596 | void RasterDecoderImpl::ExitCommandProcessingEarly() { |
| 1597 | commands_to_process_ = 0; |
| 1598 | } |
| 1599 | |
Helmut Januschka | b81e97dc | 2024-04-17 14:57:05 | [diff] [blame] | 1600 | std::string_view RasterDecoderImpl::GetLogPrefix() { |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1601 | return logger_.GetLogPrefix(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1602 | } |
| 1603 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1604 | gles2::ContextGroup* RasterDecoderImpl::GetContextGroup() { |
Antoine Labour | 914f3af | 2019-02-14 20:24:13 | [diff] [blame] | 1605 | return nullptr; |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1606 | } |
| 1607 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1608 | gles2::ErrorState* RasterDecoderImpl::GetErrorState() { |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 1609 | return error_state_.get(); |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1610 | } |
| 1611 | |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1612 | bool RasterDecoderImpl::IsCompressedTextureFormat(unsigned format) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1613 | return feature_info()->validators()->compressed_texture_format.IsValid( |
| 1614 | format); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | bool RasterDecoderImpl::ClearLevel(gles2::Texture* texture, |
| 1618 | unsigned target, |
| 1619 | int level, |
| 1620 | unsigned format, |
| 1621 | unsigned type, |
| 1622 | int xoffset, |
| 1623 | int yoffset, |
| 1624 | int width, |
| 1625 | int height) { |
Peter BostrÃļm | a11556e | 2024-10-31 04:49:10 | [diff] [blame] | 1626 | NOTREACHED(); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | bool RasterDecoderImpl::ClearCompressedTextureLevel(gles2::Texture* texture, |
| 1630 | unsigned target, |
| 1631 | int level, |
| 1632 | unsigned format, |
| 1633 | int width, |
| 1634 | int height) { |
Peter BostrÃļm | a11556e | 2024-10-31 04:49:10 | [diff] [blame] | 1635 | NOTREACHED(); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1636 | } |
| 1637 | |
shrekshao | ad452548 | 2020-03-12 00:30:55 | [diff] [blame] | 1638 | bool RasterDecoderImpl::ClearCompressedTextureLevel3D(gles2::Texture* texture, |
| 1639 | unsigned target, |
| 1640 | int level, |
| 1641 | unsigned format, |
| 1642 | int width, |
| 1643 | int height, |
| 1644 | int depth) { |
Peter BostrÃļm | a11556e | 2024-10-31 04:49:10 | [diff] [blame] | 1645 | NOTREACHED(); |
shrekshao | ad452548 | 2020-03-12 00:30:55 | [diff] [blame] | 1646 | } |
| 1647 | |
Andres Calderon Jaramillo | b870ca6 | 2019-01-29 16:33:35 | [diff] [blame] | 1648 | int RasterDecoderImpl::GetRasterDecoderId() const { |
| 1649 | return raster_decoder_id_; |
| 1650 | } |
| 1651 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 1652 | int RasterDecoderImpl::DecoderIdForTest() { |
| 1653 | return raster_decoder_id_; |
| 1654 | } |
| 1655 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1656 | ServiceTransferCache* RasterDecoderImpl::GetTransferCacheForTest() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1657 | return shared_context_state_->transfer_cache(); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1658 | } |
| 1659 | |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 1660 | void RasterDecoderImpl::SetUpForRasterCHROMIUMForTest() { |
| 1661 | // Some tests use mock GL which doesn't work with skia. Just use a bitmap |
| 1662 | // backed surface for OOP raster commands. |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 1663 | auto info = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType, |
| 1664 | SkColorSpace::MakeSRGB()); |
Ian Prest | e598eece | 2020-10-19 23:31:02 | [diff] [blame] | 1665 | SkSurfaceProps props = skia::LegacyDisplayGlobals::GetSkSurfaceProps(); |
Kevin Lubick | 671644d | 2023-05-12 16:32:00 | [diff] [blame] | 1666 | sk_surface_for_testing_ = SkSurfaces::Raster(info, &props); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 1667 | sk_surface_ = sk_surface_for_testing_.get(); |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 1668 | raster_canvas_ = sk_surface_->getCanvas(); |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 1669 | } |
| 1670 | |
Jonathan Backer | c7b8297 | 2018-11-21 19:08:48 | [diff] [blame] | 1671 | void RasterDecoderImpl::SetOOMErrorForTest() { |
| 1672 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "SetOOMErrorForTest", |
| 1673 | "synthetic out of memory"); |
| 1674 | } |
| 1675 | |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 1676 | void RasterDecoderImpl::DisableFlushWorkaroundForTest() { |
| 1677 | flush_workaround_disabled_for_test_ = true; |
| 1678 | } |
| 1679 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1680 | void RasterDecoderImpl::OnContextLostError() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1681 | if (!WasContextLost()) { |
| 1682 | // Need to lose current context before broadcasting! |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1683 | shared_context_state_->CheckResetStatus(/*needs_gl=*/false); |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1684 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1685 | } |
| 1686 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1687 | void RasterDecoderImpl::OnOutOfMemoryError() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1688 | if (lose_context_when_out_of_memory_ && !WasContextLost()) { |
Jonathan Backer | baf79d9 | 2020-06-01 21:30:30 | [diff] [blame] | 1689 | if (!shared_context_state_->CheckResetStatus(/*needs_gl=*/false)) { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1690 | MarkContextLost(error::kOutOfMemory); |
| 1691 | } |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1692 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1693 | } |
| 1694 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1695 | error::Error RasterDecoderImpl::HandleBeginQueryEXT( |
| 1696 | uint32_t immediate_data_size, |
| 1697 | const volatile void* cmd_data) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1698 | const volatile raster::cmds::BeginQueryEXT& c = |
| 1699 | *static_cast<const volatile raster::cmds::BeginQueryEXT*>(cmd_data); |
| 1700 | GLenum target = static_cast<GLenum>(c.target); |
| 1701 | GLuint client_id = static_cast<GLuint>(c.id); |
| 1702 | int32_t sync_shm_id = static_cast<int32_t>(c.sync_data_shm_id); |
| 1703 | uint32_t sync_shm_offset = static_cast<uint32_t>(c.sync_data_shm_offset); |
| 1704 | |
| 1705 | switch (target) { |
| 1706 | case GL_COMMANDS_ISSUED_CHROMIUM: |
Jonathan Backer | 80b27029 | 2018-12-13 19:13:55 | [diff] [blame] | 1707 | break; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1708 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
Jonathan Backer | 80b27029 | 2018-12-13 19:13:55 | [diff] [blame] | 1709 | if (!features().chromium_sync_query) { |
| 1710 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1711 | "not enabled for commands completed queries"); |
| 1712 | return error::kNoError; |
| 1713 | } |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1714 | break; |
| 1715 | default: |
| 1716 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "glBeginQueryEXT", |
| 1717 | "unknown query target"); |
| 1718 | return error::kNoError; |
| 1719 | } |
| 1720 | |
| 1721 | if (query_manager_->GetActiveQuery(target)) { |
| 1722 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1723 | "query already in progress"); |
| 1724 | return error::kNoError; |
| 1725 | } |
| 1726 | |
| 1727 | if (client_id == 0) { |
| 1728 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
| 1729 | return error::kNoError; |
| 1730 | } |
| 1731 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1732 | scoped_refptr<Buffer> buffer = GetSharedMemoryBuffer(sync_shm_id); |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1733 | if (!buffer) |
| 1734 | return error::kInvalidArguments; |
| 1735 | QuerySync* sync = static_cast<QuerySync*>( |
| 1736 | buffer->GetDataAddress(sync_shm_offset, sizeof(QuerySync))); |
| 1737 | if (!sync) |
| 1738 | return error::kOutOfBounds; |
| 1739 | |
| 1740 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 1741 | if (!query) { |
| 1742 | if (!query_manager_->IsValidQuery(client_id)) { |
| 1743 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1744 | "id not made by glGenQueriesEXT"); |
| 1745 | return error::kNoError; |
| 1746 | } |
| 1747 | |
| 1748 | query = |
| 1749 | query_manager_->CreateQuery(target, client_id, std::move(buffer), sync); |
| 1750 | } else { |
| 1751 | if (query->target() != target) { |
| 1752 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1753 | "target does not match"); |
| 1754 | return error::kNoError; |
| 1755 | } else if (query->sync() != sync) { |
| 1756 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 1757 | return error::kInvalidArguments; |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | query_manager_->BeginQuery(query); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1762 | return error::kNoError; |
| 1763 | } |
| 1764 | |
| 1765 | error::Error RasterDecoderImpl::HandleEndQueryEXT( |
| 1766 | uint32_t immediate_data_size, |
| 1767 | const volatile void* cmd_data) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1768 | const volatile raster::cmds::EndQueryEXT& c = |
| 1769 | *static_cast<const volatile raster::cmds::EndQueryEXT*>(cmd_data); |
| 1770 | GLenum target = static_cast<GLenum>(c.target); |
| 1771 | uint32_t submit_count = static_cast<GLuint>(c.submit_count); |
| 1772 | |
| 1773 | QueryManager::Query* query = query_manager_->GetActiveQuery(target); |
| 1774 | if (!query) { |
| 1775 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glEndQueryEXT", |
| 1776 | "No active query"); |
| 1777 | return error::kNoError; |
| 1778 | } |
| 1779 | |
| 1780 | query_manager_->EndQuery(query, submit_count); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1781 | return error::kNoError; |
| 1782 | } |
| 1783 | |
Andres Calderon Jaramillo | 21e9815 | 2019-08-22 01:38:04 | [diff] [blame] | 1784 | error::Error RasterDecoderImpl::HandleQueryCounterEXT( |
| 1785 | uint32_t immediate_data_size, |
| 1786 | const volatile void* cmd_data) { |
| 1787 | const volatile raster::cmds::QueryCounterEXT& c = |
| 1788 | *static_cast<const volatile raster::cmds::QueryCounterEXT*>(cmd_data); |
| 1789 | GLenum target = static_cast<GLenum>(c.target); |
| 1790 | GLuint client_id = static_cast<GLuint>(c.id); |
| 1791 | int32_t sync_shm_id = static_cast<int32_t>(c.sync_data_shm_id); |
| 1792 | uint32_t sync_shm_offset = static_cast<uint32_t>(c.sync_data_shm_offset); |
| 1793 | uint32_t submit_count = static_cast<GLuint>(c.submit_count); |
| 1794 | |
| 1795 | if (target != GL_COMMANDS_ISSUED_TIMESTAMP_CHROMIUM) { |
| 1796 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "glQueryCounterEXT", |
| 1797 | "unknown query target"); |
| 1798 | return error::kNoError; |
| 1799 | } |
| 1800 | |
| 1801 | scoped_refptr<Buffer> buffer = GetSharedMemoryBuffer(sync_shm_id); |
| 1802 | if (!buffer) |
| 1803 | return error::kInvalidArguments; |
| 1804 | QuerySync* sync = static_cast<QuerySync*>( |
| 1805 | buffer->GetDataAddress(sync_shm_offset, sizeof(QuerySync))); |
| 1806 | if (!sync) |
| 1807 | return error::kOutOfBounds; |
| 1808 | |
| 1809 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 1810 | if (!query) { |
| 1811 | if (!query_manager_->IsValidQuery(client_id)) { |
| 1812 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glQueryCounterEXT", |
| 1813 | "id not made by glGenQueriesEXT"); |
| 1814 | return error::kNoError; |
| 1815 | } |
| 1816 | query = |
| 1817 | query_manager_->CreateQuery(target, client_id, std::move(buffer), sync); |
| 1818 | } else { |
| 1819 | if (query->target() != target) { |
| 1820 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glQueryCounterEXT", |
| 1821 | "target does not match"); |
| 1822 | return error::kNoError; |
| 1823 | } else if (query->sync() != sync) { |
| 1824 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 1825 | return error::kInvalidArguments; |
| 1826 | } |
| 1827 | } |
| 1828 | query_manager_->QueryCounter(query, submit_count); |
| 1829 | |
| 1830 | return error::kNoError; |
| 1831 | } |
| 1832 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1833 | void RasterDecoderImpl::DoFinish() { |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 1834 | shared_context_state_->FlushAndSubmit(/*sync_to_cpu=*/true); |
Peng Huang | 63ef887 | 2021-06-17 22:31:20 | [diff] [blame] | 1835 | ProcessPendingQueries(/*did_finish=*/true); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | void RasterDecoderImpl::DoFlush() { |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 1839 | shared_context_state_->FlushAndSubmit(/*sync_to_cpu=*/false); |
Peng Huang | 63ef887 | 2021-06-17 22:31:20 | [diff] [blame] | 1840 | ProcessPendingQueries(/*did_finish=*/false); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1841 | } |
| 1842 | |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1843 | bool RasterDecoderImpl::GenQueriesEXTHelper(GLsizei n, |
| 1844 | const GLuint* client_ids) { |
| 1845 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 1846 | if (query_manager_->IsValidQuery(client_ids[ii])) { |
| 1847 | return false; |
| 1848 | } |
| 1849 | } |
| 1850 | query_manager_->GenQueries(n, client_ids); |
| 1851 | return true; |
| 1852 | } |
| 1853 | |
| 1854 | void RasterDecoderImpl::DeleteQueriesEXTHelper( |
| 1855 | GLsizei n, |
| 1856 | const volatile GLuint* client_ids) { |
| 1857 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 1858 | GLuint client_id = client_ids[ii]; |
| 1859 | query_manager_->RemoveQuery(client_id); |
| 1860 | } |
| 1861 | } |
| 1862 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1863 | error::Error RasterDecoderImpl::HandleTraceBeginCHROMIUM( |
| 1864 | uint32_t immediate_data_size, |
| 1865 | const volatile void* cmd_data) { |
| 1866 | const volatile gles2::cmds::TraceBeginCHROMIUM& c = |
| 1867 | *static_cast<const volatile gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); |
| 1868 | Bucket* category_bucket = GetBucket(c.category_bucket_id); |
| 1869 | Bucket* name_bucket = GetBucket(c.name_bucket_id); |
Jonathan Backer | ff2ac0f | 2018-07-18 15:53:47 | [diff] [blame] | 1870 | static constexpr size_t kMaxStrLen = 256; |
| 1871 | if (!category_bucket || category_bucket->size() == 0 || |
| 1872 | category_bucket->size() > kMaxStrLen || !name_bucket || |
| 1873 | name_bucket->size() == 0 || name_bucket->size() > kMaxStrLen) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1874 | return error::kInvalidArguments; |
| 1875 | } |
| 1876 | |
| 1877 | std::string category_name; |
| 1878 | std::string trace_name; |
| 1879 | if (!category_bucket->GetAsString(&category_name) || |
| 1880 | !name_bucket->GetAsString(&trace_name)) { |
| 1881 | return error::kInvalidArguments; |
| 1882 | } |
| 1883 | |
| 1884 | debug_marker_manager_.PushGroup(trace_name); |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1885 | if (!gpu_tracer_->Begin(category_name, trace_name, gles2::kTraceCHROMIUM)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1886 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glTraceBeginCHROMIUM", |
| 1887 | "unable to create begin trace"); |
| 1888 | return error::kNoError; |
| 1889 | } |
| 1890 | return error::kNoError; |
| 1891 | } |
| 1892 | |
| 1893 | void RasterDecoderImpl::DoTraceEndCHROMIUM() { |
| 1894 | debug_marker_manager_.PopGroup(); |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1895 | if (!gpu_tracer_->End(gles2::kTraceCHROMIUM)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1896 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glTraceEndCHROMIUM", |
| 1897 | "no trace begin found"); |
| 1898 | return; |
| 1899 | } |
| 1900 | } |
| 1901 | |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1902 | error::Error RasterDecoderImpl::HandleSetActiveURLCHROMIUM( |
| 1903 | uint32_t immediate_data_size, |
| 1904 | const volatile void* cmd_data) { |
| 1905 | const volatile cmds::SetActiveURLCHROMIUM& c = |
| 1906 | *static_cast<const volatile cmds::SetActiveURLCHROMIUM*>(cmd_data); |
| 1907 | Bucket* url_bucket = GetBucket(c.url_bucket_id); |
| 1908 | static constexpr size_t kMaxStrLen = 1024; |
| 1909 | if (!url_bucket || url_bucket->size() == 0 || |
Khushal | da1fb833 | 2018-10-26 19:26:22 | [diff] [blame] | 1910 | url_bucket->size() > kMaxStrLen) { |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1911 | return error::kInvalidArguments; |
| 1912 | } |
| 1913 | |
Khushal | da1fb833 | 2018-10-26 19:26:22 | [diff] [blame] | 1914 | size_t size = url_bucket->size(); |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1915 | const char* url_str = url_bucket->GetDataAs<const char*>(0, size); |
| 1916 | if (!url_str) |
| 1917 | return error::kInvalidArguments; |
| 1918 | |
Helmut Januschka | b81e97dc | 2024-04-17 14:57:05 | [diff] [blame] | 1919 | GURL url(std::string_view(url_str, size)); |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1920 | client()->SetActiveURL(std::move(url)); |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1921 | return error::kNoError; |
| 1922 | } |
| 1923 | |
Saifuddin Hitawala | 20790cb | 2023-01-31 17:01:12 | [diff] [blame] | 1924 | void RasterDecoderImpl::DoCopySharedImageINTERNAL( |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1925 | GLint xoffset, |
| 1926 | GLint yoffset, |
| 1927 | GLint x, |
| 1928 | GLint y, |
Ilya Nikolaevskiy | 18fd297 | 2025-09-09 17:19:46 | [diff] [blame] | 1929 | GLsizei src_width, |
| 1930 | GLsizei src_height, |
| 1931 | GLsizei dst_width, |
| 1932 | GLsizei dst_height, |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1933 | const volatile GLbyte* mailboxes) { |
Saifuddin Hitawala | c457bbd | 2023-02-07 21:19:24 | [diff] [blame] | 1934 | CopySharedImageHelper helper(&shared_image_representation_factory_, |
| 1935 | shared_context_state_.get()); |
Vasiliy Telezhnikov | 1dbbecd3 | 2024-11-06 16:36:17 | [diff] [blame] | 1936 | auto result = |
Ilya Nikolaevskiy | 18fd297 | 2025-09-09 17:19:46 | [diff] [blame] | 1937 | helper.CopySharedImage(xoffset, yoffset, x, y, src_width, src_height, |
| 1938 | dst_width, dst_height, mailboxes); |
Saifuddin Hitawala | c457bbd | 2023-02-07 21:19:24 | [diff] [blame] | 1939 | if (!result.has_value()) { |
| 1940 | LOCAL_SET_GL_ERROR(result.error().gl_error, |
| 1941 | result.error().function_name.c_str(), |
| 1942 | result.error().msg.c_str()); |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1943 | } |
Nathan Zabriskie | 67a4fbc | 2021-01-07 19:39:10 | [diff] [blame] | 1944 | } |
| 1945 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 1946 | void RasterDecoderImpl::DoWritePixelsINTERNAL(GLint x_offset, |
| 1947 | GLint y_offset, |
| 1948 | GLuint src_width, |
| 1949 | GLuint src_height, |
| 1950 | GLuint row_bytes, |
| 1951 | GLuint src_sk_color_type, |
| 1952 | GLuint src_sk_alpha_type, |
| 1953 | GLint shm_id, |
| 1954 | GLuint shm_offset, |
| 1955 | GLuint pixels_offset, |
| 1956 | const volatile GLbyte* mailbox) { |
Justin Novosad | 129aa3ea4 | 2021-12-10 20:06:31 | [diff] [blame] | 1957 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoWritePixelsINTERNAL"); |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 1958 | if (src_sk_color_type < 0 || src_sk_color_type > kLastEnum_SkColorType) { |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 1959 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "WritePixels", |
| 1960 | "src_sk_color_type must be a valid SkColorType"); |
| 1961 | return; |
| 1962 | } |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 1963 | if (src_sk_alpha_type < 0 || src_sk_alpha_type > kLastEnum_SkAlphaType) { |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 1964 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "WritePixels", |
| 1965 | "src_sk_alpha_type must be a valid SkAlphaType"); |
| 1966 | return; |
| 1967 | } |
| 1968 | |
| 1969 | Mailbox dest_mailbox = Mailbox::FromVolatile( |
| 1970 | *reinterpret_cast<const volatile Mailbox*>(mailbox)); |
| 1971 | DLOG_IF(ERROR, !dest_mailbox.Verify()) |
| 1972 | << "WritePixels was passed an invalid mailbox"; |
| 1973 | auto dest_shared_image = shared_image_representation_factory_.ProduceSkia( |
| 1974 | dest_mailbox, shared_context_state_); |
| 1975 | if (!dest_shared_image) { |
| 1976 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 1977 | "Attempting to write to unknown mailbox."); |
| 1978 | return; |
| 1979 | } |
| 1980 | |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 1981 | viz::SharedImageFormat dest_format = dest_shared_image->format(); |
Vasiliy Telezhnikov | 1470c97 | 2025-01-13 15:49:44 | [diff] [blame] | 1982 | if (SkColorTypeBytesPerPixel(viz::ToClosestSkColorType(dest_format)) != |
Nathan Zabriskie | 108c1828 | 2020-05-28 16:45:07 | [diff] [blame] | 1983 | SkColorTypeBytesPerPixel(static_cast<SkColorType>(src_sk_color_type))) { |
| 1984 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 1985 | "Bytes per pixel for src SkColorType and dst " |
| 1986 | "SkColorType must be the same."); |
| 1987 | return; |
| 1988 | } |
| 1989 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 1990 | // If present, the color space is serialized into shared memory before the |
| 1991 | // pixel data. |
| 1992 | sk_sp<SkColorSpace> color_space; |
| 1993 | if (pixels_offset > 0) { |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 1994 | // For multiplanar formats write is per plane, and source color |
| 1995 | // space must be nullptr to allow letting Skia assume srgb color space. |
| 1996 | if (dest_format.is_multi_plane()) { |
| 1997 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 1998 | "Unexpected color space for multiplanar shared image"); |
| 1999 | return; |
| 2000 | } |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2001 | void* color_space_bytes = |
| 2002 | GetSharedMemoryAs<void*>(shm_id, shm_offset, pixels_offset); |
Nathan Zabriskie | a0f955c3 | 2020-04-16 21:29:10 | [diff] [blame] | 2003 | if (!color_space_bytes) { |
| 2004 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 2005 | "Failed to retrieve serialized SkColorSpace."); |
| 2006 | return; |
| 2007 | } |
| 2008 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2009 | color_space = SkColorSpace::Deserialize(color_space_bytes, pixels_offset); |
| 2010 | if (!color_space) { |
| 2011 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 2012 | "Failed to deserialize expected SkColorSpace"); |
| 2013 | return; |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | SkImageInfo src_info = SkImageInfo::Make( |
| 2018 | src_width, src_height, static_cast<SkColorType>(src_sk_color_type), |
| 2019 | static_cast<SkAlphaType>(src_sk_alpha_type), std::move(color_space)); |
| 2020 | |
Nathan Zabriskie | ee59b5e | 2020-06-10 06:15:47 | [diff] [blame] | 2021 | if (row_bytes < src_info.minRowBytes()) { |
| 2022 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glWritePixels", |
| 2023 | "row_bytes be >= " |
| 2024 | "SkImageInfo::minRowBytes() for source image."); |
| 2025 | return; |
| 2026 | } |
| 2027 | |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2028 | size_t byte_size = src_info.computeByteSize(row_bytes); |
| 2029 | if (byte_size > UINT32_MAX) { |
| 2030 | LOCAL_SET_GL_ERROR( |
| 2031 | GL_INVALID_VALUE, "glWritePixels", |
| 2032 | "Cannot request a memory chunk larger than UINT32_MAX bytes"); |
| 2033 | return; |
| 2034 | } |
| 2035 | |
| 2036 | // The pixels are stored after the serialized SkColorSpace + padding |
| 2037 | void* pixel_data = |
| 2038 | GetSharedMemoryAs<void*>(shm_id, shm_offset + pixels_offset, byte_size); |
| 2039 | if (!pixel_data) { |
| 2040 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 2041 | "Couldn't retrieve pixel data."); |
| 2042 | return; |
| 2043 | } |
| 2044 | |
| 2045 | // Try a direct texture upload without using SkSurface. |
Sunny Sachanandani | d6e0b5f | 2023-06-14 13:30:37 | [diff] [blame] | 2046 | if (gfx::Size(src_width, src_height) == dest_shared_image->size() && |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2047 | x_offset == 0 && y_offset == 0 && |
Justin Novosad | 4fb0c0e4 | 2022-02-08 16:10:27 | [diff] [blame] | 2048 | (src_info.alphaType() == dest_shared_image->alpha_type() || |
| 2049 | src_info.alphaType() == kUnknown_SkAlphaType) && |
| 2050 | SkColorSpace::Equals( |
| 2051 | src_info.colorSpace(), |
| 2052 | dest_shared_image->color_space().ToSkColorSpace().get()) && |
Saifuddin Hitawala | 8c8af1e | 2024-04-09 19:45:32 | [diff] [blame] | 2053 | DoWritePixelsINTERNALDirectTextureUpload( |
| 2054 | dest_shared_image.get(), src_info, pixel_data, row_bytes)) { |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2055 | if (!dest_shared_image->IsCleared()) { |
| 2056 | dest_shared_image->SetClearedRect( |
| 2057 | gfx::Rect(src_info.width(), src_info.height())); |
| 2058 | } |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2059 | return; |
| 2060 | } |
| 2061 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2062 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2063 | std::vector<GrBackendSemaphore> end_semaphores; |
| 2064 | |
| 2065 | // Allow uncleared access, as we manually handle clear tracking. |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 2066 | std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess> |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2067 | dest_scoped_access = dest_shared_image->BeginScopedWriteAccess( |
| 2068 | &begin_semaphores, &end_semaphores, |
| 2069 | SharedImageRepresentation::AllowUnclearedAccess::kYes); |
| 2070 | if (!dest_scoped_access) { |
| 2071 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glWritePixels", |
| 2072 | "Dest shared image is not writable"); |
| 2073 | return; |
| 2074 | } |
| 2075 | |
Saifuddin Hitawala | 8c8af1e | 2024-04-09 19:45:32 | [diff] [blame] | 2076 | auto* surface = dest_scoped_access->surface(); |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2077 | DCHECK(surface); |
| 2078 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2079 | if (!begin_semaphores.empty()) { |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2080 | bool result = |
| 2081 | surface->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2082 | /*deleteSemaphoresAfterWait=*/false); |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2083 | if (!result) { |
| 2084 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 2085 | "Unable to obtain write access to dest shared image."); |
| 2086 | return; |
| 2087 | } |
| 2088 | } |
| 2089 | |
Saifuddin Hitawala | a5126a70 | 2023-04-04 20:16:39 | [diff] [blame] | 2090 | auto* canvas = surface->getCanvas(); |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2091 | bool written = |
| 2092 | canvas->writePixels(src_info, pixel_data, row_bytes, x_offset, y_offset); |
| 2093 | if (!written) { |
| 2094 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixels", |
| 2095 | "Failed to write pixels to SkCanvas"); |
| 2096 | } |
| 2097 | |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2098 | shared_context_state_->FlushWriteAccess(dest_scoped_access.get()); |
Saifuddin Hitawala | 7065278 | 2024-08-21 14:13:32 | [diff] [blame] | 2099 | shared_context_state_->SubmitIfNecessary( |
| 2100 | std::move(end_semaphores), |
| 2101 | dest_scoped_access->NeedGraphiteContextSubmit()); |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 2102 | |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2103 | if (!dest_shared_image->IsCleared()) { |
| 2104 | dest_shared_image->SetClearedRect( |
| 2105 | gfx::Rect(x_offset, y_offset, src_width, src_height)); |
| 2106 | } |
| 2107 | } |
| 2108 | |
Saifuddin Hitawala | 9d8a52dd | 2023-06-26 20:21:37 | [diff] [blame] | 2109 | void RasterDecoderImpl::DoWritePixelsYUVINTERNAL( |
| 2110 | GLuint src_width, |
| 2111 | GLuint src_height, |
| 2112 | GLuint src_row_bytes_plane1, |
| 2113 | GLuint src_row_bytes_plane2, |
| 2114 | GLuint src_row_bytes_plane3, |
| 2115 | GLuint src_row_bytes_plane4, |
| 2116 | GLuint src_yuv_plane_config, |
| 2117 | GLuint src_yuv_subsampling, |
| 2118 | GLuint src_yuv_datatype, |
| 2119 | GLint shm_id, |
| 2120 | GLuint shm_offset, |
| 2121 | GLuint plane2_offset, |
| 2122 | GLuint plane3_offset, |
| 2123 | GLuint plane4_offset, |
| 2124 | const volatile GLbyte* mailbox) { |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2125 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoWritePixelsYUVINTERNAL"); |
| 2126 | if (src_yuv_plane_config < 0 || |
| 2127 | src_yuv_plane_config > static_cast<int>(SkYUVAInfo::PlaneConfig::kLast)) { |
| 2128 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "WritePixelsYUV", |
| 2129 | "src_yuv_plane_config must be a valid PlaneConfig"); |
| 2130 | return; |
| 2131 | } |
| 2132 | if (src_yuv_subsampling < 0 || |
| 2133 | src_yuv_subsampling > static_cast<int>(SkYUVAInfo::Subsampling::kLast)) { |
| 2134 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "WritePixelsYUV", |
| 2135 | "src_yuv_subsampling must be a valid Subsampling"); |
| 2136 | return; |
| 2137 | } |
| 2138 | if (src_yuv_datatype < 0 || |
| 2139 | src_yuv_datatype > static_cast<int>(SkYUVAPixmapInfo::DataType::kLast)) { |
| 2140 | LOCAL_SET_GL_ERROR( |
| 2141 | GL_INVALID_ENUM, "WritePixelsYUV", |
| 2142 | "src_yuv_datatype must be a valid SkYUVAPixmapInfo::DataType"); |
| 2143 | return; |
| 2144 | } |
| 2145 | |
| 2146 | Mailbox dest_mailbox = Mailbox::FromVolatile( |
| 2147 | *reinterpret_cast<const volatile Mailbox*>(mailbox)); |
| 2148 | DLOG_IF(ERROR, !dest_mailbox.Verify()) |
| 2149 | << "WritePixelsYUV was passed an invalid mailbox"; |
| 2150 | auto dest_shared_image = shared_image_representation_factory_.ProduceSkia( |
| 2151 | dest_mailbox, shared_context_state_); |
| 2152 | if (!dest_shared_image) { |
| 2153 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2154 | "Attempting to write to unknown mailbox."); |
| 2155 | return; |
| 2156 | } |
| 2157 | |
| 2158 | SkYUVAInfo::PlaneConfig src_plane_config = |
| 2159 | static_cast<SkYUVAInfo::PlaneConfig>(src_yuv_plane_config); |
| 2160 | SkYUVAInfo::Subsampling src_subsampling = |
| 2161 | static_cast<SkYUVAInfo::Subsampling>(src_yuv_subsampling); |
| 2162 | SkYUVAPixmapInfo::DataType src_datatype = |
| 2163 | static_cast<SkYUVAPixmapInfo::DataType>(src_yuv_datatype); |
| 2164 | viz::SharedImageFormat dest_format = dest_shared_image->format(); |
| 2165 | if (!dest_format.is_multi_plane()) { |
| 2166 | LOCAL_SET_GL_ERROR( |
| 2167 | GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2168 | "dest_format must be a valid multiplanar SharedImageFormat."); |
| 2169 | return; |
| 2170 | } |
| 2171 | if (src_plane_config != ToSkYUVAPlaneConfig(dest_format)) { |
| 2172 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2173 | "PlaneConfig mismatch between source texture format and " |
| 2174 | "the destination shared image format"); |
| 2175 | return; |
| 2176 | } |
| 2177 | if (src_subsampling != ToSkYUVASubsampling(dest_format)) { |
| 2178 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2179 | "Subsampling mismatch between source texture format and " |
| 2180 | "the destination shared image format"); |
| 2181 | return; |
| 2182 | } |
| 2183 | if (src_datatype != ToSkYUVADataType(dest_format)) { |
| 2184 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2185 | "ChannelFormat mismatch between source texture format " |
| 2186 | "and the destination shared image format"); |
| 2187 | return; |
| 2188 | } |
| 2189 | |
| 2190 | SkYUVAInfo yuv_info(SkISize::Make(src_width, src_height), src_plane_config, |
| 2191 | src_subsampling, |
| 2192 | SkYUVColorSpace::kIdentity_SkYUVColorSpace); |
| 2193 | if (yuv_info.numPlanes() != dest_format.NumberOfPlanes()) { |
| 2194 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2195 | "Planes mismatch between source texture format and the " |
| 2196 | "destination shared image format"); |
| 2197 | return; |
| 2198 | } |
| 2199 | |
| 2200 | if (gfx::Size(src_width, src_height) != dest_shared_image->size()) { |
| 2201 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2202 | "Unexpected size for multiplanar shared image"); |
| 2203 | return; |
| 2204 | } |
| 2205 | |
Arthur Sonzogni | 6718b70 | 2025-01-09 10:49:10 | [diff] [blame] | 2206 | std::array<size_t, SkYUVAInfo::kMaxPlanes> row_bytes; |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2207 | row_bytes[0] = src_row_bytes_plane1; |
| 2208 | row_bytes[1] = src_row_bytes_plane2; |
| 2209 | row_bytes[2] = src_row_bytes_plane3; |
| 2210 | row_bytes[3] = src_row_bytes_plane4; |
| 2211 | |
Arthur Sonzogni | 6718b70 | 2025-01-09 10:49:10 | [diff] [blame] | 2212 | std::array<size_t, SkYUVAInfo::kMaxPlanes> plane_offsets; |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2213 | plane_offsets[0] = 0; |
| 2214 | plane_offsets[1] = plane2_offset; |
| 2215 | plane_offsets[2] = plane3_offset; |
| 2216 | plane_offsets[3] = plane4_offset; |
| 2217 | |
Saifuddin Hitawala | 67ecd0a | 2023-07-06 18:00:14 | [diff] [blame] | 2218 | std::array<SkPixmap, SkYUVAInfo::kMaxPlanes> pixmaps = {}; |
| 2219 | |
Saifuddin Hitawala | 80dcaeb9 | 2024-01-08 18:38:07 | [diff] [blame] | 2220 | size_t prev_byte_size = 0; |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2221 | for (int plane = 0; plane < yuv_info.numPlanes(); plane++) { |
Vasiliy Telezhnikov | f240843 | 2024-12-12 14:59:38 | [diff] [blame] | 2222 | auto color_type = viz::ToClosestSkColorType(dest_format, plane); |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2223 | auto plane_size = |
| 2224 | dest_format.GetPlaneSize(plane, gfx::Size(src_width, src_height)); |
| 2225 | SkImageInfo src_info = |
| 2226 | SkImageInfo::Make(gfx::SizeToSkISize(plane_size), color_type, |
| 2227 | SkAlphaType::kPremul_SkAlphaType, nullptr); |
| 2228 | |
| 2229 | if (row_bytes[plane] < src_info.minRowBytes()) { |
| 2230 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glWritePixelsYUV", |
| 2231 | "row_bytes must be >= " |
| 2232 | "SkImageInfo::minRowBytes() for source image."); |
| 2233 | return; |
| 2234 | } |
| 2235 | |
| 2236 | size_t byte_size = src_info.computeByteSize(row_bytes[plane]); |
| 2237 | if (byte_size > UINT32_MAX) { |
| 2238 | LOCAL_SET_GL_ERROR( |
| 2239 | GL_INVALID_VALUE, "glWritePixelsYUV", |
| 2240 | "Cannot request a memory chunk larger than UINT32_MAX bytes"); |
| 2241 | return; |
| 2242 | } |
| 2243 | if (plane > 0 && |
Saifuddin Hitawala | 80dcaeb9 | 2024-01-08 18:38:07 | [diff] [blame] | 2244 | plane_offsets[plane] < plane_offsets[plane - 1] + prev_byte_size) { |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2245 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glWritePixelsYUV", |
| 2246 | "plane_offsets[plane] must be >= plane_offsets[plane " |
Saifuddin Hitawala | 80dcaeb9 | 2024-01-08 18:38:07 | [diff] [blame] | 2247 | "- 1] + prev_byte_size"); |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2248 | return; |
| 2249 | } |
| 2250 | |
| 2251 | // The pixels are stored contiguously for all the planes one after another |
| 2252 | // with padding. |
| 2253 | void* pixel_data = GetSharedMemoryAs<void*>( |
| 2254 | shm_id, shm_offset + plane_offsets[plane], byte_size); |
| 2255 | if (!pixel_data) { |
| 2256 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2257 | "Couldn't retrieve pixel data."); |
| 2258 | return; |
| 2259 | } |
| 2260 | |
Saifuddin Hitawala | 67ecd0a | 2023-07-06 18:00:14 | [diff] [blame] | 2261 | // Create an SkPixmap for the plane. |
| 2262 | pixmaps[plane] = SkPixmap(src_info, pixel_data, row_bytes[plane]); |
Saifuddin Hitawala | 80dcaeb9 | 2024-01-08 18:38:07 | [diff] [blame] | 2263 | prev_byte_size = byte_size; |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2264 | } |
| 2265 | |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2266 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2267 | std::vector<GrBackendSemaphore> end_semaphores; |
| 2268 | |
| 2269 | // Allow uncleared access, as we manually handle clear tracking. |
| 2270 | std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess> |
| 2271 | dest_scoped_access = dest_shared_image->BeginScopedWriteAccess( |
| 2272 | &begin_semaphores, &end_semaphores, |
| 2273 | SharedImageRepresentation::AllowUnclearedAccess::kYes, |
| 2274 | /*use_sk_surface=*/false); |
| 2275 | if (!dest_scoped_access) { |
| 2276 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glWritePixelsYUV", |
| 2277 | "Failed to begin scoped write access."); |
| 2278 | return; |
| 2279 | } |
| 2280 | if (!begin_semaphores.empty()) { |
| 2281 | // The Graphite SharedImage representation does not set semaphores. |
| 2282 | CHECK(gr_context()); |
| 2283 | bool result = |
| 2284 | gr_context()->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2285 | /*deleteSemaphoresAfterWait=*/false); |
| 2286 | CHECK(result); |
| 2287 | } |
| 2288 | |
Saifuddin Hitawala | 67ecd0a | 2023-07-06 18:00:14 | [diff] [blame] | 2289 | // Try a direct texture upload without using SkSurface. |
| 2290 | CopySharedImageHelper helper(&shared_image_representation_factory_, |
| 2291 | shared_context_state_.get()); |
| 2292 | auto helper_result = helper.WritePixelsYUV( |
| 2293 | src_width, src_height, pixmaps, std::move(end_semaphores), |
| 2294 | std::move(dest_shared_image), std::move(dest_scoped_access)); |
| 2295 | if (!helper_result.has_value()) { |
| 2296 | LOCAL_SET_GL_ERROR(helper_result.error().gl_error, |
| 2297 | helper_result.error().function_name.c_str(), |
| 2298 | helper_result.error().msg.c_str()); |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2299 | } |
Saifuddin Hitawala | 9d8a52dd | 2023-06-26 20:21:37 | [diff] [blame] | 2300 | } |
| 2301 | |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2302 | bool RasterDecoderImpl::DoWritePixelsINTERNALDirectTextureUpload( |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 2303 | SkiaImageRepresentation* dest_shared_image, |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2304 | const SkImageInfo& src_info, |
| 2305 | const void* pixel_data, |
| 2306 | size_t row_bytes) { |
| 2307 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2308 | std::vector<GrBackendSemaphore> end_semaphores; |
| 2309 | |
| 2310 | // Allow uncleared access, as we manually handle clear tracking. |
Saifuddin Hitawala | daed597 | 2022-07-20 22:01:01 | [diff] [blame] | 2311 | std::unique_ptr<SkiaImageRepresentation::ScopedWriteAccess> |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2312 | dest_scoped_access = dest_shared_image->BeginScopedWriteAccess( |
| 2313 | &begin_semaphores, &end_semaphores, |
| 2314 | SharedImageRepresentation::AllowUnclearedAccess::kYes, |
Saifuddin Hitawala | c1eeaa9c | 2023-06-26 20:33:07 | [diff] [blame] | 2315 | /*use_sk_surface=*/false); |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2316 | if (!dest_scoped_access) { |
| 2317 | return false; |
| 2318 | } |
| 2319 | if (!begin_semaphores.empty()) { |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2320 | // The Graphite SharedImage representation does not set semaphores. |
| 2321 | CHECK(gr_context()); |
| 2322 | bool result = |
| 2323 | gr_context()->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2324 | /*deleteSemaphoresAfterWait=*/false); |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2325 | DCHECK(result); |
| 2326 | } |
| 2327 | |
| 2328 | SkPixmap pixmap(src_info, pixel_data, row_bytes); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2329 | bool written = false; |
| 2330 | if (gr_context()) { |
| 2331 | written = gr_context()->updateBackendTexture( |
Saifuddin Hitawala | 8c8af1e | 2024-04-09 19:45:32 | [diff] [blame] | 2332 | dest_scoped_access->promise_image_texture(/*plane_index=*/0) |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2333 | ->backendTexture(), |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2334 | &pixmap, /*numLevels=*/1, dest_shared_image->surface_origin(), |
| 2335 | /*finishedProc=*/nullptr, /*finishedContext=*/nullptr); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2336 | } else { |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 2337 | CHECK(graphite_shared_context()); |
Le Hoang Quyen | 9b068a8 | 2025-02-27 21:50:46 | [diff] [blame] | 2338 | auto graphite_texture_ref = |
| 2339 | dest_scoped_access->graphite_texture_holder(/*plane_index=*/0); |
| 2340 | auto* graphite_texture_ptr = graphite_texture_ref.release(); |
| 2341 | using graphite_texture_ptr_type = decltype(graphite_texture_ptr); |
| 2342 | auto release_proc = [](void* context, skgpu::CallbackResult) { |
| 2343 | static_cast<graphite_texture_ptr_type>(context)->Release(); |
| 2344 | }; |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2345 | written = graphite_recorder()->updateBackendTexture( |
Le Hoang Quyen | 9b068a8 | 2025-02-27 21:50:46 | [diff] [blame] | 2346 | graphite_texture_ptr->texture(), &pixmap, |
| 2347 | /*numLevels=*/1, release_proc, graphite_texture_ptr); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2348 | } |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2349 | |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2350 | shared_context_state_->FlushWriteAccess(dest_scoped_access.get()); |
Le Hoang Quyen | 9b068a8 | 2025-02-27 21:50:46 | [diff] [blame] | 2351 | shared_context_state_->SubmitIfNecessary( |
| 2352 | std::move(end_semaphores), |
| 2353 | dest_scoped_access->NeedGraphiteContextSubmit()); |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2354 | |
Jonah Chin | 67897ae6 | 2020-12-08 21:13:20 | [diff] [blame] | 2355 | return written; |
| 2356 | } |
| 2357 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2358 | void RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL( |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2359 | GLint src_x, |
| 2360 | GLint src_y, |
Saifuddin Hitawala | f32b28c | 2023-02-22 23:30:38 | [diff] [blame] | 2361 | GLint plane_index, |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2362 | GLuint dst_width, |
| 2363 | GLuint dst_height, |
| 2364 | GLuint row_bytes, |
| 2365 | GLuint dst_sk_color_type, |
| 2366 | GLuint dst_sk_alpha_type, |
| 2367 | GLint shm_id, |
| 2368 | GLuint shm_offset, |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2369 | GLuint color_space_offset, |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2370 | GLuint pixels_offset, |
| 2371 | const volatile GLbyte* mailbox) { |
Justin Novosad | 129aa3ea4 | 2021-12-10 20:06:31 | [diff] [blame] | 2372 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoReadbackARGBImagePixelsINTERNAL"); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2373 | if (dst_sk_color_type > kLastEnum_SkColorType) { |
| 2374 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "ReadbackImagePixels", |
| 2375 | "dst_sk_color_type must be a valid SkColorType"); |
| 2376 | return; |
| 2377 | } |
| 2378 | if (dst_sk_alpha_type > kLastEnum_SkAlphaType) { |
| 2379 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "ReadbackImagePixels", |
| 2380 | "dst_sk_alpha_type must be a valid SkAlphaType"); |
| 2381 | return; |
| 2382 | } |
| 2383 | |
| 2384 | Mailbox source_mailbox = Mailbox::FromVolatile( |
| 2385 | *reinterpret_cast<const volatile Mailbox*>(mailbox)); |
| 2386 | DLOG_IF(ERROR, !source_mailbox.Verify()) |
| 2387 | << "ReadbackImagePixels was passed an invalid mailbox"; |
| 2388 | auto source_shared_image = shared_image_representation_factory_.ProduceSkia( |
| 2389 | source_mailbox, shared_context_state_); |
| 2390 | if (!source_shared_image) { |
| 2391 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2392 | "Unknown mailbox"); |
| 2393 | return; |
| 2394 | } |
| 2395 | |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2396 | viz::SharedImageFormat source_format = source_shared_image->format(); |
| 2397 | |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2398 | // If present, the color space is serialized into shared memory after the |
| 2399 | // result and before the pixel data. |
| 2400 | if (color_space_offset > pixels_offset) { |
| 2401 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2402 | "|pixels_offset| must be >= |color_space_offset|"); |
| 2403 | return; |
| 2404 | } |
| 2405 | unsigned int color_space_size = pixels_offset - color_space_offset; |
| 2406 | |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2407 | sk_sp<SkColorSpace> dst_color_space; |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2408 | if (color_space_size) { |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2409 | // For multiplanar formats readback is per plane, and destination color |
Saifuddin Hitawala | 6c8b833 | 2023-03-03 18:21:30 | [diff] [blame] | 2410 | // space must be nullptr to avoid unexpected color conversions. |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2411 | if (source_format.is_multi_plane()) { |
| 2412 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
| 2413 | "Unexpected color space for multiplanar shared image"); |
| 2414 | return; |
| 2415 | } |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2416 | void* color_space_bytes = GetSharedMemoryAs<void*>( |
| 2417 | shm_id, shm_offset + color_space_offset, color_space_size); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2418 | if (!color_space_bytes) { |
| 2419 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
| 2420 | "Failed to retrieve serialized SkColorSpace."); |
| 2421 | return; |
| 2422 | } |
| 2423 | dst_color_space = |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2424 | SkColorSpace::Deserialize(color_space_bytes, color_space_size); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2425 | if (!dst_color_space) { |
| 2426 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
| 2427 | "Failed to deserialize expected SkColorSpace"); |
| 2428 | return; |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | SkImageInfo dst_info = SkImageInfo::Make( |
| 2433 | dst_width, dst_height, static_cast<SkColorType>(dst_sk_color_type), |
| 2434 | static_cast<SkAlphaType>(dst_sk_alpha_type), std::move(dst_color_space)); |
| 2435 | |
| 2436 | if (row_bytes < dst_info.minRowBytes()) { |
| 2437 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2438 | "row_bytes be >= " |
| 2439 | "SkImageInfo::minRowBytes() for dest image."); |
| 2440 | return; |
| 2441 | } |
| 2442 | |
Jonah Chin | 76a78002 | 2020-08-13 20:45:26 | [diff] [blame] | 2443 | size_t byte_size = dst_info.computeByteSize(row_bytes); |
| 2444 | if (byte_size > UINT32_MAX) { |
| 2445 | LOCAL_SET_GL_ERROR( |
| 2446 | GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2447 | "Cannot request a memory chunk larger than UINT32_MAX bytes"); |
| 2448 | return; |
| 2449 | } |
| 2450 | |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2451 | void* pixel_address = |
Jonah Chin | 76a78002 | 2020-08-13 20:45:26 | [diff] [blame] | 2452 | GetSharedMemoryAs<void*>(shm_id, shm_offset + pixels_offset, byte_size); |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2453 | if (!pixel_address) { |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2454 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2455 | "Failed to retrieve memory for readPixels output"); |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2456 | return; |
| 2457 | } |
| 2458 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2459 | typedef cmds::ReadbackARGBImagePixelsINTERNALImmediate::Result Result; |
Nathan Zabriskie | 7febc870 | 2021-04-29 18:52:40 | [diff] [blame] | 2460 | Result* result = |
| 2461 | GetSharedMemoryAs<Result*>(shm_id, shm_offset, sizeof(Result)); |
| 2462 | if (!result) { |
| 2463 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
| 2464 | "Failed to retrieve memory for readPixels result"); |
| 2465 | return; |
Jonah Chin | f16050a | 2021-02-24 03:27:44 | [diff] [blame] | 2466 | } |
| 2467 | |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2468 | if (!source_format.IsValidPlaneIndex(plane_index)) { |
| 2469 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
| 2470 | "Invalid plane_index"); |
| 2471 | return; |
| 2472 | } |
| 2473 | |
Vasiliy Telezhnikov | 3758806 | 2024-01-12 13:58:37 | [diff] [blame] | 2474 | // Readback is potentially slow, so report progress here. |
| 2475 | gl::ScopedProgressReporter report_progress( |
| 2476 | shared_context_state_->progress_reporter()); |
| 2477 | |
Saifuddin Hitawala | 6c8b833 | 2023-03-03 18:21:30 | [diff] [blame] | 2478 | CopySharedImageHelper helper(&shared_image_representation_factory_, |
| 2479 | shared_context_state_.get()); |
| 2480 | auto helper_result = |
| 2481 | helper.ReadPixels(src_x, src_y, plane_index, row_bytes, dst_info, |
| 2482 | pixel_address, std::move(source_shared_image)); |
| 2483 | if (!helper_result.has_value()) { |
| 2484 | LOCAL_SET_GL_ERROR(helper_result.error().gl_error, |
| 2485 | helper_result.error().function_name.c_str(), |
| 2486 | helper_result.error().msg.c_str()); |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2487 | } else { |
Saifuddin Hitawala | 6c8b833 | 2023-03-03 18:21:30 | [diff] [blame] | 2488 | *result = 1; |
Saifuddin Hitawala | 3db13d0 | 2023-02-23 13:27:19 | [diff] [blame] | 2489 | } |
Jonah Chin | d9d7a73 | 2020-07-17 23:32:11 | [diff] [blame] | 2490 | } |
| 2491 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2492 | namespace { |
| 2493 | struct YUVReadbackResult { |
| 2494 | std::unique_ptr<const SkImage::AsyncReadResult> async_result; |
Vasiliy Telezhnikov | 081df1e | 2023-01-16 15:41:34 | [diff] [blame] | 2495 | bool finished = false; |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2496 | }; |
| 2497 | |
| 2498 | void OnReadYUVImagePixelsDone( |
| 2499 | void* raw_ctx, |
| 2500 | std::unique_ptr<const SkImage::AsyncReadResult> async_result) { |
| 2501 | YUVReadbackResult* context = reinterpret_cast<YUVReadbackResult*>(raw_ctx); |
| 2502 | context->async_result = std::move(async_result); |
Vasiliy Telezhnikov | 081df1e | 2023-01-16 15:41:34 | [diff] [blame] | 2503 | context->finished = true; |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2504 | } |
| 2505 | } // namespace |
| 2506 | |
| 2507 | void RasterDecoderImpl::DoReadbackYUVImagePixelsINTERNAL( |
| 2508 | GLuint dst_width, |
| 2509 | GLuint dst_height, |
| 2510 | GLint shm_id, |
| 2511 | GLuint shm_offset, |
| 2512 | GLuint y_offset, |
| 2513 | GLuint y_stride, |
| 2514 | GLuint u_offset, |
| 2515 | GLuint u_stride, |
| 2516 | GLuint v_offset, |
| 2517 | GLuint v_stride, |
| 2518 | const volatile GLbyte* mailbox) { |
Justin Novosad | 129aa3ea4 | 2021-12-10 20:06:31 | [diff] [blame] | 2519 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoReadbackYUVImagePixelsINTERNAL"); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2520 | if (dst_width % 2 != 0 || dst_height % 2 != 0) { |
| 2521 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2522 | "|dst_width| and |dst_height| must be divisible by 2"); |
| 2523 | return; |
| 2524 | } |
| 2525 | |
Vasiliy Telezhnikov | f3f0ffd | 2021-06-22 14:19:18 | [diff] [blame] | 2526 | if (y_stride < dst_width) { |
| 2527 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2528 | "|y_stride| must be >= the width of the y plane."); |
| 2529 | return; |
| 2530 | } |
| 2531 | |
| 2532 | if (u_stride < ((dst_width + 1) / 2)) { |
| 2533 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2534 | "|u_stride| must be >= the width of the u plane."); |
| 2535 | return; |
| 2536 | } |
| 2537 | if (v_stride < ((dst_width + 1) / 2)) { |
| 2538 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2539 | "|v_stride| must be >= the width of the u plane."); |
| 2540 | return; |
| 2541 | } |
| 2542 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2543 | Mailbox source_mailbox = Mailbox::FromVolatile( |
| 2544 | *reinterpret_cast<const volatile Mailbox*>(mailbox)); |
| 2545 | DLOG_IF(ERROR, !source_mailbox.Verify()) |
| 2546 | << "ReadbackImagePixels was passed an invalid mailbox"; |
| 2547 | auto source_shared_image = shared_image_representation_factory_.ProduceSkia( |
| 2548 | source_mailbox, shared_context_state_); |
| 2549 | if (!source_shared_image) { |
| 2550 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2551 | "Unknown mailbox"); |
| 2552 | return; |
| 2553 | } |
| 2554 | |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2555 | auto* result = GetSharedMemoryAs< |
| 2556 | cmds::ReadbackARGBImagePixelsINTERNALImmediate::Result*>( |
| 2557 | shm_id, shm_offset, |
| 2558 | sizeof(cmds::ReadbackARGBImagePixelsINTERNALImmediate::Result)); |
| 2559 | if (!result) { |
| 2560 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2561 | "Failed to retrieve memory for readPixels result"); |
| 2562 | return; |
| 2563 | } |
| 2564 | |
Nathan Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 2565 | // Large plane strides or heights could potentially overflow the unsigned int |
| 2566 | // parameters of GetSharedMemoryAs() below. We use base::CheckedNumeric to |
| 2567 | // prevent using any values that overflowed which could cause us to request |
| 2568 | // incorrect shared memory regions. |
| 2569 | base::CheckedNumeric<unsigned int> checked_shm_offset(shm_offset); |
| 2570 | base::CheckedNumeric<unsigned int> checked_dst_height(dst_height); |
| 2571 | |
| 2572 | base::CheckedNumeric<unsigned int> y_size = checked_dst_height * y_stride; |
| 2573 | base::CheckedNumeric<unsigned int> y_plane_offset = |
| 2574 | checked_shm_offset + y_offset; |
| 2575 | if (!y_size.IsValid() || !y_plane_offset.IsValid()) { |
| 2576 | LOCAL_SET_GL_ERROR( |
| 2577 | GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2578 | "y plane size or offset too large. Both must fit in unsigned int."); |
| 2579 | return; |
| 2580 | } |
| 2581 | |
| 2582 | // |y_plane_offset| and |y_size| are guaranteed valid by the checks above and |
| 2583 | // won't die here. Same with the u and v planes below. |
| 2584 | uint8_t* y_out = GetSharedMemoryAs<uint8_t*>( |
| 2585 | shm_id, y_plane_offset.ValueOrDie(), y_size.ValueOrDie()); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2586 | if (!y_out) { |
| 2587 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2588 | "Failed to get memory for y plane output"); |
| 2589 | return; |
| 2590 | } |
| 2591 | |
Nathan Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 2592 | base::CheckedNumeric<unsigned int> checked_uv_plane_height = |
| 2593 | (checked_dst_height + 1) / 2; |
| 2594 | |
| 2595 | base::CheckedNumeric<unsigned int> u_size = |
| 2596 | checked_uv_plane_height * u_stride; |
| 2597 | base::CheckedNumeric<unsigned int> u_plane_offset = |
| 2598 | checked_shm_offset + u_offset; |
| 2599 | if (!u_size.IsValid() || !u_plane_offset.IsValid()) { |
| 2600 | LOCAL_SET_GL_ERROR( |
| 2601 | GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2602 | "u plane size or offset too large. Both must fit in unsigned int."); |
| 2603 | return; |
| 2604 | } |
| 2605 | uint8_t* u_out = GetSharedMemoryAs<uint8_t*>( |
| 2606 | shm_id, u_plane_offset.ValueOrDie(), u_size.ValueOrDie()); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2607 | if (!u_out) { |
| 2608 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2609 | "Failed to get memory for u plane output"); |
| 2610 | return; |
| 2611 | } |
| 2612 | |
Nathan Zabriskie | 4912893 | 2021-07-08 20:00:31 | [diff] [blame] | 2613 | base::CheckedNumeric<unsigned int> v_size = |
| 2614 | checked_uv_plane_height * v_stride; |
| 2615 | base::CheckedNumeric<unsigned int> v_plane_offset = |
| 2616 | checked_shm_offset + v_offset; |
| 2617 | if (!v_size.IsValid() || !v_plane_offset.IsValid()) { |
| 2618 | LOCAL_SET_GL_ERROR( |
| 2619 | GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2620 | "v plane size or offset too large. Both must fit in unsigned int."); |
| 2621 | return; |
| 2622 | } |
| 2623 | uint8_t* v_out = GetSharedMemoryAs<uint8_t*>( |
| 2624 | shm_id, v_plane_offset.ValueOrDie(), v_size.ValueOrDie()); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2625 | if (!v_out) { |
| 2626 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2627 | "Failed to get memory for v plane output"); |
| 2628 | return; |
| 2629 | } |
| 2630 | |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2631 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2632 | std::vector<GrBackendSemaphore> end_semaphores; |
| 2633 | |
| 2634 | // We don't use |end_semaphores| here because we're going to sync with |
| 2635 | // with the CPU later regardless. |
| 2636 | std::unique_ptr<SkiaImageRepresentation::ScopedReadAccess> |
| 2637 | source_scoped_access = source_shared_image->BeginScopedReadAccess( |
| 2638 | &begin_semaphores, &end_semaphores); |
| 2639 | |
| 2640 | if (!begin_semaphores.empty()) { |
| 2641 | CHECK(gr_context()); |
| 2642 | bool wait_result = |
| 2643 | gr_context()->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2644 | /*deleteSemaphoresAfterWait=*/false); |
| 2645 | DCHECK(wait_result); |
| 2646 | } |
| 2647 | |
| 2648 | if (!source_scoped_access) { |
| 2649 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadbackImagePixels", |
| 2650 | "Source shared image is not accessible"); |
| 2651 | return; |
| 2652 | } |
| 2653 | |
| 2654 | auto sk_image = |
| 2655 | source_scoped_access->CreateSkImage(shared_context_state_.get()); |
| 2656 | if (!sk_image) { |
| 2657 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackImagePixels", |
| 2658 | "Couldn't create SkImage for reading."); |
| 2659 | // Perform ApplyBackendSurfaceEndState() on the ScopedReadAccess before |
| 2660 | // exiting. |
| 2661 | source_scoped_access->ApplyBackendSurfaceEndState(); |
Saifuddin Hitawala | 7065278 | 2024-08-21 14:13:32 | [diff] [blame] | 2662 | shared_context_state_->SubmitIfNecessary( |
| 2663 | std::move(end_semaphores), |
| 2664 | source_scoped_access->NeedGraphiteContextSubmit()); |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2665 | return; |
| 2666 | } |
| 2667 | |
Sunny Sachanandani | bbeca84 | 2023-06-30 08:07:59 | [diff] [blame] | 2668 | const SkIRect src_rect = SkIRect::MakeSize(sk_image->dimensions()); |
| 2669 | const SkISize dst_size = SkISize::Make(dst_width, dst_height); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2670 | |
Vasiliy Telezhnikov | 3758806 | 2024-01-12 13:58:37 | [diff] [blame] | 2671 | // Readback is potentially slow, so report progress here. |
| 2672 | gl::ScopedProgressReporter report_progress( |
| 2673 | shared_context_state_->progress_reporter()); |
| 2674 | |
Sunny Sachanandani | bbeca84 | 2023-06-30 08:07:59 | [diff] [blame] | 2675 | // While this function indicates it's asynchronous, the DoFinish() call below |
| 2676 | // ensures it completes synchronously. |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2677 | YUVReadbackResult yuv_result; |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 2678 | if (graphite_shared_context()) { |
Sunny Sachanandani | 1a163cf | 2023-07-05 22:00:29 | [diff] [blame] | 2679 | // SkImage/SkSurface asyncRescaleAndReadPixels methods won't be implemented |
| 2680 | // for Graphite. Instead the equivalent methods will be on Graphite Context. |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 2681 | graphite_shared_context()->asyncRescaleAndReadPixelsYUV420( |
Sunny Sachanandani | bbeca84 | 2023-06-30 08:07:59 | [diff] [blame] | 2682 | sk_image.get(), kJPEG_Full_SkYUVColorSpace, SkColorSpace::MakeSRGB(), |
| 2683 | src_rect, dst_size, SkImage::RescaleGamma::kSrc, |
Maggie Chen | fb6a9868 | 2025-05-12 19:59:50 | [diff] [blame] | 2684 | SkImage::RescaleMode::kRepeatedLinear, |
| 2685 | base::BindOnce(&OnReadYUVImagePixelsDone), &yuv_result); |
Sunny Sachanandani | bbeca84 | 2023-06-30 08:07:59 | [diff] [blame] | 2686 | } else { |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2687 | CHECK(gr_context()); |
Sunny Sachanandani | bbeca84 | 2023-06-30 08:07:59 | [diff] [blame] | 2688 | sk_image->asyncRescaleAndReadPixelsYUV420( |
| 2689 | kJPEG_Full_SkYUVColorSpace, SkColorSpace::MakeSRGB(), src_rect, |
| 2690 | dst_size, SkImage::RescaleGamma::kSrc, |
| 2691 | SkImage::RescaleMode::kRepeatedLinear, &OnReadYUVImagePixelsDone, |
| 2692 | &yuv_result); |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 2693 | source_scoped_access->ApplyBackendSurfaceEndState(); |
| 2694 | if (!end_semaphores.empty()) { |
| 2695 | GrFlushInfo flush_info = { |
| 2696 | .fNumSemaphores = end_semaphores.size(), |
| 2697 | .fSignalSemaphores = end_semaphores.data(), |
| 2698 | }; |
| 2699 | AddVulkanCleanupTaskForSkiaFlush( |
| 2700 | shared_context_state_->vk_context_provider(), &flush_info); |
| 2701 | gr_context()->flush(flush_info); |
| 2702 | } |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 2703 | } |
| 2704 | |
Alison Gale | 47d1537d | 2024-04-19 21:31:46 | [diff] [blame] | 2705 | // TODO(crbug.com/40106956): Use COMMANDS_COMPLETED query for async readback. |
Saifuddin Hitawala | d902766 | 2023-05-12 14:50:10 | [diff] [blame] | 2706 | DoFinish(); |
Vasiliy Telezhnikov | 081df1e | 2023-01-16 15:41:34 | [diff] [blame] | 2707 | |
| 2708 | // The call above will sync up gpu and CPU, resulting in callback being run |
Sunny Sachanandani | bbeca84 | 2023-06-30 08:07:59 | [diff] [blame] | 2709 | // during DoFinish(). To prevent UAF make sure it indeed happened. |
Vasiliy Telezhnikov | 081df1e | 2023-01-16 15:41:34 | [diff] [blame] | 2710 | CHECK(yuv_result.finished); |
Nathan Zabriskie | f5f270e | 2021-04-30 20:53:06 | [diff] [blame] | 2711 | if (!yuv_result.async_result) { |
| 2712 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glReadbackYUVImagePixels", |
| 2713 | "Failed to read pixels from SkImage"); |
| 2714 | return; |
| 2715 | } |
| 2716 | |
| 2717 | auto& async_result = yuv_result.async_result; |
| 2718 | libyuv::I420Copy(static_cast<const uint8_t*>(async_result->data(0)), |
| 2719 | async_result->rowBytes(0), |
| 2720 | static_cast<const uint8_t*>(async_result->data(1)), |
| 2721 | async_result->rowBytes(1), |
| 2722 | static_cast<const uint8_t*>(async_result->data(2)), |
| 2723 | async_result->rowBytes(2), y_out, y_stride, u_out, u_stride, |
| 2724 | v_out, v_stride, dst_width, dst_height); |
| 2725 | |
| 2726 | *result = 1; |
| 2727 | } |
| 2728 | |
Jonah Chin | 053aa6c | 2021-01-22 20:26:14 | [diff] [blame] | 2729 | void RasterDecoderImpl::DoLoseContextCHROMIUM(GLenum current, GLenum other) { |
| 2730 | MarkContextLost(gles2::GetContextLostReasonFromResetStatus(current)); |
| 2731 | } |
| 2732 | |
Nathan Zabriskie | 366b893 | 2020-04-28 01:07:13 | [diff] [blame] | 2733 | namespace { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2734 | |
| 2735 | // Helper to read client data from transfer cache. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2736 | class TransferCacheDeserializeHelperImpl final |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2737 | : public cc::TransferCacheDeserializeHelper { |
| 2738 | public: |
| 2739 | explicit TransferCacheDeserializeHelperImpl( |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2740 | int raster_decoder_id, |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2741 | ServiceTransferCache* transfer_cache) |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2742 | : raster_decoder_id_(raster_decoder_id), transfer_cache_(transfer_cache) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2743 | DCHECK(transfer_cache_); |
| 2744 | } |
Peter BostrÃļm | dbacdc2 | 2021-09-23 22:11:46 | [diff] [blame] | 2745 | |
| 2746 | TransferCacheDeserializeHelperImpl( |
| 2747 | const TransferCacheDeserializeHelperImpl&) = delete; |
| 2748 | TransferCacheDeserializeHelperImpl& operator=( |
| 2749 | const TransferCacheDeserializeHelperImpl&) = delete; |
| 2750 | |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2751 | ~TransferCacheDeserializeHelperImpl() override = default; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2752 | |
Adrienne Walker | 90b79a2 | 2018-05-08 21:40:42 | [diff] [blame] | 2753 | void CreateLocalEntry( |
| 2754 | uint32_t id, |
| 2755 | std::unique_ptr<cc::ServiceTransferCacheEntry> entry) override { |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2756 | auto type = entry->Type(); |
| 2757 | transfer_cache_->CreateLocalEntry( |
| 2758 | ServiceTransferCache::EntryKey(raster_decoder_id_, type, id), |
| 2759 | std::move(entry)); |
Adrienne Walker | 90b79a2 | 2018-05-08 21:40:42 | [diff] [blame] | 2760 | } |
| 2761 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2762 | private: |
| 2763 | cc::ServiceTransferCacheEntry* GetEntryInternal( |
| 2764 | cc::TransferCacheEntryType entry_type, |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2765 | uint32_t entry_id) override { |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2766 | return transfer_cache_->GetEntry(ServiceTransferCache::EntryKey( |
| 2767 | raster_decoder_id_, entry_type, entry_id)); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2768 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2769 | |
| 2770 | const int raster_decoder_id_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 2771 | const raw_ptr<ServiceTransferCache> transfer_cache_; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2772 | }; |
| 2773 | |
| 2774 | } // namespace |
| 2775 | |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2776 | void RasterDecoderImpl::DeletePaintCachePathsINTERNALHelper( |
| 2777 | GLsizei n, |
| 2778 | const volatile GLuint* paint_cache_ids) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2779 | if (!use_gpu_raster_) { |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2780 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 2781 | "glDeletePaintCacheEntriesINTERNAL", |
| 2782 | "No chromium raster support"); |
| 2783 | return; |
| 2784 | } |
| 2785 | |
Khushal | cb653fb | 2018-11-15 08:56:28 | [diff] [blame] | 2786 | paint_cache_->Purge(cc::PaintCacheDataType::kPath, n, paint_cache_ids); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2787 | } |
| 2788 | |
William Liu | 88a553387 | 2025-03-18 19:11:47 | [diff] [blame] | 2789 | void RasterDecoderImpl::DeletePaintCacheEffectsINTERNALHelper( |
| 2790 | GLsizei n, |
| 2791 | const volatile GLuint* paint_cache_ids) { |
| 2792 | if (!use_gpu_raster_) { |
| 2793 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 2794 | "glDeletePaintCacheEntriesINTERNAL", |
| 2795 | "No chromium raster support"); |
| 2796 | return; |
| 2797 | } |
| 2798 | paint_cache_->Purge(cc::PaintCacheDataType::kSkRuntimeEffect, n, |
| 2799 | paint_cache_ids); |
| 2800 | } |
| 2801 | |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2802 | void RasterDecoderImpl::DoClearPaintCacheINTERNAL() { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2803 | if (!use_gpu_raster_) { |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2804 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glClearPaintCacheINTERNAL", |
| 2805 | "No chromium raster support"); |
| 2806 | return; |
| 2807 | } |
| 2808 | |
| 2809 | paint_cache_->PurgeAll(); |
| 2810 | } |
| 2811 | |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2812 | void RasterDecoderImpl::DoBeginRasterCHROMIUM(GLfloat r, |
| 2813 | GLfloat g, |
| 2814 | GLfloat b, |
| 2815 | GLfloat a, |
Sunny Sachanandani | b461e21 | 2021-03-05 19:22:12 | [diff] [blame] | 2816 | GLboolean needs_clear, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2817 | GLuint msaa_sample_count, |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2818 | MsaaMode msaa_mode, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2819 | GLboolean can_use_lcd_text, |
Peng Huang | 5ff70dff | 2022-03-03 19:55:11 | [diff] [blame] | 2820 | GLboolean visible, |
Christopher Cameron | 060d382e7 | 2023-10-04 23:12:42 | [diff] [blame] | 2821 | GLfloat hdr_headroom, |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2822 | const volatile GLbyte* key) { |
Vikas Soni | 9db200c | 2023-11-20 19:26:20 | [diff] [blame] | 2823 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoBeginRasterCHROMIUM"); |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 2824 | // Workaround for https://crbug.com/906453: Flush before BeginRaster (the |
| 2825 | // commands between BeginRaster and EndRaster will not flush). |
| 2826 | FlushToWorkAroundMacCrashes(); |
| 2827 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2828 | if (!use_gpu_raster_) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2829 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 2830 | "No chromium raster support"); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2831 | return; |
| 2832 | } |
| 2833 | if (sk_surface_) { |
| 2834 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2835 | "BeginRasterCHROMIUM without EndRasterCHROMIUM"); |
| 2836 | return; |
| 2837 | } |
| 2838 | |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 2839 | Mailbox mailbox = |
| 2840 | Mailbox::FromVolatile(*reinterpret_cast<const volatile Mailbox*>(key)); |
| 2841 | DLOG_IF(ERROR, !mailbox.Verify()) << "BeginRasterCHROMIUM was " |
| 2842 | "passed a mailbox that was not " |
| 2843 | "generated by ProduceTextureCHROMIUM."; |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2844 | |
| 2845 | DCHECK(!shared_image_); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2846 | DCHECK(!shared_image_raster_); |
| 2847 | |
| 2848 | SharedImageRepresentation* shared_image = nullptr; |
| 2849 | if (is_raw_draw_enabled_) { |
| 2850 | shared_image_raster_ = |
| 2851 | shared_image_representation_factory_.ProduceRaster(mailbox); |
| 2852 | shared_image = shared_image_raster_.get(); |
| 2853 | } |
| 2854 | |
| 2855 | if (!shared_image) { |
| 2856 | shared_image_ = shared_image_representation_factory_.ProduceSkia( |
| 2857 | mailbox, shared_context_state_.get()); |
| 2858 | shared_image = shared_image_.get(); |
| 2859 | } |
| 2860 | |
| 2861 | if (!shared_image) { |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 2862 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glBeginRasterCHROMIUM", |
| 2863 | "passed invalid mailbox."); |
| 2864 | return; |
| 2865 | } |
| 2866 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2867 | if (!needs_clear && !shared_image->IsCleared()) { |
Sunny Sachanandani | bb3dfad | 2021-06-04 19:04:22 | [diff] [blame] | 2868 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2869 | "SharedImage not cleared before use."); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2870 | shared_image_raster_.reset(); |
Sunny Sachanandani | 8f8b4eae | 2021-06-07 19:14:16 | [diff] [blame] | 2871 | shared_image_.reset(); |
Sunny Sachanandani | bb3dfad | 2021-06-04 19:04:22 | [diff] [blame] | 2872 | return; |
| 2873 | } |
| 2874 | |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 2875 | DCHECK(locked_handles_.empty()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2876 | DCHECK(!raster_canvas_); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2877 | |
Vasiliy Telezhnikov | 1470c97 | 2025-01-13 15:49:44 | [diff] [blame] | 2878 | SkColorType sk_color_type = viz::ToClosestSkColorType(shared_image->format()); |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2879 | |
| 2880 | int final_msaa_count; |
| 2881 | uint32_t flags; |
| 2882 | switch (msaa_mode) { |
| 2883 | default: |
| 2884 | case kNoMSAA: |
| 2885 | final_msaa_count = 0; |
| 2886 | flags = 0; |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2887 | break; |
| 2888 | case kMSAA: |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2889 | // Graphite operates as in the kDMSAA case below. |
Maggie Chen | 5d35a014 | 2025-04-17 18:35:22 | [diff] [blame] | 2890 | if (graphite_shared_context()) { |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2891 | final_msaa_count = 1; |
| 2892 | flags = SkSurfaceProps::kDynamicMSAA_Flag; |
| 2893 | break; |
| 2894 | } |
| 2895 | |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2896 | // If we can't match requested MSAA samples, don't use MSAA. |
| 2897 | final_msaa_count = std::max(static_cast<int>(msaa_sample_count), 0); |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2898 | if (gr_context() && |
| 2899 | final_msaa_count > |
| 2900 | gr_context()->maxSurfaceSampleCountForColorType(sk_color_type)) { |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2901 | final_msaa_count = 0; |
Colin Blundell | d7b7b47 | 2023-05-12 07:38:12 | [diff] [blame] | 2902 | } |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2903 | flags = 0; |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2904 | break; |
| 2905 | case kDMSAA: |
| 2906 | final_msaa_count = 1; |
| 2907 | flags = SkSurfaceProps::kDynamicMSAA_Flag; |
Justin Novosad | 7cc290af | 2021-07-20 17:13:07 | [diff] [blame] | 2908 | break; |
| 2909 | } |
| 2910 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2911 | // Use unknown pixel geometry to disable LCD text. |
| 2912 | SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 2913 | if (can_use_lcd_text) { |
Ian Prest | e598eece | 2020-10-19 23:31:02 | [diff] [blame] | 2914 | surface_props = skia::LegacyDisplayGlobals::GetSkSurfaceProps(flags); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2915 | } |
| 2916 | |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2917 | SkColor4f sk_color_4f = {r, g, b, a}; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2918 | if (shared_image_raster_) { |
Arthur Sonzogni | 59ac822 | 2023-11-10 09:46:54 | [diff] [blame] | 2919 | std::optional<SkColor4f> clear_color; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2920 | if (needs_clear) |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2921 | clear_color.emplace(sk_color_4f); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2922 | scoped_shared_image_raster_write_ = |
| 2923 | shared_image_raster_->BeginScopedWriteAccess( |
Peng Huang | 5ff70dff | 2022-03-03 19:55:11 | [diff] [blame] | 2924 | shared_context_state_, final_msaa_count, surface_props, clear_color, |
| 2925 | visible); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 2926 | if (!scoped_shared_image_raster_write_) { |
| 2927 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2928 | "failed to create surface"); |
| 2929 | shared_image_raster_.reset(); |
| 2930 | return; |
| 2931 | } |
| 2932 | |
| 2933 | if (needs_clear) |
| 2934 | shared_image_raster_->SetCleared(); |
| 2935 | |
| 2936 | return; |
| 2937 | } |
| 2938 | |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2939 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2940 | DCHECK(end_semaphores_.empty()); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2941 | DCHECK(!scoped_shared_image_write_); |
Nathan Zabriskie | 31e4dc9 | 2020-04-15 23:10:27 | [diff] [blame] | 2942 | // Allow uncleared access, as raster specifically handles uncleared images |
| 2943 | // by clearing them before writing. |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2944 | scoped_shared_image_write_ = shared_image_->BeginScopedWriteAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 2945 | final_msaa_count, surface_props, &begin_semaphores, &end_semaphores_, |
| 2946 | SharedImageRepresentation::AllowUnclearedAccess::kYes); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2947 | if (!scoped_shared_image_write_) { |
| 2948 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2949 | "failed to create surface"); |
| 2950 | shared_image_.reset(); |
| 2951 | return; |
| 2952 | } |
| 2953 | |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2954 | sk_surface_ = scoped_shared_image_write_->surface(); |
Christopher Cameron | 578e3dd | 2023-10-06 09:34:07 | [diff] [blame] | 2955 | sk_surface_hdr_headroom_ = hdr_headroom; |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2956 | |
| 2957 | if (!begin_semaphores.empty()) { |
| 2958 | bool result = |
Peng Huang | 1c6d058 | 2020-07-31 12:14:11 | [diff] [blame] | 2959 | sk_surface_->wait(begin_semaphores.size(), begin_semaphores.data(), |
| 2960 | /*deleteSemaphoresAfterWait=*/false); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2961 | DCHECK(result); |
| 2962 | } |
| 2963 | |
Peng Huang | 38a628064 | 2024-04-16 23:56:55 | [diff] [blame] | 2964 | if (no_draw_canvas_) { |
| 2965 | no_draw_canvas_->resetCanvas(sk_surface_->width(), sk_surface_->height()); |
| 2966 | raster_canvas_ = no_draw_canvas_.get(); |
| 2967 | } else { |
| 2968 | raster_canvas_ = sk_surface_->getCanvas(); |
| 2969 | } |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2970 | |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 2971 | paint_op_shared_image_provider_ = std::make_unique<SharedImageProviderImpl>( |
| 2972 | &shared_image_representation_factory_, shared_context_state_, sk_surface_, |
Vasiliy Telezhnikov | 9837f90 | 2022-08-17 15:03:07 | [diff] [blame] | 2973 | &end_semaphores_, error_state_.get()); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 2974 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2975 | // 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] | 2976 | // is the "used" part of the texture. A separate |needs_clear| flag is needed |
| 2977 | // because clear tracking on the shared image cannot be used for this purpose |
| 2978 | // with passthrough decoder shared images which are always considered cleared. |
| 2979 | // |
| 2980 | // TODO(enne): This doesn't handle the case where the background color changes |
| 2981 | // and so any extra pixels outside the raster area that get sampled may be |
| 2982 | // incorrect. |
| 2983 | if (needs_clear) { |
Aaron Krajeski | d7d51a5 | 2022-05-25 13:29:09 | [diff] [blame] | 2984 | raster_canvas_->drawColor(sk_color_4f, SkBlendMode::kSrc); |
Sunny Sachanandani | b461e21 | 2021-03-05 19:22:12 | [diff] [blame] | 2985 | shared_image_->SetCleared(); |
| 2986 | } |
| 2987 | DCHECK(shared_image_->IsCleared()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2988 | } |
| 2989 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2990 | scoped_refptr<Buffer> RasterDecoderImpl::GetShmBuffer(uint32_t shm_id) { |
| 2991 | return GetSharedMemoryBuffer(shm_id); |
| 2992 | } |
| 2993 | |
Khushal | 39641b9 | 2019-06-03 21:32:54 | [diff] [blame] | 2994 | void RasterDecoderImpl::ReportProgress() { |
| 2995 | if (shared_context_state_->progress_reporter()) |
| 2996 | shared_context_state_->progress_reporter()->ReportProgress(); |
| 2997 | } |
| 2998 | |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 2999 | error::Error RasterDecoderImpl::DoRasterCHROMIUM(GLuint raster_shm_id, |
| 3000 | GLuint raster_shm_offset, |
| 3001 | GLuint raster_shm_size, |
| 3002 | GLuint font_shm_id, |
| 3003 | GLuint font_shm_offset, |
| 3004 | GLuint font_shm_size) { |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 3005 | TRACE_EVENT1("gpu", "RasterDecoderImpl::DoRasterCHROMIUM", "raster_id", |
| 3006 | ++raster_chromium_id_); |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 3007 | |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3008 | if (!use_gpu_raster_) { |
| 3009 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 3010 | "No chromium raster support"); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3011 | return error::kNoError; |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3012 | } |
| 3013 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 3014 | if (!sk_surface_ && !scoped_shared_image_raster_write_) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3015 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 3016 | "RasterCHROMIUM without BeginRasterCHROMIUM"); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3017 | return error::kNoError; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3018 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3019 | DCHECK(transfer_cache()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3020 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 3021 | char* paint_buffer_memory = GetSharedMemoryAs<char*>( |
| 3022 | raster_shm_id, raster_shm_offset, raster_shm_size); |
| 3023 | if (!paint_buffer_memory) { |
| 3024 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 3025 | "Can not read paint buffer."); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3026 | return error::kNoError; |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 3027 | } |
| 3028 | |
Peng Huang | a8bda89 | 2022-05-06 17:15:59 | [diff] [blame] | 3029 | if (paint_buffer_memory != base::bits::AlignUp(paint_buffer_memory, 16u)) { |
| 3030 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 3031 | "Buffer is not aligned with 16 bytes."); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3032 | return error::kNoError; |
Peng Huang | a8bda89 | 2022-05-06 17:15:59 | [diff] [blame] | 3033 | } |
| 3034 | |
Aaron Krajeski | d55f4900 | 2020-12-09 17:27:51 | [diff] [blame] | 3035 | cc::PlaybackParams playback_params(nullptr, SkM44()); |
Christopher Cameron | 9c177af | 2025-07-02 11:50:46 | [diff] [blame] | 3036 | playback_params.destination_hdr_headroom = sk_surface_hdr_headroom_; |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3037 | TransferCacheDeserializeHelperImpl impl(raster_decoder_id_, transfer_cache()); |
Xianzhu Wang | 6521075 | 2024-03-25 18:57:32 | [diff] [blame] | 3038 | cc::PaintOp::DeserializeOptions options{ |
| 3039 | .transfer_cache = &impl, |
| 3040 | .paint_cache = paint_cache_.get(), |
| 3041 | .strike_client = font_manager_->strike_client(), |
| 3042 | .scratch_buffer = |
| 3043 | *shared_context_state_->scratch_deserialization_buffer(), |
| 3044 | .crash_dump_on_failure = !gpu_preferences_.disable_oopr_debug_crash_dump, |
| 3045 | .is_privileged = is_privileged_, |
Xianzhu Wang | 6521075 | 2024-03-25 18:57:32 | [diff] [blame] | 3046 | .shared_image_provider = paint_op_shared_image_provider_.get()}; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3047 | |
Xianzhu Wang | a0711d7 | 2023-02-08 22:54:26 | [diff] [blame] | 3048 | alignas(cc::PaintOpBuffer::kPaintOpAlign) char |
| 3049 | data[cc::kLargestPaintOpAlignedSize]; |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 3050 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 3051 | size_t paint_buffer_size = raster_shm_size; |
Adrienne Walker | d8a5646 | 2019-03-16 03:11:47 | [diff] [blame] | 3052 | gl::ScopedProgressReporter report_progress( |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 3053 | shared_context_state_->progress_reporter()); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3054 | |
| 3055 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoRasterCHROMIUM::Deserializing"); |
| 3056 | |
| 3057 | if (scoped_shared_image_raster_write_) { |
| 3058 | DCHECK(!deferred_raster_paint_buffer_offset_.has_value()); |
| 3059 | auto* paint_op_buffer = |
| 3060 | scoped_shared_image_raster_write_->paint_op_buffer(); |
| 3061 | paint_op_buffer->Deserialize(paint_buffer_memory, raster_shm_size, options); |
| 3062 | return error::kNoError; |
| 3063 | } |
| 3064 | |
| 3065 | if (deferred_raster_paint_buffer_offset_.has_value()) { |
| 3066 | paint_buffer_size -= *deferred_raster_paint_buffer_offset_; |
| 3067 | paint_buffer_memory += *deferred_raster_paint_buffer_offset_; |
| 3068 | deferred_raster_paint_buffer_offset_.reset(); |
| 3069 | } else { |
| 3070 | if (font_shm_size > 0) { |
| 3071 | // Deserialize fonts before raster. |
| 3072 | volatile uint8_t* font_buffer_memory = GetSharedMemoryAs<uint8_t*>( |
| 3073 | font_shm_id, font_shm_offset, font_shm_size); |
| 3074 | if (!font_buffer_memory) { |
| 3075 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 3076 | "Can not read font buffer."); |
| 3077 | return error::kNoError; |
| 3078 | } |
| 3079 | |
| 3080 | std::vector<SkDiscardableHandleId> new_locked_handles; |
| 3081 | if (!font_manager_->Deserialize(font_buffer_memory, font_shm_size, |
| 3082 | &new_locked_handles)) { |
| 3083 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 3084 | "Invalid font buffer."); |
| 3085 | return error::kNoError; |
| 3086 | } |
| 3087 | locked_handles_.insert(locked_handles_.end(), new_locked_handles.begin(), |
| 3088 | new_locked_handles.end()); |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | size_t processed_commands = 0; |
| 3093 | |
Khushal | a415686 | 2018-06-08 22:46:02 | [diff] [blame] | 3094 | while (paint_buffer_size > 0) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3095 | size_t skip = 0; |
Xianzhu Wang | a0711d7 | 2023-02-08 22:54:26 | [diff] [blame] | 3096 | cc::PaintOp* deserialized_op = |
| 3097 | cc::PaintOp::Deserialize(paint_buffer_memory, paint_buffer_size, data, |
| 3098 | std::size(data), &skip, options); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3099 | if (!deserialized_op) { |
Adrienne Walker | e62484a | 2018-11-27 18:41:30 | [diff] [blame] | 3100 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 3101 | "RasterCHROMIUM: serialization failure"); |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3102 | return error::kNoError; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3103 | } |
| 3104 | |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 3105 | deserialized_op->Raster(raster_canvas_, playback_params); |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 3106 | deserialized_op->DestroyThis(); |
| 3107 | |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 3108 | paint_buffer_size -= skip; |
| 3109 | paint_buffer_memory += skip; |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3110 | processed_commands++; |
| 3111 | |
| 3112 | if (check_for_yield_op_count_.has_value() && |
| 3113 | processed_commands % check_for_yield_op_count_.value() == 0 && |
| 3114 | paint_buffer_size && client()->ShouldYield()) { |
| 3115 | // Pause command batch to check if we should yield execution. |
| 3116 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoRasterCHROMIUM::Yield"); |
| 3117 | deferred_raster_paint_buffer_offset_ = |
| 3118 | raster_shm_size - paint_buffer_size; |
| 3119 | return error::kDeferCommandUntilLater; |
| 3120 | } |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3121 | } |
Scott Violet | 39a6a82 | 2024-08-09 23:44:00 | [diff] [blame] | 3122 | |
| 3123 | return error::kNoError; |
| 3124 | } |
| 3125 | |
| 3126 | error::Error RasterDecoderImpl::HandleRasterCHROMIUM( |
| 3127 | uint32_t immediate_data_size, |
| 3128 | const volatile void* cmd_data) { |
| 3129 | const volatile raster::cmds::RasterCHROMIUM& c = |
| 3130 | *static_cast<const volatile raster::cmds::RasterCHROMIUM*>(cmd_data); |
| 3131 | GLuint raster_shm_id = static_cast<GLuint>(c.raster_shm_id); |
| 3132 | GLuint raster_shm_offset = static_cast<GLuint>(c.raster_shm_offset); |
| 3133 | GLuint raster_shm_size = static_cast<GLuint>(c.raster_shm_size); |
| 3134 | GLuint font_shm_id = static_cast<GLuint>(c.font_shm_id); |
| 3135 | GLuint font_shm_offset = static_cast<GLuint>(c.font_shm_offset); |
| 3136 | GLuint font_shm_size = static_cast<GLuint>(c.font_shm_size); |
| 3137 | return DoRasterCHROMIUM(raster_shm_id, raster_shm_offset, raster_shm_size, |
| 3138 | font_shm_id, font_shm_offset, font_shm_size); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | void RasterDecoderImpl::DoEndRasterCHROMIUM() { |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 3142 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM"); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 3143 | if (!sk_surface_ && !scoped_shared_image_raster_write_) { |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 3144 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glEndRasterCHROMIUM", |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3145 | "EndRasterCHROMIUM without BeginRasterCHROMIUM"); |
| 3146 | return; |
| 3147 | } |
| 3148 | |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 3149 | if (scoped_shared_image_raster_write_) { |
| 3150 | scoped_shared_image_raster_write_->set_callback(base::BindOnce( |
| 3151 | [](scoped_refptr<ServiceFontManager> font_manager, |
| 3152 | std::vector<SkDiscardableHandleId> handles) { |
Peng Huang | 410ae6b2 | 2022-04-15 03:31:01 | [diff] [blame] | 3153 | font_manager->Unlock(handles); |
Peng Huang | b447da4 | 2021-09-22 19:21:26 | [diff] [blame] | 3154 | }, |
| 3155 | font_manager_, std::move(locked_handles_))); |
| 3156 | scoped_shared_image_raster_write_.reset(); |
| 3157 | shared_image_raster_.reset(); |
| 3158 | locked_handles_.clear(); |
| 3159 | return; |
| 3160 | } |
| 3161 | |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 3162 | raster_canvas_ = nullptr; |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 3163 | |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 3164 | { |
Peng Huang | d960843 | 2019-07-29 15:56:36 | [diff] [blame] | 3165 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM::Flush"); |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 3166 | // This is a slow operation since skia will execute the GPU work for the |
| 3167 | // complete tile. Make sure the progress reporter is notified to avoid |
| 3168 | // hangs. |
Adrienne Walker | d8a5646 | 2019-03-16 03:11:47 | [diff] [blame] | 3169 | gl::ScopedProgressReporter report_progress( |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 3170 | shared_context_state_->progress_reporter()); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 3171 | |
| 3172 | // scoped_shared_image_write_ can be nullptr if sk_surface_ was set by |
| 3173 | // SetUpForRasterCHROMIUMForTest. |
| 3174 | if (scoped_shared_image_write_) { |
Sunny Sachanandani | a209421 | 2024-03-20 21:50:55 | [diff] [blame] | 3175 | shared_context_state_->FlushWriteAccess(scoped_shared_image_write_.get()); |
Vasiliy Telezhnikov | f1562c4f | 2022-08-06 14:02:05 | [diff] [blame] | 3176 | // Flushing surface will cause vulkan command buffer to be recorded with |
| 3177 | // image layout transitions as necessary. Transitioning layout back to |
| 3178 | // desired need to be happening after. |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 3179 | paint_op_shared_image_provider_->ApplyEndAccessState(); |
Saifuddin Hitawala | 7065278 | 2024-08-21 14:13:32 | [diff] [blame] | 3180 | bool need_graphite_submit = |
| 3181 | paint_op_shared_image_provider_->NeedGraphiteContextSubmit() || |
| 3182 | scoped_shared_image_write_->NeedGraphiteContextSubmit(); |
| 3183 | shared_context_state_->SubmitIfNecessary(std::move(end_semaphores_), |
| 3184 | need_graphite_submit); |
Vasiliy Telezhnikov | 6414a25 | 2022-04-26 04:42:11 | [diff] [blame] | 3185 | } else { |
| 3186 | DCHECK(end_semaphores_.empty()); |
| 3187 | } |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 3188 | } |
| 3189 | |
Kramer Ge | ddcac353 | 2019-12-12 23:33:10 | [diff] [blame] | 3190 | shared_context_state_->UpdateSkiaOwnedMemorySize(); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 3191 | sk_surface_ = nullptr; |
Peng Huang | b63db21 | 2020-06-01 14:37:39 | [diff] [blame] | 3192 | scoped_shared_image_write_.reset(); |
| 3193 | shared_image_.reset(); |
Nathan Zabriskie | ffc21069 | 2020-07-09 07:36:47 | [diff] [blame] | 3194 | paint_op_shared_image_provider_.reset(); |
| 3195 | |
Peng Huang | b63db21 | 2020-06-01 14:37:39 | [diff] [blame] | 3196 | // Test only path for SetUpForRasterCHROMIUMForTest. |
| 3197 | sk_surface_for_testing_.reset(); |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 3198 | |
| 3199 | // Unlock all font handles. This needs to be deferred until |
Greg Daniel | 18362e9d | 2019-04-15 19:54:50 | [diff] [blame] | 3200 | // SkSurface::flush since that flushes batched Gr operations |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3201 | // in skia that access the glyph data. |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 3202 | if (!font_manager_->Unlock(locked_handles_)) { |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 3203 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 3204 | "Invalid font discardable handle."); |
| 3205 | } |
| 3206 | locked_handles_.clear(); |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 3207 | |
Victor Miura | 6bb4ab5c | 2023-05-10 21:35:12 | [diff] [blame] | 3208 | // We just unlocked a bunch of handles. Give a call to skia to |
| 3209 | // attempt to purge any unlocked handles. |
| 3210 | SkGraphics::PurgePinnedFontCache(); |
| 3211 | |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 3212 | // 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] | 3213 | // flush above. Yield to the Scheduler to allow pre-emption before |
| 3214 | // processing more commands. |
| 3215 | ExitCommandProcessingEarly(); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 3216 | } |
| 3217 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3218 | void RasterDecoderImpl::DoCreateTransferCacheEntryINTERNAL( |
| 3219 | GLuint raw_entry_type, |
| 3220 | GLuint entry_id, |
| 3221 | GLuint handle_shm_id, |
| 3222 | GLuint handle_shm_offset, |
| 3223 | GLuint data_shm_id, |
| 3224 | GLuint data_shm_offset, |
| 3225 | GLuint data_size) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3226 | if (!use_gpu_raster_) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3227 | LOCAL_SET_GL_ERROR( |
| 3228 | GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3229 | "Attempt to use OOP transfer cache on a context without OOP raster."); |
| 3230 | return; |
| 3231 | } |
Saifuddin Hitawala | d902766 | 2023-05-12 14:50:10 | [diff] [blame] | 3232 | CHECK(gr_context() || graphite_recorder()); |
| 3233 | CHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3234 | |
| 3235 | // Validate the type we are about to create. |
| 3236 | cc::TransferCacheEntryType entry_type; |
| 3237 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 3238 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3239 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3240 | "Attempt to use OOP transfer cache with an invalid " |
| 3241 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3242 | return; |
| 3243 | } |
| 3244 | |
Khushal | c11f57b | 2020-03-20 16:56:15 | [diff] [blame] | 3245 | if (entry_type == cc::TransferCacheEntryType::kSkottie && !is_privileged_) { |
| 3246 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3247 | "Attempt to use skottie on a non privileged channel"); |
| 3248 | return; |
| 3249 | } |
| 3250 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3251 | uint8_t* data_memory = |
| 3252 | GetSharedMemoryAs<uint8_t*>(data_shm_id, data_shm_offset, data_size); |
| 3253 | if (!data_memory) { |
| 3254 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3255 | "Can not read transfer cache entry data."); |
| 3256 | return; |
| 3257 | } |
| 3258 | |
| 3259 | scoped_refptr<Buffer> handle_buffer = GetSharedMemoryBuffer(handle_shm_id); |
| 3260 | if (!DiscardableHandleBase::ValidateParameters(handle_buffer.get(), |
| 3261 | handle_shm_offset)) { |
| 3262 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3263 | "Invalid shm for discardable handle."); |
| 3264 | return; |
| 3265 | } |
| 3266 | ServiceDiscardableHandle handle(std::move(handle_buffer), handle_shm_offset, |
| 3267 | handle_shm_id); |
| 3268 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3269 | // If the entry is going to use skia during deserialization, make sure we |
| 3270 | // mark the context state dirty. |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3271 | bool use_gpu = cc::ServiceTransferCacheEntry::UsesGpuContext(entry_type); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3272 | if (!transfer_cache()->CreateLockedEntry( |
| 3273 | ServiceTransferCache::EntryKey(raster_decoder_id_, entry_type, |
| 3274 | entry_id), |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3275 | handle, use_gpu ? gr_context() : nullptr, |
| 3276 | use_gpu ? graphite_recorder() : nullptr, |
Peter Kasting | 24c7c99 | 2024-12-02 19:35:31 | [diff] [blame] | 3277 | base::span(data_memory, data_size))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3278 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 3279 | "Failure to deserialize transfer cache entry."); |
| 3280 | return; |
| 3281 | } |
Khushal Sagar | b3f5329 | 2019-06-05 04:24:23 | [diff] [blame] | 3282 | |
| 3283 | // The only entry using the GrContext are image transfer cache entries for |
| 3284 | // image uploads. Since this tends to a slow operation, yield to allow the |
| 3285 | // decoder to be pre-empted. |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3286 | if (use_gpu) { |
Khushal Sagar | b3f5329 | 2019-06-05 04:24:23 | [diff] [blame] | 3287 | ExitCommandProcessingEarly(); |
Sunny Sachanandani | 5fcc572 | 2023-05-09 00:50:36 | [diff] [blame] | 3288 | } |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | void RasterDecoderImpl::DoUnlockTransferCacheEntryINTERNAL( |
| 3292 | GLuint raw_entry_type, |
| 3293 | GLuint entry_id) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3294 | if (!use_gpu_raster_) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3295 | LOCAL_SET_GL_ERROR( |
| 3296 | GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 3297 | "Attempt to use OOP transfer cache on a context without OOP raster."); |
| 3298 | return; |
| 3299 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3300 | DCHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3301 | cc::TransferCacheEntryType entry_type; |
| 3302 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 3303 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3304 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 3305 | "Attempt to use OOP transfer cache with an invalid " |
| 3306 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3307 | return; |
| 3308 | } |
| 3309 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3310 | if (!transfer_cache()->UnlockEntry(ServiceTransferCache::EntryKey( |
| 3311 | raster_decoder_id_, entry_type, entry_id))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3312 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 3313 | "Attempt to unlock an invalid ID"); |
| 3314 | } |
| 3315 | } |
| 3316 | |
| 3317 | void RasterDecoderImpl::DoDeleteTransferCacheEntryINTERNAL( |
| 3318 | GLuint raw_entry_type, |
| 3319 | GLuint entry_id) { |
kylechar | ee733817 | 2022-02-02 16:59:10 | [diff] [blame] | 3320 | if (!use_gpu_raster_) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3321 | LOCAL_SET_GL_ERROR( |
| 3322 | GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 3323 | "Attempt to use OOP transfer cache on a context without OOP raster."); |
| 3324 | return; |
| 3325 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3326 | DCHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3327 | cc::TransferCacheEntryType entry_type; |
| 3328 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 3329 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 3330 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 3331 | "Attempt to use OOP transfer cache with an invalid " |
| 3332 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3333 | return; |
| 3334 | } |
| 3335 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 3336 | if (!transfer_cache()->DeleteEntry(ServiceTransferCache::EntryKey( |
| 3337 | raster_decoder_id_, entry_type, entry_id))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 3338 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 3339 | "Attempt to delete an invalid ID"); |
| 3340 | } |
| 3341 | } |
| 3342 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 3343 | void RasterDecoderImpl::RestoreStateForAttrib(GLuint attrib_index, |
| 3344 | bool restore_array_binding) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 3345 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 3346 | } |
| 3347 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 3348 | // Include the auto-generated part of this file. We split this because it means |
| 3349 | // we can easily edit the non-auto generated parts right here in this file |
| 3350 | // instead of having to edit some template or the code generator. |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 3351 | #include "gpu/command_buffer/service/raster_decoder_autogen.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 3352 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 3353 | } // namespace raster |
| 3354 | } // namespace gpu |