OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/gles2_cmd_decoder_passthrough.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_passthrough.h" |
6 | 6 |
7 #include "gpu/command_buffer/service/feature_info.h" | 7 #include "gpu/command_buffer/service/feature_info.h" |
8 #include "gpu/command_buffer/service/gl_utils.h" | 8 #include "gpu/command_buffer/service/gl_utils.h" |
9 #include "ui/gl/gl_version_info.h" | 9 #include "ui/gl/gl_version_info.h" |
10 | 10 |
11 namespace gpu { | 11 namespace gpu { |
12 namespace gles2 { | 12 namespace gles2 { |
13 | 13 |
| 14 namespace { |
| 15 template <typename ClientType, typename ServiceType, typename DeleteFunction> |
| 16 void DeleteServiceObjects(ClientServiceMap<ClientType, ServiceType>* id_map, |
| 17 bool have_context, |
| 18 DeleteFunction delete_function) { |
| 19 if (have_context) { |
| 20 for (auto client_service_id_pair : *id_map) { |
| 21 delete_function(client_service_id_pair.second); |
| 22 } |
| 23 } |
| 24 |
| 25 id_map->Clear(); |
| 26 } |
| 27 |
| 28 } // anonymous namespace |
| 29 |
| 30 PassthroughResources::PassthroughResources() {} |
| 31 |
| 32 PassthroughResources::~PassthroughResources() {} |
| 33 |
| 34 void PassthroughResources::Destroy(bool have_context) { |
| 35 DeleteServiceObjects(&texture_id_map, have_context, |
| 36 [](GLuint texture) { glDeleteTextures(1, &texture); }); |
| 37 DeleteServiceObjects(&buffer_id_map, have_context, |
| 38 [](GLuint buffer) { glDeleteBuffersARB(1, &buffer); }); |
| 39 DeleteServiceObjects( |
| 40 &renderbuffer_id_map, have_context, |
| 41 [](GLuint renderbuffer) { glDeleteRenderbuffersEXT(1, &renderbuffer); }); |
| 42 DeleteServiceObjects(&sampler_id_map, have_context, |
| 43 [](GLuint sampler) { glDeleteSamplers(1, &sampler); }); |
| 44 DeleteServiceObjects(&program_id_map, have_context, |
| 45 [](GLuint program) { glDeleteProgram(program); }); |
| 46 DeleteServiceObjects(&shader_id_map, have_context, |
| 47 [](GLuint shader) { glDeleteShader(shader); }); |
| 48 DeleteServiceObjects(&sync_id_map, have_context, [](uintptr_t sync) { |
| 49 glDeleteSync(reinterpret_cast<GLsync>(sync)); |
| 50 }); |
| 51 |
| 52 if (!have_context) { |
| 53 for (auto passthrough_texture : texture_object_map) { |
| 54 passthrough_texture.second->MarkContextLost(); |
| 55 } |
| 56 } |
| 57 texture_object_map.clear(); |
| 58 } |
| 59 |
14 GLES2DecoderPassthroughImpl::GLES2DecoderPassthroughImpl(ContextGroup* group) | 60 GLES2DecoderPassthroughImpl::GLES2DecoderPassthroughImpl(ContextGroup* group) |
15 : commands_to_process_(0), | 61 : commands_to_process_(0), |
16 debug_marker_manager_(), | 62 debug_marker_manager_(), |
17 logger_(&debug_marker_manager_), | 63 logger_(&debug_marker_manager_), |
18 surface_(), | 64 surface_(), |
19 context_(), | 65 context_(), |
20 group_(group), | 66 group_(group), |
21 feature_info_(group->feature_info()) { | 67 feature_info_(group->feature_info()) { |
22 DCHECK(group); | 68 DCHECK(group); |
23 } | 69 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 152 |
107 if (!group_->Initialize(this, attrib_helper.context_type, | 153 if (!group_->Initialize(this, attrib_helper.context_type, |
108 disallowed_features)) { | 154 disallowed_features)) { |
109 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. | 155 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
110 Destroy(true); | 156 Destroy(true); |
111 return false; | 157 return false; |
112 } | 158 } |
113 | 159 |
114 image_manager_.reset(new ImageManager()); | 160 image_manager_.reset(new ImageManager()); |
115 | 161 |
| 162 bind_generates_resource_ = group_->bind_generates_resource(); |
| 163 |
| 164 resources_ = group_->passthrough_resources(); |
| 165 |
| 166 mailbox_manager_ = group_->mailbox_manager(); |
| 167 |
| 168 // Query information about the texture units |
| 169 GLint num_texture_units = 0; |
| 170 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &num_texture_units); |
| 171 |
| 172 active_texture_unit_ = 0; |
| 173 bound_textures_.resize(num_texture_units, 0); |
| 174 |
116 set_initialized(); | 175 set_initialized(); |
117 return true; | 176 return true; |
118 } | 177 } |
119 | 178 |
120 void GLES2DecoderPassthroughImpl::Destroy(bool have_context) { | 179 void GLES2DecoderPassthroughImpl::Destroy(bool have_context) { |
121 if (image_manager_.get()) { | 180 if (image_manager_.get()) { |
122 image_manager_->Destroy(have_context); | 181 image_manager_->Destroy(have_context); |
123 image_manager_.reset(); | 182 image_manager_.reset(); |
124 } | 183 } |
| 184 |
| 185 DeleteServiceObjects( |
| 186 &framebuffer_id_map_, have_context, |
| 187 [](GLuint framebuffer) { glDeleteFramebuffersEXT(1, &framebuffer); }); |
| 188 DeleteServiceObjects(&transform_feedback_id_map_, have_context, |
| 189 [](GLuint transform_feedback) { |
| 190 glDeleteTransformFeedbacks(1, &transform_feedback); |
| 191 }); |
| 192 DeleteServiceObjects(&query_id_map_, have_context, |
| 193 [](GLuint query) { glDeleteQueries(1, &query); }); |
| 194 DeleteServiceObjects( |
| 195 &vertex_array_id_map_, have_context, |
| 196 [](GLuint vertex_array) { glDeleteVertexArraysOES(1, &vertex_array); }); |
| 197 |
| 198 if (group_) { |
| 199 group_->Destroy(this, have_context); |
| 200 group_ = nullptr; |
| 201 } |
125 } | 202 } |
126 | 203 |
127 void GLES2DecoderPassthroughImpl::SetSurface( | 204 void GLES2DecoderPassthroughImpl::SetSurface( |
128 const scoped_refptr<gl::GLSurface>& surface) { | 205 const scoped_refptr<gl::GLSurface>& surface) { |
129 DCHECK(context_->IsCurrent(nullptr)); | 206 DCHECK(context_->IsCurrent(nullptr)); |
130 DCHECK(surface_.get()); | 207 DCHECK(surface_.get()); |
131 surface_ = surface; | 208 surface_ = surface; |
132 } | 209 } |
133 | 210 |
134 void GLES2DecoderPassthroughImpl::ReleaseSurface() { | 211 void GLES2DecoderPassthroughImpl::ReleaseSurface() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 245 |
169 gpu::gles2::GLES2Util* GLES2DecoderPassthroughImpl::GetGLES2Util() { | 246 gpu::gles2::GLES2Util* GLES2DecoderPassthroughImpl::GetGLES2Util() { |
170 return nullptr; | 247 return nullptr; |
171 } | 248 } |
172 | 249 |
173 gl::GLContext* GLES2DecoderPassthroughImpl::GetGLContext() { | 250 gl::GLContext* GLES2DecoderPassthroughImpl::GetGLContext() { |
174 return nullptr; | 251 return nullptr; |
175 } | 252 } |
176 | 253 |
177 gpu::gles2::ContextGroup* GLES2DecoderPassthroughImpl::GetContextGroup() { | 254 gpu::gles2::ContextGroup* GLES2DecoderPassthroughImpl::GetContextGroup() { |
178 return nullptr; | 255 return group_.get(); |
179 } | 256 } |
180 | 257 |
181 const FeatureInfo* GLES2DecoderPassthroughImpl::GetFeatureInfo() const { | 258 const FeatureInfo* GLES2DecoderPassthroughImpl::GetFeatureInfo() const { |
182 return nullptr; | 259 return group_->feature_info(); |
183 } | 260 } |
184 | 261 |
185 gpu::Capabilities GLES2DecoderPassthroughImpl::GetCapabilities() { | 262 gpu::Capabilities GLES2DecoderPassthroughImpl::GetCapabilities() { |
186 DCHECK(initialized()); | 263 DCHECK(initialized()); |
187 Capabilities caps; | 264 Capabilities caps; |
188 | 265 |
189 PopulateNumericCapabilities(&caps, feature_info_.get()); | 266 PopulateNumericCapabilities(&caps, feature_info_.get()); |
190 | 267 |
191 caps.bind_generates_resource_chromium = group_->bind_generates_resource(); | 268 caps.bind_generates_resource_chromium = group_->bind_generates_resource(); |
192 caps.egl_image_external = | 269 caps.egl_image_external = |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 364 |
288 size_t GLES2DecoderPassthroughImpl::GetSavedBackTextureCountForTest() { | 365 size_t GLES2DecoderPassthroughImpl::GetSavedBackTextureCountForTest() { |
289 return 0; | 366 return 0; |
290 } | 367 } |
291 | 368 |
292 size_t GLES2DecoderPassthroughImpl::GetCreatedBackTextureCountForTest() { | 369 size_t GLES2DecoderPassthroughImpl::GetCreatedBackTextureCountForTest() { |
293 return 0; | 370 return 0; |
294 } | 371 } |
295 | 372 |
296 void GLES2DecoderPassthroughImpl::SetFenceSyncReleaseCallback( | 373 void GLES2DecoderPassthroughImpl::SetFenceSyncReleaseCallback( |
297 const FenceSyncReleaseCallback& callback) {} | 374 const FenceSyncReleaseCallback& callback) { |
| 375 fence_sync_release_callback_ = callback; |
| 376 } |
298 | 377 |
299 void GLES2DecoderPassthroughImpl::SetWaitFenceSyncCallback( | 378 void GLES2DecoderPassthroughImpl::SetWaitFenceSyncCallback( |
300 const WaitFenceSyncCallback& callback) {} | 379 const WaitFenceSyncCallback& callback) { |
| 380 wait_fence_sync_callback_ = callback; |
| 381 } |
301 | 382 |
302 void GLES2DecoderPassthroughImpl::SetDescheduleUntilFinishedCallback( | 383 void GLES2DecoderPassthroughImpl::SetDescheduleUntilFinishedCallback( |
303 const NoParamCallback& callback) {} | 384 const NoParamCallback& callback) {} |
304 | 385 |
305 void GLES2DecoderPassthroughImpl::SetRescheduleAfterFinishedCallback( | 386 void GLES2DecoderPassthroughImpl::SetRescheduleAfterFinishedCallback( |
306 const NoParamCallback& callback) {} | 387 const NoParamCallback& callback) {} |
307 | 388 |
308 gpu::gles2::QueryManager* GLES2DecoderPassthroughImpl::GetQueryManager() { | 389 gpu::gles2::QueryManager* GLES2DecoderPassthroughImpl::GetQueryManager() { |
309 return nullptr; | 390 return nullptr; |
310 } | 391 } |
(...skipping 26 matching lines...) Expand all Loading... |
337 | 418 |
338 bool GLES2DecoderPassthroughImpl::HasPollingWork() const { | 419 bool GLES2DecoderPassthroughImpl::HasPollingWork() const { |
339 return false; | 420 return false; |
340 } | 421 } |
341 | 422 |
342 void GLES2DecoderPassthroughImpl::PerformPollingWork() {} | 423 void GLES2DecoderPassthroughImpl::PerformPollingWork() {} |
343 | 424 |
344 bool GLES2DecoderPassthroughImpl::GetServiceTextureId( | 425 bool GLES2DecoderPassthroughImpl::GetServiceTextureId( |
345 uint32_t client_texture_id, | 426 uint32_t client_texture_id, |
346 uint32_t* service_texture_id) { | 427 uint32_t* service_texture_id) { |
347 return false; | 428 return resources_->texture_id_map.GetServiceID(client_texture_id, |
| 429 service_texture_id); |
348 } | 430 } |
349 | 431 |
350 gpu::error::ContextLostReason | 432 gpu::error::ContextLostReason |
351 GLES2DecoderPassthroughImpl::GetContextLostReason() { | 433 GLES2DecoderPassthroughImpl::GetContextLostReason() { |
352 return error::kUnknown; | 434 return error::kUnknown; |
353 } | 435 } |
354 | 436 |
355 bool GLES2DecoderPassthroughImpl::ClearLevel(Texture* texture, | 437 bool GLES2DecoderPassthroughImpl::ClearLevel(Texture* texture, |
356 unsigned target, | 438 unsigned target, |
357 int level, | 439 int level, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 }, /* NOLINT */ | 525 }, /* NOLINT */ |
444 | 526 |
445 const GLES2DecoderPassthroughImpl::CommandInfo | 527 const GLES2DecoderPassthroughImpl::CommandInfo |
446 GLES2DecoderPassthroughImpl::command_info[] = { | 528 GLES2DecoderPassthroughImpl::command_info[] = { |
447 GLES2_COMMAND_LIST(GLES2_CMD_OP)}; | 529 GLES2_COMMAND_LIST(GLES2_CMD_OP)}; |
448 | 530 |
449 #undef GLES2_CMD_OP | 531 #undef GLES2_CMD_OP |
450 | 532 |
451 } // namespace gles2 | 533 } // namespace gles2 |
452 } // namespace gpu | 534 } // namespace gpu |
OLD | NEW |