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; |
105 virtual void OnResize(gfx::Size size) OVERRIDE; | 106 virtual void OnResize(gfx::Size size) OVERRIDE; |
106 | 107 |
107 private: | 108 private: |
108 virtual ~EGLImageTransportSurface() OVERRIDE; | 109 virtual ~EGLImageTransportSurface() OVERRIDE; |
109 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 110 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
110 void SendBuffersSwapped(); | 111 void SendBuffersSwapped(); |
111 void SendPostSubBuffer(int x, int y, int width, int height); | 112 void SendPostSubBuffer(int x, int y, int width, int height); |
112 | 113 |
113 // Tracks the current buffer allocation state. | 114 // Tracks the current buffer allocation state. |
114 BufferAllocationState buffer_allocation_state_; | 115 bool backbuffer_suggested_allocation_; |
116 bool frontbuffer_suggested_allocation_; | |
117 | |
118 // The expected size when visible. | |
119 gfx::Size visible_size_; | |
115 | 120 |
116 uint32 fbo_id_; | 121 uint32 fbo_id_; |
117 | 122 |
118 scoped_refptr<EGLAcceleratedSurface> back_surface_; | 123 scoped_refptr<EGLAcceleratedSurface> back_surface_; |
119 scoped_refptr<EGLAcceleratedSurface> front_surface_; | 124 scoped_refptr<EGLAcceleratedSurface> front_surface_; |
120 gfx::Rect previous_damage_rect_; | 125 gfx::Rect previous_damage_rect_; |
121 | 126 |
122 // Whether or not we've successfully made the surface current once. | 127 // Whether or not we've successfully made the surface current once. |
123 bool made_current_; | 128 bool made_current_; |
124 | 129 |
(...skipping 13 matching lines...) Expand all Loading... | |
138 GpuCommandBufferStub* stub); | 143 GpuCommandBufferStub* stub); |
139 | 144 |
140 // gfx::GLSurface implementation: | 145 // gfx::GLSurface implementation: |
141 virtual bool Initialize() OVERRIDE; | 146 virtual bool Initialize() OVERRIDE; |
142 virtual void Destroy() OVERRIDE; | 147 virtual void Destroy() OVERRIDE; |
143 virtual bool SwapBuffers() OVERRIDE; | 148 virtual bool SwapBuffers() OVERRIDE; |
144 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 149 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
145 virtual std::string GetExtensions(); | 150 virtual std::string GetExtensions(); |
146 virtual gfx::Size GetSize() OVERRIDE; | 151 virtual gfx::Size GetSize() OVERRIDE; |
147 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 152 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
148 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 153 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
154 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | |
149 | 155 |
150 protected: | 156 protected: |
151 // ImageTransportSurface implementation: | 157 // ImageTransportSurface implementation: |
152 virtual void OnNewSurfaceACK( | 158 virtual void OnNewSurfaceACK( |
153 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; | 159 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
154 virtual void OnBuffersSwappedACK() OVERRIDE; | 160 virtual void OnBuffersSwappedACK() OVERRIDE; |
155 virtual void OnPostSubBufferACK() OVERRIDE; | 161 virtual void OnPostSubBufferACK() OVERRIDE; |
156 virtual void OnResizeViewACK() OVERRIDE; | 162 virtual void OnResizeViewACK() OVERRIDE; |
157 virtual void OnResize(gfx::Size size) OVERRIDE; | 163 virtual void OnResize(gfx::Size size) OVERRIDE; |
158 | 164 |
159 private: | 165 private: |
160 virtual ~GLXImageTransportSurface(); | 166 virtual ~GLXImageTransportSurface(); |
161 | 167 |
162 // Tell the browser to release the surface. | 168 // Tell the browser to release the surface. |
163 void ReleaseSurface(); | 169 void ReleaseSurface(); |
164 | 170 |
165 void SendBuffersSwapped(); | 171 void SendBuffersSwapped(); |
166 void SendPostSubBuffer(int x, int y, int width, int height); | 172 void SendPostSubBuffer(int x, int y, int width, int height); |
167 | 173 |
168 void ResizeSurface(gfx::Size size); | 174 void ResizeSurface(gfx::Size size); |
169 | 175 |
170 // Tracks the current buffer allocation state. | 176 // Tracks the current buffer allocation state. |
171 BufferAllocationState buffer_allocation_state_; | 177 bool backbuffer_suggested_allocation_; |
178 bool frontbuffer_suggested_allocation_; | |
172 | 179 |
173 XID dummy_parent_; | 180 XID dummy_parent_; |
174 gfx::Size size_; | 181 gfx::Size size_; |
175 | 182 |
176 // Whether or not the image has been bound on the browser side. | 183 // Whether or not the image has been bound on the browser side. |
177 bool bound_; | 184 bool bound_; |
178 | 185 |
179 // Whether or not we need to send a resize on the next swap. | 186 // Whether or not we need to send a resize on the next swap. |
180 bool needs_resize_; | 187 bool needs_resize_; |
181 | 188 |
(...skipping 81 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_suggested_allocation_(true), |
281 frontbuffer_suggested_allocation_(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_suggested_allocation_ == allocated) |
341 if (buffer_allocation_state_ == state) | |
342 return; | 349 return; |
343 buffer_allocation_state_ = state; | 350 backbuffer_suggested_allocation_ = allocated; |
344 | 351 |
345 switch (state) { | 352 if (!!back_surface_.get() != backbuffer_suggested_allocation_) { |
jonathan.backer
2012/05/11 18:43:15
This check seems redundant (just testing my unders
mmocny
2012/05/14 17:10:36
Yes, you are right.
On 2012/05/11 18:43:15, jonath
| |
346 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 353 if (backbuffer_suggested_allocation_) |
347 if (!back_surface_.get() && front_surface_.get()) | 354 OnResize(visible_size_); |
348 OnResize(front_surface_->size()); | 355 else |
349 break; | 356 ReleaseSurface(&back_surface_); |
357 } | |
358 } | |
350 | 359 |
351 case BUFFER_ALLOCATION_FRONT_ONLY: | 360 void EGLImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
352 if (back_surface_.get() && front_surface_.get()) | 361 if (frontbuffer_suggested_allocation_ == allocated) |
353 ReleaseSurface(&back_surface_); | 362 return; |
354 break; | 363 frontbuffer_suggested_allocation_ = allocated; |
jonathan.backer
2012/05/11 18:43:15
Can we release the frontbuffer here?
mmocny
2012/05/14 17:10:36
We can -- but that should be a subsequent patch, r
| |
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 } | 364 } |
365 | 365 |
366 void EGLImageTransportSurface::ReleaseSurface( | 366 void EGLImageTransportSurface::ReleaseSurface( |
367 scoped_refptr<EGLAcceleratedSurface>* surface) { | 367 scoped_refptr<EGLAcceleratedSurface>* surface) { |
368 if (surface->get()) { | 368 if (surface->get()) { |
369 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 369 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
370 params.identifier = (*surface)->pixmap(); | 370 params.identifier = (*surface)->pixmap(); |
371 helper_->SendAcceleratedSurfaceRelease(params); | 371 helper_->SendAcceleratedSurfaceRelease(params); |
372 *surface = NULL; | 372 *surface = NULL; |
373 } | 373 } |
374 } | 374 } |
375 | 375 |
376 void EGLImageTransportSurface::OnResize(gfx::Size size) { | 376 void EGLImageTransportSurface::OnResize(gfx::Size size) { |
377 visible_size_ = size; | |
377 back_surface_ = new EGLAcceleratedSurface(size); | 378 back_surface_ = new EGLAcceleratedSurface(size); |
378 | 379 |
379 GLint previous_fbo_id = 0; | 380 GLint previous_fbo_id = 0; |
380 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previous_fbo_id); | 381 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previous_fbo_id); |
381 | 382 |
382 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); | 383 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); |
383 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 384 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
384 GL_COLOR_ATTACHMENT0, | 385 GL_COLOR_ATTACHMENT0, |
385 GL_TEXTURE_2D, | 386 GL_TEXTURE_2D, |
386 back_surface_->texture(), | 387 back_surface_->texture(), |
387 0); | 388 0); |
388 glFlush(); | 389 glFlush(); |
389 | 390 |
390 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previous_fbo_id); | 391 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previous_fbo_id); |
391 | 392 |
392 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 393 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
393 params.width = size.width(); | 394 params.width = size.width(); |
394 params.height = size.height(); | 395 params.height = size.height(); |
395 params.surface_handle = back_surface_->pixmap(); | 396 params.surface_handle = back_surface_->pixmap(); |
396 helper_->SendAcceleratedSurfaceNew(params); | 397 helper_->SendAcceleratedSurfaceNew(params); |
397 | 398 |
398 helper_->SetScheduled(false); | 399 helper_->SetScheduled(false); |
399 } | 400 } |
400 | 401 |
401 bool EGLImageTransportSurface::SwapBuffers() { | 402 bool EGLImageTransportSurface::SwapBuffers() { |
403 DCHECK(backbuffer_suggested_allocation_); | |
404 DCHECK(frontbuffer_suggested_allocation_); | |
402 front_surface_.swap(back_surface_); | 405 front_surface_.swap(back_surface_); |
403 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 406 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
404 helper_->DeferToFence(base::Bind( | 407 helper_->DeferToFence(base::Bind( |
405 &EGLImageTransportSurface::SendBuffersSwapped, | 408 &EGLImageTransportSurface::SendBuffersSwapped, |
406 AsWeakPtr())); | 409 AsWeakPtr())); |
407 | 410 |
408 gfx::Size expected_size = front_surface_->size(); | 411 gfx::Size expected_size = front_surface_->size(); |
409 if (!back_surface_.get() || back_surface_->size() != expected_size) { | 412 if (!back_surface_.get() || back_surface_->size() != expected_size) { |
410 OnResize(expected_size); | 413 OnResize(expected_size); |
411 } else { | 414 } else { |
412 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 415 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
413 GL_COLOR_ATTACHMENT0, | 416 GL_COLOR_ATTACHMENT0, |
414 GL_TEXTURE_2D, | 417 GL_TEXTURE_2D, |
415 back_surface_->texture(), | 418 back_surface_->texture(), |
416 0); | 419 0); |
417 } | 420 } |
418 previous_damage_rect_ = gfx::Rect(front_surface_->size()); | 421 previous_damage_rect_ = gfx::Rect(front_surface_->size()); |
419 return true; | 422 return true; |
420 } | 423 } |
421 | 424 |
422 void EGLImageTransportSurface::SendBuffersSwapped() { | 425 void EGLImageTransportSurface::SendBuffersSwapped() { |
423 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 426 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
424 params.surface_handle = front_surface_->pixmap(); | 427 params.surface_handle = front_surface_->pixmap(); |
425 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 428 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
426 helper_->SetScheduled(false); | 429 helper_->SetScheduled(false); |
427 } | 430 } |
428 | 431 |
429 bool EGLImageTransportSurface::PostSubBuffer( | 432 bool EGLImageTransportSurface::PostSubBuffer( |
430 int x, int y, int width, int height) { | 433 int x, int y, int width, int height) { |
431 | 434 DCHECK(backbuffer_suggested_allocation_); |
435 DCHECK(frontbuffer_suggested_allocation_); | |
432 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 436 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
433 gfx::Size expected_size = back_surface_->size(); | 437 gfx::Size expected_size = back_surface_->size(); |
434 bool surfaces_same_size = front_surface_.get() && | 438 bool surfaces_same_size = front_surface_.get() && |
435 front_surface_->size() == expected_size; | 439 front_surface_->size() == expected_size; |
436 | 440 |
437 const gfx::Rect new_damage_rect(x, y, width, height); | 441 const gfx::Rect new_damage_rect(x, y, width, height); |
438 | 442 |
439 // An empty damage rect is a successful no-op. | 443 // An empty damage rect is a successful no-op. |
440 if (new_damage_rect.IsEmpty()) | 444 if (new_damage_rect.IsEmpty()) |
441 return true; | 445 return true; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 } | 524 } |
521 | 525 |
522 void EGLImageTransportSurface::OnResizeViewACK() { | 526 void EGLImageTransportSurface::OnResizeViewACK() { |
523 NOTREACHED(); | 527 NOTREACHED(); |
524 } | 528 } |
525 | 529 |
526 GLXImageTransportSurface::GLXImageTransportSurface( | 530 GLXImageTransportSurface::GLXImageTransportSurface( |
527 GpuChannelManager* manager, | 531 GpuChannelManager* manager, |
528 GpuCommandBufferStub* stub) | 532 GpuCommandBufferStub* stub) |
529 : gfx::NativeViewGLSurfaceGLX(), | 533 : gfx::NativeViewGLSurfaceGLX(), |
530 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 534 backbuffer_suggested_allocation_(true), |
535 frontbuffer_suggested_allocation_(true), | |
531 dummy_parent_(0), | 536 dummy_parent_(0), |
532 size_(1, 1), | 537 size_(1, 1), |
533 bound_(false), | 538 bound_(false), |
534 needs_resize_(false), | 539 needs_resize_(false), |
535 made_current_(false) { | 540 made_current_(false) { |
536 helper_.reset(new ImageTransportHelper(this, | 541 helper_.reset(new ImageTransportHelper(this, |
537 manager, | 542 manager, |
538 stub, | 543 stub, |
539 gfx::kNullPluginWindow)); | 544 gfx::kNullPluginWindow)); |
540 } | 545 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 } | 609 } |
605 | 610 |
606 void GLXImageTransportSurface::ReleaseSurface() { | 611 void GLXImageTransportSurface::ReleaseSurface() { |
607 DCHECK(bound_); | 612 DCHECK(bound_); |
608 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 613 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
609 params.identifier = window_; | 614 params.identifier = window_; |
610 helper_->SendAcceleratedSurfaceRelease(params); | 615 helper_->SendAcceleratedSurfaceRelease(params); |
611 bound_ = false; | 616 bound_ = false; |
612 } | 617 } |
613 | 618 |
614 void GLXImageTransportSurface::SetBufferAllocation( | 619 void GLXImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
615 BufferAllocationState state) { | 620 if (backbuffer_suggested_allocation_ == allocated) |
616 if (buffer_allocation_state_ == state) | |
617 return; | 621 return; |
618 buffer_allocation_state_ = state; | 622 backbuffer_suggested_allocation_ = allocated; |
619 | 623 |
620 switch (state) { | 624 if (backbuffer_suggested_allocation_) |
621 case BUFFER_ALLOCATION_FRONT_AND_BACK: { | 625 ResizeSurface(size_); |
622 ResizeSurface(size_); | 626 else |
623 break; | 627 ResizeSurface(gfx::Size(1,1)); |
624 } | 628 } |
625 case BUFFER_ALLOCATION_FRONT_ONLY: { | 629 |
626 ResizeSurface(gfx::Size(1,1)); | 630 void GLXImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
627 break; | 631 if (frontbuffer_suggested_allocation_ == allocated) |
628 } | 632 return; |
629 case BUFFER_ALLOCATION_NONE: { | 633 frontbuffer_suggested_allocation_ = allocated; |
630 ResizeSurface(gfx::Size(1,1)); | 634 |
631 if (bound_) | 635 // We recreate frontbuffer by recreating backbuffer and swapping. |
632 ReleaseSurface(); | 636 // But we release frontbuffer by telling UI to release its handle on it. |
633 break; | 637 if (!frontbuffer_suggested_allocation_ && bound_) |
634 } | 638 ReleaseSurface(); |
635 default: | |
636 NOTREACHED(); | |
637 } | |
638 } | 639 } |
639 | 640 |
640 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { | 641 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { |
641 Display* dpy = static_cast<Display*>(GetDisplay()); | 642 Display* dpy = static_cast<Display*>(GetDisplay()); |
642 XResizeWindow(dpy, window_, size.width(), size.height()); | 643 XResizeWindow(dpy, window_, size.width(), size.height()); |
643 glXWaitX(); | 644 glXWaitX(); |
644 // Seems necessary to perform a swap after a resize | 645 // Seems necessary to perform a swap after a resize |
645 // in order to resize the front and back buffers (Intel driver bug). | 646 // 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. | 647 // 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) | 648 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) |
648 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 649 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
649 needs_resize_ = true; | 650 needs_resize_ = true; |
650 } | 651 } |
651 | 652 |
652 void GLXImageTransportSurface::OnResize(gfx::Size size) { | 653 void GLXImageTransportSurface::OnResize(gfx::Size size) { |
653 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); | 654 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); |
654 size_ = size; | 655 size_ = size; |
655 ResizeSurface(size_); | 656 ResizeSurface(size_); |
656 } | 657 } |
657 | 658 |
658 bool GLXImageTransportSurface::SwapBuffers() { | 659 bool GLXImageTransportSurface::SwapBuffers() { |
660 DCHECK(backbuffer_suggested_allocation_); | |
661 DCHECK(frontbuffer_suggested_allocation_); | |
659 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 662 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
660 helper_->DeferToFence(base::Bind( | 663 helper_->DeferToFence(base::Bind( |
661 &GLXImageTransportSurface::SendBuffersSwapped, | 664 &GLXImageTransportSurface::SendBuffersSwapped, |
662 AsWeakPtr())); | 665 AsWeakPtr())); |
663 | 666 |
664 if (needs_resize_) { | 667 if (needs_resize_) { |
665 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 668 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
666 params.width = size_.width(); | 669 params.width = size_.width(); |
667 params.height = size_.height(); | 670 params.height = size_.height(); |
668 params.surface_handle = window_; | 671 params.surface_handle = window_; |
669 helper_->SendAcceleratedSurfaceNew(params); | 672 helper_->SendAcceleratedSurfaceNew(params); |
670 bound_ = true; | 673 bound_ = true; |
671 needs_resize_ = false; | 674 needs_resize_ = false; |
672 } | 675 } |
673 return true; | 676 return true; |
674 } | 677 } |
675 | 678 |
676 void GLXImageTransportSurface::SendBuffersSwapped() { | 679 void GLXImageTransportSurface::SendBuffersSwapped() { |
677 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 680 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
678 params.surface_handle = window_; | 681 params.surface_handle = window_; |
679 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 682 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
680 helper_->SetScheduled(false); | 683 helper_->SetScheduled(false); |
681 } | 684 } |
682 | 685 |
683 bool GLXImageTransportSurface::PostSubBuffer( | 686 bool GLXImageTransportSurface::PostSubBuffer( |
684 int x, int y, int width, int height) { | 687 int x, int y, int width, int height) { |
688 DCHECK(backbuffer_suggested_allocation_); | |
689 DCHECK(frontbuffer_suggested_allocation_); | |
685 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); | 690 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); |
686 helper_->DeferToFence(base::Bind( | 691 helper_->DeferToFence(base::Bind( |
687 &GLXImageTransportSurface::SendPostSubBuffer, | 692 &GLXImageTransportSurface::SendPostSubBuffer, |
688 AsWeakPtr(), x, y, width, height)); | 693 AsWeakPtr(), x, y, width, height)); |
689 | 694 |
690 if (needs_resize_) { | 695 if (needs_resize_) { |
691 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 696 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
692 params.width = size_.width(); | 697 params.width = size_.width(); |
693 params.height = size_.height(); | 698 params.height = size_.height(); |
694 params.surface_handle = window_; | 699 params.surface_handle = window_; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 stub, | 944 stub, |
940 surface.get(), | 945 surface.get(), |
941 handle.transport); | 946 handle.transport); |
942 } | 947 } |
943 | 948 |
944 if (surface->Initialize()) | 949 if (surface->Initialize()) |
945 return surface; | 950 return surface; |
946 else | 951 else |
947 return NULL; | 952 return NULL; |
948 } | 953 } |
OLD | NEW |