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 #ifndef GPU_COMMAND_BUFFER_CLIENT_RASTER_IMPLEMENTATION_GLES_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_RASTER_IMPLEMENTATION_GLES_H_ 7 8 #include <unordered_map> 9 10 #include "base/containers/flat_map.h" 11 #include "base/macros.h" 12 #include "base/optional.h" 13 #include "gpu/command_buffer/client/client_font_manager.h" 14 #include "gpu/command_buffer/client/gles2_interface.h" 15 #include "gpu/command_buffer/client/raster_interface.h" 16 #include "gpu/command_buffer/common/capabilities.h" 17 #include "gpu/raster_export.h" 18 #include "third_party/skia/include/core/SkColorSpace.h" 19 20 namespace gpu { 21 22 class ContextSupport; 23 class GLHelper; 24 25 namespace raster { 26 27 // An implementation of RasterInterface on top of GLES2Interface. 28 class RASTER_EXPORT RasterImplementationGLES : public RasterInterface { 29 public: 30 explicit RasterImplementationGLES(gles2::GLES2Interface* gl, 31 ContextSupport* context_support); 32 ~RasterImplementationGLES() override; 33 34 // Command buffer Flush / Finish. 35 void Finish() override; 36 void Flush() override; 37 void ShallowFlushCHROMIUM() override; 38 void OrderingBarrierCHROMIUM() override; 39 40 // Command buffer state. 41 GLenum GetError() override; 42 GLenum GetGraphicsResetStatusKHR() override; 43 void LoseContextCHROMIUM(GLenum current, GLenum other) override; 44 45 // Queries: 46 // - GL_COMMANDS_ISSUED_CHROMIUM 47 // - GL_COMMANDS_ISSUED_TIMESTAMP_CHROMIUM 48 // - GL_COMMANDS_COMPLETED_CHROMIUM 49 void GenQueriesEXT(GLsizei n, GLuint* queries) override; 50 void DeleteQueriesEXT(GLsizei n, const GLuint* queries) override; 51 void BeginQueryEXT(GLenum target, GLuint id) override; 52 void EndQueryEXT(GLenum target) override; 53 void QueryCounterEXT(GLuint id, GLenum target) override; 54 void GetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint* params) override; 55 void GetQueryObjectui64vEXT(GLuint id, 56 GLenum pname, 57 GLuint64* params) override; 58 59 // Texture copying. 60 void CopySubTexture(const gpu::Mailbox& source_mailbox, 61 const gpu::Mailbox& dest_mailbox, 62 GLenum dest_target, 63 GLint xoffset, 64 GLint yoffset, 65 GLint x, 66 GLint y, 67 GLsizei width, 68 GLsizei height, 69 GLboolean unpack_flip_y, 70 GLboolean unpack_premultiply_alpha) override; 71 72 void WritePixels(const gpu::Mailbox& dest_mailbox, 73 int dst_x_offset, 74 int dst_y_offset, 75 GLenum texture_target, 76 GLuint row_bytes, 77 const SkImageInfo& src_info, 78 const void* src_pixels) override; 79 80 void ConvertYUVMailboxesToRGB(const gpu::Mailbox& dest_mailbox, 81 SkYUVColorSpace planes_yuv_color_space, 82 const gpu::Mailbox& y_plane_mailbox, 83 const gpu::Mailbox& u_plane_mailbox, 84 const gpu::Mailbox& v_plane_mailbox) override; 85 86 void ConvertNV12MailboxesToRGB( 87 const gpu::Mailbox& dest_mailbox, 88 SkYUVColorSpace planes_yuv_color_space, 89 const gpu::Mailbox& y_plane_mailbox, 90 const gpu::Mailbox& uv_planes_mailbox) override; 91 92 // OOP-Raster 93 void BeginRasterCHROMIUM(GLuint sk_color, 94 GLuint msaa_sample_count, 95 GLboolean can_use_lcd_text, 96 const gfx::ColorSpace& color_space, 97 const GLbyte* mailbox) override; 98 void RasterCHROMIUM(const cc::DisplayItemList* list, 99 cc::ImageProvider* provider, 100 const gfx::Size& content_size, 101 const gfx::Rect& full_raster_rect, 102 const gfx::Rect& playback_rect, 103 const gfx::Vector2dF& post_translate, 104 GLfloat post_scale, 105 bool requires_clear, 106 size_t* max_op_size_hint) override; 107 void EndRasterCHROMIUM() override; 108 109 // Image decode acceleration. 110 SyncToken ScheduleImageDecode(base::span<const uint8_t> encoded_data, 111 const gfx::Size& output_size, 112 uint32_t transfer_cache_entry_id, 113 const gfx::ColorSpace& target_color_space, 114 bool needs_mips) override; 115 116 void ReadbackARGBPixelsAsync( 117 const gpu::Mailbox& source_mailbox, 118 GLenum source_target, 119 const gfx::Size& dst_size, 120 unsigned char* out, 121 GLenum format, 122 base::OnceCallback<void(bool)> callback) override; 123 124 void ReadbackYUVPixelsAsync( 125 const gpu::Mailbox& source_mailbox, 126 GLenum source_target, 127 const gfx::Size& source_size, 128 const gfx::Rect& output_rect, 129 bool vertically_flip_texture, 130 int y_plane_row_stride_bytes, 131 unsigned char* y_plane_data, 132 int u_plane_row_stride_bytes, 133 unsigned char* u_plane_data, 134 int v_plane_row_stride_bytes, 135 unsigned char* v_plane_data, 136 const gfx::Point& paste_location, 137 base::OnceCallback<void()> release_mailbox, 138 base::OnceCallback<void(bool)> readback_done) override; 139 140 void ReadbackImagePixels(const gpu::Mailbox& source_mailbox, 141 const SkImageInfo& dst_info, 142 GLuint dst_row_bytes, 143 int src_x, 144 int src_y, 145 void* dst_pixels) override; 146 147 // Raster via GrContext. 148 GLuint CreateAndConsumeForGpuRaster(const gpu::Mailbox& mailbox) override; 149 void DeleteGpuRasterTexture(GLuint texture) override; 150 void BeginGpuRaster() override; 151 void EndGpuRaster() override; 152 void BeginSharedImageAccessDirectCHROMIUM(GLuint texture, 153 GLenum mode) override; 154 void EndSharedImageAccessDirectCHROMIUM(GLuint texture) override; 155 156 void InitializeDiscardableTextureCHROMIUM(GLuint texture) override; 157 void UnlockDiscardableTextureCHROMIUM(GLuint texture) override; 158 bool LockDiscardableTextureCHROMIUM(GLuint texture) override; 159 160 void TraceBeginCHROMIUM(const char* category_name, 161 const char* trace_name) override; 162 void TraceEndCHROMIUM() override; 163 164 void SetActiveURLCHROMIUM(const char* url) override; 165 166 // InterfaceBase implementation. 167 void GenSyncTokenCHROMIUM(GLbyte* sync_token) override; 168 void GenUnverifiedSyncTokenCHROMIUM(GLbyte* sync_token) override; 169 void VerifySyncTokensCHROMIUM(GLbyte** sync_tokens, GLsizei count) override; 170 void WaitSyncTokenCHROMIUM(const GLbyte* sync_token) override; 171 172 private: 173 GLHelper* GetGLHelper(); 174 void OnReadARGBPixelsAsync(GLuint texture_id, 175 base::OnceCallback<void(bool)> callback, 176 bool success); 177 void OnReadYUVPixelsAsync(GLuint copy_texture_id, 178 base::OnceCallback<void()> on_release_mailbox, 179 base::OnceCallback<void(bool)> readback_done, 180 bool success); 181 void OnReleaseMailbox(GLuint shared_texture_id, 182 base::OnceCallback<void()> release_mailbox); 183 184 gles2::GLES2Interface* gl_; 185 ContextSupport* context_support_; 186 std::unique_ptr<GLHelper> gl_helper_; 187 base::WeakPtrFactory<RasterImplementationGLES> weak_ptr_factory_{this}; 188 189 DISALLOW_COPY_AND_ASSIGN(RasterImplementationGLES); 190 }; 191 192 } // namespace raster 193 } // namespace gpu 194 195 #endif // GPU_COMMAND_BUFFER_CLIENT_RASTER_IMPLEMENTATION_GLES_H_ 196