OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/texture_image_transport_surface.h" | 5 #include "content/common/gpu/texture_image_transport_surface.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 GpuCommandBufferStub* stub, | 35 GpuCommandBufferStub* stub, |
36 const gfx::GLSurfaceHandle& handle) | 36 const gfx::GLSurfaceHandle& handle) |
37 : fbo_id_(0), | 37 : fbo_id_(0), |
38 front_(0), | 38 front_(0), |
39 stub_destroyed_(false), | 39 stub_destroyed_(false), |
40 backbuffer_suggested_allocation_(true), | 40 backbuffer_suggested_allocation_(true), |
41 frontbuffer_suggested_allocation_(true), | 41 frontbuffer_suggested_allocation_(true), |
42 frontbuffer_is_protected_(true), | 42 frontbuffer_is_protected_(true), |
43 protection_state_id_(0), | 43 protection_state_id_(0), |
44 handle_(handle), | 44 handle_(handle), |
45 parent_stub_(NULL) { | 45 parent_stub_(NULL), |
| 46 is_swap_buffers_pending_(false), |
| 47 did_unschedule_(false) { |
46 helper_.reset(new ImageTransportHelper(this, | 48 helper_.reset(new ImageTransportHelper(this, |
47 manager, | 49 manager, |
48 stub, | 50 stub, |
49 gfx::kNullPluginWindow)); | 51 gfx::kNullPluginWindow)); |
50 } | 52 } |
51 | 53 |
52 TextureImageTransportSurface::~TextureImageTransportSurface() { | 54 TextureImageTransportSurface::~TextureImageTransportSurface() { |
53 DCHECK(stub_destroyed_); | 55 DCHECK(stub_destroyed_); |
54 Destroy(); | 56 Destroy(); |
55 } | 57 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 parent_stub_->decoder()->MakeCurrent(); | 109 parent_stub_->decoder()->MakeCurrent(); |
108 ReleaseParentStub(); | 110 ReleaseParentStub(); |
109 } | 111 } |
110 | 112 |
111 if (surface_.get()) | 113 if (surface_.get()) |
112 surface_ = NULL; | 114 surface_ = NULL; |
113 | 115 |
114 helper_->Destroy(); | 116 helper_->Destroy(); |
115 } | 117 } |
116 | 118 |
| 119 bool TextureImageTransportSurface::DeferDraws() { |
| 120 // The command buffer hit a draw/clear command that could clobber the |
| 121 // texture in use by the UI compositor. If a Swap is pending, abort |
| 122 // processing of the command by returning true and unschedule until the Swap |
| 123 // Ack arrives. |
| 124 DCHECK(!did_unschedule_); |
| 125 if (is_swap_buffers_pending_) { |
| 126 did_unschedule_ = true; |
| 127 helper_->SetScheduled(false); |
| 128 return true; |
| 129 } |
| 130 return false; |
| 131 } |
| 132 |
117 bool TextureImageTransportSurface::Resize(const gfx::Size&) { | 133 bool TextureImageTransportSurface::Resize(const gfx::Size&) { |
118 return true; | 134 return true; |
119 } | 135 } |
120 | 136 |
121 bool TextureImageTransportSurface::IsOffscreen() { | 137 bool TextureImageTransportSurface::IsOffscreen() { |
122 return true; | 138 return true; |
123 } | 139 } |
124 | 140 |
125 bool TextureImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 141 bool TextureImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
126 if (stub_destroyed_) { | 142 if (stub_destroyed_) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 front_ = back(); | 261 front_ = back(); |
246 previous_damage_rect_ = gfx::Rect(textures_[front()].size); | 262 previous_damage_rect_ = gfx::Rect(textures_[front()].size); |
247 | 263 |
248 DCHECK(textures_[front()].client_id != 0); | 264 DCHECK(textures_[front()].client_id != 0); |
249 | 265 |
250 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 266 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
251 params.surface_handle = textures_[front()].client_id; | 267 params.surface_handle = textures_[front()].client_id; |
252 params.protection_state_id = protection_state_id_; | 268 params.protection_state_id = protection_state_id_; |
253 params.skip_ack = false; | 269 params.skip_ack = false; |
254 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 270 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
255 helper_->SetScheduled(false); | 271 |
| 272 DCHECK(!is_swap_buffers_pending_); |
| 273 is_swap_buffers_pending_ = true; |
256 return true; | 274 return true; |
257 } | 275 } |
258 | 276 |
259 bool TextureImageTransportSurface::PostSubBuffer( | 277 bool TextureImageTransportSurface::PostSubBuffer( |
260 int x, int y, int width, int height) { | 278 int x, int y, int width, int height) { |
261 DCHECK(backbuffer_suggested_allocation_); | 279 DCHECK(backbuffer_suggested_allocation_); |
262 DCHECK(textures_[back()].info->service_id()); | 280 DCHECK(textures_[back()].info->service_id()); |
263 if (!frontbuffer_suggested_allocation_ || !frontbuffer_is_protected_) | 281 if (!frontbuffer_suggested_allocation_ || !frontbuffer_is_protected_) |
264 return true; | 282 return true; |
265 // If we are recreating the frontbuffer with this swap, make sure we are | 283 // If we are recreating the frontbuffer with this swap, make sure we are |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 DCHECK(textures_[front()].client_id); | 332 DCHECK(textures_[front()].client_id); |
315 | 333 |
316 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; | 334 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; |
317 params.surface_handle = textures_[front()].client_id; | 335 params.surface_handle = textures_[front()].client_id; |
318 params.x = x; | 336 params.x = x; |
319 params.y = y; | 337 params.y = y; |
320 params.width = width; | 338 params.width = width; |
321 params.height = height; | 339 params.height = height; |
322 params.protection_state_id = protection_state_id_; | 340 params.protection_state_id = protection_state_id_; |
323 helper_->SendAcceleratedSurfacePostSubBuffer(params); | 341 helper_->SendAcceleratedSurfacePostSubBuffer(params); |
324 helper_->SetScheduled(false); | 342 |
| 343 DCHECK(!is_swap_buffers_pending_); |
| 344 is_swap_buffers_pending_ = true; |
325 return true; | 345 return true; |
326 } | 346 } |
327 | 347 |
328 std::string TextureImageTransportSurface::GetExtensions() { | 348 std::string TextureImageTransportSurface::GetExtensions() { |
329 std::string extensions = gfx::GLSurface::GetExtensions(); | 349 std::string extensions = gfx::GLSurface::GetExtensions(); |
330 extensions += extensions.empty() ? "" : " "; | 350 extensions += extensions.empty() ? "" : " "; |
331 extensions += "GL_CHROMIUM_front_buffer_cached "; | 351 extensions += "GL_CHROMIUM_front_buffer_cached "; |
332 extensions += "GL_CHROMIUM_post_sub_buffer"; | 352 extensions += "GL_CHROMIUM_post_sub_buffer"; |
333 return extensions; | 353 return extensions; |
334 } | 354 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 BufferPresentedImpl(); | 394 BufferPresentedImpl(); |
375 } else { | 395 } else { |
376 helper_->manager()->sync_point_manager()->AddSyncPointCallback( | 396 helper_->manager()->sync_point_manager()->AddSyncPointCallback( |
377 sync_point, | 397 sync_point, |
378 base::Bind(&TextureImageTransportSurface::BufferPresentedImpl, | 398 base::Bind(&TextureImageTransportSurface::BufferPresentedImpl, |
379 this->AsWeakPtr())); | 399 this->AsWeakPtr())); |
380 } | 400 } |
381 } | 401 } |
382 | 402 |
383 void TextureImageTransportSurface::BufferPresentedImpl() { | 403 void TextureImageTransportSurface::BufferPresentedImpl() { |
| 404 DCHECK(is_swap_buffers_pending_); |
| 405 is_swap_buffers_pending_ = false; |
| 406 |
384 // We're relying on the fact that the parent context is | 407 // We're relying on the fact that the parent context is |
385 // finished with it's context when it inserts the sync point that | 408 // finished with it's context when it inserts the sync point that |
386 // triggers this callback. | 409 // triggers this callback. |
387 if (helper_->MakeCurrent()) { | 410 if (helper_->MakeCurrent()) { |
388 if (textures_[front()].size != textures_[back()].size || | 411 if (textures_[front()].size != textures_[back()].size || |
389 !textures_[back()].info->service_id() || | 412 !textures_[back()].info->service_id() || |
390 !textures_[back()].sent_to_client) { | 413 !textures_[back()].sent_to_client) { |
391 // We may get an ACK from a stale swap just to reschedule. In that case, | 414 // We may get an ACK from a stale swap just to reschedule. In that case, |
392 // we may not have a backbuffer suggestion and should not recreate one. | 415 // we may not have a backbuffer suggestion and should not recreate one. |
393 if (backbuffer_suggested_allocation_) | 416 if (backbuffer_suggested_allocation_) |
394 CreateBackTexture(textures_[front()].size); | 417 CreateBackTexture(textures_[front()].size); |
395 } else { | 418 } else { |
396 AttachBackTextureToFBO(); | 419 AttachBackTextureToFBO(); |
397 } | 420 } |
398 } | 421 } |
399 | 422 |
400 // Even if MakeCurrent fails, schedule anyway, to trigger the lost context | 423 // Even if MakeCurrent fails, schedule anyway, to trigger the lost context |
401 // logic. | 424 // logic. |
402 helper_->SetScheduled(true); | 425 if (did_unschedule_) { |
| 426 did_unschedule_ = false; |
| 427 helper_->SetScheduled(true); |
| 428 } |
403 } | 429 } |
404 | 430 |
405 void TextureImageTransportSurface::OnResizeViewACK() { | 431 void TextureImageTransportSurface::OnResizeViewACK() { |
406 NOTREACHED(); | 432 NOTREACHED(); |
407 } | 433 } |
408 | 434 |
409 void TextureImageTransportSurface::ReleaseTexture(int id) { | 435 void TextureImageTransportSurface::ReleaseTexture(int id) { |
410 if (!parent_stub_) | 436 if (!parent_stub_) |
411 return; | 437 return; |
412 Texture& texture = textures_[id]; | 438 Texture& texture = textures_[id]; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 Texture& texture = textures_[i]; | 539 Texture& texture = textures_[i]; |
514 texture.info = NULL; | 540 texture.info = NULL; |
515 if (!texture.sent_to_client) | 541 if (!texture.sent_to_client) |
516 continue; | 542 continue; |
517 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 543 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
518 params.identifier = texture.client_id; | 544 params.identifier = texture.client_id; |
519 helper_->SendAcceleratedSurfaceRelease(params); | 545 helper_->SendAcceleratedSurfaceRelease(params); |
520 } | 546 } |
521 parent_stub_ = NULL; | 547 parent_stub_ = NULL; |
522 } | 548 } |
OLD | NEW |