Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1 | // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gpu/command_buffer/service/raster_decoder.h" |
| 6 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 11 | #include <string> |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 12 | #include <utility> |
Jonathan Backer | 6307cee9 | 2018-04-25 19:53:43 | [diff] [blame] | 13 | #include <vector> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 14 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 15 | #include "base/atomic_sequence_num.h" |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 16 | #include "base/bind.h" |
Peng Huang | cb204209 | 2018-12-04 13:42:34 | [diff] [blame] | 17 | #include "base/containers/flat_map.h" |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 18 | #include "base/debug/crash_logging.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 19 | #include "base/logging.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 20 | #include "base/memory/ref_counted.h" |
| 21 | #include "base/memory/weak_ptr.h" |
Avi Drissman | 6fc2408c | 2018-12-25 21:29:08 | [diff] [blame] | 22 | #include "base/stl_util.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 23 | #include "base/strings/stringprintf.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 24 | #include "base/trace_event/trace_event.h" |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 25 | #include "build/build_config.h" |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 26 | #include "cc/paint/paint_cache.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 27 | #include "cc/paint/paint_op_buffer.h" |
| 28 | #include "cc/paint/transfer_cache_entry.h" |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 29 | #include "components/viz/common/resources/resource_format_utils.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 30 | #include "gpu/command_buffer/common/capabilities.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 31 | #include "gpu/command_buffer/common/command_buffer_id.h" |
| 32 | #include "gpu/command_buffer/common/constants.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 33 | #include "gpu/command_buffer/common/context_result.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 34 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 35 | #include "gpu/command_buffer/common/mailbox.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 36 | #include "gpu/command_buffer/common/raster_cmd_format.h" |
| 37 | #include "gpu/command_buffer/common/raster_cmd_ids.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 38 | #include "gpu/command_buffer/common/sync_token.h" |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 39 | #include "gpu/command_buffer/service/command_buffer_service.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 40 | #include "gpu/command_buffer/service/context_state.h" |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 41 | #include "gpu/command_buffer/service/decoder_client.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 42 | #include "gpu/command_buffer/service/error_state.h" |
| 43 | #include "gpu/command_buffer/service/feature_info.h" |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/gl_stream_texture_image.h" |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/gl_utils.h" |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 46 | #include "gpu/command_buffer/service/gles2_cmd_copy_tex_image.h" |
| 47 | #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 48 | #include "gpu/command_buffer/service/gpu_tracer.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 49 | #include "gpu/command_buffer/service/logger.h" |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 50 | #include "gpu/command_buffer/service/mailbox_manager.h" |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 51 | #include "gpu/command_buffer/service/query_manager.h" |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 52 | #include "gpu/command_buffer/service/raster_cmd_validation.h" |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 53 | #include "gpu/command_buffer/service/service_font_manager.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 54 | #include "gpu/command_buffer/service/service_transfer_cache.h" |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/service_utils.h" |
Peng Huang | 8294a5a7f | 2019-01-23 18:56:26 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/shared_context_state.h" |
Eric Karl | d69119cb | 2018-10-31 22:19:37 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/shared_image_factory.h" |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 58 | #include "gpu/command_buffer/service/shared_image_representation.h" |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 59 | #include "gpu/command_buffer/service/skia_utils.h" |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 60 | #include "gpu/command_buffer/service/wrapped_sk_image.h" |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 61 | #include "gpu/vulkan/buildflags.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 62 | #include "third_party/skia/include/core/SkCanvas.h" |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 63 | #include "third_party/skia/include/core/SkDeferredDisplayListRecorder.h" |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 64 | #include "third_party/skia/include/core/SkPromiseImageTexture.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 65 | #include "third_party/skia/include/core/SkSurface.h" |
| 66 | #include "third_party/skia/include/core/SkSurfaceProps.h" |
| 67 | #include "third_party/skia/include/core/SkTypeface.h" |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 68 | #include "third_party/skia/include/gpu/GrBackendSemaphore.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 69 | #include "third_party/skia/include/gpu/GrBackendSurface.h" |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 70 | #include "third_party/skia/include/gpu/GrContext.h" |
Jonathan Backer | 4fb9f5acb | 2018-05-10 22:19:33 | [diff] [blame] | 71 | #include "third_party/skia/include/gpu/GrTypes.h" |
Jonathan Backer | 76dfd50 | 2018-05-03 18:34:31 | [diff] [blame] | 72 | #include "ui/gfx/buffer_format_util.h" |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 73 | #include "ui/gfx/skia_util.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 74 | #include "ui/gl/gl_context.h" |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 75 | #include "ui/gl/gl_gl_api_implementation.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 76 | #include "ui/gl/gl_surface.h" |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 77 | #include "ui/gl/gl_version_info.h" |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 78 | |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 79 | #if BUILDFLAG(ENABLE_VULKAN) |
| 80 | #include "components/viz/common/gpu/vulkan_context_provider.h" |
| 81 | #include "gpu/vulkan/vulkan_device_queue.h" |
| 82 | #endif |
| 83 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 84 | // Local versions of the SET_GL_ERROR macros |
| 85 | #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 86 | ERRORSTATE_SET_GL_ERROR(error_state_.get(), error, function_name, msg) |
| 87 | #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ |
| 88 | ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state_.get(), function_name, \ |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 89 | static_cast<uint32_t>(value), label) |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 90 | #define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 91 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 92 | #define LOCAL_PEEK_GL_ERROR(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 93 | ERRORSTATE_PEEK_GL_ERROR(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 94 | #define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \ |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 95 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_.get(), function_name) |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 96 | #define LOCAL_PERFORMANCE_WARNING(msg) \ |
| 97 | PerformanceWarning(__FILE__, __LINE__, msg) |
| 98 | #define LOCAL_RENDER_WARNING(msg) RenderWarning(__FILE__, __LINE__, msg) |
| 99 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 100 | namespace gpu { |
| 101 | namespace raster { |
| 102 | |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 103 | namespace { |
| 104 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 105 | base::AtomicSequenceNumber g_raster_decoder_id; |
| 106 | |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 107 | // This class prevents any GL errors that occur when it is in scope from |
| 108 | // being reported to the client. |
| 109 | class ScopedGLErrorSuppressor { |
| 110 | public: |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 111 | ScopedGLErrorSuppressor(const char* function_name, |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 112 | gles2::ErrorState* error_state) |
| 113 | : function_name_(function_name), error_state_(error_state) { |
| 114 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); |
| 115 | } |
| 116 | ~ScopedGLErrorSuppressor() { |
| 117 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
| 118 | } |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 119 | |
| 120 | private: |
| 121 | const char* function_name_; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 122 | gles2::ErrorState* error_state_; |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 123 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 124 | }; |
| 125 | |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 126 | // Temporarily changes a decoder's bound texture and restore it when this |
| 127 | // object goes out of scope. Also temporarily switches to using active texture |
| 128 | // unit zero in case the client has changed that to something invalid. |
| 129 | class ScopedTextureBinder { |
| 130 | public: |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 131 | ScopedTextureBinder(gles2::ContextState* state, |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 132 | GLenum target, |
| 133 | GLuint texture, |
Antoine Labour | 2c9d3fb | 2019-01-19 08:43:43 | [diff] [blame] | 134 | GrContext* gr_context) |
| 135 | : state_(state), target_(target) { |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 136 | auto* api = state->api(); |
| 137 | api->glActiveTextureFn(GL_TEXTURE0); |
| 138 | api->glBindTextureFn(target_, texture); |
| 139 | if (gr_context) |
| 140 | gr_context->resetContext(kTextureBinding_GrGLBackendState); |
| 141 | } |
| 142 | |
Antoine Labour | 2c9d3fb | 2019-01-19 08:43:43 | [diff] [blame] | 143 | ~ScopedTextureBinder() { state_->api()->glBindTextureFn(target_, 0); } |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 144 | |
| 145 | private: |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 146 | gles2::ContextState* state_; |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 147 | GLenum target_; |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 148 | |
| 149 | DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); |
| 150 | }; |
| 151 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 152 | // Temporarily changes a decoder's PIXEL_UNPACK_BUFFER to 0 and set pixel |
| 153 | // unpack params to default, and restore them when this object goes out of |
| 154 | // scope. |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 155 | class ScopedPixelUnpackState { |
| 156 | public: |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 157 | explicit ScopedPixelUnpackState(gles2::ContextState* state, |
| 158 | GrContext* gr_context, |
| 159 | const gles2::FeatureInfo* feature_info) { |
| 160 | DCHECK(state); |
| 161 | auto* api = state->api(); |
| 162 | api->glPixelStoreiFn(GL_UNPACK_ALIGNMENT, 4); |
| 163 | if (feature_info->gl_version_info().is_es3 || |
| 164 | feature_info->gl_version_info().is_desktop_core_profile || |
| 165 | feature_info->feature_flags().ext_pixel_buffer_object) |
| 166 | api->glBindBufferFn(GL_PIXEL_UNPACK_BUFFER, 0); |
| 167 | |
| 168 | if (feature_info->gl_version_info().is_es3 || |
| 169 | feature_info->gl_version_info().is_desktop_core_profile || |
| 170 | feature_info->feature_flags().ext_unpack_subimage) |
| 171 | api->glPixelStoreiFn(GL_UNPACK_ROW_LENGTH, 0); |
| 172 | if (gr_context) { |
| 173 | gr_context->resetContext(kMisc_GrGLBackendState | |
| 174 | kPixelStore_GrGLBackendState); |
| 175 | } |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 176 | } |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 177 | ~ScopedPixelUnpackState() = default; |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 178 | |
| 179 | private: |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 180 | DISALLOW_COPY_AND_ASSIGN(ScopedPixelUnpackState); |
| 181 | }; |
| 182 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 183 | // Commands that are whitelisted as OK to occur between BeginRasterCHROMIUM |
| 184 | // and EndRasterCHROMIUM. They do not invalidate GrContext state tracking. |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 185 | bool AllowedBetweenBeginEndRaster(CommandId command) { |
| 186 | switch (command) { |
| 187 | case kCreateTransferCacheEntryINTERNAL: |
| 188 | case kDeleteTransferCacheEntryINTERNAL: |
| 189 | case kEndRasterCHROMIUM: |
| 190 | case kFinish: |
| 191 | case kFlush: |
| 192 | case kGetError: |
| 193 | case kRasterCHROMIUM: |
| 194 | case kUnlockTransferCacheEntryINTERNAL: |
| 195 | return true; |
| 196 | default: |
| 197 | return false; |
| 198 | } |
| 199 | } |
| 200 | |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 201 | } // namespace |
| 202 | |
Jonathan Backer | 5ac08a7 | 2018-06-27 16:15:35 | [diff] [blame] | 203 | // RasterDecoderImpl uses two separate state trackers (gpu::gles2::ContextState |
| 204 | // and GrContext) that cache the current GL driver state. Each class sees a |
| 205 | // fraction of the GL calls issued and can easily become inconsistent with GL |
| 206 | // state. We guard against that by resetting. But resetting is expensive, so we |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 207 | // avoid it as much as possible. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 208 | class RasterDecoderImpl final : public RasterDecoder, |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 209 | public gles2::ErrorStateClient, |
| 210 | public ServiceFontManager::Client { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 211 | public: |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 212 | RasterDecoderImpl(DecoderClient* client, |
| 213 | CommandBufferServiceBase* command_buffer_service, |
| 214 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 215 | const GpuFeatureInfo& gpu_feature_info, |
| 216 | const GpuPreferences& gpu_preferences, |
| 217 | MemoryTracker* memory_tracker, |
| 218 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame^] | 219 | scoped_refptr<SharedContextState> shared_context_state, |
| 220 | bool is_privileged); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 221 | ~RasterDecoderImpl() override; |
| 222 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 223 | gles2::GLES2Util* GetGLES2Util() override { return &util_; } |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 224 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 225 | // DecoderContext implementation. |
| 226 | base::WeakPtr<DecoderContext> AsWeakPtr() override; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 227 | ContextResult Initialize( |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 228 | const scoped_refptr<gl::GLSurface>& surface, |
| 229 | const scoped_refptr<gl::GLContext>& context, |
| 230 | bool offscreen, |
| 231 | const gles2::DisallowedFeatures& disallowed_features, |
| 232 | const ContextCreationAttribs& attrib_helper) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 233 | void Destroy(bool have_context) override; |
| 234 | bool MakeCurrent() override; |
| 235 | gl::GLContext* GetGLContext() override; |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 236 | gl::GLSurface* GetGLSurface() override; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 237 | const gles2::FeatureInfo* GetFeatureInfo() const override { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 238 | return feature_info(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 239 | } |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 240 | Capabilities GetCapabilities() override; |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 241 | const gles2::ContextState* GetContextState() override; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 242 | |
| 243 | // TODO(penghuang): Remove unused context state related methods. |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 244 | void RestoreGlobalState() const override; |
| 245 | void ClearAllAttributes() const override; |
| 246 | void RestoreAllAttributes() const override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 247 | void RestoreState(const gles2::ContextState* prev_state) override; |
| 248 | void RestoreActiveTexture() const override; |
| 249 | void RestoreAllTextureUnitAndSamplerBindings( |
| 250 | const gles2::ContextState* prev_state) const override; |
| 251 | void RestoreActiveTextureUnitBinding(unsigned int target) const override; |
| 252 | void RestoreBufferBinding(unsigned int target) override; |
| 253 | void RestoreBufferBindings() const override; |
| 254 | void RestoreFramebufferBindings() const override; |
| 255 | void RestoreRenderbufferBindings() override; |
| 256 | void RestoreProgramBindings() const override; |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 257 | void RestoreTextureState(unsigned service_id) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 258 | void RestoreTextureUnitBindings(unsigned unit) const override; |
| 259 | void RestoreVertexAttribArray(unsigned index) override; |
| 260 | void RestoreAllExternalTextureBindingsIfNeeded() override; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 261 | QueryManager* GetQueryManager() override; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 262 | |
Geoff Lang | 85287e1 | 2018-05-22 17:26:40 | [diff] [blame] | 263 | void SetQueryCallback(unsigned int query_client_id, |
| 264 | base::OnceClosure callback) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 265 | gles2::GpuFenceManager* GetGpuFenceManager() override; |
| 266 | bool HasPendingQueries() const override; |
| 267 | void ProcessPendingQueries(bool did_finish) override; |
| 268 | bool HasMoreIdleWork() const override; |
| 269 | void PerformIdleWork() override; |
| 270 | bool HasPollingWork() const override; |
| 271 | void PerformPollingWork() override; |
| 272 | TextureBase* GetTextureBase(uint32_t client_id) override; |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 273 | void SetLevelInfo(uint32_t client_id, |
| 274 | int level, |
| 275 | unsigned internal_format, |
| 276 | unsigned width, |
| 277 | unsigned height, |
| 278 | unsigned depth, |
| 279 | unsigned format, |
| 280 | unsigned type, |
| 281 | const gfx::Rect& cleared_rect) override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 282 | bool WasContextLost() const override; |
| 283 | bool WasContextLostByRobustnessExtension() const override; |
| 284 | void MarkContextLost(error::ContextLostReason reason) override; |
| 285 | bool CheckResetStatus() override; |
| 286 | void BeginDecoding() override; |
| 287 | void EndDecoding() override; |
| 288 | const char* GetCommandName(unsigned int command_id) const; |
| 289 | error::Error DoCommands(unsigned int num_commands, |
| 290 | const volatile void* buffer, |
| 291 | int num_entries, |
| 292 | int* entries_processed) override; |
| 293 | base::StringPiece GetLogPrefix() override; |
| 294 | void BindImage(uint32_t client_texture_id, |
| 295 | uint32_t texture_target, |
| 296 | gl::GLImage* image, |
| 297 | bool can_bind_to_sampler) override; |
| 298 | gles2::ContextGroup* GetContextGroup() override; |
| 299 | gles2::ErrorState* GetErrorState() override; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 300 | std::unique_ptr<gles2::AbstractTexture> CreateAbstractTexture( |
| 301 | GLenum target, |
| 302 | GLenum internal_format, |
| 303 | GLsizei width, |
| 304 | GLsizei height, |
| 305 | GLsizei depth, |
| 306 | GLint border, |
| 307 | GLenum format, |
| 308 | GLenum type) override; |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 309 | bool IsCompressedTextureFormat(unsigned format) override; |
| 310 | bool ClearLevel(gles2::Texture* texture, |
| 311 | unsigned target, |
| 312 | int level, |
| 313 | unsigned format, |
| 314 | unsigned type, |
| 315 | int xoffset, |
| 316 | int yoffset, |
| 317 | int width, |
| 318 | int height) override; |
| 319 | bool ClearCompressedTextureLevel(gles2::Texture* texture, |
| 320 | unsigned target, |
| 321 | int level, |
| 322 | unsigned format, |
| 323 | int width, |
| 324 | int height) override; |
| 325 | bool ClearLevel3D(gles2::Texture* texture, |
| 326 | unsigned target, |
| 327 | int level, |
| 328 | unsigned format, |
| 329 | unsigned type, |
| 330 | int width, |
| 331 | int height, |
| 332 | int depth) override { |
| 333 | NOTIMPLEMENTED(); |
| 334 | return false; |
| 335 | } |
Andres Calderon Jaramillo | b870ca6 | 2019-01-29 16:33:35 | [diff] [blame] | 336 | int GetRasterDecoderId() const override; |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 337 | int DecoderIdForTest() override; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 338 | ServiceTransferCache* GetTransferCacheForTest() override; |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 339 | void SetUpForRasterCHROMIUMForTest() override; |
Jonathan Backer | c7b8297 | 2018-11-21 19:08:48 | [diff] [blame] | 340 | void SetOOMErrorForTest() override; |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 341 | void DisableFlushWorkaroundForTest() override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 342 | |
| 343 | // ErrorClientState implementation. |
| 344 | void OnContextLostError() override; |
| 345 | void OnOutOfMemoryError() override; |
| 346 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 347 | gles2::Logger* GetLogger() override; |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 348 | |
| 349 | void SetIgnoreCachedStateForTest(bool ignore) override; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 350 | gles2::ImageManager* GetImageManagerForTest() override; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 351 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 352 | void SetCopyTextureResourceManagerForTest( |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 353 | gles2::CopyTextureCHROMIUMResourceManager* copy_texture_resource_manager) |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 354 | override; |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 355 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 356 | // ServiceFontManager::Client implementation. |
| 357 | scoped_refptr<Buffer> GetShmBuffer(uint32_t shm_id) override; |
Khushal | 39641b9 | 2019-06-03 21:32:54 | [diff] [blame] | 358 | void ReportProgress() override; |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 359 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 360 | private: |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 361 | gles2::ContextState* state() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 362 | if (use_passthrough_) { |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 363 | NOTREACHED(); |
| 364 | return nullptr; |
| 365 | } |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 366 | return shared_context_state_->context_state(); |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 367 | } |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 368 | gl::GLApi* api() const { return api_; } |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 369 | GrContext* gr_context() const { return shared_context_state_->gr_context(); } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 370 | ServiceTransferCache* transfer_cache() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 371 | return shared_context_state_->transfer_cache(); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 372 | } |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 373 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 374 | const gles2::FeatureInfo* feature_info() const { |
| 375 | return shared_context_state_->feature_info(); |
| 376 | } |
| 377 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 378 | const gles2::FeatureInfo::FeatureFlags& features() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 379 | return feature_info()->feature_flags(); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 380 | } |
| 381 | |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 382 | const GpuDriverBugWorkarounds& workarounds() const { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 383 | return feature_info()->workarounds(); |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 384 | } |
| 385 | |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 386 | void FlushToWorkAroundMacCrashes() { |
| 387 | #if defined(OS_MACOSX) |
Christopher Cameron | f787d0b | 2019-05-15 23:52:18 | [diff] [blame] | 388 | if (!shared_context_state_->GrContextIsGL()) |
| 389 | return; |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 390 | // This function does aggressive flushes to work around crashes in the |
| 391 | // macOS OpenGL driver. |
| 392 | // https://crbug.com/906453 |
| 393 | if (!flush_workaround_disabled_for_test_) { |
| 394 | if (gr_context()) |
| 395 | gr_context()->flush(); |
| 396 | api()->glFlushFn(); |
Khushal | d15c591 | 2019-06-14 17:51:04 | [diff] [blame] | 397 | |
| 398 | // Flushes can be expensive, yield to allow interruption after each flush. |
| 399 | ExitCommandProcessingEarly(); |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 400 | } |
| 401 | #endif |
| 402 | } |
| 403 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 404 | const gl::GLVersionInfo& gl_version_info() { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 405 | return feature_info()->gl_version_info(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 406 | } |
| 407 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 408 | // Set remaining commands to process to 0 to force DoCommands to return |
| 409 | // and allow context preemption and GPU watchdog checks in |
| 410 | // CommandExecutor(). |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 411 | void ExitCommandProcessingEarly() override; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 412 | |
| 413 | template <bool DebugImpl> |
| 414 | error::Error DoCommandsImpl(unsigned int num_commands, |
| 415 | const volatile void* buffer, |
| 416 | int num_entries, |
| 417 | int* entries_processed); |
| 418 | |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 419 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 420 | void DeleteQueriesEXTHelper(GLsizei n, const volatile GLuint* client_ids); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 421 | void DoFinish(); |
| 422 | void DoFlush(); |
| 423 | void DoGetIntegerv(GLenum pname, GLint* params, GLsizei params_size); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 424 | void DoTraceEndCHROMIUM(); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 425 | bool InitializeCopyTexImageBlitter(); |
| 426 | bool InitializeCopyTextureCHROMIUM(); |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 427 | void DoCopySubTextureINTERNAL(GLint xoffset, |
Antoine Labour | aeb4bd70e | 2019-01-16 02:33:28 | [diff] [blame] | 428 | GLint yoffset, |
| 429 | GLint x, |
| 430 | GLint y, |
| 431 | GLsizei width, |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 432 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 433 | GLboolean unpack_flip_y, |
| 434 | GLboolean unpack_premultiply_alpha, |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 435 | const volatile GLbyte* mailboxes); |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 436 | void DoCopySubTextureINTERNALGLPassthrough(GLint xoffset, |
| 437 | GLint yoffset, |
| 438 | GLint x, |
| 439 | GLint y, |
| 440 | GLsizei width, |
| 441 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 442 | GLboolean unpack_flip_y, |
| 443 | GLboolean unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 444 | const Mailbox& source_mailbox, |
| 445 | const Mailbox& dest_mailbox); |
| 446 | void DoCopySubTextureINTERNALGL(GLint xoffset, |
| 447 | GLint yoffset, |
| 448 | GLint x, |
| 449 | GLint y, |
| 450 | GLsizei width, |
| 451 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 452 | GLboolean unpack_flip_y, |
| 453 | GLboolean unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 454 | const Mailbox& source_mailbox, |
| 455 | const Mailbox& dest_mailbox); |
| 456 | void DoCopySubTextureINTERNALSkia(GLint xoffset, |
| 457 | GLint yoffset, |
| 458 | GLint x, |
| 459 | GLint y, |
| 460 | GLsizei width, |
| 461 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 462 | GLboolean unpack_flip_y, |
| 463 | GLboolean unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 464 | const Mailbox& source_mailbox, |
| 465 | const Mailbox& dest_mailbox); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 466 | void DoLoseContextCHROMIUM(GLenum current, GLenum other) { NOTIMPLEMENTED(); } |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 467 | void DoBeginRasterCHROMIUM(GLuint sk_color, |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 468 | GLuint msaa_sample_count, |
| 469 | GLboolean can_use_lcd_text, |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 470 | const volatile GLbyte* key); |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 471 | void DoRasterCHROMIUM(GLuint raster_shm_id, |
| 472 | GLuint raster_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 473 | GLuint raster_shm_size, |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 474 | GLuint font_shm_id, |
| 475 | GLuint font_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 476 | GLuint font_shm_size); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 477 | void DoEndRasterCHROMIUM(); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 478 | void DoCreateTransferCacheEntryINTERNAL(GLuint entry_type, |
| 479 | GLuint entry_id, |
| 480 | GLuint handle_shm_id, |
| 481 | GLuint handle_shm_offset, |
| 482 | GLuint data_shm_id, |
| 483 | GLuint data_shm_offset, |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 484 | GLuint data_size); |
| 485 | void DoUnlockTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id); |
| 486 | void DoDeleteTransferCacheEntryINTERNAL(GLuint entry_type, GLuint entry_id); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 487 | void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 488 | void DeletePaintCacheTextBlobsINTERNALHelper( |
| 489 | GLsizei n, |
| 490 | const volatile GLuint* paint_cache_ids); |
| 491 | void DeletePaintCachePathsINTERNALHelper( |
| 492 | GLsizei n, |
| 493 | const volatile GLuint* paint_cache_ids); |
| 494 | void DoClearPaintCacheINTERNAL(); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 495 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 496 | #if defined(NDEBUG) |
| 497 | void LogClientServiceMapping(const char* /* function_name */, |
| 498 | GLuint /* client_id */, |
| 499 | GLuint /* service_id */) {} |
| 500 | template <typename T> |
| 501 | void LogClientServiceForInfo(T* /* info */, |
| 502 | GLuint /* client_id */, |
| 503 | const char* /* function_name */) {} |
| 504 | #else |
| 505 | void LogClientServiceMapping(const char* function_name, |
| 506 | GLuint client_id, |
| 507 | GLuint service_id) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 508 | if (gpu_preferences_.enable_gpu_service_logging_gpu) { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 509 | VLOG(1) << "[" << logger_.GetLogPrefix() << "] " << function_name |
| 510 | << ": client_id = " << client_id |
| 511 | << ", service_id = " << service_id; |
| 512 | } |
| 513 | } |
| 514 | template <typename T> |
| 515 | void LogClientServiceForInfo(T* info, |
| 516 | GLuint client_id, |
| 517 | const char* function_name) { |
| 518 | if (info) { |
| 519 | LogClientServiceMapping(function_name, client_id, info->service_id()); |
| 520 | } |
| 521 | } |
| 522 | #endif |
| 523 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 524 | // Generate a member function prototype for each command in an automated and |
| 525 | // typesafe way. |
| 526 | #define RASTER_CMD_OP(name) \ |
| 527 | Error Handle##name(uint32_t immediate_data_size, const volatile void* data); |
| 528 | |
| 529 | RASTER_COMMAND_LIST(RASTER_CMD_OP) |
| 530 | #undef RASTER_CMD_OP |
| 531 | |
| 532 | typedef error::Error (RasterDecoderImpl::*CmdHandler)( |
| 533 | uint32_t immediate_data_size, |
| 534 | const volatile void* data); |
| 535 | |
| 536 | // A struct to hold info about each command. |
| 537 | struct CommandInfo { |
| 538 | CmdHandler cmd_handler; |
| 539 | uint8_t arg_flags; // How to handle the arguments for this command |
| 540 | uint8_t cmd_flags; // How to handle this command |
| 541 | uint16_t arg_count; // How many arguments are expected for this command. |
| 542 | }; |
| 543 | |
| 544 | // A table of CommandInfo for all the commands. |
| 545 | static const CommandInfo command_info[kNumCommands - kFirstRasterCommand]; |
| 546 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 547 | const int raster_decoder_id_; |
| 548 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 549 | // Number of commands remaining to be processed in DoCommands(). |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 550 | int commands_to_process_ = 0; |
| 551 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 552 | bool supports_gpu_raster_ = false; |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 553 | bool supports_oop_raster_ = false; |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 554 | bool use_passthrough_ = false; |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 555 | bool use_ddl_ = false; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 556 | |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 557 | bool reset_by_robustness_extension_ = false; |
| 558 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 559 | // The current decoder error communicates the decoder error through command |
| 560 | // processing functions that do not return the error value. Should be set |
| 561 | // only if not returning an error. |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 562 | error::Error current_decoder_error_ = error::kNoError; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 563 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 564 | GpuPreferences gpu_preferences_; |
| 565 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 566 | gles2::DebugMarkerManager debug_marker_manager_; |
| 567 | gles2::Logger logger_; |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 568 | std::unique_ptr<gles2::ErrorState> error_state_; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 569 | bool context_lost_ = false; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 570 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 571 | scoped_refptr<SharedContextState> shared_context_state_; |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 572 | std::unique_ptr<Validators> validators_; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 573 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 574 | SharedImageRepresentationFactory shared_image_representation_factory_; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 575 | std::unique_ptr<QueryManager> query_manager_; |
| 576 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 577 | gles2::GLES2Util util_; |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 578 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 579 | // An optional behaviour to lose the context when OOM. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 580 | bool lose_context_when_out_of_memory_ = false; |
| 581 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 582 | std::unique_ptr<gles2::CopyTexImageResourceManager> copy_tex_image_blit_; |
| 583 | std::unique_ptr<gles2::CopyTextureCHROMIUMResourceManager> |
| 584 | copy_texture_chromium_; |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 585 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 586 | std::unique_ptr<gles2::GPUTracer> gpu_tracer_; |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 587 | const unsigned char* gpu_decoder_category_; |
| 588 | static constexpr int gpu_trace_level_ = 2; |
| 589 | bool gpu_trace_commands_ = false; |
| 590 | bool gpu_debug_commands_ = false; |
| 591 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 592 | // Raster helpers. |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 593 | scoped_refptr<ServiceFontManager> font_manager_; |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 594 | std::unique_ptr<SharedImageRepresentationSkia> shared_image_; |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 595 | std::unique_ptr<SharedImageRepresentationSkia::ScopedWriteAccess> |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 596 | scoped_shared_image_write_; |
| 597 | SkSurface* sk_surface_ = nullptr; |
| 598 | sk_sp<SkSurface> sk_surface_for_testing_; |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 599 | std::vector<GrBackendSemaphore> end_semaphores_; |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 600 | std::unique_ptr<cc::ServicePaintCache> paint_cache_; |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 601 | |
| 602 | std::unique_ptr<SkDeferredDisplayListRecorder> recorder_; |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 603 | SkCanvas* raster_canvas_ = nullptr; // ptr into recorder_ or sk_surface_ |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 604 | std::vector<SkDiscardableHandleId> locked_handles_; |
Jonathan Backer | 4fb9f5acb | 2018-05-10 22:19:33 | [diff] [blame] | 605 | |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 606 | // Tracing helpers. |
| 607 | int raster_chromium_id_ = 0; |
| 608 | |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 609 | // Workaround for https://crbug.com/906453 |
| 610 | bool flush_workaround_disabled_for_test_ = false; |
| 611 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 612 | bool in_copy_sub_texture_ = false; |
| 613 | bool reset_texture_state_ = false; |
| 614 | |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame^] | 615 | bool is_privileged_ = false; |
| 616 | |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 617 | gl::GLApi* api_ = nullptr; |
| 618 | |
Jeremy Roman | 28926e9 | 2019-07-15 15:42:16 | [diff] [blame] | 619 | base::WeakPtrFactory<DecoderContext> weak_ptr_factory_{this}; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 620 | |
| 621 | DISALLOW_COPY_AND_ASSIGN(RasterDecoderImpl); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 622 | }; |
| 623 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 624 | constexpr RasterDecoderImpl::CommandInfo RasterDecoderImpl::command_info[] = { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 625 | #define RASTER_CMD_OP(name) \ |
| 626 | { \ |
| 627 | &RasterDecoderImpl::Handle##name, \ |
| 628 | cmds::name::kArgFlags, \ |
| 629 | cmds::name::cmd_flags, \ |
| 630 | sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 631 | }, /* NOLINT */ |
| 632 | RASTER_COMMAND_LIST(RASTER_CMD_OP) |
| 633 | #undef RASTER_CMD_OP |
| 634 | }; |
| 635 | |
| 636 | // static |
| 637 | RasterDecoder* RasterDecoder::Create( |
| 638 | DecoderClient* client, |
| 639 | CommandBufferServiceBase* command_buffer_service, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 640 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 641 | const GpuFeatureInfo& gpu_feature_info, |
| 642 | const GpuPreferences& gpu_preferences, |
| 643 | MemoryTracker* memory_tracker, |
| 644 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame^] | 645 | scoped_refptr<SharedContextState> shared_context_state, |
| 646 | bool is_privileged) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 647 | return new RasterDecoderImpl(client, command_buffer_service, outputter, |
| 648 | gpu_feature_info, gpu_preferences, |
| 649 | memory_tracker, shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame^] | 650 | std::move(shared_context_state), is_privileged); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 651 | } |
| 652 | |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 653 | RasterDecoder::RasterDecoder(DecoderClient* client, |
| 654 | CommandBufferServiceBase* command_buffer_service, |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 655 | gles2::Outputter* outputter) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 656 | : CommonDecoder(client, command_buffer_service), outputter_(outputter) {} |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 657 | |
| 658 | RasterDecoder::~RasterDecoder() {} |
| 659 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 660 | bool RasterDecoder::initialized() const { |
| 661 | return initialized_; |
| 662 | } |
| 663 | |
| 664 | TextureBase* RasterDecoder::GetTextureBase(uint32_t client_id) { |
| 665 | return nullptr; |
| 666 | } |
| 667 | |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 668 | void RasterDecoder::SetLevelInfo(uint32_t client_id, |
| 669 | int level, |
| 670 | unsigned internal_format, |
| 671 | unsigned width, |
| 672 | unsigned height, |
| 673 | unsigned depth, |
| 674 | unsigned format, |
| 675 | unsigned type, |
| 676 | const gfx::Rect& cleared_rect) {} |
| 677 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 678 | void RasterDecoder::BeginDecoding() {} |
| 679 | |
| 680 | void RasterDecoder::EndDecoding() {} |
| 681 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 682 | void RasterDecoder::SetLogCommands(bool log_commands) { |
| 683 | log_commands_ = log_commands; |
| 684 | } |
| 685 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 686 | gles2::Outputter* RasterDecoder::outputter() const { |
| 687 | return outputter_; |
| 688 | } |
| 689 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 690 | base::StringPiece RasterDecoder::GetLogPrefix() { |
| 691 | return GetLogger()->GetLogPrefix(); |
| 692 | } |
| 693 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 694 | RasterDecoderImpl::RasterDecoderImpl( |
| 695 | DecoderClient* client, |
| 696 | CommandBufferServiceBase* command_buffer_service, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 697 | gles2::Outputter* outputter, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 698 | const GpuFeatureInfo& gpu_feature_info, |
| 699 | const GpuPreferences& gpu_preferences, |
| 700 | MemoryTracker* memory_tracker, |
| 701 | SharedImageManager* shared_image_manager, |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame^] | 702 | scoped_refptr<SharedContextState> shared_context_state, |
| 703 | bool is_privileged) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 704 | : RasterDecoder(client, command_buffer_service, outputter), |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 705 | raster_decoder_id_(g_raster_decoder_id.GetNext() + 1), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 706 | supports_gpu_raster_( |
| 707 | gpu_feature_info.status_values[GPU_FEATURE_TYPE_GPU_RASTERIZATION] == |
| 708 | kGpuFeatureStatusEnabled), |
| 709 | use_passthrough_(gles2::PassthroughCommandDecoderSupported() && |
| 710 | gpu_preferences.use_passthrough_cmd_decoder), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 711 | gpu_preferences_(gpu_preferences), |
Peng Huang | 61eccfe4 | 2018-11-15 22:10:13 | [diff] [blame] | 712 | logger_(&debug_marker_manager_, |
| 713 | base::BindRepeating(&DecoderClient::OnConsoleMessage, |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 714 | base::Unretained(client), |
James Darpinian | 104af6f | 2018-12-06 03:24:55 | [diff] [blame] | 715 | 0), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 716 | gpu_preferences_.disable_gl_error_limit), |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 717 | error_state_(gles2::ErrorState::Create(this, &logger_)), |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 718 | shared_context_state_(std::move(shared_context_state)), |
Jonathan Backer | 9267bf1ec | 2018-03-06 19:56:50 | [diff] [blame] | 719 | validators_(new Validators), |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 720 | shared_image_representation_factory_(shared_image_manager, |
| 721 | memory_tracker), |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 722 | gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
Miguel Casas | 510fbfcb | 2018-11-13 23:40:57 | [diff] [blame] | 723 | TRACE_DISABLED_BY_DEFAULT("gpu.decoder"))), |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame^] | 724 | font_manager_(base::MakeRefCounted<ServiceFontManager>(this)), |
| 725 | is_privileged_(is_privileged) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 726 | DCHECK(shared_context_state_); |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 727 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 728 | |
Andres Calderon Jaramillo | 56d9f1ea | 2019-05-24 19:57:34 | [diff] [blame] | 729 | RasterDecoderImpl::~RasterDecoderImpl() = default; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 730 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 731 | base::WeakPtr<DecoderContext> RasterDecoderImpl::AsWeakPtr() { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 732 | return weak_ptr_factory_.GetWeakPtr(); |
| 733 | } |
| 734 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 735 | ContextResult RasterDecoderImpl::Initialize( |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 736 | const scoped_refptr<gl::GLSurface>& surface, |
| 737 | const scoped_refptr<gl::GLContext>& context, |
| 738 | bool offscreen, |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 739 | const gles2::DisallowedFeatures& disallowed_features, |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 740 | const ContextCreationAttribs& attrib_helper) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 741 | TRACE_EVENT0("gpu", "RasterDecoderImpl::Initialize"); |
Jonathan Backer | 19258679 | 2019-12-18 16:36:33 | [diff] [blame] | 742 | DCHECK(shared_context_state_->IsCurrent(nullptr)); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 743 | |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 744 | api_ = gl::g_current_gl_context; |
| 745 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 746 | set_initialized(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 747 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 748 | if (!offscreen) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 749 | return ContextResult::kFatalFailure; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 750 | } |
| 751 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 752 | if (gpu_preferences_.enable_gpu_debugging) |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 753 | set_debug(true); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 754 | |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 755 | if (gpu_preferences_.enable_gpu_command_logging) |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 756 | SetLogCommands(true); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 757 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 758 | DCHECK_EQ(surface.get(), shared_context_state_->surface()); |
| 759 | DCHECK_EQ(context.get(), shared_context_state_->context()); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 760 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 761 | // Create GPU Tracer for timing values. |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 762 | gpu_tracer_.reset(new gles2::GPUTracer(this)); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 763 | |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 764 | // Save the loseContextWhenOutOfMemory context creation attribute. |
| 765 | lose_context_when_out_of_memory_ = |
| 766 | attrib_helper.lose_context_when_out_of_memory; |
| 767 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 768 | CHECK_GL_ERROR(); |
| 769 | |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 770 | query_manager_ = std::make_unique<QueryManager>(); |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 771 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 772 | if (attrib_helper.enable_oop_rasterization) { |
| 773 | if (!features().chromium_raster_transport) { |
| 774 | LOG(ERROR) << "ContextResult::kFatalFailure: " |
| 775 | "chromium_raster_transport not present"; |
Jonathan Backer | 15dbca3 | 2018-06-04 20:39:33 | [diff] [blame] | 776 | Destroy(true); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 777 | return ContextResult::kFatalFailure; |
| 778 | } |
| 779 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 780 | supports_oop_raster_ = !!shared_context_state_->gr_context(); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 781 | if (supports_oop_raster_) |
| 782 | paint_cache_ = std::make_unique<cc::ServicePaintCache>(); |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 783 | use_ddl_ = gpu_preferences_.enable_oop_rasterization_ddl; |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 784 | } |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 785 | |
| 786 | return ContextResult::kSuccess; |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 787 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 788 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 789 | void RasterDecoderImpl::Destroy(bool have_context) { |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 790 | if (!initialized()) |
| 791 | return; |
| 792 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 793 | DCHECK(!have_context || shared_context_state_->context()->IsCurrent(nullptr)); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 794 | |
| 795 | if (have_context) { |
Andres Calderon Jaramillo | 56d9f1ea | 2019-05-24 19:57:34 | [diff] [blame] | 796 | if (supports_oop_raster_) { |
| 797 | transfer_cache()->DeleteAllEntriesForDecoder(raster_decoder_id_); |
| 798 | } |
| 799 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 800 | if (copy_tex_image_blit_.get()) { |
| 801 | copy_tex_image_blit_->Destroy(); |
Jonathan Backer | 36c8a52 | 2018-06-27 20:45:25 | [diff] [blame] | 802 | copy_tex_image_blit_.reset(); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | if (copy_texture_chromium_.get()) { |
| 806 | copy_texture_chromium_->Destroy(); |
Jonathan Backer | 36c8a52 | 2018-06-27 20:45:25 | [diff] [blame] | 807 | copy_texture_chromium_.reset(); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 808 | } |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 809 | |
| 810 | // Make sure we flush any pending skia work on this context. |
| 811 | if (sk_surface_) { |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 812 | GrFlushInfo flush_info = { |
| 813 | .fFlags = kNone_GrFlushFlags, |
| 814 | .fNumSemaphores = end_semaphores_.size(), |
| 815 | .fSignalSemaphores = end_semaphores_.data(), |
| 816 | }; |
Sergey Ulanov | c528c0d | 2019-05-08 21:06:06 | [diff] [blame] | 817 | AddVulkanCleanupTaskForSkiaFlush( |
Eric Karl | 32d9d2e | 2019-05-03 17:09:47 | [diff] [blame] | 818 | shared_context_state_->vk_context_provider(), &flush_info); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 819 | auto result = sk_surface_->flush( |
| 820 | SkSurface::BackendSurfaceAccess::kPresent, flush_info); |
| 821 | DCHECK(result == GrSemaphoresSubmitted::kYes || end_semaphores_.empty()); |
| 822 | end_semaphores_.clear(); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 823 | sk_surface_ = nullptr; |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 824 | if (shared_image_) { |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 825 | scoped_shared_image_write_.reset(); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 826 | shared_image_.reset(); |
| 827 | } else { |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 828 | sk_surface_for_testing_.reset(); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 829 | } |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 830 | } |
| 831 | if (gr_context()) { |
| 832 | gr_context()->flush(); |
| 833 | } |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 834 | } |
| 835 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 836 | copy_tex_image_blit_.reset(); |
| 837 | copy_texture_chromium_.reset(); |
| 838 | |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 839 | if (query_manager_.get()) { |
| 840 | query_manager_->Destroy(have_context); |
| 841 | query_manager_.reset(); |
| 842 | } |
| 843 | |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 844 | font_manager_->Destroy(); |
| 845 | font_manager_.reset(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 846 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 847 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 848 | // Make this decoder's GL context current. |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 849 | bool RasterDecoderImpl::MakeCurrent() { |
Christopher Cameron | dd7812d | 2019-04-23 03:12:21 | [diff] [blame] | 850 | if (!shared_context_state_->GrContextIsGL()) |
Jonathan Backer | 7621ec9 | 2018-12-11 00:02:44 | [diff] [blame] | 851 | return true; |
| 852 | |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 853 | if (context_lost_) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 854 | LOG(ERROR) << " RasterDecoderImpl: Trying to make lost context current."; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 855 | return false; |
| 856 | } |
| 857 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 858 | if (shared_context_state_->context_lost() || |
| 859 | !shared_context_state_->MakeCurrent(nullptr)) { |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 860 | LOG(ERROR) << " RasterDecoderImpl: Context lost during MakeCurrent."; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 861 | MarkContextLost(error::kMakeCurrentFailed); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 862 | return false; |
| 863 | } |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 864 | |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 865 | DCHECK_EQ(api(), gl::g_current_gl_context); |
| 866 | |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 867 | if (CheckResetStatus()) { |
| 868 | LOG(ERROR) |
| 869 | << " RasterDecoderImpl: Context reset detected after MakeCurrent."; |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 870 | return false; |
| 871 | } |
| 872 | |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 873 | // Rebind textures if the service ids may have changed. |
| 874 | RestoreAllExternalTextureBindingsIfNeeded(); |
| 875 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 876 | return true; |
| 877 | } |
| 878 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 879 | gl::GLContext* RasterDecoderImpl::GetGLContext() { |
Jonathan Backer | 19258679 | 2019-12-18 16:36:33 | [diff] [blame] | 880 | return shared_context_state_->context(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 881 | } |
| 882 | |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 883 | gl::GLSurface* RasterDecoderImpl::GetGLSurface() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 884 | return shared_context_state_->surface(); |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 885 | } |
| 886 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 887 | Capabilities RasterDecoderImpl::GetCapabilities() { |
Adrienne Walker | 693f34d | 2019-07-29 22:07:04 | [diff] [blame] | 888 | // TODO(enne): reconcile this with gles2_cmd_decoder's capability settings. |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 889 | Capabilities caps; |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 890 | caps.gpu_rasterization = supports_gpu_raster_; |
Jonathan Backer | eba6af4 | 2018-05-03 22:47:43 | [diff] [blame] | 891 | caps.supports_oop_raster = supports_oop_raster_; |
Antoine Labour | 0f9bee7 | 2018-11-06 07:35:43 | [diff] [blame] | 892 | caps.gpu_memory_buffer_formats = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 893 | feature_info()->feature_flags().gpu_memory_buffer_formats; |
Victor Miura | cabdfac | 2018-01-05 02:18:18 | [diff] [blame] | 894 | caps.texture_target_exception_list = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 895 | gpu_preferences_.texture_target_exception_list; |
Jonathan Backer | a07c4a9e | 2018-03-21 15:13:16 | [diff] [blame] | 896 | caps.texture_format_bgra8888 = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 897 | feature_info()->feature_flags().ext_texture_format_bgra8888; |
Jonathan Backer | 1994ff2e | 2018-03-22 21:24:33 | [diff] [blame] | 898 | caps.texture_storage_image = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 899 | feature_info()->feature_flags().chromium_texture_storage_image; |
| 900 | caps.texture_storage = feature_info()->feature_flags().ext_texture_storage; |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 901 | // TODO(piman): have a consistent limit in shared image backings. |
| 902 | // https://crbug.com/960588 |
| 903 | if (shared_context_state_->GrContextIsGL()) { |
| 904 | api()->glGetIntegervFn(GL_MAX_TEXTURE_SIZE, &caps.max_texture_size); |
| 905 | } else if (shared_context_state_->GrContextIsVulkan()) { |
| 906 | #if BUILDFLAG(ENABLE_VULKAN) |
| 907 | caps.max_texture_size = shared_context_state_->vk_context_provider() |
| 908 | ->GetDeviceQueue() |
| 909 | ->vk_physical_device_properties() |
| 910 | .limits.maxImageDimension2D; |
| 911 | #else |
| 912 | NOTREACHED(); |
| 913 | #endif |
| 914 | } else { |
| 915 | NOTIMPLEMENTED(); |
| 916 | } |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 917 | if (feature_info()->workarounds().max_texture_size) { |
| 918 | caps.max_texture_size = std::min( |
| 919 | caps.max_texture_size, feature_info()->workarounds().max_texture_size); |
James Darpinian | 3c42203 | 2019-04-06 00:20:16 | [diff] [blame] | 920 | caps.max_cube_map_texture_size = |
| 921 | std::min(caps.max_cube_map_texture_size, |
| 922 | feature_info()->workarounds().max_texture_size); |
| 923 | } |
| 924 | if (feature_info()->workarounds().max_3d_array_texture_size) { |
| 925 | caps.max_3d_texture_size = |
| 926 | std::min(caps.max_3d_texture_size, |
| 927 | feature_info()->workarounds().max_3d_array_texture_size); |
| 928 | caps.max_array_texture_layers = |
| 929 | std::min(caps.max_array_texture_layers, |
| 930 | feature_info()->workarounds().max_3d_array_texture_size); |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 931 | } |
| 932 | caps.sync_query = feature_info()->feature_flags().chromium_sync_query; |
Adrienne Walker | 693f34d | 2019-07-29 22:07:04 | [diff] [blame] | 933 | caps.msaa_is_slow = feature_info()->workarounds().msaa_is_slow; |
| 934 | caps.avoid_stencil_buffers = |
| 935 | feature_info()->workarounds().avoid_stencil_buffers; |
Khushal | 315f2fd | 2018-05-29 03:20:39 | [diff] [blame] | 936 | |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 937 | if (gr_context()) { |
Khushal | 315f2fd | 2018-05-29 03:20:39 | [diff] [blame] | 938 | caps.context_supports_distance_field_text = |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 939 | gr_context()->supportsDistanceFieldText(); |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 940 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 941 | return caps; |
| 942 | } |
| 943 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 944 | const gles2::ContextState* RasterDecoderImpl::GetContextState() { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 945 | NOTREACHED(); |
| 946 | return nullptr; |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 947 | } |
| 948 | |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 949 | void RasterDecoderImpl::RestoreGlobalState() const { |
Peng Huang | d7aaf78 | 2019-01-09 22:03:08 | [diff] [blame] | 950 | // We mark the context state is dirty instead of restoring global |
| 951 | // state, and the global state will be restored by the next context. |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 952 | shared_context_state_->set_need_context_state_reset(true); |
| 953 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 954 | } |
| 955 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 956 | void RasterDecoderImpl::ClearAllAttributes() const {} |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 957 | |
| 958 | void RasterDecoderImpl::RestoreAllAttributes() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 959 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 34008d88 | 2018-03-27 18:57:55 | [diff] [blame] | 960 | } |
| 961 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 962 | void RasterDecoderImpl::RestoreState(const gles2::ContextState* prev_state) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 963 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 964 | } |
| 965 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 966 | void RasterDecoderImpl::RestoreActiveTexture() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 967 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 968 | } |
| 969 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 970 | void RasterDecoderImpl::RestoreAllTextureUnitAndSamplerBindings( |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 971 | const gles2::ContextState* prev_state) const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 972 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 973 | } |
| 974 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 975 | void RasterDecoderImpl::RestoreActiveTextureUnitBinding( |
| 976 | unsigned int target) const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 977 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 978 | } |
| 979 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 980 | void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 981 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 982 | } |
| 983 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 984 | void RasterDecoderImpl::RestoreBufferBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 985 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 986 | } |
| 987 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 988 | void RasterDecoderImpl::RestoreFramebufferBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 989 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 990 | } |
| 991 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 992 | void RasterDecoderImpl::RestoreRenderbufferBindings() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 993 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 994 | } |
| 995 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 996 | void RasterDecoderImpl::RestoreProgramBindings() const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 997 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 998 | } |
| 999 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1000 | void RasterDecoderImpl::RestoreTextureState(unsigned service_id) { |
| 1001 | DCHECK(in_copy_sub_texture_); |
| 1002 | reset_texture_state_ = true; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1003 | } |
| 1004 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1005 | void RasterDecoderImpl::RestoreTextureUnitBindings(unsigned unit) const { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1006 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1007 | } |
| 1008 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1009 | void RasterDecoderImpl::RestoreVertexAttribArray(unsigned index) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1010 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1011 | } |
| 1012 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1013 | void RasterDecoderImpl::RestoreAllExternalTextureBindingsIfNeeded() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1014 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1015 | } |
| 1016 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1017 | QueryManager* RasterDecoderImpl::GetQueryManager() { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1018 | return query_manager_.get(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1019 | } |
| 1020 | |
Geoff Lang | 85287e1 | 2018-05-22 17:26:40 | [diff] [blame] | 1021 | void RasterDecoderImpl::SetQueryCallback(unsigned int query_client_id, |
| 1022 | base::OnceClosure callback) { |
| 1023 | QueryManager::Query* query = query_manager_->GetQuery(query_client_id); |
| 1024 | if (query) { |
| 1025 | query->AddCallback(std::move(callback)); |
| 1026 | } else { |
| 1027 | VLOG(1) << "RasterDecoderImpl::SetQueryCallback: No query with ID " |
| 1028 | << query_client_id << ". Running the callback immediately."; |
| 1029 | std::move(callback).Run(); |
| 1030 | } |
| 1031 | } |
| 1032 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1033 | gles2::GpuFenceManager* RasterDecoderImpl::GetGpuFenceManager() { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1034 | NOTIMPLEMENTED(); |
| 1035 | return nullptr; |
| 1036 | } |
| 1037 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1038 | bool RasterDecoderImpl::HasPendingQueries() const { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1039 | return query_manager_ && query_manager_->HavePendingQueries(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1040 | } |
| 1041 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1042 | void RasterDecoderImpl::ProcessPendingQueries(bool did_finish) { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1043 | if (query_manager_) |
| 1044 | query_manager_->ProcessPendingQueries(did_finish); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1045 | } |
| 1046 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1047 | bool RasterDecoderImpl::HasMoreIdleWork() const { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1048 | return gpu_tracer_->HasTracesToProcess(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1049 | } |
| 1050 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1051 | void RasterDecoderImpl::PerformIdleWork() { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1052 | gpu_tracer_->ProcessTraces(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1053 | } |
| 1054 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1055 | bool RasterDecoderImpl::HasPollingWork() const { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1056 | return false; |
| 1057 | } |
| 1058 | |
Jonathan Backer | c2b0efa | 2018-03-21 16:58:35 | [diff] [blame] | 1059 | void RasterDecoderImpl::PerformPollingWork() {} |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1060 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1061 | TextureBase* RasterDecoderImpl::GetTextureBase(uint32_t client_id) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1062 | NOTIMPLEMENTED(); |
| 1063 | return nullptr; |
| 1064 | } |
| 1065 | |
Julien Isorce | fd6c15f | 2018-03-15 16:51:17 | [diff] [blame] | 1066 | void RasterDecoderImpl::SetLevelInfo(uint32_t client_id, |
| 1067 | int level, |
| 1068 | unsigned internal_format, |
| 1069 | unsigned width, |
| 1070 | unsigned height, |
| 1071 | unsigned depth, |
| 1072 | unsigned format, |
| 1073 | unsigned type, |
| 1074 | const gfx::Rect& cleared_rect) { |
| 1075 | NOTIMPLEMENTED(); |
| 1076 | } |
| 1077 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1078 | bool RasterDecoderImpl::WasContextLost() const { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1079 | return context_lost_; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1080 | } |
| 1081 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1082 | bool RasterDecoderImpl::WasContextLostByRobustnessExtension() const { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1083 | return WasContextLost() && reset_by_robustness_extension_; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1084 | } |
| 1085 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1086 | void RasterDecoderImpl::MarkContextLost(error::ContextLostReason reason) { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1087 | // Only lose the context once. |
| 1088 | if (WasContextLost()) |
| 1089 | return; |
| 1090 | |
| 1091 | // Don't make GL calls in here, the context might not be current. |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1092 | context_lost_ = true; |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1093 | command_buffer_service()->SetContextLostReason(reason); |
| 1094 | current_decoder_error_ = error::kLostContext; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1095 | } |
| 1096 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1097 | bool RasterDecoderImpl::CheckResetStatus() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1098 | DCHECK(!WasContextLost()); |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1099 | DCHECK(shared_context_state_->context()->IsCurrent(nullptr)); |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1100 | |
Antoine Labour | dce1ba1 | 2019-06-22 02:05:59 | [diff] [blame] | 1101 | // If the reason for the call was a GL error, we can try to determine the |
| 1102 | // reset status more accurately. |
| 1103 | GLenum driver_status = |
| 1104 | shared_context_state_->context()->CheckStickyGraphicsResetStatus(); |
| 1105 | if (driver_status == GL_NO_ERROR) |
| 1106 | return false; |
| 1107 | |
| 1108 | LOG(ERROR) << "RasterDecoder context lost via ARB/EXT_robustness. Reset " |
| 1109 | "status = " |
| 1110 | << gles2::GLES2Util::GetStringEnum(driver_status); |
| 1111 | |
| 1112 | switch (driver_status) { |
| 1113 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 1114 | MarkContextLost(error::kGuilty); |
| 1115 | break; |
| 1116 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 1117 | MarkContextLost(error::kInnocent); |
| 1118 | break; |
| 1119 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 1120 | MarkContextLost(error::kUnknown); |
| 1121 | break; |
| 1122 | default: |
| 1123 | NOTREACHED(); |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1124 | return false; |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1125 | } |
Antoine Labour | dce1ba1 | 2019-06-22 02:05:59 | [diff] [blame] | 1126 | reset_by_robustness_extension_ = true; |
| 1127 | return true; |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1128 | } |
| 1129 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1130 | gles2::Logger* RasterDecoderImpl::GetLogger() { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1131 | return &logger_; |
| 1132 | } |
| 1133 | |
| 1134 | void RasterDecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1135 | if (use_passthrough_) |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 1136 | return; |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1137 | state()->SetIgnoreCachedStateForTest(ignore); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1138 | } |
| 1139 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1140 | gles2::ImageManager* RasterDecoderImpl::GetImageManagerForTest() { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1141 | NOTREACHED(); |
| 1142 | return nullptr; |
Jonathan Backer | ac62dde | 2018-03-27 21:26:09 | [diff] [blame] | 1143 | } |
| 1144 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1145 | void RasterDecoderImpl::SetCopyTextureResourceManagerForTest( |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1146 | gles2::CopyTextureCHROMIUMResourceManager* copy_texture_resource_manager) { |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1147 | copy_texture_chromium_.reset(copy_texture_resource_manager); |
| 1148 | } |
| 1149 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1150 | void RasterDecoderImpl::BeginDecoding() { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1151 | gpu_tracer_->BeginDecoding(); |
| 1152 | gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_; |
| 1153 | gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_; |
Khushal | cd8fbb77 | 2018-10-16 22:46:14 | [diff] [blame] | 1154 | query_manager_->BeginProcessingCommands(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1155 | } |
| 1156 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1157 | void RasterDecoderImpl::EndDecoding() { |
| 1158 | gpu_tracer_->EndDecoding(); |
Khushal | cd8fbb77 | 2018-10-16 22:46:14 | [diff] [blame] | 1159 | query_manager_->EndProcessingCommands(); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1160 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1161 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1162 | const char* RasterDecoderImpl::GetCommandName(unsigned int command_id) const { |
| 1163 | if (command_id >= kFirstRasterCommand && command_id < kNumCommands) { |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1164 | return raster::GetCommandName(static_cast<CommandId>(command_id)); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1165 | } |
| 1166 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 1167 | } |
| 1168 | |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1169 | template <bool DebugImpl> |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1170 | error::Error RasterDecoderImpl::DoCommandsImpl(unsigned int num_commands, |
| 1171 | const volatile void* buffer, |
| 1172 | int num_entries, |
| 1173 | int* entries_processed) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1174 | DCHECK(entries_processed); |
| 1175 | commands_to_process_ = num_commands; |
| 1176 | error::Error result = error::kNoError; |
| 1177 | const volatile CommandBufferEntry* cmd_data = |
| 1178 | static_cast<const volatile CommandBufferEntry*>(buffer); |
| 1179 | int process_pos = 0; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1180 | CommandId command = static_cast<CommandId>(0); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1181 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1182 | while (process_pos < num_entries && result == error::kNoError && |
| 1183 | commands_to_process_--) { |
| 1184 | const unsigned int size = cmd_data->value_header.size; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1185 | command = static_cast<CommandId>(cmd_data->value_header.command); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1186 | |
| 1187 | if (size == 0) { |
| 1188 | result = error::kInvalidSize; |
| 1189 | break; |
| 1190 | } |
| 1191 | |
| 1192 | if (static_cast<int>(size) + process_pos > num_entries) { |
| 1193 | result = error::kOutOfBounds; |
| 1194 | break; |
| 1195 | } |
| 1196 | |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1197 | if (DebugImpl && log_commands()) { |
| 1198 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" |
| 1199 | << "cmd: " << GetCommandName(command); |
| 1200 | } |
| 1201 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1202 | const unsigned int arg_count = size - 1; |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1203 | unsigned int command_index = command - kFirstRasterCommand; |
Avi Drissman | 6fc2408c | 2018-12-25 21:29:08 | [diff] [blame] | 1204 | if (command_index < base::size(command_info)) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1205 | const CommandInfo& info = command_info[command_index]; |
Jonathan Backer | 2231a00 | 2018-05-14 19:55:22 | [diff] [blame] | 1206 | if (sk_surface_) { |
| 1207 | if (!AllowedBetweenBeginEndRaster(command)) { |
| 1208 | LOCAL_SET_GL_ERROR( |
| 1209 | GL_INVALID_OPERATION, GetCommandName(command), |
| 1210 | "Unexpected command between BeginRasterCHROMIUM and " |
| 1211 | "EndRasterCHROMIUM"); |
| 1212 | process_pos += size; |
| 1213 | cmd_data += size; |
| 1214 | continue; |
| 1215 | } |
| 1216 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1217 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 1218 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 1219 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1220 | bool doing_gpu_trace = false; |
| 1221 | if (DebugImpl && gpu_trace_commands_) { |
| 1222 | if (CMD_FLAG_GET_TRACE_LEVEL(info.cmd_flags) <= gpu_trace_level_) { |
| 1223 | doing_gpu_trace = true; |
Miguel Casas | 510fbfcb | 2018-11-13 23:40:57 | [diff] [blame] | 1224 | gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu.decoder"), |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1225 | GetCommandName(command), gles2::kTraceDecoder); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1229 | uint32_t immediate_data_size = (arg_count - info_arg_count) * |
| 1230 | sizeof(CommandBufferEntry); // NOLINT |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1231 | result = (this->*info.cmd_handler)(immediate_data_size, cmd_data); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1232 | |
| 1233 | if (DebugImpl && doing_gpu_trace) |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1234 | gpu_tracer_->End(gles2::kTraceDecoder); |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1235 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1236 | if (DebugImpl && debug() && !WasContextLost()) { |
| 1237 | GLenum error; |
| 1238 | while ((error = api()->glGetErrorFn()) != GL_NO_ERROR) { |
| 1239 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1240 | << "GL ERROR: " << gles2::GLES2Util::GetStringEnum(error) |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1241 | << " : " << GetCommandName(command); |
| 1242 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1243 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1244 | } |
| 1245 | } else { |
| 1246 | result = error::kInvalidArguments; |
| 1247 | } |
| 1248 | } else { |
| 1249 | result = DoCommonCommand(command, arg_count, cmd_data); |
| 1250 | } |
| 1251 | |
| 1252 | if (result == error::kNoError && |
| 1253 | current_decoder_error_ != error::kNoError) { |
| 1254 | result = current_decoder_error_; |
| 1255 | current_decoder_error_ = error::kNoError; |
| 1256 | } |
| 1257 | |
| 1258 | if (result != error::kDeferCommandUntilLater) { |
| 1259 | process_pos += size; |
| 1260 | cmd_data += size; |
| 1261 | } |
Christopher Cameron | 02e3149a | 2019-01-25 19:52:23 | [diff] [blame] | 1262 | |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 1263 | // Workaround for https://crbug.com/906453: Flush after every command that |
| 1264 | // is not between a BeginRaster and EndRaster. |
| 1265 | if (!sk_surface_) |
| 1266 | FlushToWorkAroundMacCrashes(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | *entries_processed = process_pos; |
| 1270 | |
| 1271 | if (error::IsError(result)) { |
| 1272 | LOG(ERROR) << "Error: " << result << " for Command " |
| 1273 | << GetCommandName(command); |
| 1274 | } |
| 1275 | |
Khushal | 7324ec4 | 2018-07-10 20:01:45 | [diff] [blame] | 1276 | if (supports_oop_raster_) |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1277 | client()->ScheduleGrContextCleanup(); |
Khushal | 7324ec4 | 2018-07-10 20:01:45 | [diff] [blame] | 1278 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1279 | return result; |
| 1280 | } |
| 1281 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1282 | error::Error RasterDecoderImpl::DoCommands(unsigned int num_commands, |
| 1283 | const volatile void* buffer, |
| 1284 | int num_entries, |
| 1285 | int* entries_processed) { |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1286 | if (gpu_debug_commands_) { |
| 1287 | return DoCommandsImpl<true>(num_commands, buffer, num_entries, |
| 1288 | entries_processed); |
| 1289 | } else { |
| 1290 | return DoCommandsImpl<false>(num_commands, buffer, num_entries, |
| 1291 | entries_processed); |
| 1292 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1293 | } |
| 1294 | |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1295 | void RasterDecoderImpl::ExitCommandProcessingEarly() { |
| 1296 | commands_to_process_ = 0; |
| 1297 | } |
| 1298 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1299 | base::StringPiece RasterDecoderImpl::GetLogPrefix() { |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1300 | return logger_.GetLogPrefix(); |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1301 | } |
| 1302 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1303 | void RasterDecoderImpl::BindImage(uint32_t client_texture_id, |
| 1304 | uint32_t texture_target, |
| 1305 | gl::GLImage* image, |
| 1306 | bool can_bind_to_sampler) { |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1307 | NOTIMPLEMENTED(); |
| 1308 | } |
| 1309 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1310 | gles2::ContextGroup* RasterDecoderImpl::GetContextGroup() { |
Antoine Labour | 914f3af | 2019-02-14 20:24:13 | [diff] [blame] | 1311 | return nullptr; |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1312 | } |
| 1313 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1314 | gles2::ErrorState* RasterDecoderImpl::GetErrorState() { |
Peng Huang | b4ed185 | 2018-12-05 03:35:29 | [diff] [blame] | 1315 | return error_state_.get(); |
Jonathan Backer | 1d807a4 | 2018-01-08 20:45:54 | [diff] [blame] | 1316 | } |
| 1317 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1318 | std::unique_ptr<gles2::AbstractTexture> |
| 1319 | RasterDecoderImpl::CreateAbstractTexture(GLenum target, |
| 1320 | GLenum internal_format, |
| 1321 | GLsizei width, |
| 1322 | GLsizei height, |
| 1323 | GLsizei depth, |
| 1324 | GLint border, |
| 1325 | GLenum format, |
| 1326 | GLenum type) { |
liberato@chromium.org | 00c8a6c | 2018-06-05 02:22:41 | [diff] [blame] | 1327 | return nullptr; |
| 1328 | } |
| 1329 | |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1330 | bool RasterDecoderImpl::IsCompressedTextureFormat(unsigned format) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1331 | return feature_info()->validators()->compressed_texture_format.IsValid( |
| 1332 | format); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | bool RasterDecoderImpl::ClearLevel(gles2::Texture* texture, |
| 1336 | unsigned target, |
| 1337 | int level, |
| 1338 | unsigned format, |
| 1339 | unsigned type, |
| 1340 | int xoffset, |
| 1341 | int yoffset, |
| 1342 | int width, |
| 1343 | int height) { |
| 1344 | DCHECK(target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY && |
| 1345 | target != GL_TEXTURE_EXTERNAL_OES); |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1346 | uint32_t channels = gles2::GLES2Util::GetChannelsForFormat(format); |
| 1347 | if (channels & gles2::GLES2Util::kDepth) { |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1348 | DCHECK(false) << "depth not supported"; |
| 1349 | return false; |
| 1350 | } |
| 1351 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1352 | static constexpr uint32_t kMaxZeroSize = 1024 * 1024 * 4; |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1353 | |
| 1354 | uint32_t size; |
| 1355 | uint32_t padded_row_size; |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 1356 | constexpr GLint unpack_alignment = 4; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1357 | if (!gles2::GLES2Util::ComputeImageDataSizes(width, height, 1, format, type, |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 1358 | unpack_alignment, &size, nullptr, |
| 1359 | &padded_row_size)) { |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1360 | return false; |
| 1361 | } |
| 1362 | |
| 1363 | TRACE_EVENT1("gpu", "RasterDecoderImpl::ClearLevel", "size", size); |
| 1364 | |
| 1365 | int tile_height; |
| 1366 | |
| 1367 | if (size > kMaxZeroSize) { |
| 1368 | if (kMaxZeroSize < padded_row_size) { |
| 1369 | // That'd be an awfully large texture. |
| 1370 | return false; |
| 1371 | } |
| 1372 | // We should never have a large total size with a zero row size. |
| 1373 | DCHECK_GT(padded_row_size, 0U); |
| 1374 | tile_height = kMaxZeroSize / padded_row_size; |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1375 | if (!gles2::GLES2Util::ComputeImageDataSizes(width, tile_height, 1, format, |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 1376 | type, unpack_alignment, &size, |
| 1377 | nullptr, nullptr)) { |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1378 | return false; |
| 1379 | } |
| 1380 | } else { |
| 1381 | tile_height = height; |
| 1382 | } |
| 1383 | |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1384 | { |
Peng Huang | 66a7a376 | 2018-12-07 20:05:38 | [diff] [blame] | 1385 | ScopedTextureBinder binder(state(), texture->target(), |
Antoine Labour | 2c9d3fb | 2019-01-19 08:43:43 | [diff] [blame] | 1386 | texture->service_id(), gr_context()); |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 1387 | base::Optional<ScopedPixelUnpackState> pixel_unpack_state; |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1388 | if (shared_context_state_->need_context_state_reset()) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1389 | pixel_unpack_state.emplace(state(), gr_context(), feature_info()); |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 1390 | } |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1391 | // Add extra scope to destroy zero and the object it owns right |
| 1392 | // after its usage. |
| 1393 | // Assumes the size has already been checked. |
| 1394 | std::unique_ptr<char[]> zero(new char[size]); |
| 1395 | memset(zero.get(), 0, size); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1396 | GLint y = 0; |
| 1397 | while (y < height) { |
| 1398 | GLint h = y + tile_height > height ? height - y : tile_height; |
| 1399 | api()->glTexSubImage2DFn( |
| 1400 | target, level, xoffset, yoffset + y, width, h, |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1401 | gles2::TextureManager::AdjustTexFormat(feature_info(), format), type, |
| 1402 | zero.get()); |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1403 | y += tile_height; |
| 1404 | } |
| 1405 | } |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1406 | DCHECK(glGetError() == GL_NO_ERROR); |
| 1407 | return true; |
| 1408 | } |
| 1409 | |
| 1410 | bool RasterDecoderImpl::ClearCompressedTextureLevel(gles2::Texture* texture, |
| 1411 | unsigned target, |
| 1412 | int level, |
| 1413 | unsigned format, |
| 1414 | int width, |
| 1415 | int height) { |
Peng Huang | e89c2a05 | 2018-12-04 11:35:11 | [diff] [blame] | 1416 | NOTREACHED(); |
| 1417 | return false; |
Jonathan Backer | c26060e | 2018-03-29 15:06:29 | [diff] [blame] | 1418 | } |
| 1419 | |
Andres Calderon Jaramillo | b870ca6 | 2019-01-29 16:33:35 | [diff] [blame] | 1420 | int RasterDecoderImpl::GetRasterDecoderId() const { |
| 1421 | return raster_decoder_id_; |
| 1422 | } |
| 1423 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 1424 | int RasterDecoderImpl::DecoderIdForTest() { |
| 1425 | return raster_decoder_id_; |
| 1426 | } |
| 1427 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1428 | ServiceTransferCache* RasterDecoderImpl::GetTransferCacheForTest() { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 1429 | return shared_context_state_->transfer_cache(); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1430 | } |
| 1431 | |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 1432 | void RasterDecoderImpl::SetUpForRasterCHROMIUMForTest() { |
| 1433 | // Some tests use mock GL which doesn't work with skia. Just use a bitmap |
| 1434 | // backed surface for OOP raster commands. |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 1435 | auto info = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType, |
| 1436 | SkColorSpace::MakeSRGB()); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 1437 | sk_surface_for_testing_ = SkSurface::MakeRaster(info); |
| 1438 | sk_surface_ = sk_surface_for_testing_.get(); |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 1439 | raster_canvas_ = sk_surface_->getCanvas(); |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 1440 | } |
| 1441 | |
Jonathan Backer | c7b8297 | 2018-11-21 19:08:48 | [diff] [blame] | 1442 | void RasterDecoderImpl::SetOOMErrorForTest() { |
| 1443 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "SetOOMErrorForTest", |
| 1444 | "synthetic out of memory"); |
| 1445 | } |
| 1446 | |
Christopher Cameron | 386e1858 | 2019-01-11 20:17:34 | [diff] [blame] | 1447 | void RasterDecoderImpl::DisableFlushWorkaroundForTest() { |
| 1448 | flush_workaround_disabled_for_test_ = true; |
| 1449 | } |
| 1450 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1451 | void RasterDecoderImpl::OnContextLostError() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1452 | if (!WasContextLost()) { |
| 1453 | // Need to lose current context before broadcasting! |
| 1454 | CheckResetStatus(); |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1455 | reset_by_robustness_extension_ = true; |
| 1456 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1457 | } |
| 1458 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1459 | void RasterDecoderImpl::OnOutOfMemoryError() { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1460 | if (lose_context_when_out_of_memory_ && !WasContextLost()) { |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1461 | if (!CheckResetStatus()) { |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1462 | MarkContextLost(error::kOutOfMemory); |
| 1463 | } |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 1464 | } |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 1465 | } |
| 1466 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1467 | error::Error RasterDecoderImpl::HandleBeginQueryEXT( |
| 1468 | uint32_t immediate_data_size, |
| 1469 | const volatile void* cmd_data) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1470 | const volatile raster::cmds::BeginQueryEXT& c = |
| 1471 | *static_cast<const volatile raster::cmds::BeginQueryEXT*>(cmd_data); |
| 1472 | GLenum target = static_cast<GLenum>(c.target); |
| 1473 | GLuint client_id = static_cast<GLuint>(c.id); |
| 1474 | int32_t sync_shm_id = static_cast<int32_t>(c.sync_data_shm_id); |
| 1475 | uint32_t sync_shm_offset = static_cast<uint32_t>(c.sync_data_shm_offset); |
| 1476 | |
| 1477 | switch (target) { |
| 1478 | case GL_COMMANDS_ISSUED_CHROMIUM: |
Jonathan Backer | 80b27029 | 2018-12-13 19:13:55 | [diff] [blame] | 1479 | break; |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1480 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
Jonathan Backer | 80b27029 | 2018-12-13 19:13:55 | [diff] [blame] | 1481 | if (!features().chromium_sync_query) { |
| 1482 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1483 | "not enabled for commands completed queries"); |
| 1484 | return error::kNoError; |
| 1485 | } |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1486 | break; |
| 1487 | default: |
| 1488 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "glBeginQueryEXT", |
| 1489 | "unknown query target"); |
| 1490 | return error::kNoError; |
| 1491 | } |
| 1492 | |
| 1493 | if (query_manager_->GetActiveQuery(target)) { |
| 1494 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1495 | "query already in progress"); |
| 1496 | return error::kNoError; |
| 1497 | } |
| 1498 | |
| 1499 | if (client_id == 0) { |
| 1500 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
| 1501 | return error::kNoError; |
| 1502 | } |
| 1503 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 1504 | scoped_refptr<Buffer> buffer = GetSharedMemoryBuffer(sync_shm_id); |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1505 | if (!buffer) |
| 1506 | return error::kInvalidArguments; |
| 1507 | QuerySync* sync = static_cast<QuerySync*>( |
| 1508 | buffer->GetDataAddress(sync_shm_offset, sizeof(QuerySync))); |
| 1509 | if (!sync) |
| 1510 | return error::kOutOfBounds; |
| 1511 | |
| 1512 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 1513 | if (!query) { |
| 1514 | if (!query_manager_->IsValidQuery(client_id)) { |
| 1515 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1516 | "id not made by glGenQueriesEXT"); |
| 1517 | return error::kNoError; |
| 1518 | } |
| 1519 | |
| 1520 | query = |
| 1521 | query_manager_->CreateQuery(target, client_id, std::move(buffer), sync); |
| 1522 | } else { |
| 1523 | if (query->target() != target) { |
| 1524 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 1525 | "target does not match"); |
| 1526 | return error::kNoError; |
| 1527 | } else if (query->sync() != sync) { |
| 1528 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 1529 | return error::kInvalidArguments; |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | query_manager_->BeginQuery(query); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1534 | return error::kNoError; |
| 1535 | } |
| 1536 | |
| 1537 | error::Error RasterDecoderImpl::HandleEndQueryEXT( |
| 1538 | uint32_t immediate_data_size, |
| 1539 | const volatile void* cmd_data) { |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1540 | const volatile raster::cmds::EndQueryEXT& c = |
| 1541 | *static_cast<const volatile raster::cmds::EndQueryEXT*>(cmd_data); |
| 1542 | GLenum target = static_cast<GLenum>(c.target); |
| 1543 | uint32_t submit_count = static_cast<GLuint>(c.submit_count); |
| 1544 | |
| 1545 | QueryManager::Query* query = query_manager_->GetActiveQuery(target); |
| 1546 | if (!query) { |
| 1547 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glEndQueryEXT", |
| 1548 | "No active query"); |
| 1549 | return error::kNoError; |
| 1550 | } |
| 1551 | |
| 1552 | query_manager_->EndQuery(query, submit_count); |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 1553 | return error::kNoError; |
| 1554 | } |
| 1555 | |
Andres Calderon Jaramillo | 21e9815 | 2019-08-22 01:38:04 | [diff] [blame] | 1556 | error::Error RasterDecoderImpl::HandleQueryCounterEXT( |
| 1557 | uint32_t immediate_data_size, |
| 1558 | const volatile void* cmd_data) { |
| 1559 | const volatile raster::cmds::QueryCounterEXT& c = |
| 1560 | *static_cast<const volatile raster::cmds::QueryCounterEXT*>(cmd_data); |
| 1561 | GLenum target = static_cast<GLenum>(c.target); |
| 1562 | GLuint client_id = static_cast<GLuint>(c.id); |
| 1563 | int32_t sync_shm_id = static_cast<int32_t>(c.sync_data_shm_id); |
| 1564 | uint32_t sync_shm_offset = static_cast<uint32_t>(c.sync_data_shm_offset); |
| 1565 | uint32_t submit_count = static_cast<GLuint>(c.submit_count); |
| 1566 | |
| 1567 | if (target != GL_COMMANDS_ISSUED_TIMESTAMP_CHROMIUM) { |
| 1568 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, "glQueryCounterEXT", |
| 1569 | "unknown query target"); |
| 1570 | return error::kNoError; |
| 1571 | } |
| 1572 | |
| 1573 | scoped_refptr<Buffer> buffer = GetSharedMemoryBuffer(sync_shm_id); |
| 1574 | if (!buffer) |
| 1575 | return error::kInvalidArguments; |
| 1576 | QuerySync* sync = static_cast<QuerySync*>( |
| 1577 | buffer->GetDataAddress(sync_shm_offset, sizeof(QuerySync))); |
| 1578 | if (!sync) |
| 1579 | return error::kOutOfBounds; |
| 1580 | |
| 1581 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 1582 | if (!query) { |
| 1583 | if (!query_manager_->IsValidQuery(client_id)) { |
| 1584 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glQueryCounterEXT", |
| 1585 | "id not made by glGenQueriesEXT"); |
| 1586 | return error::kNoError; |
| 1587 | } |
| 1588 | query = |
| 1589 | query_manager_->CreateQuery(target, client_id, std::move(buffer), sync); |
| 1590 | } else { |
| 1591 | if (query->target() != target) { |
| 1592 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glQueryCounterEXT", |
| 1593 | "target does not match"); |
| 1594 | return error::kNoError; |
| 1595 | } else if (query->sync() != sync) { |
| 1596 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 1597 | return error::kInvalidArguments; |
| 1598 | } |
| 1599 | } |
| 1600 | query_manager_->QueryCounter(query, submit_count); |
| 1601 | |
| 1602 | return error::kNoError; |
| 1603 | } |
| 1604 | |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1605 | void RasterDecoderImpl::DoFinish() { |
Christopher Cameron | dd7812d | 2019-04-23 03:12:21 | [diff] [blame] | 1606 | if (shared_context_state_->GrContextIsGL()) |
Jonathan Backer | 7621ec9 | 2018-12-11 00:02:44 | [diff] [blame] | 1607 | api()->glFinishFn(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1608 | ProcessPendingQueries(true); |
| 1609 | } |
| 1610 | |
| 1611 | void RasterDecoderImpl::DoFlush() { |
Christopher Cameron | dd7812d | 2019-04-23 03:12:21 | [diff] [blame] | 1612 | if (shared_context_state_->GrContextIsGL()) |
Jonathan Backer | 7621ec9 | 2018-12-11 00:02:44 | [diff] [blame] | 1613 | api()->glFlushFn(); |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 1614 | ProcessPendingQueries(false); |
| 1615 | } |
| 1616 | |
Jonathan Backer | 016bd97e | 2018-03-14 15:26:39 | [diff] [blame] | 1617 | bool RasterDecoderImpl::GenQueriesEXTHelper(GLsizei n, |
| 1618 | const GLuint* client_ids) { |
| 1619 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 1620 | if (query_manager_->IsValidQuery(client_ids[ii])) { |
| 1621 | return false; |
| 1622 | } |
| 1623 | } |
| 1624 | query_manager_->GenQueries(n, client_ids); |
| 1625 | return true; |
| 1626 | } |
| 1627 | |
| 1628 | void RasterDecoderImpl::DeleteQueriesEXTHelper( |
| 1629 | GLsizei n, |
| 1630 | const volatile GLuint* client_ids) { |
| 1631 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 1632 | GLuint client_id = client_ids[ii]; |
| 1633 | query_manager_->RemoveQuery(client_id); |
| 1634 | } |
| 1635 | } |
| 1636 | |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1637 | error::Error RasterDecoderImpl::HandleTraceBeginCHROMIUM( |
| 1638 | uint32_t immediate_data_size, |
| 1639 | const volatile void* cmd_data) { |
| 1640 | const volatile gles2::cmds::TraceBeginCHROMIUM& c = |
| 1641 | *static_cast<const volatile gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); |
| 1642 | Bucket* category_bucket = GetBucket(c.category_bucket_id); |
| 1643 | Bucket* name_bucket = GetBucket(c.name_bucket_id); |
Jonathan Backer | ff2ac0f | 2018-07-18 15:53:47 | [diff] [blame] | 1644 | static constexpr size_t kMaxStrLen = 256; |
| 1645 | if (!category_bucket || category_bucket->size() == 0 || |
| 1646 | category_bucket->size() > kMaxStrLen || !name_bucket || |
| 1647 | name_bucket->size() == 0 || name_bucket->size() > kMaxStrLen) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1648 | return error::kInvalidArguments; |
| 1649 | } |
| 1650 | |
| 1651 | std::string category_name; |
| 1652 | std::string trace_name; |
| 1653 | if (!category_bucket->GetAsString(&category_name) || |
| 1654 | !name_bucket->GetAsString(&trace_name)) { |
| 1655 | return error::kInvalidArguments; |
| 1656 | } |
| 1657 | |
| 1658 | debug_marker_manager_.PushGroup(trace_name); |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1659 | if (!gpu_tracer_->Begin(category_name, trace_name, gles2::kTraceCHROMIUM)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1660 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glTraceBeginCHROMIUM", |
| 1661 | "unable to create begin trace"); |
| 1662 | return error::kNoError; |
| 1663 | } |
| 1664 | return error::kNoError; |
| 1665 | } |
| 1666 | |
| 1667 | void RasterDecoderImpl::DoTraceEndCHROMIUM() { |
| 1668 | debug_marker_manager_.PopGroup(); |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1669 | if (!gpu_tracer_->End(gles2::kTraceCHROMIUM)) { |
Jonathan Backer | e26739c | 2018-05-15 13:27:07 | [diff] [blame] | 1670 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glTraceEndCHROMIUM", |
| 1671 | "no trace begin found"); |
| 1672 | return; |
| 1673 | } |
| 1674 | } |
| 1675 | |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1676 | error::Error RasterDecoderImpl::HandleSetActiveURLCHROMIUM( |
| 1677 | uint32_t immediate_data_size, |
| 1678 | const volatile void* cmd_data) { |
| 1679 | const volatile cmds::SetActiveURLCHROMIUM& c = |
| 1680 | *static_cast<const volatile cmds::SetActiveURLCHROMIUM*>(cmd_data); |
| 1681 | Bucket* url_bucket = GetBucket(c.url_bucket_id); |
| 1682 | static constexpr size_t kMaxStrLen = 1024; |
| 1683 | if (!url_bucket || url_bucket->size() == 0 || |
Khushal | da1fb833 | 2018-10-26 19:26:22 | [diff] [blame] | 1684 | url_bucket->size() > kMaxStrLen) { |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1685 | return error::kInvalidArguments; |
| 1686 | } |
| 1687 | |
Khushal | da1fb833 | 2018-10-26 19:26:22 | [diff] [blame] | 1688 | size_t size = url_bucket->size(); |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1689 | const char* url_str = url_bucket->GetDataAs<const char*>(0, size); |
| 1690 | if (!url_str) |
| 1691 | return error::kInvalidArguments; |
| 1692 | |
| 1693 | GURL url(base::StringPiece(url_str, size)); |
Corentin Wallez | 0f412f0 | 2019-04-03 22:42:38 | [diff] [blame] | 1694 | client()->SetActiveURL(std::move(url)); |
Khushal | 49836ab | 2018-07-25 02:08:45 | [diff] [blame] | 1695 | return error::kNoError; |
| 1696 | } |
| 1697 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1698 | bool RasterDecoderImpl::InitializeCopyTexImageBlitter() { |
| 1699 | if (!copy_tex_image_blit_.get()) { |
| 1700 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopySubTexture"); |
| 1701 | copy_tex_image_blit_.reset( |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1702 | new gles2::CopyTexImageResourceManager(feature_info())); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1703 | copy_tex_image_blit_->Initialize(this); |
| 1704 | if (LOCAL_PEEK_GL_ERROR("glCopySubTexture") != GL_NO_ERROR) |
| 1705 | return false; |
| 1706 | } |
| 1707 | return true; |
| 1708 | } |
| 1709 | |
| 1710 | bool RasterDecoderImpl::InitializeCopyTextureCHROMIUM() { |
| 1711 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 1712 | // needed because it takes 10s of milliseconds to initialize. |
| 1713 | if (!copy_texture_chromium_.get()) { |
| 1714 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopySubTexture"); |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1715 | copy_texture_chromium_.reset( |
| 1716 | gles2::CopyTextureCHROMIUMResourceManager::Create()); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1717 | copy_texture_chromium_->Initialize(this, features()); |
| 1718 | if (LOCAL_PEEK_GL_ERROR("glCopySubTexture") != GL_NO_ERROR) |
| 1719 | return false; |
| 1720 | |
| 1721 | // On the desktop core profile this also needs emulation of |
| 1722 | // CopyTex{Sub}Image2D for luminance, alpha, and luminance_alpha |
| 1723 | // textures. |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 1724 | if (gles2::CopyTexImageResourceManager::CopyTexImageRequiresBlit( |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1725 | feature_info(), GL_LUMINANCE)) { |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1726 | if (!InitializeCopyTexImageBlitter()) |
| 1727 | return false; |
| 1728 | } |
| 1729 | } |
| 1730 | return true; |
| 1731 | } |
| 1732 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1733 | void RasterDecoderImpl::DoCopySubTextureINTERNAL( |
| 1734 | GLint xoffset, |
| 1735 | GLint yoffset, |
| 1736 | GLint x, |
| 1737 | GLint y, |
| 1738 | GLsizei width, |
| 1739 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1740 | GLboolean unpack_flip_y, |
| 1741 | GLboolean unpack_premultiply_alpha, |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1742 | const volatile GLbyte* mailboxes) { |
| 1743 | Mailbox source_mailbox = Mailbox::FromVolatile( |
| 1744 | reinterpret_cast<const volatile Mailbox*>(mailboxes)[0]); |
| 1745 | DLOG_IF(ERROR, !source_mailbox.Verify()) |
| 1746 | << "CopySubTexture was passed an invalid mailbox"; |
| 1747 | Mailbox dest_mailbox = Mailbox::FromVolatile( |
| 1748 | reinterpret_cast<const volatile Mailbox*>(mailboxes)[1]); |
| 1749 | DLOG_IF(ERROR, !dest_mailbox.Verify()) |
| 1750 | << "CopySubTexture was passed an invalid mailbox"; |
| 1751 | |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1752 | if (source_mailbox == dest_mailbox) { |
| 1753 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTexture", |
| 1754 | "source and destination mailboxes are the same"); |
| 1755 | return; |
| 1756 | } |
| 1757 | |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1758 | if (!shared_context_state_->GrContextIsGL()) { |
| 1759 | // Use Skia to copy texture if raster's gr_context() is not using GL. |
| 1760 | DoCopySubTextureINTERNALSkia(xoffset, yoffset, x, y, width, height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1761 | unpack_flip_y, unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1762 | source_mailbox, dest_mailbox); |
| 1763 | } else if (use_passthrough_) { |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1764 | DoCopySubTextureINTERNALGLPassthrough( |
| 1765 | xoffset, yoffset, x, y, width, height, unpack_flip_y, |
| 1766 | unpack_premultiply_alpha, source_mailbox, dest_mailbox); |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1767 | } else { |
| 1768 | DoCopySubTextureINTERNALGL(xoffset, yoffset, x, y, width, height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1769 | unpack_flip_y, unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1770 | source_mailbox, dest_mailbox); |
| 1771 | } |
| 1772 | } |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1773 | |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1774 | void RasterDecoderImpl::DoCopySubTextureINTERNALGLPassthrough( |
| 1775 | GLint xoffset, |
| 1776 | GLint yoffset, |
| 1777 | GLint x, |
| 1778 | GLint y, |
| 1779 | GLsizei width, |
| 1780 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1781 | GLboolean unpack_flip_y, |
| 1782 | GLboolean unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1783 | const Mailbox& source_mailbox, |
| 1784 | const Mailbox& dest_mailbox) { |
| 1785 | DCHECK(source_mailbox != dest_mailbox); |
| 1786 | DCHECK(use_passthrough_); |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 1787 | |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1788 | std::unique_ptr<SharedImageRepresentationGLTexturePassthrough> |
| 1789 | source_shared_image = |
| 1790 | shared_image_representation_factory_.ProduceGLTexturePassthrough( |
| 1791 | source_mailbox); |
| 1792 | std::unique_ptr<SharedImageRepresentationGLTexturePassthrough> |
| 1793 | dest_shared_image = |
| 1794 | shared_image_representation_factory_.ProduceGLTexturePassthrough( |
| 1795 | dest_mailbox); |
| 1796 | if (!source_shared_image || !dest_shared_image) { |
| 1797 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", "unknown mailbox"); |
Jonathan Backer | 628d73f8 | 2019-01-17 17:34:18 | [diff] [blame] | 1798 | return; |
| 1799 | } |
| 1800 | |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1801 | std::unique_ptr<SharedImageRepresentationGLTexturePassthrough::ScopedAccess> |
| 1802 | source_access = source_shared_image->BeginScopedAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 1803 | GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM, |
| 1804 | SharedImageRepresentation::AllowUnclearedAccess::kNo); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1805 | if (!source_access) { |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1806 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1807 | "unable to access source for read"); |
| 1808 | return; |
| 1809 | } |
| 1810 | |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 1811 | // Allow uncleared access, as we manually handle clear tracking. |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1812 | std::unique_ptr<SharedImageRepresentationGLTexturePassthrough::ScopedAccess> |
| 1813 | dest_access = dest_shared_image->BeginScopedAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 1814 | GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM, |
| 1815 | SharedImageRepresentation::AllowUnclearedAccess::kYes); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1816 | if (!dest_access) { |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1817 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1818 | "unable to access destination for write"); |
| 1819 | return; |
| 1820 | } |
| 1821 | |
Eric Karl | b25e1b6 | 2019-12-17 23:07:49 | [diff] [blame] | 1822 | gfx::Rect new_cleared_rect; |
| 1823 | gfx::Rect old_cleared_rect = dest_shared_image->ClearedRect(); |
| 1824 | gfx::Rect dest_rect(xoffset, yoffset, width, height); |
| 1825 | if (gles2::TextureManager::CombineAdjacentRects(old_cleared_rect, dest_rect, |
| 1826 | &new_cleared_rect)) { |
| 1827 | DCHECK(old_cleared_rect.IsEmpty() || |
| 1828 | new_cleared_rect.Contains(old_cleared_rect)); |
| 1829 | } else { |
| 1830 | // No users of RasterDecoder leverage this functionality. Clearing uncleared |
| 1831 | // regions could be added here if needed. |
| 1832 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1833 | "Cannot clear non-combineable rects."); |
| 1834 | return; |
| 1835 | } |
| 1836 | |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1837 | gles2::TexturePassthrough* source_texture = |
| 1838 | source_shared_image->GetTexturePassthrough().get(); |
| 1839 | gles2::TexturePassthrough* dest_texture = |
| 1840 | dest_shared_image->GetTexturePassthrough().get(); |
| 1841 | DCHECK(!source_texture->is_bind_pending()); |
| 1842 | DCHECK_NE(source_texture->service_id(), dest_texture->service_id()); |
| 1843 | |
| 1844 | api()->glCopySubTextureCHROMIUMFn( |
| 1845 | source_texture->service_id(), /*source_level=*/0, dest_texture->target(), |
| 1846 | dest_texture->service_id(), |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1847 | /*dest_level=*/0, xoffset, yoffset, x, y, width, height, unpack_flip_y, |
| 1848 | unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1849 | /*unpack_unmultiply_alpha=*/false); |
| 1850 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopySubTexture"); |
Eric Karl | b25e1b6 | 2019-12-17 23:07:49 | [diff] [blame] | 1851 | |
| 1852 | if (!dest_shared_image->IsCleared()) { |
| 1853 | dest_shared_image->SetClearedRect(new_cleared_rect); |
| 1854 | } |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | void RasterDecoderImpl::DoCopySubTextureINTERNALGL( |
| 1858 | GLint xoffset, |
| 1859 | GLint yoffset, |
| 1860 | GLint x, |
| 1861 | GLint y, |
| 1862 | GLsizei width, |
| 1863 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 1864 | GLboolean unpack_flip_y, |
| 1865 | GLboolean unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 1866 | const Mailbox& source_mailbox, |
| 1867 | const Mailbox& dest_mailbox) { |
| 1868 | DCHECK(source_mailbox != dest_mailbox); |
| 1869 | DCHECK(shared_context_state_->GrContextIsGL()); |
| 1870 | |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1871 | std::unique_ptr<SharedImageRepresentationGLTexture> source_shared_image = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1872 | shared_image_representation_factory_.ProduceGLTexture(source_mailbox); |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1873 | std::unique_ptr<SharedImageRepresentationGLTexture> dest_shared_image = |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1874 | shared_image_representation_factory_.ProduceGLTexture(dest_mailbox); |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1875 | if (!source_shared_image || !dest_shared_image) { |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 1876 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", "unknown mailbox"); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1877 | return; |
| 1878 | } |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1879 | |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1880 | std::unique_ptr<SharedImageRepresentationGLTexture::ScopedAccess> |
| 1881 | source_access = source_shared_image->BeginScopedAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 1882 | GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM, |
| 1883 | SharedImageRepresentation::AllowUnclearedAccess::kNo); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1884 | if (!source_access) { |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1885 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1886 | "unable to access source for read"); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1887 | return; |
| 1888 | } |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1889 | |
| 1890 | gles2::Texture* source_texture = source_shared_image->GetTexture(); |
Antoine Labour | aeb4bd70e | 2019-01-16 02:33:28 | [diff] [blame] | 1891 | GLenum source_target = source_texture->target(); |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1892 | DCHECK(source_target); |
| 1893 | GLint source_level = 0; |
| 1894 | gfx::Size source_size = source_shared_image->size(); |
| 1895 | gfx::Rect source_rect(x, y, width, height); |
| 1896 | if (!gfx::Rect(source_size).Contains(source_rect)) { |
| 1897 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1898 | "source texture bad dimensions."); |
Antoine Labour | a2da080 | 2019-01-22 21:06:59 | [diff] [blame] | 1899 | return; |
| 1900 | } |
| 1901 | |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 1902 | // Allow uncleared access, as we manually handle clear tracking. |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1903 | std::unique_ptr<SharedImageRepresentationGLTexture::ScopedAccess> |
| 1904 | dest_access = dest_shared_image->BeginScopedAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 1905 | GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM, |
| 1906 | SharedImageRepresentation::AllowUnclearedAccess::kYes); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 1907 | if (!dest_access) { |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1908 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1909 | "unable to access destination for write"); |
| 1910 | return; |
Findit | 1f74b7f | 2019-01-23 01:32:41 | [diff] [blame] | 1911 | } |
Antoine Labour | a2da080 | 2019-01-22 21:06:59 | [diff] [blame] | 1912 | |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1913 | gles2::Texture* dest_texture = dest_shared_image->GetTexture(); |
| 1914 | GLenum dest_target = dest_texture->target(); |
| 1915 | DCHECK(dest_target); |
| 1916 | GLint dest_level = 0; |
| 1917 | gfx::Size dest_size = dest_shared_image->size(); |
| 1918 | gfx::Rect dest_rect(xoffset, yoffset, width, height); |
| 1919 | if (!gfx::Rect(dest_size).Contains(dest_rect)) { |
| 1920 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1921 | "destination texture bad dimensions."); |
| 1922 | return; |
| 1923 | } |
| 1924 | |
| 1925 | DCHECK_NE(source_texture->service_id(), dest_texture->service_id()); |
| 1926 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1927 | GLenum source_type = 0; |
| 1928 | GLenum source_internal_format = 0; |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1929 | source_texture->GetLevelType(source_target, source_level, &source_type, |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1930 | &source_internal_format); |
| 1931 | |
| 1932 | GLenum dest_type = 0; |
| 1933 | GLenum dest_internal_format = 0; |
| 1934 | bool dest_level_defined = dest_texture->GetLevelType( |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1935 | dest_target, dest_level, &dest_type, &dest_internal_format); |
| 1936 | DCHECK(dest_level_defined); |
| 1937 | |
| 1938 | // TODO(piman): Do we need this check? It might always be true by |
| 1939 | // construction. |
Jonathan Backer | 4cb165c8 | 2018-07-03 20:25:33 | [diff] [blame] | 1940 | std::string output_error_msg; |
| 1941 | if (!ValidateCopyTextureCHROMIUMInternalFormats( |
| 1942 | GetFeatureInfo(), source_internal_format, dest_internal_format, |
| 1943 | &output_error_msg)) { |
| 1944 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTexture", |
| 1945 | output_error_msg.c_str()); |
| 1946 | return; |
| 1947 | } |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1948 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1949 | // Clear the source texture if necessary. |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1950 | if (!gles2::TextureManager::ClearTextureLevel(this, source_texture, |
| 1951 | source_target, 0 /* level */)) { |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1952 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTexture", |
| 1953 | "source texture dimensions too big"); |
| 1954 | return; |
| 1955 | } |
| 1956 | |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1957 | gfx::Rect new_cleared_rect; |
| 1958 | gfx::Rect old_cleared_rect = |
| 1959 | dest_texture->GetLevelClearedRect(dest_target, dest_level); |
| 1960 | if (gles2::TextureManager::CombineAdjacentRects( |
| 1961 | dest_texture->GetLevelClearedRect(dest_target, dest_level), dest_rect, |
| 1962 | &new_cleared_rect)) { |
| 1963 | DCHECK(old_cleared_rect.IsEmpty() || |
| 1964 | new_cleared_rect.Contains(old_cleared_rect)); |
| 1965 | } else { |
Eric Karl | b25e1b6 | 2019-12-17 23:07:49 | [diff] [blame] | 1966 | // No users of RasterDecoder leverage this functionality. Clearing uncleared |
| 1967 | // regions could be added here if needed. |
| 1968 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 1969 | "Cannot clear non-combineable rects."); |
| 1970 | return; |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | ScopedTextureBinder binder(state(), dest_target, dest_texture->service_id(), |
| 1974 | gr_context()); |
| 1975 | |
| 1976 | gles2::Texture::ImageState image_state; |
Dave Tapuska | b8a73b3 | 2019-09-10 13:38:39 | [diff] [blame] | 1977 | if (gl::GLImage* image = |
| 1978 | source_texture->GetLevelImage(source_target, 0, &image_state)) { |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1979 | base::Optional<ScopedPixelUnpackState> pixel_unpack_state; |
| 1980 | if (image->GetType() == gl::GLImage::Type::MEMORY && |
| 1981 | shared_context_state_->need_context_state_reset()) { |
| 1982 | // If the image is in shared memory, we may need upload the pixel data |
| 1983 | // with SubTexImage2D, so we need reset pixel unpack state if gl context |
| 1984 | // state has been touched by skia. |
Antoine Labour | 10dddca1 | 2019-02-19 19:09:26 | [diff] [blame] | 1985 | pixel_unpack_state.emplace(state(), gr_context(), feature_info()); |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | // Try to copy by uploading to the destination texture. |
| 1989 | if (dest_internal_format == source_internal_format) { |
| 1990 | if (image->CopyTexSubImage(dest_target, gfx::Point(xoffset, yoffset), |
| 1991 | gfx::Rect(x, y, width, height))) { |
| 1992 | dest_texture->SetLevelClearedRect(dest_target, dest_level, |
| 1993 | new_cleared_rect); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1994 | return; |
| 1995 | } |
| 1996 | } |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 1997 | |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 1998 | // Otherwise, update the source if needed. |
| 1999 | if (image_state == gles2::Texture::UNBOUND) { |
| 2000 | ScopedGLErrorSuppressor suppressor( |
| 2001 | "RasterDecoderImpl::DoCopySubTextureINTERNAL", error_state_.get()); |
| 2002 | api()->glBindTextureFn(source_target, source_texture->service_id()); |
| 2003 | if (image->ShouldBindOrCopy() == gl::GLImage::BIND) { |
| 2004 | bool rv = image->BindTexImage(source_target); |
| 2005 | DCHECK(rv) << "BindTexImage() failed"; |
| 2006 | image_state = gles2::Texture::BOUND; |
| 2007 | } else { |
| 2008 | bool rv = image->CopyTexImage(source_target); |
| 2009 | DCHECK(rv) << "CopyTexImage() failed"; |
| 2010 | image_state = gles2::Texture::COPIED; |
| 2011 | } |
| 2012 | source_texture->SetLevelImageState(source_target, 0, image_state); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | if (!InitializeCopyTextureCHROMIUM()) |
| 2017 | return; |
| 2018 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2019 | // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 2020 | // before presenting. |
| 2021 | if (source_target == GL_TEXTURE_EXTERNAL_OES) { |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 2022 | if (gles2::GLStreamTextureImage* image = |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2023 | source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, |
| 2024 | source_level)) { |
| 2025 | GLfloat transform_matrix[16]; |
| 2026 | image->GetTextureMatrix(transform_matrix); |
Jonathan Backer | 76dfd50 | 2018-05-03 18:34:31 | [diff] [blame] | 2027 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2028 | copy_texture_chromium_->DoCopySubTextureWithTransform( |
| 2029 | this, source_target, source_texture->service_id(), source_level, |
| 2030 | source_internal_format, dest_target, dest_texture->service_id(), |
| 2031 | dest_level, dest_internal_format, xoffset, yoffset, x, y, width, |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 2032 | height, dest_size.width(), dest_size.height(), source_size.width(), |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 2033 | source_size.height(), unpack_flip_y, unpack_premultiply_alpha, |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2034 | false /* unpack_unmultiply_alpha */, false /* dither */, |
| 2035 | transform_matrix, copy_tex_image_blit_.get()); |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 2036 | dest_texture->SetLevelClearedRect(dest_target, dest_level, |
| 2037 | new_cleared_rect); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2038 | return; |
| 2039 | } |
| 2040 | } |
| 2041 | |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 2042 | gles2::CopyTextureMethod method = GetCopyTextureCHROMIUMMethod( |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2043 | GetFeatureInfo(), source_target, source_level, source_internal_format, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 2044 | source_type, dest_target, dest_level, dest_internal_format, unpack_flip_y, |
| 2045 | unpack_premultiply_alpha, false /* unpack_unmultiply_alpha */, |
| 2046 | false /* dither */); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2047 | #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 2048 | // glDrawArrays is faster than glCopyTexSubImage2D on IA Mesa driver, |
| 2049 | // although opposite in Android. |
| 2050 | // TODO(dshwang): After Mesa fixes this issue, remove this hack. |
| 2051 | // https://bugs.freedesktop.org/show_bug.cgi?id=98478, |
| 2052 | // https://crbug.com/535198. |
Daniel Bratell | aabc8d68e | 2018-07-18 19:20:26 | [diff] [blame] | 2053 | if (gles2::Texture::ColorRenderable(GetFeatureInfo(), dest_internal_format, |
| 2054 | dest_texture->IsImmutable()) && |
| 2055 | method == gles2::CopyTextureMethod::DIRECT_COPY) { |
| 2056 | method = gles2::CopyTextureMethod::DIRECT_DRAW; |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2057 | } |
| 2058 | #endif |
| 2059 | |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 2060 | in_copy_sub_texture_ = true; |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2061 | copy_texture_chromium_->DoCopySubTexture( |
| 2062 | this, source_target, source_texture->service_id(), source_level, |
| 2063 | source_internal_format, dest_target, dest_texture->service_id(), |
| 2064 | dest_level, dest_internal_format, xoffset, yoffset, x, y, width, height, |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 2065 | dest_size.width(), dest_size.height(), source_size.width(), |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 2066 | source_size.height(), unpack_flip_y, unpack_premultiply_alpha, |
| 2067 | false /* unpack_unmultiply_alpha */, false /* dither */, method, |
| 2068 | copy_tex_image_blit_.get()); |
Antoine Labour | b9f903b | 2019-02-04 18:06:57 | [diff] [blame] | 2069 | dest_texture->SetLevelClearedRect(dest_target, dest_level, new_cleared_rect); |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 2070 | in_copy_sub_texture_ = false; |
| 2071 | if (reset_texture_state_) { |
| 2072 | reset_texture_state_ = false; |
| 2073 | for (auto* texture : {source_texture, dest_texture}) { |
| 2074 | GLenum target = texture->target(); |
| 2075 | api()->glBindTextureFn(target, texture->service_id()); |
| 2076 | api()->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, texture->wrap_s()); |
| 2077 | api()->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, texture->wrap_t()); |
| 2078 | api()->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, |
| 2079 | texture->min_filter()); |
| 2080 | api()->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, |
| 2081 | texture->mag_filter()); |
| 2082 | } |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 2083 | shared_context_state_->PessimisticallyResetGrContext(); |
Antoine Labour | 9ddf6ac | 2019-01-17 01:59:39 | [diff] [blame] | 2084 | } |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2085 | } |
| 2086 | |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2087 | void RasterDecoderImpl::DoCopySubTextureINTERNALSkia( |
| 2088 | GLint xoffset, |
| 2089 | GLint yoffset, |
| 2090 | GLint x, |
| 2091 | GLint y, |
| 2092 | GLsizei width, |
| 2093 | GLsizei height, |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 2094 | GLboolean unpack_flip_y, |
| 2095 | GLboolean unpack_premultiply_alpha, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2096 | const Mailbox& source_mailbox, |
| 2097 | const Mailbox& dest_mailbox) { |
| 2098 | DCHECK(source_mailbox != dest_mailbox); |
| 2099 | |
| 2100 | // Use Skia to copy texture if raster's gr_context() is not using GL. |
| 2101 | auto source_shared_image = shared_image_representation_factory_.ProduceSkia( |
| 2102 | source_mailbox, shared_context_state_); |
| 2103 | auto dest_shared_image = shared_image_representation_factory_.ProduceSkia( |
| 2104 | dest_mailbox, shared_context_state_); |
| 2105 | if (!source_shared_image || !dest_shared_image) { |
| 2106 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", "unknown mailbox"); |
| 2107 | return; |
| 2108 | } |
| 2109 | |
| 2110 | gfx::Size source_size = source_shared_image->size(); |
| 2111 | gfx::Rect source_rect(x, y, width, height); |
| 2112 | if (!gfx::Rect(source_size).Contains(source_rect)) { |
| 2113 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 2114 | "source texture bad dimensions."); |
| 2115 | return; |
| 2116 | } |
| 2117 | |
| 2118 | gfx::Size dest_size = dest_shared_image->size(); |
| 2119 | gfx::Rect dest_rect(xoffset, yoffset, width, height); |
| 2120 | if (!gfx::Rect(dest_size).Contains(dest_rect)) { |
| 2121 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 2122 | "destination texture bad dimensions."); |
| 2123 | return; |
| 2124 | } |
| 2125 | |
| 2126 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2127 | std::vector<GrBackendSemaphore> end_semaphores; |
| 2128 | |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 2129 | // Allow uncleared access, as we manually handle clear tracking. |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2130 | std::unique_ptr<SharedImageRepresentationSkia::ScopedWriteAccess> |
| 2131 | dest_scoped_access = dest_shared_image->BeginScopedWriteAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 2132 | &begin_semaphores, &end_semaphores, |
| 2133 | SharedImageRepresentation::AllowUnclearedAccess::kYes); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2134 | if (!dest_scoped_access) { |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2135 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 2136 | "Dest shared image is not writable"); |
| 2137 | return; |
| 2138 | } |
| 2139 | |
Eric Karl | b25e1b6 | 2019-12-17 23:07:49 | [diff] [blame] | 2140 | gfx::Rect new_cleared_rect; |
| 2141 | gfx::Rect old_cleared_rect = dest_shared_image->ClearedRect(); |
| 2142 | if (gles2::TextureManager::CombineAdjacentRects(old_cleared_rect, dest_rect, |
| 2143 | &new_cleared_rect)) { |
| 2144 | DCHECK(old_cleared_rect.IsEmpty() || |
| 2145 | new_cleared_rect.Contains(old_cleared_rect)); |
| 2146 | } else { |
| 2147 | // No users of RasterDecoder leverage this functionality. Clearing uncleared |
| 2148 | // regions could be added here if needed. |
| 2149 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 2150 | "Cannot clear non-combineable rects."); |
| 2151 | return; |
| 2152 | } |
| 2153 | |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2154 | // With OneCopyRasterBufferProvider, source_shared_image->BeginReadAccess() |
| 2155 | // will copy pixels from SHM GMB to the texture in |source_shared_image|, |
| 2156 | // and then use drawImageRect() to draw that texure to the target |
| 2157 | // |dest_shared_image|. We can save one copy by drawing the SHM GMB to the |
| 2158 | // target |dest_shared_image| directly. |
| 2159 | // TODO(penghuang): get rid of the one extra copy. https://crbug.com/984045 |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2160 | std::unique_ptr<SharedImageRepresentationSkia::ScopedReadAccess> |
| 2161 | source_scoped_access = source_shared_image->BeginScopedReadAccess( |
| 2162 | &begin_semaphores, &end_semaphores); |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2163 | |
| 2164 | if (!begin_semaphores.empty()) { |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2165 | bool result = dest_scoped_access->surface()->wait(begin_semaphores.size(), |
| 2166 | begin_semaphores.data()); |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2167 | DCHECK(result); |
| 2168 | } |
| 2169 | |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2170 | if (!source_scoped_access) { |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2171 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTexture", |
| 2172 | "Source shared image is not accessable"); |
| 2173 | } else { |
| 2174 | auto color_type = viz::ResourceFormatToClosestSkColorType( |
| 2175 | true /* gpu_compositing */, source_shared_image->format()); |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 2176 | |
| 2177 | // TODO(http://crbug.com/1034086): We should initialize alpha_type and |
| 2178 | // origin using metadata stored with the shared image. |
| 2179 | SkAlphaType alpha_type = kPremul_SkAlphaType; |
| 2180 | if (unpack_premultiply_alpha) |
| 2181 | alpha_type = kUnpremul_SkAlphaType; |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2182 | auto source_image = SkImage::MakeFromTexture( |
| 2183 | shared_context_state_->gr_context(), |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2184 | source_scoped_access->promise_image_texture()->backendTexture(), |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 2185 | kTopLeft_GrSurfaceOrigin, color_type, alpha_type, |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2186 | nullptr /* colorSpace */); |
| 2187 | |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2188 | auto* canvas = dest_scoped_access->surface()->getCanvas(); |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2189 | SkPaint paint; |
Nathan Zabriskie | f1095d7b | 2019-12-21 00:33:57 | [diff] [blame] | 2190 | if (unpack_flip_y) { |
| 2191 | canvas->scale(1, -1); |
| 2192 | canvas->translate(0, -height); |
| 2193 | } |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2194 | paint.setBlendMode(SkBlendMode::kSrc); |
| 2195 | canvas->drawImageRect(source_image, gfx::RectToSkRect(source_rect), |
| 2196 | gfx::RectToSkRect(dest_rect), &paint); |
| 2197 | } |
| 2198 | |
| 2199 | // Always flush the surface even if source_scoped_access.success() is false, |
| 2200 | // so the begin_semaphores can be released, and end_semaphores can be |
| 2201 | // signalled. |
| 2202 | GrFlushInfo flush_info = { |
| 2203 | .fFlags = kNone_GrFlushFlags, |
| 2204 | .fNumSemaphores = end_semaphores.size(), |
| 2205 | .fSignalSemaphores = end_semaphores.data(), |
| 2206 | }; |
| 2207 | gpu::AddVulkanCleanupTaskForSkiaFlush( |
| 2208 | shared_context_state_->vk_context_provider(), &flush_info); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2209 | dest_scoped_access->surface()->flush( |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2210 | SkSurface::BackendSurfaceAccess::kNoAccess, flush_info); |
Eric Karl | b25e1b6 | 2019-12-17 23:07:49 | [diff] [blame] | 2211 | |
| 2212 | if (!dest_shared_image->IsCleared()) { |
| 2213 | dest_shared_image->SetClearedRect(new_cleared_rect); |
| 2214 | } |
Peng Huang | a8b0e42 | 2019-07-16 17:48:57 | [diff] [blame] | 2215 | } |
| 2216 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2217 | namespace { |
| 2218 | |
| 2219 | // Helper to read client data from transfer cache. |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2220 | class TransferCacheDeserializeHelperImpl final |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2221 | : public cc::TransferCacheDeserializeHelper { |
| 2222 | public: |
| 2223 | explicit TransferCacheDeserializeHelperImpl( |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2224 | int raster_decoder_id, |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2225 | ServiceTransferCache* transfer_cache) |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2226 | : raster_decoder_id_(raster_decoder_id), transfer_cache_(transfer_cache) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2227 | DCHECK(transfer_cache_); |
| 2228 | } |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2229 | ~TransferCacheDeserializeHelperImpl() override = default; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2230 | |
Adrienne Walker | 90b79a2 | 2018-05-08 21:40:42 | [diff] [blame] | 2231 | void CreateLocalEntry( |
| 2232 | uint32_t id, |
| 2233 | std::unique_ptr<cc::ServiceTransferCacheEntry> entry) override { |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2234 | auto type = entry->Type(); |
| 2235 | transfer_cache_->CreateLocalEntry( |
| 2236 | ServiceTransferCache::EntryKey(raster_decoder_id_, type, id), |
| 2237 | std::move(entry)); |
Adrienne Walker | 90b79a2 | 2018-05-08 21:40:42 | [diff] [blame] | 2238 | } |
| 2239 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2240 | private: |
| 2241 | cc::ServiceTransferCacheEntry* GetEntryInternal( |
| 2242 | cc::TransferCacheEntryType entry_type, |
Jonathan Backer | 4f9ee5fb | 2018-04-25 14:03:38 | [diff] [blame] | 2243 | uint32_t entry_id) override { |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2244 | return transfer_cache_->GetEntry(ServiceTransferCache::EntryKey( |
| 2245 | raster_decoder_id_, entry_type, entry_id)); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2246 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2247 | |
| 2248 | const int raster_decoder_id_; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2249 | ServiceTransferCache* const transfer_cache_; |
| 2250 | |
| 2251 | DISALLOW_COPY_AND_ASSIGN(TransferCacheDeserializeHelperImpl); |
| 2252 | }; |
| 2253 | |
| 2254 | } // namespace |
| 2255 | |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2256 | void RasterDecoderImpl::DeletePaintCacheTextBlobsINTERNALHelper( |
| 2257 | GLsizei n, |
| 2258 | const volatile GLuint* paint_cache_ids) { |
| 2259 | if (!supports_oop_raster_) { |
| 2260 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 2261 | "glDeletePaintCacheEntriesINTERNAL", |
| 2262 | "No chromium raster support"); |
| 2263 | return; |
| 2264 | } |
| 2265 | |
Khushal | cb653fb | 2018-11-15 08:56:28 | [diff] [blame] | 2266 | paint_cache_->Purge(cc::PaintCacheDataType::kTextBlob, n, paint_cache_ids); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | void RasterDecoderImpl::DeletePaintCachePathsINTERNALHelper( |
| 2270 | GLsizei n, |
| 2271 | const volatile GLuint* paint_cache_ids) { |
| 2272 | if (!supports_oop_raster_) { |
| 2273 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 2274 | "glDeletePaintCacheEntriesINTERNAL", |
| 2275 | "No chromium raster support"); |
| 2276 | return; |
| 2277 | } |
| 2278 | |
Khushal | cb653fb | 2018-11-15 08:56:28 | [diff] [blame] | 2279 | paint_cache_->Purge(cc::PaintCacheDataType::kPath, n, paint_cache_ids); |
Khushal | 33205a7 | 2018-11-08 10:12:29 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | void RasterDecoderImpl::DoClearPaintCacheINTERNAL() { |
| 2283 | if (!supports_oop_raster_) { |
| 2284 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glClearPaintCacheINTERNAL", |
| 2285 | "No chromium raster support"); |
| 2286 | return; |
| 2287 | } |
| 2288 | |
| 2289 | paint_cache_->PurgeAll(); |
| 2290 | } |
| 2291 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2292 | void RasterDecoderImpl::DoBeginRasterCHROMIUM( |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2293 | GLuint sk_color, |
| 2294 | GLuint msaa_sample_count, |
| 2295 | GLboolean can_use_lcd_text, |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 2296 | const volatile GLbyte* key) { |
Christopher Cameron | beb5f27 | 2019-02-04 22:49:13 | [diff] [blame] | 2297 | // Workaround for https://crbug.com/906453: Flush before BeginRaster (the |
| 2298 | // commands between BeginRaster and EndRaster will not flush). |
| 2299 | FlushToWorkAroundMacCrashes(); |
| 2300 | |
Adrienne Walker | 2e2270c | 2019-07-22 20:44:10 | [diff] [blame] | 2301 | if (!gr_context() || !supports_oop_raster_) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2302 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2303 | "chromium_raster_transport not enabled via attribs"); |
| 2304 | return; |
| 2305 | } |
| 2306 | if (sk_surface_) { |
| 2307 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2308 | "BeginRasterCHROMIUM without EndRasterCHROMIUM"); |
| 2309 | return; |
| 2310 | } |
| 2311 | |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 2312 | Mailbox mailbox = |
| 2313 | Mailbox::FromVolatile(*reinterpret_cast<const volatile Mailbox*>(key)); |
| 2314 | DLOG_IF(ERROR, !mailbox.Verify()) << "BeginRasterCHROMIUM was " |
| 2315 | "passed a mailbox that was not " |
| 2316 | "generated by ProduceTextureCHROMIUM."; |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2317 | |
| 2318 | DCHECK(!shared_image_); |
Chris Blume | ff2de642 | 2019-04-02 01:48:49 | [diff] [blame] | 2319 | shared_image_ = shared_image_representation_factory_.ProduceSkia( |
| 2320 | mailbox, shared_context_state_.get()); |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2321 | if (!shared_image_) { |
Jonathan Backer | 7e749252 | 2018-07-20 00:23:55 | [diff] [blame] | 2322 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glBeginRasterCHROMIUM", |
| 2323 | "passed invalid mailbox."); |
| 2324 | return; |
| 2325 | } |
| 2326 | |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 2327 | DCHECK(locked_handles_.empty()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2328 | DCHECK(!raster_canvas_); |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 2329 | shared_context_state_->set_need_context_state_reset(true); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2330 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2331 | // Use unknown pixel geometry to disable LCD text. |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 2332 | uint32_t flags = 0; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2333 | SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 2334 | if (can_use_lcd_text) { |
| 2335 | // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 2336 | surface_props = |
| 2337 | SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 2338 | } |
| 2339 | |
Jonathan Backer | d95c803 | 2018-12-13 16:51:29 | [diff] [blame] | 2340 | SkColorType sk_color_type = viz::ResourceFormatToClosestSkColorType( |
| 2341 | /*gpu_compositing=*/true, shared_image_->format()); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2342 | // If we can't match requested MSAA samples, don't use MSAA. |
| 2343 | int final_msaa_count = std::max(static_cast<int>(msaa_sample_count), 0); |
| 2344 | if (final_msaa_count > |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 2345 | gr_context()->maxSurfaceSampleCountForColorType(sk_color_type)) |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2346 | final_msaa_count = 0; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2347 | |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2348 | std::vector<GrBackendSemaphore> begin_semaphores; |
| 2349 | DCHECK(end_semaphores_.empty()); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2350 | DCHECK(!scoped_shared_image_write_); |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 2351 | // Allow uncleared access, as raster specifically handles uncleared images by |
| 2352 | // clearing them before writing. |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2353 | scoped_shared_image_write_ = shared_image_->BeginScopedWriteAccess( |
Eric Karl | 14bfb99 | 2020-01-03 01:32:21 | [diff] [blame] | 2354 | final_msaa_count, surface_props, &begin_semaphores, &end_semaphores_, |
| 2355 | SharedImageRepresentation::AllowUnclearedAccess::kYes); |
Eric Karl | 707c1b9 | 2019-12-10 06:50:08 | [diff] [blame] | 2356 | if (!scoped_shared_image_write_) { |
| 2357 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginRasterCHROMIUM", |
| 2358 | "failed to create surface"); |
| 2359 | shared_image_.reset(); |
| 2360 | return; |
| 2361 | } |
| 2362 | |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2363 | sk_surface_ = scoped_shared_image_write_->surface(); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2364 | |
| 2365 | if (!begin_semaphores.empty()) { |
| 2366 | bool result = |
| 2367 | sk_surface_->wait(begin_semaphores.size(), begin_semaphores.data()); |
| 2368 | DCHECK(result); |
| 2369 | } |
| 2370 | |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2371 | if (use_ddl_) { |
| 2372 | SkSurfaceCharacterization characterization; |
| 2373 | bool result = sk_surface_->characterize(&characterization); |
| 2374 | DCHECK(result) << "Failed to characterize raster SkSurface."; |
| 2375 | recorder_ = |
| 2376 | std::make_unique<SkDeferredDisplayListRecorder>(characterization); |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 2377 | raster_canvas_ = recorder_->getCanvas(); |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2378 | } else { |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 2379 | raster_canvas_ = sk_surface_->getCanvas(); |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2380 | } |
| 2381 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2382 | // All or nothing clearing, as no way to validate the client's input on what |
| 2383 | // is the "used" part of the texture. |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2384 | // TODO(enne): This doesn't handle the case where the background color |
| 2385 | // changes and so any extra pixels outside the raster area that get |
| 2386 | // sampled may be incorrect. |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2387 | if (shared_image_->IsCleared()) |
| 2388 | return; |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 2389 | |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2390 | raster_canvas_->drawColor(sk_color); |
| 2391 | shared_image_->SetCleared(); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2392 | } |
| 2393 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2394 | scoped_refptr<Buffer> RasterDecoderImpl::GetShmBuffer(uint32_t shm_id) { |
| 2395 | return GetSharedMemoryBuffer(shm_id); |
| 2396 | } |
| 2397 | |
Khushal | 39641b9 | 2019-06-03 21:32:54 | [diff] [blame] | 2398 | void RasterDecoderImpl::ReportProgress() { |
| 2399 | if (shared_context_state_->progress_reporter()) |
| 2400 | shared_context_state_->progress_reporter()->ReportProgress(); |
| 2401 | } |
| 2402 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2403 | void RasterDecoderImpl::DoRasterCHROMIUM(GLuint raster_shm_id, |
| 2404 | GLuint raster_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 2405 | GLuint raster_shm_size, |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2406 | GLuint font_shm_id, |
| 2407 | GLuint font_shm_offset, |
Antoine Labour | 423fe59 | 2019-01-10 22:13:09 | [diff] [blame] | 2408 | GLuint font_shm_size) { |
Khushal | f975070 | 2018-06-09 00:42:13 | [diff] [blame] | 2409 | TRACE_EVENT1("gpu", "RasterDecoderImpl::DoRasterCHROMIUM", "raster_id", |
| 2410 | ++raster_chromium_id_); |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2411 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2412 | if (!sk_surface_) { |
| 2413 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 2414 | "RasterCHROMIUM without BeginRasterCHROMIUM"); |
| 2415 | return; |
| 2416 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2417 | DCHECK(transfer_cache()); |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 2418 | shared_context_state_->set_need_context_state_reset(true); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2419 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2420 | if (font_shm_size > 0) { |
| 2421 | // Deserialize fonts before raster. |
| 2422 | volatile char* font_buffer_memory = |
| 2423 | GetSharedMemoryAs<char*>(font_shm_id, font_shm_offset, font_shm_size); |
| 2424 | if (!font_buffer_memory) { |
| 2425 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 2426 | "Can not read font buffer."); |
| 2427 | return; |
| 2428 | } |
| 2429 | |
Khushal | db6ea3c | 2018-05-31 00:53:09 | [diff] [blame] | 2430 | std::vector<SkDiscardableHandleId> new_locked_handles; |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 2431 | if (!font_manager_->Deserialize(font_buffer_memory, font_shm_size, |
| 2432 | &new_locked_handles)) { |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2433 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 2434 | "Invalid font buffer."); |
| 2435 | return; |
| 2436 | } |
Khushal | db6ea3c | 2018-05-31 00:53:09 | [diff] [blame] | 2437 | locked_handles_.insert(locked_handles_.end(), new_locked_handles.begin(), |
| 2438 | new_locked_handles.end()); |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | char* paint_buffer_memory = GetSharedMemoryAs<char*>( |
| 2442 | raster_shm_id, raster_shm_offset, raster_shm_size); |
| 2443 | if (!paint_buffer_memory) { |
| 2444 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 2445 | "Can not read paint buffer."); |
| 2446 | return; |
| 2447 | } |
| 2448 | |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2449 | alignas( |
| 2450 | cc::PaintOpBuffer::PaintOpAlign) char data[sizeof(cc::LargestPaintOp)]; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2451 | |
Khushal | 48cbd2a1 | 2018-09-18 20:02:51 | [diff] [blame] | 2452 | cc::PlaybackParams playback_params(nullptr, SkMatrix::I()); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2453 | TransferCacheDeserializeHelperImpl impl(raster_decoder_id_, transfer_cache()); |
Adrienne Walker | 5a4952e | 2019-01-07 21:16:29 | [diff] [blame] | 2454 | cc::PaintOp::DeserializeOptions options( |
| 2455 | &impl, paint_cache_.get(), font_manager_->strike_client(), |
Malay Keshav | a154dcb | 2020-01-18 00:17:55 | [diff] [blame^] | 2456 | shared_context_state_->scratch_deserialization_buffer(), is_privileged_); |
Adrienne Walker | e62484a | 2018-11-27 18:41:30 | [diff] [blame] | 2457 | options.crash_dump_on_failure = true; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2458 | |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2459 | size_t paint_buffer_size = raster_shm_size; |
Adrienne Walker | d8a5646 | 2019-03-16 03:11:47 | [diff] [blame] | 2460 | gl::ScopedProgressReporter report_progress( |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2461 | shared_context_state_->progress_reporter()); |
Khushal | a415686 | 2018-06-08 22:46:02 | [diff] [blame] | 2462 | while (paint_buffer_size > 0) { |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2463 | size_t skip = 0; |
| 2464 | cc::PaintOp* deserialized_op = cc::PaintOp::Deserialize( |
Khushal | a8d5064 | 2018-05-03 01:29:06 | [diff] [blame] | 2465 | paint_buffer_memory, paint_buffer_size, &data[0], |
| 2466 | sizeof(cc::LargestPaintOp), &skip, options); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2467 | if (!deserialized_op) { |
Adrienne Walker | e62484a | 2018-11-27 18:41:30 | [diff] [blame] | 2468 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glRasterCHROMIUM", |
| 2469 | "RasterCHROMIUM: serialization failure"); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2470 | return; |
| 2471 | } |
| 2472 | |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 2473 | deserialized_op->Raster(raster_canvas_, playback_params); |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 2474 | deserialized_op->DestroyThis(); |
| 2475 | |
Christopher Cameron | d5698f68 | 2018-12-11 00:59:20 | [diff] [blame] | 2476 | paint_buffer_size -= skip; |
| 2477 | paint_buffer_memory += skip; |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2478 | } |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | void RasterDecoderImpl::DoEndRasterCHROMIUM() { |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2482 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM"); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2483 | if (!sk_surface_) { |
Jonathan Backer | a1f3d7c | 2018-10-16 14:46:32 | [diff] [blame] | 2484 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glEndRasterCHROMIUM", |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2485 | "EndRasterCHROMIUM without BeginRasterCHROMIUM"); |
| 2486 | return; |
| 2487 | } |
| 2488 | |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 2489 | shared_context_state_->set_need_context_state_reset(true); |
Jonathan Backer | 4fb9f5acb | 2018-05-10 22:19:33 | [diff] [blame] | 2490 | |
Mike Reed | 421f75d | 2019-02-25 20:30:03 | [diff] [blame] | 2491 | raster_canvas_ = nullptr; |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2492 | |
| 2493 | if (use_ddl_) { |
Peng Huang | d960843 | 2019-07-29 15:56:36 | [diff] [blame] | 2494 | TRACE_EVENT0("gpu", |
| 2495 | "RasterDecoderImpl::DoEndRasterCHROMIUM::DetachAndDrawDDL"); |
Peng Huang | 050dee5 | 2018-09-05 15:54:08 | [diff] [blame] | 2496 | auto ddl = recorder_->detach(); |
| 2497 | recorder_ = nullptr; |
| 2498 | sk_surface_->draw(ddl.get()); |
| 2499 | } |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2500 | |
| 2501 | { |
Peng Huang | d960843 | 2019-07-29 15:56:36 | [diff] [blame] | 2502 | TRACE_EVENT0("gpu", "RasterDecoderImpl::DoEndRasterCHROMIUM::Flush"); |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2503 | // This is a slow operation since skia will execute the GPU work for the |
| 2504 | // complete tile. Make sure the progress reporter is notified to avoid |
| 2505 | // hangs. |
Adrienne Walker | d8a5646 | 2019-03-16 03:11:47 | [diff] [blame] | 2506 | gl::ScopedProgressReporter report_progress( |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2507 | shared_context_state_->progress_reporter()); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2508 | GrFlushInfo flush_info = { |
| 2509 | .fFlags = kNone_GrFlushFlags, |
| 2510 | .fNumSemaphores = end_semaphores_.size(), |
| 2511 | .fSignalSemaphores = end_semaphores_.data(), |
| 2512 | }; |
Sergey Ulanov | c528c0d | 2019-05-08 21:06:06 | [diff] [blame] | 2513 | AddVulkanCleanupTaskForSkiaFlush( |
Eric Karl | 32d9d2e | 2019-05-03 17:09:47 | [diff] [blame] | 2514 | shared_context_state_->vk_context_provider(), &flush_info); |
Peng Huang | 72545ea | 2019-07-24 20:42:36 | [diff] [blame] | 2515 | auto result = sk_surface_->flush(SkSurface::BackendSurfaceAccess::kPresent, |
| 2516 | flush_info); |
| 2517 | DCHECK(result == GrSemaphoresSubmitted::kYes || end_semaphores_.empty()); |
Peng Huang | 5f9118b0 | 2019-04-24 20:18:21 | [diff] [blame] | 2518 | end_semaphores_.clear(); |
Khushal | 61977dfc | 2019-02-22 02:24:29 | [diff] [blame] | 2519 | } |
| 2520 | |
Kramer Ge | ddcac353 | 2019-12-12 23:33:10 | [diff] [blame] | 2521 | shared_context_state_->UpdateSkiaOwnedMemorySize(); |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2522 | sk_surface_ = nullptr; |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2523 | if (!shared_image_) { |
| 2524 | // Test only path for SetUpForRasterCHROMIUMForTest. |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2525 | sk_surface_for_testing_.reset(); |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2526 | } else { |
Peng Huang | e9b41cd | 2019-08-12 19:39:47 | [diff] [blame] | 2527 | scoped_shared_image_write_.reset(); |
Eric Karl | 3750cfa | 2018-10-25 16:54:17 | [diff] [blame] | 2528 | shared_image_.reset(); |
| 2529 | } |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 2530 | |
| 2531 | // Unlock all font handles. This needs to be deferred until |
Greg Daniel | 18362e9d | 2019-04-15 19:54:50 | [diff] [blame] | 2532 | // SkSurface::flush since that flushes batched Gr operations |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 2533 | // in skia that access the glyph data. |
| 2534 | // TODO(khushalsagar): We just unlocked a bunch of handles, do we need to |
| 2535 | // give a call to skia to attempt to purge any unlocked handles? |
Khushal | 3d0b890 | 2018-09-18 03:03:34 | [diff] [blame] | 2536 | if (!font_manager_->Unlock(locked_handles_)) { |
Khushal | 22204a4 | 2018-05-17 23:06:21 | [diff] [blame] | 2537 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glRasterCHROMIUM", |
| 2538 | "Invalid font discardable handle."); |
| 2539 | } |
| 2540 | locked_handles_.clear(); |
Khushal | 15b6abb | 2018-06-28 00:16:25 | [diff] [blame] | 2541 | |
| 2542 | // 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] | 2543 | // flush above. Yield to the Scheduler to allow pre-emption before |
| 2544 | // processing more commands. |
| 2545 | ExitCommandProcessingEarly(); |
Jonathan Backer | e19973e8 | 2018-04-18 20:08:09 | [diff] [blame] | 2546 | } |
| 2547 | |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2548 | void RasterDecoderImpl::DoCreateTransferCacheEntryINTERNAL( |
| 2549 | GLuint raw_entry_type, |
| 2550 | GLuint entry_id, |
| 2551 | GLuint handle_shm_id, |
| 2552 | GLuint handle_shm_offset, |
| 2553 | GLuint data_shm_id, |
| 2554 | GLuint data_shm_offset, |
| 2555 | GLuint data_size) { |
| 2556 | if (!supports_oop_raster_) { |
| 2557 | LOCAL_SET_GL_ERROR( |
| 2558 | GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 2559 | "Attempt to use OOP transfer cache on a context without OOP raster."); |
| 2560 | return; |
| 2561 | } |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 2562 | DCHECK(gr_context()); |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2563 | DCHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2564 | |
| 2565 | // Validate the type we are about to create. |
| 2566 | cc::TransferCacheEntryType entry_type; |
| 2567 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 2568 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 2569 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 2570 | "Attempt to use OOP transfer cache with an invalid " |
| 2571 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2572 | return; |
| 2573 | } |
| 2574 | |
| 2575 | uint8_t* data_memory = |
| 2576 | GetSharedMemoryAs<uint8_t*>(data_shm_id, data_shm_offset, data_size); |
| 2577 | if (!data_memory) { |
| 2578 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 2579 | "Can not read transfer cache entry data."); |
| 2580 | return; |
| 2581 | } |
| 2582 | |
| 2583 | scoped_refptr<Buffer> handle_buffer = GetSharedMemoryBuffer(handle_shm_id); |
| 2584 | if (!DiscardableHandleBase::ValidateParameters(handle_buffer.get(), |
| 2585 | handle_shm_offset)) { |
| 2586 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 2587 | "Invalid shm for discardable handle."); |
| 2588 | return; |
| 2589 | } |
| 2590 | ServiceDiscardableHandle handle(std::move(handle_buffer), handle_shm_offset, |
| 2591 | handle_shm_id); |
| 2592 | |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 2593 | // If the entry is going to use skia during deserialization, make sure we |
| 2594 | // mark the context state dirty. |
Khushal | 6a090ff | 2018-11-17 04:12:23 | [diff] [blame] | 2595 | GrContext* context_for_entry = |
| 2596 | cc::ServiceTransferCacheEntry::UsesGrContext(entry_type) ? gr_context() |
| 2597 | : nullptr; |
| 2598 | if (context_for_entry) |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 2599 | shared_context_state_->set_need_context_state_reset(true); |
Khushal | 6a090ff | 2018-11-17 04:12:23 | [diff] [blame] | 2600 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2601 | if (!transfer_cache()->CreateLockedEntry( |
| 2602 | ServiceTransferCache::EntryKey(raster_decoder_id_, entry_type, |
| 2603 | entry_id), |
Khushal | 6a090ff | 2018-11-17 04:12:23 | [diff] [blame] | 2604 | handle, context_for_entry, base::make_span(data_memory, data_size))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2605 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCreateTransferCacheEntryINTERNAL", |
| 2606 | "Failure to deserialize transfer cache entry."); |
| 2607 | return; |
| 2608 | } |
Khushal Sagar | b3f5329 | 2019-06-05 04:24:23 | [diff] [blame] | 2609 | |
| 2610 | // The only entry using the GrContext are image transfer cache entries for |
| 2611 | // image uploads. Since this tends to a slow operation, yield to allow the |
| 2612 | // decoder to be pre-empted. |
| 2613 | if (context_for_entry) |
| 2614 | ExitCommandProcessingEarly(); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | void RasterDecoderImpl::DoUnlockTransferCacheEntryINTERNAL( |
| 2618 | GLuint raw_entry_type, |
| 2619 | GLuint entry_id) { |
| 2620 | if (!supports_oop_raster_) { |
| 2621 | LOCAL_SET_GL_ERROR( |
| 2622 | GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 2623 | "Attempt to use OOP transfer cache on a context without OOP raster."); |
| 2624 | return; |
| 2625 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2626 | DCHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2627 | cc::TransferCacheEntryType entry_type; |
| 2628 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 2629 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 2630 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 2631 | "Attempt to use OOP transfer cache with an invalid " |
| 2632 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2633 | return; |
| 2634 | } |
| 2635 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2636 | if (!transfer_cache()->UnlockEntry(ServiceTransferCache::EntryKey( |
| 2637 | raster_decoder_id_, entry_type, entry_id))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2638 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glUnlockTransferCacheEntryINTERNAL", |
| 2639 | "Attempt to unlock an invalid ID"); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | void RasterDecoderImpl::DoDeleteTransferCacheEntryINTERNAL( |
| 2644 | GLuint raw_entry_type, |
| 2645 | GLuint entry_id) { |
| 2646 | if (!supports_oop_raster_) { |
| 2647 | LOCAL_SET_GL_ERROR( |
| 2648 | GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 2649 | "Attempt to use OOP transfer cache on a context without OOP raster."); |
| 2650 | return; |
| 2651 | } |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2652 | DCHECK(transfer_cache()); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2653 | cc::TransferCacheEntryType entry_type; |
| 2654 | if (!cc::ServiceTransferCacheEntry::SafeConvertToType(raw_entry_type, |
| 2655 | &entry_type)) { |
Peng Huang | c6a7607 | 2018-11-27 23:17:31 | [diff] [blame] | 2656 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 2657 | "Attempt to use OOP transfer cache with an invalid " |
| 2658 | "cache entry type."); |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2659 | return; |
| 2660 | } |
| 2661 | |
Khushal | 996e991 | 2018-07-13 08:31:00 | [diff] [blame] | 2662 | if (!transfer_cache()->DeleteEntry(ServiceTransferCache::EntryKey( |
| 2663 | raster_decoder_id_, entry_type, entry_id))) { |
Jonathan Backer | 0cd1c432 | 2018-04-17 16:57:10 | [diff] [blame] | 2664 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteTransferCacheEntryINTERNAL", |
| 2665 | "Attempt to delete an invalid ID"); |
| 2666 | } |
| 2667 | } |
| 2668 | |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2669 | void RasterDecoderImpl::RestoreStateForAttrib(GLuint attrib_index, |
| 2670 | bool restore_array_binding) { |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 2671 | shared_context_state_->PessimisticallyResetGrContext(); |
Jonathan Backer | 10821a8 | 2018-04-04 23:56:03 | [diff] [blame] | 2672 | } |
| 2673 | |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 2674 | // Include the auto-generated part of this file. We split this because it means |
| 2675 | // we can easily edit the non-auto generated parts right here in this file |
| 2676 | // instead of having to edit some template or the code generator. |
| 2677 | #include "base/macros.h" |
Jonathan Backer | a4568da1 | 2018-01-31 16:25:04 | [diff] [blame] | 2678 | #include "gpu/command_buffer/service/raster_decoder_autogen.h" |
Jonathan Backer | 7471b278 | 2018-01-25 18:14:19 | [diff] [blame] | 2679 | |
Jonathan Backer | 7f90dfb66 | 2017-12-18 16:52:04 | [diff] [blame] | 2680 | } // namespace raster |
| 2681 | } // namespace gpu |