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/image_transport_surface.h" | 5 #include "content/common/gpu/image_transport_surface.h" |
6 | 6 |
7 // This conflicts with the defines in Xlib.h and must come first. | 7 // This conflicts with the defines in Xlib.h and must come first. |
8 #include "content/common/gpu/gpu_messages.h" | 8 #include "content/common/gpu/gpu_messages.h" |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // gfx::GLSurface implementation | 86 // gfx::GLSurface implementation |
87 virtual bool Initialize() OVERRIDE; | 87 virtual bool Initialize() OVERRIDE; |
88 virtual void Destroy() OVERRIDE; | 88 virtual void Destroy() OVERRIDE; |
89 virtual bool IsOffscreen() OVERRIDE; | 89 virtual bool IsOffscreen() OVERRIDE; |
90 virtual bool SwapBuffers() OVERRIDE; | 90 virtual bool SwapBuffers() OVERRIDE; |
91 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 91 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
92 virtual std::string GetExtensions() OVERRIDE; | 92 virtual std::string GetExtensions() OVERRIDE; |
93 virtual gfx::Size GetSize() OVERRIDE; | 93 virtual gfx::Size GetSize() OVERRIDE; |
94 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 94 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
95 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 95 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
96 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 96 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 97 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
97 | 98 |
98 protected: | 99 protected: |
99 // ImageTransportSurface implementation | 100 // ImageTransportSurface implementation |
100 virtual void OnNewSurfaceACK( | 101 virtual void OnNewSurfaceACK( |
101 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 102 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
102 virtual void OnBuffersSwappedACK() OVERRIDE; | 103 virtual void OnBuffersSwappedACK() OVERRIDE; |
103 virtual void OnPostSubBufferACK() OVERRIDE; | 104 virtual void OnPostSubBufferACK() OVERRIDE; |
104 virtual void OnResizeViewACK() OVERRIDE; | 105 virtual void OnResizeViewACK() OVERRIDE; |
| 106 virtual void OnDiscardSurface(uint64 surface_id) OVERRIDE; |
105 virtual void OnResize(gfx::Size size) OVERRIDE; | 107 virtual void OnResize(gfx::Size size) OVERRIDE; |
106 | 108 |
107 private: | 109 private: |
108 virtual ~EGLImageTransportSurface() OVERRIDE; | 110 virtual ~EGLImageTransportSurface() OVERRIDE; |
109 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 111 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
110 void SendBuffersSwapped(); | 112 void SendBuffersSwapped(); |
111 void SendPostSubBuffer(int x, int y, int width, int height); | 113 void SendPostSubBuffer(int x, int y, int width, int height); |
112 | 114 |
113 // Tracks the current buffer allocation state. | 115 // Tracks the current buffer allocation state. |
114 BufferAllocationState buffer_allocation_state_; | 116 bool backbuffer_allocated_; |
| 117 bool frontbuffer_allocated_; |
115 | 118 |
116 uint32 fbo_id_; | 119 uint32 fbo_id_; |
117 | 120 |
118 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 121 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
119 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 122 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
120 gfx::Rect previous_damage_rect_; | 123 gfx::Rect previous_damage_rect_; |
121 | 124 |
122 // Whether or not we've successfully made the surface current once. | 125 // Whether or not we've successfully made the surface current once. |
123 bool made_current_; | 126 bool made_current_; |
124 | 127 |
(...skipping 13 matching lines...) Expand all Loading... |
138 GpuCommandBufferStub* stub); | 141 GpuCommandBufferStub* stub); |
139 | 142 |
140 // gfx::GLSurface implementation: | 143 // gfx::GLSurface implementation: |
141 virtual bool Initialize() OVERRIDE; | 144 virtual bool Initialize() OVERRIDE; |
142 virtual void Destroy() OVERRIDE; | 145 virtual void Destroy() OVERRIDE; |
143 virtual bool SwapBuffers() OVERRIDE; | 146 virtual bool SwapBuffers() OVERRIDE; |
144 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 147 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
145 virtual std::string GetExtensions(); | 148 virtual std::string GetExtensions(); |
146 virtual gfx::Size GetSize() OVERRIDE; | 149 virtual gfx::Size GetSize() OVERRIDE; |
147 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 150 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
148 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 151 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 152 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
149 | 153 |
150 protected: | 154 protected: |
151 // ImageTransportSurface implementation: | 155 // ImageTransportSurface implementation: |
152 virtual void OnNewSurfaceACK( | 156 virtual void OnNewSurfaceACK( |
153 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 157 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
154 virtual void OnBuffersSwappedACK() OVERRIDE; | 158 virtual void OnBuffersSwappedACK() OVERRIDE; |
155 virtual void OnPostSubBufferACK() OVERRIDE; | 159 virtual void OnPostSubBufferACK() OVERRIDE; |
156 virtual void OnResizeViewACK() OVERRIDE; | 160 virtual void OnResizeViewACK() OVERRIDE; |
| 161 virtual void OnDiscardSurface(uint64 surface_id) OVERRIDE; |
157 virtual void OnResize(gfx::Size size) OVERRIDE; | 162 virtual void OnResize(gfx::Size size) OVERRIDE; |
158 | 163 |
159 private: | 164 private: |
160 virtual ~GLXImageTransportSurface(); | 165 virtual ~GLXImageTransportSurface(); |
161 | 166 |
162 // Tell the browser to release the surface. | 167 // Tell the browser to release the surface. |
163 void ReleaseSurface(); | 168 void ReleaseSurface(); |
164 | 169 |
165 void SendBuffersSwapped(); | 170 void SendBuffersSwapped(); |
166 void SendPostSubBuffer(int x, int y, int width, int height); | 171 void SendPostSubBuffer(int x, int y, int width, int height); |
167 | 172 |
168 void ResizeSurface(gfx::Size size); | 173 void ResizeSurface(gfx::Size size); |
169 | 174 |
170 // Tracks the current buffer allocation state. | 175 // Tracks the current buffer allocation state. |
171 BufferAllocationState buffer_allocation_state_; | 176 bool backbuffer_allocated_; |
| 177 bool frontbuffer_allocated_; |
172 | 178 |
173 XID dummy_parent_; | 179 XID dummy_parent_; |
174 gfx::Size size_; | 180 gfx::Size size_; |
175 | 181 |
176 // Whether or not the image has been bound on the browser side. | 182 // Whether or not the image has been bound on the browser side. |
177 bool bound_; | 183 bool bound_; |
178 | 184 |
179 // Whether or not we need to send a resize on the next swap. | 185 // Whether or not we need to send a resize on the next swap. |
180 bool needs_resize_; | 186 bool needs_resize_; |
181 | 187 |
(...skipping 23 matching lines...) Expand all Loading... |
205 virtual std::string GetExtensions() OVERRIDE; | 211 virtual std::string GetExtensions() OVERRIDE; |
206 virtual gfx::Size GetSize() OVERRIDE; | 212 virtual gfx::Size GetSize() OVERRIDE; |
207 | 213 |
208 protected: | 214 protected: |
209 // ImageTransportSurface implementation: | 215 // ImageTransportSurface implementation: |
210 virtual void OnNewSurfaceACK( | 216 virtual void OnNewSurfaceACK( |
211 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 217 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
212 virtual void OnBuffersSwappedACK() OVERRIDE; | 218 virtual void OnBuffersSwappedACK() OVERRIDE; |
213 virtual void OnPostSubBufferACK() OVERRIDE; | 219 virtual void OnPostSubBufferACK() OVERRIDE; |
214 virtual void OnResizeViewACK() OVERRIDE; | 220 virtual void OnResizeViewACK() OVERRIDE; |
| 221 virtual void OnDiscardSurface(uint64 surface_id) OVERRIDE; |
215 virtual void OnResize(gfx::Size size) OVERRIDE; | 222 virtual void OnResize(gfx::Size size) OVERRIDE; |
216 | 223 |
217 private: | 224 private: |
218 virtual ~OSMesaImageTransportSurface(); | 225 virtual ~OSMesaImageTransportSurface(); |
219 | 226 |
220 // Tell the browser to release the surface. | 227 // Tell the browser to release the surface. |
221 void ReleaseSurface(); | 228 void ReleaseSurface(); |
222 | 229 |
223 scoped_ptr<TransportDIB> shared_mem_; | 230 scoped_ptr<TransportDIB> shared_mem_; |
224 uint32 shared_id_; | 231 uint32 shared_id_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 EGLAcceleratedSurface::~EGLAcceleratedSurface() { | 270 EGLAcceleratedSurface::~EGLAcceleratedSurface() { |
264 glDeleteTextures(1, &texture_); | 271 glDeleteTextures(1, &texture_); |
265 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 272 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
266 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); | 273 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); |
267 } | 274 } |
268 | 275 |
269 EGLImageTransportSurface::EGLImageTransportSurface( | 276 EGLImageTransportSurface::EGLImageTransportSurface( |
270 GpuChannelManager* manager, | 277 GpuChannelManager* manager, |
271 GpuCommandBufferStub* stub) | 278 GpuCommandBufferStub* stub) |
272 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(16, 16)), | 279 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(16, 16)), |
273 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 280 backbuffer_allocated_(true), |
| 281 frontbuffer_allocated_(true), |
274 fbo_id_(0), | 282 fbo_id_(0), |
275 made_current_(false) { | 283 made_current_(false) { |
276 helper_.reset(new ImageTransportHelper(this, | 284 helper_.reset(new ImageTransportHelper(this, |
277 manager, | 285 manager, |
278 stub, | 286 stub, |
279 gfx::kNullPluginWindow)); | 287 gfx::kNullPluginWindow)); |
280 } | 288 } |
281 | 289 |
282 EGLImageTransportSurface::~EGLImageTransportSurface() { | 290 EGLImageTransportSurface::~EGLImageTransportSurface() { |
283 Destroy(); | 291 Destroy(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 337 } |
330 | 338 |
331 made_current_ = true; | 339 made_current_ = true; |
332 return true; | 340 return true; |
333 } | 341 } |
334 | 342 |
335 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { | 343 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { |
336 return fbo_id_; | 344 return fbo_id_; |
337 } | 345 } |
338 | 346 |
339 void EGLImageTransportSurface::SetBufferAllocation( | 347 void EGLImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
340 BufferAllocationState state) { | 348 if (backbuffer_allocated_ == allocated) |
341 if (buffer_allocation_state_ == state) | |
342 return; | 349 return; |
343 buffer_allocation_state_ = state; | 350 // TODO(mmocny): Remove dependancy on front_surface_->size() |
| 351 if (!front_surface_.get()) |
| 352 return; |
344 | 353 |
345 switch (state) { | 354 if (allocated) { |
346 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 355 if (!back_surface_.get()) |
347 if (!back_surface_.get() && front_surface_.get()) | 356 OnResize(front_surface_->size()); |
348 OnResize(front_surface_->size()); | 357 backbuffer_allocated_ = true; |
349 break; | 358 } else { |
| 359 if (back_surface_.get()) |
| 360 ReleaseSurface(&back_surface_); |
| 361 backbuffer_allocated_ = false; |
| 362 } |
| 363 } |
350 | 364 |
351 case BUFFER_ALLOCATION_FRONT_ONLY: | 365 void EGLImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
352 if (back_surface_.get() && front_surface_.get()) | |
353 ReleaseSurface(&back_surface_); | |
354 break; | |
355 | |
356 case BUFFER_ALLOCATION_NONE: | |
357 if (back_surface_.get() && front_surface_.get()) | |
358 ReleaseSurface(&back_surface_); | |
359 break; | |
360 | |
361 default: | |
362 NOTREACHED(); | |
363 } | |
364 } | 366 } |
365 | 367 |
366 void EGLImageTransportSurface::ReleaseSurface( | 368 void EGLImageTransportSurface::ReleaseSurface( |
367 scoped_refptr<EGLAcceleratedSurface>* surface) { | 369 scoped_refptr<EGLAcceleratedSurface>* surface) { |
368 if (surface->get()) { | 370 if (surface->get()) { |
369 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 371 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
370 params.identifier = (*surface)->pixmap(); | 372 params.identifier = (*surface)->pixmap(); |
371 helper_->SendAcceleratedSurfaceRelease(params); | 373 helper_->SendAcceleratedSurfaceRelease(params); |
372 *surface = NULL; | 374 *surface = NULL; |
373 } | 375 } |
(...skipping 18 matching lines...) Expand all Loading... |
392 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 394 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
393 params.width = size.width(); | 395 params.width = size.width(); |
394 params.height = size.height(); | 396 params.height = size.height(); |
395 params.surface_handle = back_surface_->pixmap(); | 397 params.surface_handle = back_surface_->pixmap(); |
396 helper_->SendAcceleratedSurfaceNew(params); | 398 helper_->SendAcceleratedSurfaceNew(params); |
397 | 399 |
398 helper_->SetScheduled(false); | 400 helper_->SetScheduled(false); |
399 } | 401 } |
400 | 402 |
401 bool EGLImageTransportSurface::SwapBuffers() { | 403 bool EGLImageTransportSurface::SwapBuffers() { |
| 404 DCHECK(backbuffer_allocated_); |
| 405 DCHECK(frontbuffer_allocated_); |
402 front_surface_.swap(back_surface_); | 406 front_surface_.swap(back_surface_); |
403 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 407 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
404 helper_->DeferToFence(base::Bind( | 408 helper_->DeferToFence(base::Bind( |
405 &EGLImageTransportSurface::SendBuffersSwapped, | 409 &EGLImageTransportSurface::SendBuffersSwapped, |
406 AsWeakPtr())); | 410 AsWeakPtr())); |
407 | 411 |
408 gfx::Size expected_size = front_surface_->size(); | 412 gfx::Size expected_size = front_surface_->size(); |
409 if (!back_surface_.get() || back_surface_->size() != expected_size) { | 413 if (!back_surface_.get() || back_surface_->size() != expected_size) { |
410 OnResize(expected_size); | 414 OnResize(expected_size); |
411 } else { | 415 } else { |
412 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 416 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
413 GL_COLOR_ATTACHMENT0, | 417 GL_COLOR_ATTACHMENT0, |
414 GL_TEXTURE_2D, | 418 GL_TEXTURE_2D, |
415 back_surface_->texture(), | 419 back_surface_->texture(), |
416 0); | 420 0); |
417 } | 421 } |
418 previous_damage_rect_ = gfx::Rect(front_surface_->size()); | 422 previous_damage_rect_ = gfx::Rect(front_surface_->size()); |
419 return true; | 423 return true; |
420 } | 424 } |
421 | 425 |
422 void EGLImageTransportSurface::SendBuffersSwapped() { | 426 void EGLImageTransportSurface::SendBuffersSwapped() { |
423 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 427 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
424 params.surface_handle = front_surface_->pixmap(); | 428 params.surface_handle = front_surface_->pixmap(); |
425 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 429 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
426 helper_->SetScheduled(false); | 430 helper_->SetScheduled(false); |
427 } | 431 } |
428 | 432 |
429 bool EGLImageTransportSurface::PostSubBuffer( | 433 bool EGLImageTransportSurface::PostSubBuffer( |
430 int x, int y, int width, int height) { | 434 int x, int y, int width, int height) { |
431 | 435 DCHECK(backbuffer_allocated_); |
| 436 DCHECK(frontbuffer_allocated_); |
432 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 437 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
433 gfx::Size expected_size = back_surface_->size(); | 438 gfx::Size expected_size = back_surface_->size(); |
434 bool surfaces_same_size = front_surface_.get() && | 439 bool surfaces_same_size = front_surface_.get() && |
435 front_surface_->size() == expected_size; | 440 front_surface_->size() == expected_size; |
436 | 441 |
437 const gfx::Rect new_damage_rect(x, y, width, height); | 442 const gfx::Rect new_damage_rect(x, y, width, height); |
438 | 443 |
439 // An empty damage rect is a successful no-op. | 444 // An empty damage rect is a successful no-op. |
440 if (new_damage_rect.IsEmpty()) | 445 if (new_damage_rect.IsEmpty()) |
441 return true; | 446 return true; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 gfx::Size EGLImageTransportSurface::GetSize() { | 509 gfx::Size EGLImageTransportSurface::GetSize() { |
505 return back_surface_->size(); | 510 return back_surface_->size(); |
506 } | 511 } |
507 | 512 |
508 void EGLImageTransportSurface::OnNewSurfaceACK( | 513 void EGLImageTransportSurface::OnNewSurfaceACK( |
509 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { | 514 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { |
510 DCHECK_EQ(back_surface_->pixmap(), surface_handle); | 515 DCHECK_EQ(back_surface_->pixmap(), surface_handle); |
511 helper_->SetScheduled(true); | 516 helper_->SetScheduled(true); |
512 } | 517 } |
513 | 518 |
| 519 void EGLImageTransportSurface::OnDiscardSurface( |
| 520 uint64 surface_id) { |
| 521 } |
| 522 |
514 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 523 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
515 helper_->SetScheduled(true); | 524 helper_->SetScheduled(true); |
516 } | 525 } |
517 | 526 |
518 void EGLImageTransportSurface::OnPostSubBufferACK() { | 527 void EGLImageTransportSurface::OnPostSubBufferACK() { |
519 helper_->SetScheduled(true); | 528 helper_->SetScheduled(true); |
520 } | 529 } |
521 | 530 |
522 void EGLImageTransportSurface::OnResizeViewACK() { | 531 void EGLImageTransportSurface::OnResizeViewACK() { |
523 NOTREACHED(); | 532 NOTREACHED(); |
524 } | 533 } |
525 | 534 |
526 GLXImageTransportSurface::GLXImageTransportSurface( | 535 GLXImageTransportSurface::GLXImageTransportSurface( |
527 GpuChannelManager* manager, | 536 GpuChannelManager* manager, |
528 GpuCommandBufferStub* stub) | 537 GpuCommandBufferStub* stub) |
529 : gfx::NativeViewGLSurfaceGLX(), | 538 : gfx::NativeViewGLSurfaceGLX(), |
530 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 539 backbuffer_allocated_(true), |
| 540 frontbuffer_allocated_(true), |
531 dummy_parent_(0), | 541 dummy_parent_(0), |
532 size_(1, 1), | 542 size_(1, 1), |
533 bound_(false), | 543 bound_(false), |
534 needs_resize_(false), | 544 needs_resize_(false), |
535 made_current_(false) { | 545 made_current_(false) { |
536 helper_.reset(new ImageTransportHelper(this, | 546 helper_.reset(new ImageTransportHelper(this, |
537 manager, | 547 manager, |
538 stub, | 548 stub, |
539 gfx::kNullPluginWindow)); | 549 gfx::kNullPluginWindow)); |
540 } | 550 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 614 } |
605 | 615 |
606 void GLXImageTransportSurface::ReleaseSurface() { | 616 void GLXImageTransportSurface::ReleaseSurface() { |
607 DCHECK(bound_); | 617 DCHECK(bound_); |
608 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 618 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
609 params.identifier = window_; | 619 params.identifier = window_; |
610 helper_->SendAcceleratedSurfaceRelease(params); | 620 helper_->SendAcceleratedSurfaceRelease(params); |
611 bound_ = false; | 621 bound_ = false; |
612 } | 622 } |
613 | 623 |
614 void GLXImageTransportSurface::SetBufferAllocation( | 624 void GLXImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
615 BufferAllocationState state) { | 625 if (backbuffer_allocated_ == allocated) |
616 if (buffer_allocation_state_ == state) | |
617 return; | 626 return; |
618 buffer_allocation_state_ = state; | |
619 | 627 |
620 switch (state) { | 628 if (allocated) { |
621 case BUFFER_ALLOCATION_FRONT_AND_BACK: { | 629 // cannot allocate backbuffer without also allocating a frontbuffer. |
622 ResizeSurface(size_); | 630 ResizeSurface(size_); |
623 break; | 631 backbuffer_allocated_ = true; |
624 } | 632 frontbuffer_allocated_ = true; |
625 case BUFFER_ALLOCATION_FRONT_ONLY: { | 633 } else { |
626 ResizeSurface(gfx::Size(1,1)); | 634 ResizeSurface(gfx::Size(1,1)); |
627 break; | 635 backbuffer_allocated_ = false; |
628 } | |
629 case BUFFER_ALLOCATION_NONE: { | |
630 ResizeSurface(gfx::Size(1,1)); | |
631 if (bound_) | |
632 ReleaseSurface(); | |
633 break; | |
634 } | |
635 default: | |
636 NOTREACHED(); | |
637 } | 636 } |
638 } | 637 } |
639 | 638 |
| 639 void GLXImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
| 640 } |
| 641 |
640 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { | 642 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { |
641 Display* dpy = static_cast<Display*>(GetDisplay()); | 643 Display* dpy = static_cast<Display*>(GetDisplay()); |
642 XResizeWindow(dpy, window_, size.width(), size.height()); | 644 XResizeWindow(dpy, window_, size.width(), size.height()); |
643 glXWaitX(); | 645 glXWaitX(); |
644 // Seems necessary to perform a swap after a resize | 646 // Seems necessary to perform a swap after a resize |
645 // in order to resize the front and back buffers (Intel driver bug). | 647 // in order to resize the front and back buffers (Intel driver bug). |
646 // This doesn't always happen with scissoring enabled, so do it now. | 648 // This doesn't always happen with scissoring enabled, so do it now. |
647 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) | 649 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) |
648 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 650 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
649 needs_resize_ = true; | 651 needs_resize_ = true; |
650 } | 652 } |
651 | 653 |
652 void GLXImageTransportSurface::OnResize(gfx::Size size) { | 654 void GLXImageTransportSurface::OnResize(gfx::Size size) { |
653 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); | 655 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); |
654 size_ = size; | 656 size_ = size; |
655 ResizeSurface(size_); | 657 ResizeSurface(size_); |
656 } | 658 } |
657 | 659 |
658 bool GLXImageTransportSurface::SwapBuffers() { | 660 bool GLXImageTransportSurface::SwapBuffers() { |
| 661 DCHECK(backbuffer_allocated_); |
| 662 DCHECK(frontbuffer_allocated_); |
659 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 663 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
660 helper_->DeferToFence(base::Bind( | 664 helper_->DeferToFence(base::Bind( |
661 &GLXImageTransportSurface::SendBuffersSwapped, | 665 &GLXImageTransportSurface::SendBuffersSwapped, |
662 AsWeakPtr())); | 666 AsWeakPtr())); |
663 | 667 |
664 if (needs_resize_) { | 668 if (needs_resize_) { |
665 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 669 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
666 params.width = size_.width(); | 670 params.width = size_.width(); |
667 params.height = size_.height(); | 671 params.height = size_.height(); |
668 params.surface_handle = window_; | 672 params.surface_handle = window_; |
669 helper_->SendAcceleratedSurfaceNew(params); | 673 helper_->SendAcceleratedSurfaceNew(params); |
670 bound_ = true; | 674 bound_ = true; |
671 needs_resize_ = false; | 675 needs_resize_ = false; |
672 } | 676 } |
673 return true; | 677 return true; |
674 } | 678 } |
675 | 679 |
676 void GLXImageTransportSurface::SendBuffersSwapped() { | 680 void GLXImageTransportSurface::SendBuffersSwapped() { |
677 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 681 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
678 params.surface_handle = window_; | 682 params.surface_handle = window_; |
679 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 683 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
680 helper_->SetScheduled(false); | 684 helper_->SetScheduled(false); |
681 } | 685 } |
682 | 686 |
683 bool GLXImageTransportSurface::PostSubBuffer( | 687 bool GLXImageTransportSurface::PostSubBuffer( |
684 int x, int y, int width, int height) { | 688 int x, int y, int width, int height) { |
| 689 DCHECK(backbuffer_allocated_); |
| 690 DCHECK(frontbuffer_allocated_); |
685 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); | 691 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); |
686 helper_->DeferToFence(base::Bind( | 692 helper_->DeferToFence(base::Bind( |
687 &GLXImageTransportSurface::SendPostSubBuffer, | 693 &GLXImageTransportSurface::SendPostSubBuffer, |
688 AsWeakPtr(), x, y, width, height)); | 694 AsWeakPtr(), x, y, width, height)); |
689 | 695 |
690 if (needs_resize_) { | 696 if (needs_resize_) { |
691 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 697 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
692 params.width = size_.width(); | 698 params.width = size_.width(); |
693 params.height = size_.height(); | 699 params.height = size_.height(); |
694 params.surface_handle = window_; | 700 params.surface_handle = window_; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 context->SetSwapInterval(0); | 748 context->SetSwapInterval(0); |
743 | 749 |
744 made_current_ = true; | 750 made_current_ = true; |
745 return true; | 751 return true; |
746 } | 752 } |
747 | 753 |
748 void GLXImageTransportSurface::OnNewSurfaceACK( | 754 void GLXImageTransportSurface::OnNewSurfaceACK( |
749 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { | 755 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { |
750 } | 756 } |
751 | 757 |
| 758 void GLXImageTransportSurface::OnDiscardSurface( |
| 759 uint64 surface_id) { |
| 760 } |
| 761 |
752 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 762 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
753 helper_->SetScheduled(true); | 763 helper_->SetScheduled(true); |
754 } | 764 } |
755 | 765 |
756 void GLXImageTransportSurface::OnPostSubBufferACK() { | 766 void GLXImageTransportSurface::OnPostSubBufferACK() { |
757 helper_->SetScheduled(true); | 767 helper_->SetScheduled(true); |
758 } | 768 } |
759 | 769 |
760 void GLXImageTransportSurface::OnResizeViewACK() { | 770 void GLXImageTransportSurface::OnResizeViewACK() { |
761 NOTREACHED(); | 771 NOTREACHED(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 | 838 |
829 void OSMesaImageTransportSurface::OnNewSurfaceACK( | 839 void OSMesaImageTransportSurface::OnNewSurfaceACK( |
830 uint64 surface_handle, TransportDIB::Handle shm_handle) { | 840 uint64 surface_handle, TransportDIB::Handle shm_handle) { |
831 shared_id_ = surface_handle; | 841 shared_id_ = surface_handle; |
832 shared_mem_.reset(TransportDIB::Map(shm_handle)); | 842 shared_mem_.reset(TransportDIB::Map(shm_handle)); |
833 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 843 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
834 | 844 |
835 helper_->SetScheduled(true); | 845 helper_->SetScheduled(true); |
836 } | 846 } |
837 | 847 |
| 848 void OSMesaImageTransportSurface::OnDiscardSurface( |
| 849 uint64 surface_id) { |
| 850 } |
| 851 |
838 void OSMesaImageTransportSurface::OnResizeViewACK() { | 852 void OSMesaImageTransportSurface::OnResizeViewACK() { |
839 NOTREACHED(); | 853 NOTREACHED(); |
840 } | 854 } |
841 | 855 |
842 bool OSMesaImageTransportSurface::SwapBuffers() { | 856 bool OSMesaImageTransportSurface::SwapBuffers() { |
843 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 857 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
844 | 858 |
845 // Copy the OSMesa buffer to the shared memory | 859 // Copy the OSMesa buffer to the shared memory |
846 glFinish(); | 860 glFinish(); |
847 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); | 861 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 stub, | 953 stub, |
940 surface.get(), | 954 surface.get(), |
941 handle.transport); | 955 handle.transport); |
942 } | 956 } |
943 | 957 |
944 if (surface->Initialize()) | 958 if (surface->Initialize()) |
945 return surface; | 959 return surface; |
946 else | 960 else |
947 return NULL; | 961 return NULL; |
948 } | 962 } |
OLD | NEW |