| 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; |
| 103 virtual void OnReleaseSurfaceACK(uint64 surface_id, bool success) OVERRIDE; |
| 102 virtual void OnBuffersSwappedACK() OVERRIDE; | 104 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 103 virtual void OnPostSubBufferACK() OVERRIDE; | 105 virtual void OnPostSubBufferACK() OVERRIDE; |
| 104 virtual void OnResizeViewACK() OVERRIDE; | 106 virtual void OnResizeViewACK() 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; |
| 158 virtual void OnReleaseSurfaceACK(uint64 surface_id, bool success) OVERRIDE; |
| 154 virtual void OnBuffersSwappedACK() OVERRIDE; | 159 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 155 virtual void OnPostSubBufferACK() OVERRIDE; | 160 virtual void OnPostSubBufferACK() OVERRIDE; |
| 156 virtual void OnResizeViewACK() OVERRIDE; | 161 virtual void OnResizeViewACK() 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 20 matching lines...) Expand all Loading... |
| 202 virtual bool IsOffscreen() OVERRIDE; | 208 virtual bool IsOffscreen() OVERRIDE; |
| 203 virtual bool SwapBuffers() OVERRIDE; | 209 virtual bool SwapBuffers() OVERRIDE; |
| 204 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 210 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 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; |
| 218 virtual void OnReleaseSurfaceACK(uint64 surface_id, bool success) OVERRIDE; |
| 212 virtual void OnBuffersSwappedACK() OVERRIDE; | 219 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 213 virtual void OnPostSubBufferACK() OVERRIDE; | 220 virtual void OnPostSubBufferACK() OVERRIDE; |
| 214 virtual void OnResizeViewACK() OVERRIDE; | 221 virtual void OnResizeViewACK() 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(); |
| (...skipping 41 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(1, 1)), | 279 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 334 } |
| 327 | 335 |
| 328 made_current_ = true; | 336 made_current_ = true; |
| 329 return true; | 337 return true; |
| 330 } | 338 } |
| 331 | 339 |
| 332 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { | 340 unsigned int EGLImageTransportSurface::GetBackingFrameBufferObject() { |
| 333 return fbo_id_; | 341 return fbo_id_; |
| 334 } | 342 } |
| 335 | 343 |
| 336 void EGLImageTransportSurface::SetBufferAllocation( | 344 void EGLImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
| 337 BufferAllocationState state) { | 345 if (backbuffer_allocated_ == allocated) |
| 338 if (buffer_allocation_state_ == state) | |
| 339 return; | 346 return; |
| 340 buffer_allocation_state_ = state; | 347 // TODO(mmocny): Remove dependancy on front_surface_->size() |
| 348 if (!front_surface_.get()) |
| 349 return; |
| 341 | 350 |
| 342 switch (state) { | 351 if (allocated) { |
| 343 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 352 if (!back_surface_.get()) |
| 344 if (!back_surface_.get() && front_surface_.get()) | 353 OnResize(front_surface_->size()); |
| 345 OnResize(front_surface_->size()); | 354 backbuffer_allocated_ = true; |
| 346 break; | 355 } else { |
| 356 if (back_surface_.get()) |
| 357 ReleaseSurface(&back_surface_); |
| 358 backbuffer_allocated_ = false; |
| 359 } |
| 360 } |
| 347 | 361 |
| 348 case BUFFER_ALLOCATION_FRONT_ONLY: | 362 void EGLImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
| 349 if (back_surface_.get() && front_surface_.get()) | 363 // TODO(mmocny): Copy logic from texture image transport. |
| 350 ReleaseSurface(&back_surface_); | |
| 351 break; | |
| 352 | |
| 353 case BUFFER_ALLOCATION_NONE: | |
| 354 if (back_surface_.get() && front_surface_.get()) | |
| 355 ReleaseSurface(&back_surface_); | |
| 356 break; | |
| 357 | |
| 358 default: | |
| 359 NOTREACHED(); | |
| 360 } | |
| 361 } | 364 } |
| 362 | 365 |
| 363 void EGLImageTransportSurface::ReleaseSurface( | 366 void EGLImageTransportSurface::ReleaseSurface( |
| 364 scoped_refptr<EGLAcceleratedSurface>* surface) { | 367 scoped_refptr<EGLAcceleratedSurface>* surface) { |
| 365 if (surface->get()) { | 368 if (surface->get()) { |
| 366 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 369 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 367 params.identifier = (*surface)->pixmap(); | 370 params.identifier = (*surface)->pixmap(); |
| 368 helper_->SendAcceleratedSurfaceRelease(params); | 371 helper_->SendAcceleratedSurfaceRelease(params); |
| 369 *surface = NULL; | 372 *surface = NULL; |
| 370 } | 373 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 389 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 392 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 390 params.width = size.width(); | 393 params.width = size.width(); |
| 391 params.height = size.height(); | 394 params.height = size.height(); |
| 392 params.surface_handle = back_surface_->pixmap(); | 395 params.surface_handle = back_surface_->pixmap(); |
| 393 helper_->SendAcceleratedSurfaceNew(params); | 396 helper_->SendAcceleratedSurfaceNew(params); |
| 394 | 397 |
| 395 helper_->SetScheduled(false); | 398 helper_->SetScheduled(false); |
| 396 } | 399 } |
| 397 | 400 |
| 398 bool EGLImageTransportSurface::SwapBuffers() { | 401 bool EGLImageTransportSurface::SwapBuffers() { |
| 402 DCHECK(backbuffer_allocated_); |
| 403 DCHECK(frontbuffer_allocated_); |
| 399 front_surface_.swap(back_surface_); | 404 front_surface_.swap(back_surface_); |
| 400 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 405 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
| 401 helper_->DeferToFence(base::Bind( | 406 helper_->DeferToFence(base::Bind( |
| 402 &EGLImageTransportSurface::SendBuffersSwapped, | 407 &EGLImageTransportSurface::SendBuffersSwapped, |
| 403 AsWeakPtr())); | 408 AsWeakPtr())); |
| 404 | 409 |
| 405 gfx::Size expected_size = front_surface_->size(); | 410 gfx::Size expected_size = front_surface_->size(); |
| 406 if (!back_surface_.get() || back_surface_->size() != expected_size) { | 411 if (!back_surface_.get() || back_surface_->size() != expected_size) { |
| 407 OnResize(expected_size); | 412 OnResize(expected_size); |
| 408 } else { | 413 } else { |
| 409 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 414 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 410 GL_COLOR_ATTACHMENT0, | 415 GL_COLOR_ATTACHMENT0, |
| 411 GL_TEXTURE_2D, | 416 GL_TEXTURE_2D, |
| 412 back_surface_->texture(), | 417 back_surface_->texture(), |
| 413 0); | 418 0); |
| 414 } | 419 } |
| 415 previous_damage_rect_ = gfx::Rect(front_surface_->size()); | 420 previous_damage_rect_ = gfx::Rect(front_surface_->size()); |
| 416 return true; | 421 return true; |
| 417 } | 422 } |
| 418 | 423 |
| 419 void EGLImageTransportSurface::SendBuffersSwapped() { | 424 void EGLImageTransportSurface::SendBuffersSwapped() { |
| 420 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 425 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 421 params.surface_handle = front_surface_->pixmap(); | 426 params.surface_handle = front_surface_->pixmap(); |
| 422 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 427 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 423 helper_->SetScheduled(false); | 428 helper_->SetScheduled(false); |
| 424 } | 429 } |
| 425 | 430 |
| 426 bool EGLImageTransportSurface::PostSubBuffer( | 431 bool EGLImageTransportSurface::PostSubBuffer( |
| 427 int x, int y, int width, int height) { | 432 int x, int y, int width, int height) { |
| 428 | 433 DCHECK(backbuffer_allocated_); |
| 434 DCHECK(frontbuffer_allocated_); |
| 429 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 435 DCHECK_NE(back_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
| 430 gfx::Size expected_size = back_surface_->size(); | 436 gfx::Size expected_size = back_surface_->size(); |
| 431 bool surfaces_same_size = front_surface_.get() && | 437 bool surfaces_same_size = front_surface_.get() && |
| 432 front_surface_->size() == expected_size; | 438 front_surface_->size() == expected_size; |
| 433 | 439 |
| 434 const gfx::Rect new_damage_rect(x, y, width, height); | 440 const gfx::Rect new_damage_rect(x, y, width, height); |
| 435 | 441 |
| 436 // An empty damage rect is a successful no-op. | 442 // An empty damage rect is a successful no-op. |
| 437 if (new_damage_rect.IsEmpty()) | 443 if (new_damage_rect.IsEmpty()) |
| 438 return true; | 444 return true; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 gfx::Size EGLImageTransportSurface::GetSize() { | 507 gfx::Size EGLImageTransportSurface::GetSize() { |
| 502 return back_surface_->size(); | 508 return back_surface_->size(); |
| 503 } | 509 } |
| 504 | 510 |
| 505 void EGLImageTransportSurface::OnNewSurfaceACK( | 511 void EGLImageTransportSurface::OnNewSurfaceACK( |
| 506 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { | 512 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { |
| 507 DCHECK_EQ(back_surface_->pixmap(), surface_handle); | 513 DCHECK_EQ(back_surface_->pixmap(), surface_handle); |
| 508 helper_->SetScheduled(true); | 514 helper_->SetScheduled(true); |
| 509 } | 515 } |
| 510 | 516 |
| 517 void EGLImageTransportSurface::OnReleaseSurfaceACK( |
| 518 uint64 surface_id, bool success) { |
| 519 } |
| 520 |
| 511 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 521 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
| 512 helper_->SetScheduled(true); | 522 helper_->SetScheduled(true); |
| 513 } | 523 } |
| 514 | 524 |
| 515 void EGLImageTransportSurface::OnPostSubBufferACK() { | 525 void EGLImageTransportSurface::OnPostSubBufferACK() { |
| 516 helper_->SetScheduled(true); | 526 helper_->SetScheduled(true); |
| 517 } | 527 } |
| 518 | 528 |
| 519 void EGLImageTransportSurface::OnResizeViewACK() { | 529 void EGLImageTransportSurface::OnResizeViewACK() { |
| 520 NOTREACHED(); | 530 NOTREACHED(); |
| 521 } | 531 } |
| 522 | 532 |
| 523 GLXImageTransportSurface::GLXImageTransportSurface( | 533 GLXImageTransportSurface::GLXImageTransportSurface( |
| 524 GpuChannelManager* manager, | 534 GpuChannelManager* manager, |
| 525 GpuCommandBufferStub* stub) | 535 GpuCommandBufferStub* stub) |
| 526 : gfx::NativeViewGLSurfaceGLX(), | 536 : gfx::NativeViewGLSurfaceGLX(), |
| 527 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK), | 537 backbuffer_allocated_(true), |
| 538 frontbuffer_allocated_(true), |
| 528 dummy_parent_(0), | 539 dummy_parent_(0), |
| 529 size_(1, 1), | 540 size_(1, 1), |
| 530 bound_(false), | 541 bound_(false), |
| 531 needs_resize_(false), | 542 needs_resize_(false), |
| 532 made_current_(false) { | 543 made_current_(false) { |
| 533 helper_.reset(new ImageTransportHelper(this, | 544 helper_.reset(new ImageTransportHelper(this, |
| 534 manager, | 545 manager, |
| 535 stub, | 546 stub, |
| 536 gfx::kNullPluginWindow)); | 547 gfx::kNullPluginWindow)); |
| 537 } | 548 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 612 } |
| 602 | 613 |
| 603 void GLXImageTransportSurface::ReleaseSurface() { | 614 void GLXImageTransportSurface::ReleaseSurface() { |
| 604 DCHECK(bound_); | 615 DCHECK(bound_); |
| 605 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 616 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
| 606 params.identifier = window_; | 617 params.identifier = window_; |
| 607 helper_->SendAcceleratedSurfaceRelease(params); | 618 helper_->SendAcceleratedSurfaceRelease(params); |
| 608 bound_ = false; | 619 bound_ = false; |
| 609 } | 620 } |
| 610 | 621 |
| 611 void GLXImageTransportSurface::SetBufferAllocation( | 622 void GLXImageTransportSurface::SetBackbufferAllocation(bool allocated) { |
| 612 BufferAllocationState state) { | 623 if (backbuffer_allocated_ == allocated) |
| 613 if (buffer_allocation_state_ == state) | |
| 614 return; | 624 return; |
| 615 buffer_allocation_state_ = state; | |
| 616 | 625 |
| 617 switch (state) { | 626 if (allocated) { |
| 618 case BUFFER_ALLOCATION_FRONT_AND_BACK: { | 627 // cannot allocate backbuffer without also allocating a frontbuffer. |
| 619 ResizeSurface(size_); | 628 ResizeSurface(size_); |
| 620 break; | 629 backbuffer_allocated_ = true; |
| 621 } | 630 frontbuffer_allocated_ = true; |
| 622 case BUFFER_ALLOCATION_FRONT_ONLY: { | 631 } else { |
| 623 ResizeSurface(gfx::Size(1,1)); | 632 ResizeSurface(gfx::Size(1,1)); |
| 624 break; | 633 backbuffer_allocated_ = false; |
| 625 } | |
| 626 case BUFFER_ALLOCATION_NONE: { | |
| 627 ResizeSurface(gfx::Size(1,1)); | |
| 628 if (bound_) | |
| 629 ReleaseSurface(); | |
| 630 break; | |
| 631 } | |
| 632 default: | |
| 633 NOTREACHED(); | |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 | 636 |
| 637 void GLXImageTransportSurface::SetFrontbufferAllocation(bool allocated) { |
| 638 } |
| 639 |
| 637 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { | 640 void GLXImageTransportSurface::ResizeSurface(gfx::Size size) { |
| 638 Display* dpy = static_cast<Display*>(GetDisplay()); | 641 Display* dpy = static_cast<Display*>(GetDisplay()); |
| 639 XResizeWindow(dpy, window_, size.width(), size.height()); | 642 XResizeWindow(dpy, window_, size.width(), size.height()); |
| 640 glXWaitX(); | 643 glXWaitX(); |
| 641 // Seems necessary to perform a swap after a resize | 644 // Seems necessary to perform a swap after a resize |
| 642 // in order to resize the front and back buffers (Intel driver bug). | 645 // in order to resize the front and back buffers (Intel driver bug). |
| 643 // This doesn't always happen with scissoring enabled, so do it now. | 646 // This doesn't always happen with scissoring enabled, so do it now. |
| 644 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) | 647 if (gfx::g_GLX_MESA_copy_sub_buffer && gfx::GLSurface::GetCurrent() == this) |
| 645 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 648 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 646 needs_resize_ = true; | 649 needs_resize_ = true; |
| 647 } | 650 } |
| 648 | 651 |
| 649 void GLXImageTransportSurface::OnResize(gfx::Size size) { | 652 void GLXImageTransportSurface::OnResize(gfx::Size size) { |
| 650 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); | 653 TRACE_EVENT0("gpu", "GLXImageTransportSurface::OnResize"); |
| 651 size_ = size; | 654 size_ = size; |
| 652 ResizeSurface(size_); | 655 ResizeSurface(size_); |
| 653 } | 656 } |
| 654 | 657 |
| 655 bool GLXImageTransportSurface::SwapBuffers() { | 658 bool GLXImageTransportSurface::SwapBuffers() { |
| 659 DCHECK(backbuffer_allocated_); |
| 660 DCHECK(frontbuffer_allocated_); |
| 656 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 661 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 657 helper_->DeferToFence(base::Bind( | 662 helper_->DeferToFence(base::Bind( |
| 658 &GLXImageTransportSurface::SendBuffersSwapped, | 663 &GLXImageTransportSurface::SendBuffersSwapped, |
| 659 AsWeakPtr())); | 664 AsWeakPtr())); |
| 660 | 665 |
| 661 if (needs_resize_) { | 666 if (needs_resize_) { |
| 662 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 667 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 663 params.width = size_.width(); | 668 params.width = size_.width(); |
| 664 params.height = size_.height(); | 669 params.height = size_.height(); |
| 665 params.surface_handle = window_; | 670 params.surface_handle = window_; |
| 666 helper_->SendAcceleratedSurfaceNew(params); | 671 helper_->SendAcceleratedSurfaceNew(params); |
| 667 bound_ = true; | 672 bound_ = true; |
| 668 needs_resize_ = false; | 673 needs_resize_ = false; |
| 669 } | 674 } |
| 670 return true; | 675 return true; |
| 671 } | 676 } |
| 672 | 677 |
| 673 void GLXImageTransportSurface::SendBuffersSwapped() { | 678 void GLXImageTransportSurface::SendBuffersSwapped() { |
| 674 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 679 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 675 params.surface_handle = window_; | 680 params.surface_handle = window_; |
| 676 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 681 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 677 helper_->SetScheduled(false); | 682 helper_->SetScheduled(false); |
| 678 } | 683 } |
| 679 | 684 |
| 680 bool GLXImageTransportSurface::PostSubBuffer( | 685 bool GLXImageTransportSurface::PostSubBuffer( |
| 681 int x, int y, int width, int height) { | 686 int x, int y, int width, int height) { |
| 687 DCHECK(backbuffer_allocated_); |
| 688 DCHECK(frontbuffer_allocated_); |
| 682 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); | 689 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); |
| 683 helper_->DeferToFence(base::Bind( | 690 helper_->DeferToFence(base::Bind( |
| 684 &GLXImageTransportSurface::SendPostSubBuffer, | 691 &GLXImageTransportSurface::SendPostSubBuffer, |
| 685 AsWeakPtr(), x, y, width, height)); | 692 AsWeakPtr(), x, y, width, height)); |
| 686 | 693 |
| 687 if (needs_resize_) { | 694 if (needs_resize_) { |
| 688 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 695 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 689 params.width = size_.width(); | 696 params.width = size_.width(); |
| 690 params.height = size_.height(); | 697 params.height = size_.height(); |
| 691 params.surface_handle = window_; | 698 params.surface_handle = window_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 context->SetSwapInterval(0); | 746 context->SetSwapInterval(0); |
| 740 | 747 |
| 741 made_current_ = true; | 748 made_current_ = true; |
| 742 return true; | 749 return true; |
| 743 } | 750 } |
| 744 | 751 |
| 745 void GLXImageTransportSurface::OnNewSurfaceACK( | 752 void GLXImageTransportSurface::OnNewSurfaceACK( |
| 746 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { | 753 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { |
| 747 } | 754 } |
| 748 | 755 |
| 756 void GLXImageTransportSurface::OnReleaseSurfaceACK( |
| 757 uint64 surface_id, bool success) { |
| 758 } |
| 759 |
| 749 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 760 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
| 750 helper_->SetScheduled(true); | 761 helper_->SetScheduled(true); |
| 751 } | 762 } |
| 752 | 763 |
| 753 void GLXImageTransportSurface::OnPostSubBufferACK() { | 764 void GLXImageTransportSurface::OnPostSubBufferACK() { |
| 754 helper_->SetScheduled(true); | 765 helper_->SetScheduled(true); |
| 755 } | 766 } |
| 756 | 767 |
| 757 void GLXImageTransportSurface::OnResizeViewACK() { | 768 void GLXImageTransportSurface::OnResizeViewACK() { |
| 758 NOTREACHED(); | 769 NOTREACHED(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 836 |
| 826 void OSMesaImageTransportSurface::OnNewSurfaceACK( | 837 void OSMesaImageTransportSurface::OnNewSurfaceACK( |
| 827 uint64 surface_handle, TransportDIB::Handle shm_handle) { | 838 uint64 surface_handle, TransportDIB::Handle shm_handle) { |
| 828 shared_id_ = surface_handle; | 839 shared_id_ = surface_handle; |
| 829 shared_mem_.reset(TransportDIB::Map(shm_handle)); | 840 shared_mem_.reset(TransportDIB::Map(shm_handle)); |
| 830 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 841 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
| 831 | 842 |
| 832 helper_->SetScheduled(true); | 843 helper_->SetScheduled(true); |
| 833 } | 844 } |
| 834 | 845 |
| 846 void OSMesaImageTransportSurface::OnReleaseSurfaceACK( |
| 847 uint64 surface_id, bool success) { |
| 848 } |
| 849 |
| 835 void OSMesaImageTransportSurface::OnResizeViewACK() { | 850 void OSMesaImageTransportSurface::OnResizeViewACK() { |
| 836 NOTREACHED(); | 851 NOTREACHED(); |
| 837 } | 852 } |
| 838 | 853 |
| 839 bool OSMesaImageTransportSurface::SwapBuffers() { | 854 bool OSMesaImageTransportSurface::SwapBuffers() { |
| 840 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 855 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
| 841 | 856 |
| 842 // Copy the OSMesa buffer to the shared memory | 857 // Copy the OSMesa buffer to the shared memory |
| 843 glFinish(); | 858 glFinish(); |
| 844 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); | 859 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 stub, | 951 stub, |
| 937 surface.get(), | 952 surface.get(), |
| 938 handle.transport); | 953 handle.transport); |
| 939 } | 954 } |
| 940 | 955 |
| 941 if (surface->Initialize()) | 956 if (surface->Initialize()) |
| 942 return surface; | 957 return surface; |
| 943 else | 958 else |
| 944 return NULL; | 959 return NULL; |
| 945 } | 960 } |
| OLD | NEW |