| 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
| 6 | 6 |
| 7 #include "content/common/gpu/image_transport_surface.h" | 7 #include "content/common/gpu/image_transport_surface.h" |
| 8 | 8 |
| 9 // This conflicts with the defines in Xlib.h and must come first. | 9 // This conflicts with the defines in Xlib.h and must come first. |
| 10 #include "content/common/gpu/gpu_messages.h" | 10 #include "content/common/gpu/gpu_messages.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // We are backed by an Pbuffer offscreen surface for the purposes of creating a | 56 // We are backed by an Pbuffer offscreen surface for the purposes of creating a |
| 57 // context, but use FBOs to render to X Pixmap backed EGLImages. | 57 // context, but use FBOs to render to X Pixmap backed EGLImages. |
| 58 class EGLImageTransportSurface | 58 class EGLImageTransportSurface |
| 59 : public ImageTransportSurface, | 59 : public ImageTransportSurface, |
| 60 public gfx::PbufferGLSurfaceEGL, | 60 public gfx::PbufferGLSurfaceEGL, |
| 61 public base::SupportsWeakPtr<EGLImageTransportSurface> { | 61 public base::SupportsWeakPtr<EGLImageTransportSurface> { |
| 62 public: | 62 public: |
| 63 EGLImageTransportSurface(GpuChannelManager* manager, | 63 EGLImageTransportSurface(GpuChannelManager* manager, |
| 64 int32 render_view_id, | 64 GpuCommandBufferStub* stub); |
| 65 int32 client_id, | |
| 66 int32 command_buffer_id); | |
| 67 | 65 |
| 68 // gfx::GLSurface implementation | 66 // gfx::GLSurface implementation |
| 69 virtual bool Initialize() OVERRIDE; | 67 virtual bool Initialize() OVERRIDE; |
| 70 virtual void Destroy() OVERRIDE; | 68 virtual void Destroy() OVERRIDE; |
| 71 virtual bool IsOffscreen() OVERRIDE; | 69 virtual bool IsOffscreen() OVERRIDE; |
| 72 virtual bool SwapBuffers() OVERRIDE; | 70 virtual bool SwapBuffers() OVERRIDE; |
| 73 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 71 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 74 virtual std::string GetExtensions() OVERRIDE; | 72 virtual std::string GetExtensions() OVERRIDE; |
| 75 virtual gfx::Size GetSize() OVERRIDE; | 73 virtual gfx::Size GetSize() OVERRIDE; |
| 76 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 74 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 77 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 75 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
| 78 virtual void SetVisible(bool visible) OVERRIDE; | 76 virtual void SetVisible(bool visible) OVERRIDE; |
| 79 | 77 |
| 80 protected: | 78 protected: |
| 81 // ImageTransportSurface implementation | 79 // ImageTransportSurface implementation |
| 82 virtual void OnNewSurfaceACK( | 80 virtual void OnNewSurfaceACK( |
| 83 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 81 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
| 84 virtual void OnBuffersSwappedACK() OVERRIDE; | 82 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 85 virtual void OnPostSubBufferACK() OVERRIDE; | 83 virtual void OnPostSubBufferACK() OVERRIDE; |
| 86 virtual void OnResizeViewACK() OVERRIDE; | 84 virtual void OnResizeViewACK() OVERRIDE; |
| 87 virtual void OnResize(gfx::Size size) OVERRIDE; | 85 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 88 | 86 |
| 89 private: | 87 private: |
| 90 virtual ~EGLImageTransportSurface() OVERRIDE; | 88 virtual ~EGLImageTransportSurface() OVERRIDE; |
| 91 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); | 89 void ReleaseSurface(scoped_refptr<EGLAcceleratedSurface>* surface); |
| 92 void SendBuffersSwapped(); | 90 void SendBuffersSwapped(); |
| 93 | 91 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 105 }; | 103 }; |
| 106 | 104 |
| 107 // We render to an off-screen (but mapped) window that the browser process will | 105 // We render to an off-screen (but mapped) window that the browser process will |
| 108 // read from via XComposite | 106 // read from via XComposite |
| 109 class GLXImageTransportSurface | 107 class GLXImageTransportSurface |
| 110 : public ImageTransportSurface, | 108 : public ImageTransportSurface, |
| 111 public gfx::NativeViewGLSurfaceGLX, | 109 public gfx::NativeViewGLSurfaceGLX, |
| 112 public base::SupportsWeakPtr<GLXImageTransportSurface> { | 110 public base::SupportsWeakPtr<GLXImageTransportSurface> { |
| 113 public: | 111 public: |
| 114 GLXImageTransportSurface(GpuChannelManager* manager, | 112 GLXImageTransportSurface(GpuChannelManager* manager, |
| 115 int32 render_view_id, | 113 GpuCommandBufferStub* stub); |
| 116 int32 client_id, | |
| 117 int32 command_buffer_id); | |
| 118 | 114 |
| 119 // gfx::GLSurface implementation: | 115 // gfx::GLSurface implementation: |
| 120 virtual bool Initialize() OVERRIDE; | 116 virtual bool Initialize() OVERRIDE; |
| 121 virtual void Destroy() OVERRIDE; | 117 virtual void Destroy() OVERRIDE; |
| 122 virtual bool SwapBuffers() OVERRIDE; | 118 virtual bool SwapBuffers() OVERRIDE; |
| 123 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 119 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 124 virtual std::string GetExtensions(); | 120 virtual std::string GetExtensions(); |
| 125 virtual gfx::Size GetSize() OVERRIDE; | 121 virtual gfx::Size GetSize() OVERRIDE; |
| 126 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 122 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 127 virtual void SetVisible(bool visible) OVERRIDE; | 123 virtual void SetVisible(bool visible) OVERRIDE; |
| 128 | 124 |
| 129 protected: | 125 protected: |
| 130 // ImageTransportSurface implementation: | 126 // ImageTransportSurface implementation: |
| 131 virtual void OnNewSurfaceACK( | 127 virtual void OnNewSurfaceACK( |
| 132 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 128 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
| 133 virtual void OnBuffersSwappedACK() OVERRIDE; | 129 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 134 virtual void OnPostSubBufferACK() OVERRIDE; | 130 virtual void OnPostSubBufferACK() OVERRIDE; |
| 135 virtual void OnResizeViewACK() OVERRIDE; | 131 virtual void OnResizeViewACK() OVERRIDE; |
| 136 virtual void OnResize(gfx::Size size) OVERRIDE; | 132 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 137 | 133 |
| 138 private: | 134 private: |
| 139 virtual ~GLXImageTransportSurface(); | 135 virtual ~GLXImageTransportSurface(); |
| 140 | 136 |
| 141 // Tell the browser to release the surface. | 137 // Tell the browser to release the surface. |
| 142 void ReleaseSurface(); | 138 void ReleaseSurface(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 161 DISALLOW_COPY_AND_ASSIGN(GLXImageTransportSurface); | 157 DISALLOW_COPY_AND_ASSIGN(GLXImageTransportSurface); |
| 162 }; | 158 }; |
| 163 | 159 |
| 164 // We render to a hunk of shared memory that we get from the browser. | 160 // We render to a hunk of shared memory that we get from the browser. |
| 165 // Swapping buffers simply means telling the browser to read the contents | 161 // Swapping buffers simply means telling the browser to read the contents |
| 166 // of the memory. | 162 // of the memory. |
| 167 class OSMesaImageTransportSurface : public ImageTransportSurface, | 163 class OSMesaImageTransportSurface : public ImageTransportSurface, |
| 168 public gfx::GLSurfaceOSMesa { | 164 public gfx::GLSurfaceOSMesa { |
| 169 public: | 165 public: |
| 170 OSMesaImageTransportSurface(GpuChannelManager* manager, | 166 OSMesaImageTransportSurface(GpuChannelManager* manager, |
| 171 int32 render_view_id, | 167 GpuCommandBufferStub* stub); |
| 172 int32 client_id, | |
| 173 int32 command_buffer_id); | |
| 174 | 168 |
| 175 // gfx::GLSurface implementation: | 169 // gfx::GLSurface implementation: |
| 176 virtual bool Initialize() OVERRIDE; | 170 virtual bool Initialize() OVERRIDE; |
| 177 virtual void Destroy() OVERRIDE; | 171 virtual void Destroy() OVERRIDE; |
| 178 virtual bool IsOffscreen() OVERRIDE; | 172 virtual bool IsOffscreen() OVERRIDE; |
| 179 virtual bool SwapBuffers() OVERRIDE; | 173 virtual bool SwapBuffers() OVERRIDE; |
| 180 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 174 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 181 virtual std::string GetExtensions() OVERRIDE; | 175 virtual std::string GetExtensions() OVERRIDE; |
| 182 virtual gfx::Size GetSize() OVERRIDE; | 176 virtual gfx::Size GetSize() OVERRIDE; |
| 183 | 177 |
| 184 protected: | 178 protected: |
| 185 // ImageTransportSurface implementation: | 179 // ImageTransportSurface implementation: |
| 186 virtual void OnNewSurfaceACK( | 180 virtual void OnNewSurfaceACK( |
| 187 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | 181 uint64 surface_handle, TransportDIB::Handle shm_handle) OVERRIDE; |
| 188 virtual void OnBuffersSwappedACK() OVERRIDE; | 182 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 189 virtual void OnPostSubBufferACK() OVERRIDE; | 183 virtual void OnPostSubBufferACK() OVERRIDE; |
| 190 virtual void OnResizeViewACK() OVERRIDE; | 184 virtual void OnResizeViewACK() OVERRIDE; |
| 191 virtual void OnResize(gfx::Size size) OVERRIDE; | 185 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 192 | 186 |
| 193 private: | 187 private: |
| 194 virtual ~OSMesaImageTransportSurface(); | 188 virtual ~OSMesaImageTransportSurface(); |
| 195 | 189 |
| 196 // Tell the browser to release the surface. | 190 // Tell the browser to release the surface. |
| 197 void ReleaseSurface(); | 191 void ReleaseSurface(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 } | 231 } |
| 238 | 232 |
| 239 EGLAcceleratedSurface::~EGLAcceleratedSurface() { | 233 EGLAcceleratedSurface::~EGLAcceleratedSurface() { |
| 240 glDeleteTextures(1, &texture_); | 234 glDeleteTextures(1, &texture_); |
| 241 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 235 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
| 242 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); | 236 XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_); |
| 243 } | 237 } |
| 244 | 238 |
| 245 EGLImageTransportSurface::EGLImageTransportSurface( | 239 EGLImageTransportSurface::EGLImageTransportSurface( |
| 246 GpuChannelManager* manager, | 240 GpuChannelManager* manager, |
| 247 int32 render_view_id, | 241 GpuCommandBufferStub* stub) |
| 248 int32 client_id, | 242 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), |
| 249 int32 command_buffer_id) | 243 fbo_id_(0), |
| 250 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), | 244 made_current_(false) { |
| 251 fbo_id_(0), | |
| 252 made_current_(false) { | |
| 253 helper_.reset(new ImageTransportHelper(this, | 245 helper_.reset(new ImageTransportHelper(this, |
| 254 manager, | 246 manager, |
| 255 render_view_id, | 247 stub, |
| 256 client_id, | |
| 257 command_buffer_id, | |
| 258 gfx::kNullPluginWindow)); | 248 gfx::kNullPluginWindow)); |
| 259 } | 249 } |
| 260 | 250 |
| 261 EGLImageTransportSurface::~EGLImageTransportSurface() { | 251 EGLImageTransportSurface::~EGLImageTransportSurface() { |
| 262 Destroy(); | 252 Destroy(); |
| 263 } | 253 } |
| 264 | 254 |
| 265 bool EGLImageTransportSurface::Initialize() { | 255 bool EGLImageTransportSurface::Initialize() { |
| 266 if (!helper_->Initialize()) | 256 if (!helper_->Initialize()) |
| 267 return false; | 257 return false; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 GL_TEXTURE_2D, | 336 GL_TEXTURE_2D, |
| 347 back_surface_->texture(), | 337 back_surface_->texture(), |
| 348 0); | 338 0); |
| 349 glFlush(); | 339 glFlush(); |
| 350 | 340 |
| 351 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previous_fbo_id); | 341 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previous_fbo_id); |
| 352 | 342 |
| 353 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 343 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 354 params.width = size.width(); | 344 params.width = size.width(); |
| 355 params.height = size.height(); | 345 params.height = size.height(); |
| 356 params.surface_id = back_surface_->pixmap(); | 346 params.surface_handle = back_surface_->pixmap(); |
| 357 helper_->SendAcceleratedSurfaceNew(params); | 347 helper_->SendAcceleratedSurfaceNew(params); |
| 358 | 348 |
| 359 helper_->SetScheduled(false); | 349 helper_->SetScheduled(false); |
| 360 } | 350 } |
| 361 | 351 |
| 362 bool EGLImageTransportSurface::SwapBuffers() { | 352 bool EGLImageTransportSurface::SwapBuffers() { |
| 363 front_surface_.swap(back_surface_); | 353 front_surface_.swap(back_surface_); |
| 364 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); | 354 DCHECK_NE(front_surface_.get(), static_cast<EGLAcceleratedSurface*>(NULL)); |
| 365 helper_->DeferToFence(base::Bind( | 355 helper_->DeferToFence(base::Bind( |
| 366 &EGLImageTransportSurface::SendBuffersSwapped, | 356 &EGLImageTransportSurface::SendBuffersSwapped, |
| 367 AsWeakPtr())); | 357 AsWeakPtr())); |
| 368 | 358 |
| 369 gfx::Size expected_size = front_surface_->size(); | 359 gfx::Size expected_size = front_surface_->size(); |
| 370 if (!back_surface_.get() || back_surface_->size() != expected_size) { | 360 if (!back_surface_.get() || back_surface_->size() != expected_size) { |
| 371 OnResize(expected_size); | 361 OnResize(expected_size); |
| 372 } else { | 362 } else { |
| 373 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 363 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 374 GL_COLOR_ATTACHMENT0, | 364 GL_COLOR_ATTACHMENT0, |
| 375 GL_TEXTURE_2D, | 365 GL_TEXTURE_2D, |
| 376 back_surface_->texture(), | 366 back_surface_->texture(), |
| 377 0); | 367 0); |
| 378 } | 368 } |
| 379 return true; | 369 return true; |
| 380 } | 370 } |
| 381 | 371 |
| 382 void EGLImageTransportSurface::SendBuffersSwapped() { | 372 void EGLImageTransportSurface::SendBuffersSwapped() { |
| 383 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 373 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 384 params.surface_id = front_surface_->pixmap(); | 374 params.surface_handle = front_surface_->pixmap(); |
| 385 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 375 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 386 helper_->SetScheduled(false); | 376 helper_->SetScheduled(false); |
| 387 } | 377 } |
| 388 | 378 |
| 389 bool EGLImageTransportSurface::PostSubBuffer( | 379 bool EGLImageTransportSurface::PostSubBuffer( |
| 390 int x, int y, int width, int height) { | 380 int x, int y, int width, int height) { |
| 391 NOTREACHED(); | 381 NOTREACHED(); |
| 392 return false; | 382 return false; |
| 393 } | 383 } |
| 394 | 384 |
| 395 std::string EGLImageTransportSurface::GetExtensions() { | 385 std::string EGLImageTransportSurface::GetExtensions() { |
| 396 std::string extensions = gfx::GLSurface::GetExtensions(); | 386 std::string extensions = gfx::GLSurface::GetExtensions(); |
| 397 extensions += extensions.empty() ? "" : " "; | 387 extensions += extensions.empty() ? "" : " "; |
| 398 extensions += "GL_CHROMIUM_front_buffer_cached"; | 388 extensions += "GL_CHROMIUM_front_buffer_cached"; |
| 399 return extensions; | 389 return extensions; |
| 400 } | 390 } |
| 401 | 391 |
| 402 gfx::Size EGLImageTransportSurface::GetSize() { | 392 gfx::Size EGLImageTransportSurface::GetSize() { |
| 403 return back_surface_->size(); | 393 return back_surface_->size(); |
| 404 } | 394 } |
| 405 | 395 |
| 406 void EGLImageTransportSurface::OnNewSurfaceACK( | 396 void EGLImageTransportSurface::OnNewSurfaceACK( |
| 407 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 397 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { |
| 408 DCHECK_EQ(back_surface_->pixmap(), surface_id); | 398 DCHECK_EQ(back_surface_->pixmap(), surface_handle); |
| 409 helper_->SetScheduled(true); | 399 helper_->SetScheduled(true); |
| 410 } | 400 } |
| 411 | 401 |
| 412 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 402 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
| 413 helper_->SetScheduled(true); | 403 helper_->SetScheduled(true); |
| 414 } | 404 } |
| 415 | 405 |
| 416 void EGLImageTransportSurface::OnPostSubBufferACK() { | 406 void EGLImageTransportSurface::OnPostSubBufferACK() { |
| 417 NOTREACHED(); | 407 NOTREACHED(); |
| 418 } | 408 } |
| 419 | 409 |
| 420 void EGLImageTransportSurface::OnResizeViewACK() { | 410 void EGLImageTransportSurface::OnResizeViewACK() { |
| 421 NOTREACHED(); | 411 NOTREACHED(); |
| 422 } | 412 } |
| 423 | 413 |
| 424 GLXImageTransportSurface::GLXImageTransportSurface( | 414 GLXImageTransportSurface::GLXImageTransportSurface( |
| 425 GpuChannelManager* manager, | 415 GpuChannelManager* manager, |
| 426 int32 render_view_id, | 416 GpuCommandBufferStub* stub) |
| 427 int32 client_id, | 417 : gfx::NativeViewGLSurfaceGLX(), |
| 428 int32 command_buffer_id) | 418 dummy_parent_(0), |
| 429 : gfx::NativeViewGLSurfaceGLX(), | 419 size_(1, 1), |
| 430 dummy_parent_(0), | 420 bound_(false), |
| 431 size_(1, 1), | 421 needs_resize_(false), |
| 432 bound_(false), | 422 made_current_(false) { |
| 433 needs_resize_(false), | |
| 434 made_current_(false) { | |
| 435 helper_.reset(new ImageTransportHelper(this, | 423 helper_.reset(new ImageTransportHelper(this, |
| 436 manager, | 424 manager, |
| 437 render_view_id, | 425 stub, |
| 438 client_id, | |
| 439 command_buffer_id, | |
| 440 gfx::kNullPluginWindow)); | 426 gfx::kNullPluginWindow)); |
| 441 } | 427 } |
| 442 | 428 |
| 443 GLXImageTransportSurface::~GLXImageTransportSurface() { | 429 GLXImageTransportSurface::~GLXImageTransportSurface() { |
| 444 Destroy(); | 430 Destroy(); |
| 445 } | 431 } |
| 446 | 432 |
| 447 bool GLXImageTransportSurface::Initialize() { | 433 bool GLXImageTransportSurface::Initialize() { |
| 448 // Create a dummy window to host the real window. | 434 // Create a dummy window to host the real window. |
| 449 Display* dpy = static_cast<Display*>(GetDisplay()); | 435 Display* dpy = static_cast<Display*>(GetDisplay()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 bool GLXImageTransportSurface::SwapBuffers() { | 525 bool GLXImageTransportSurface::SwapBuffers() { |
| 540 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 526 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 541 helper_->DeferToFence(base::Bind( | 527 helper_->DeferToFence(base::Bind( |
| 542 &GLXImageTransportSurface::SendBuffersSwapped, | 528 &GLXImageTransportSurface::SendBuffersSwapped, |
| 543 AsWeakPtr())); | 529 AsWeakPtr())); |
| 544 | 530 |
| 545 if (needs_resize_) { | 531 if (needs_resize_) { |
| 546 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 532 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 547 params.width = size_.width(); | 533 params.width = size_.width(); |
| 548 params.height = size_.height(); | 534 params.height = size_.height(); |
| 549 params.surface_id = window_; | 535 params.surface_handle = window_; |
| 550 helper_->SendAcceleratedSurfaceNew(params); | 536 helper_->SendAcceleratedSurfaceNew(params); |
| 551 bound_ = true; | 537 bound_ = true; |
| 552 needs_resize_ = false; | 538 needs_resize_ = false; |
| 553 } | 539 } |
| 554 return true; | 540 return true; |
| 555 } | 541 } |
| 556 | 542 |
| 557 void GLXImageTransportSurface::SendBuffersSwapped() { | 543 void GLXImageTransportSurface::SendBuffersSwapped() { |
| 558 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 544 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 559 params.surface_id = window_; | 545 params.surface_handle = window_; |
| 560 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 546 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 561 helper_->SetScheduled(false); | 547 helper_->SetScheduled(false); |
| 562 } | 548 } |
| 563 | 549 |
| 564 bool GLXImageTransportSurface::PostSubBuffer( | 550 bool GLXImageTransportSurface::PostSubBuffer( |
| 565 int x, int y, int width, int height) { | 551 int x, int y, int width, int height) { |
| 566 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); | 552 gfx::NativeViewGLSurfaceGLX::PostSubBuffer(x, y, width, height); |
| 567 helper_->DeferToFence(base::Bind( | 553 helper_->DeferToFence(base::Bind( |
| 568 &GLXImageTransportSurface::SendPostSubBuffer, | 554 &GLXImageTransportSurface::SendPostSubBuffer, |
| 569 AsWeakPtr(), x, y, width, height)); | 555 AsWeakPtr(), x, y, width, height)); |
| 570 | 556 |
| 571 if (needs_resize_) { | 557 if (needs_resize_) { |
| 572 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 558 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 573 params.width = size_.width(); | 559 params.width = size_.width(); |
| 574 params.height = size_.height(); | 560 params.height = size_.height(); |
| 575 params.surface_id = window_; | 561 params.surface_handle = window_; |
| 576 helper_->SendAcceleratedSurfaceNew(params); | 562 helper_->SendAcceleratedSurfaceNew(params); |
| 577 bound_ = true; | 563 bound_ = true; |
| 578 needs_resize_ = false; | 564 needs_resize_ = false; |
| 579 } | 565 } |
| 580 return true; | 566 return true; |
| 581 } | 567 } |
| 582 | 568 |
| 583 void GLXImageTransportSurface::SendPostSubBuffer( | 569 void GLXImageTransportSurface::SendPostSubBuffer( |
| 584 int x, int y, int width, int height) { | 570 int x, int y, int width, int height) { |
| 585 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; | 571 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; |
| 586 params.surface_id = window_; | 572 params.surface_handle = window_; |
| 587 params.x = x; | 573 params.x = x; |
| 588 params.y = y; | 574 params.y = y; |
| 589 params.width = width; | 575 params.width = width; |
| 590 params.height = height; | 576 params.height = height; |
| 591 | 577 |
| 592 helper_->SendAcceleratedSurfacePostSubBuffer(params); | 578 helper_->SendAcceleratedSurfacePostSubBuffer(params); |
| 593 helper_->SetScheduled(false); | 579 helper_->SetScheduled(false); |
| 594 } | 580 } |
| 595 | 581 |
| 596 std::string GLXImageTransportSurface::GetExtensions() { | 582 std::string GLXImageTransportSurface::GetExtensions() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 620 } | 606 } |
| 621 } | 607 } |
| 622 | 608 |
| 623 context->SetSwapInterval(0); | 609 context->SetSwapInterval(0); |
| 624 | 610 |
| 625 made_current_ = true; | 611 made_current_ = true; |
| 626 return true; | 612 return true; |
| 627 } | 613 } |
| 628 | 614 |
| 629 void GLXImageTransportSurface::OnNewSurfaceACK( | 615 void GLXImageTransportSurface::OnNewSurfaceACK( |
| 630 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { | 616 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { |
| 631 } | 617 } |
| 632 | 618 |
| 633 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 619 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
| 634 helper_->SetScheduled(true); | 620 helper_->SetScheduled(true); |
| 635 } | 621 } |
| 636 | 622 |
| 637 void GLXImageTransportSurface::OnPostSubBufferACK() { | 623 void GLXImageTransportSurface::OnPostSubBufferACK() { |
| 638 helper_->SetScheduled(true); | 624 helper_->SetScheduled(true); |
| 639 } | 625 } |
| 640 | 626 |
| 641 void GLXImageTransportSurface::OnResizeViewACK() { | 627 void GLXImageTransportSurface::OnResizeViewACK() { |
| 642 NOTREACHED(); | 628 NOTREACHED(); |
| 643 } | 629 } |
| 644 | 630 |
| 645 OSMesaImageTransportSurface::OSMesaImageTransportSurface( | 631 OSMesaImageTransportSurface::OSMesaImageTransportSurface( |
| 646 GpuChannelManager* manager, | 632 GpuChannelManager* manager, |
| 647 int32 render_view_id, | 633 GpuCommandBufferStub* stub) |
| 648 int32 client_id, | 634 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), |
| 649 int32 command_buffer_id) | 635 size_(gfx::Size(1, 1)) { |
| 650 : gfx::GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)), | |
| 651 size_(gfx::Size(1, 1)) { | |
| 652 helper_.reset(new ImageTransportHelper(this, | 636 helper_.reset(new ImageTransportHelper(this, |
| 653 manager, | 637 manager, |
| 654 render_view_id, | 638 stub, |
| 655 client_id, | |
| 656 command_buffer_id, | |
| 657 gfx::kNullPluginWindow)); | 639 gfx::kNullPluginWindow)); |
| 658 } | 640 } |
| 659 | 641 |
| 660 OSMesaImageTransportSurface::~OSMesaImageTransportSurface() { | 642 OSMesaImageTransportSurface::~OSMesaImageTransportSurface() { |
| 661 Destroy(); | 643 Destroy(); |
| 662 } | 644 } |
| 663 | 645 |
| 664 bool OSMesaImageTransportSurface::Initialize() { | 646 bool OSMesaImageTransportSurface::Initialize() { |
| 665 if (!helper_->Initialize()) | 647 if (!helper_->Initialize()) |
| 666 return false; | 648 return false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 680 |
| 699 // Now that we resized/reallocated the memory buffer, we need to change | 681 // Now that we resized/reallocated the memory buffer, we need to change |
| 700 // what OSMesa is pointing at to the new buffer. | 682 // what OSMesa is pointing at to the new buffer. |
| 701 helper_->MakeCurrent(); | 683 helper_->MakeCurrent(); |
| 702 | 684 |
| 703 size_ = size; | 685 size_ = size; |
| 704 | 686 |
| 705 GpuHostMsg_AcceleratedSurfaceNew_Params params; | 687 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 706 params.width = size_.width(); | 688 params.width = size_.width(); |
| 707 params.height = size_.height(); | 689 params.height = size_.height(); |
| 708 params.surface_id = 0; // id comes from the browser with the shared mem | 690 params.surface_handle = 0; // id comes from the browser with the shared mem |
| 709 helper_->SendAcceleratedSurfaceNew(params); | 691 helper_->SendAcceleratedSurfaceNew(params); |
| 710 | 692 |
| 711 helper_->SetScheduled(false); | 693 helper_->SetScheduled(false); |
| 712 } | 694 } |
| 713 | 695 |
| 714 void OSMesaImageTransportSurface::OnNewSurfaceACK( | 696 void OSMesaImageTransportSurface::OnNewSurfaceACK( |
| 715 uint64 surface_id, TransportDIB::Handle surface_handle) { | 697 uint64 surface_handle, TransportDIB::Handle shm_handle) { |
| 716 shared_id_ = surface_id; | 698 shared_id_ = surface_handle; |
| 717 shared_mem_.reset(TransportDIB::Map(surface_handle)); | 699 shared_mem_.reset(TransportDIB::Map(shm_handle)); |
| 718 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 700 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
| 719 | 701 |
| 720 helper_->SetScheduled(true); | 702 helper_->SetScheduled(true); |
| 721 } | 703 } |
| 722 | 704 |
| 723 void OSMesaImageTransportSurface::OnResizeViewACK() { | 705 void OSMesaImageTransportSurface::OnResizeViewACK() { |
| 724 NOTREACHED(); | 706 NOTREACHED(); |
| 725 } | 707 } |
| 726 | 708 |
| 727 bool OSMesaImageTransportSurface::SwapBuffers() { | 709 bool OSMesaImageTransportSurface::SwapBuffers() { |
| 728 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 710 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
| 729 | 711 |
| 730 // Copy the OSMesa buffer to the shared memory | 712 // Copy the OSMesa buffer to the shared memory |
| 731 glFinish(); | 713 glFinish(); |
| 732 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); | 714 memcpy(shared_mem_->memory(), GetHandle(), size_.GetArea() * 4); |
| 733 | 715 |
| 734 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 716 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 735 params.surface_id = shared_id_; | 717 params.surface_handle = shared_id_; |
| 736 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 718 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 737 | 719 |
| 738 helper_->SetScheduled(false); | 720 helper_->SetScheduled(false); |
| 739 return true; | 721 return true; |
| 740 } | 722 } |
| 741 | 723 |
| 742 bool OSMesaImageTransportSurface::PostSubBuffer( | 724 bool OSMesaImageTransportSurface::PostSubBuffer( |
| 743 int x, int y, int width, int height) { | 725 int x, int y, int width, int height) { |
| 744 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | 726 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); |
| 745 | 727 |
| 746 // Copy the OSMesa buffer to the shared memory | 728 // Copy the OSMesa buffer to the shared memory |
| 747 glFinish(); | 729 glFinish(); |
| 748 | 730 |
| 749 int flipped_y = GetSize().height() - y - height; | 731 int flipped_y = GetSize().height() - y - height; |
| 750 | 732 |
| 751 for (int row = 0; row < height; ++row) { | 733 for (int row = 0; row < height; ++row) { |
| 752 int mem_offset = ((flipped_y + row) * size_.width() + x); | 734 int mem_offset = ((flipped_y + row) * size_.width() + x); |
| 753 int32* dest_address = static_cast<int32*>(shared_mem_->memory()) + | 735 int32* dest_address = static_cast<int32*>(shared_mem_->memory()) + |
| 754 mem_offset; | 736 mem_offset; |
| 755 int32* src_address = static_cast<int32*>(GetHandle()) + mem_offset; | 737 int32* src_address = static_cast<int32*>(GetHandle()) + mem_offset; |
| 756 memcpy(dest_address, src_address, width * 4); | 738 memcpy(dest_address, src_address, width * 4); |
| 757 } | 739 } |
| 758 | 740 |
| 759 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; | 741 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; |
| 760 params.surface_id = shared_id_; | 742 params.surface_handle = shared_id_; |
| 761 params.x = x; | 743 params.x = x; |
| 762 params.y = y; | 744 params.y = y; |
| 763 params.width = width; | 745 params.width = width; |
| 764 params.height = height; | 746 params.height = height; |
| 765 helper_->SendAcceleratedSurfacePostSubBuffer(params); | 747 helper_->SendAcceleratedSurfacePostSubBuffer(params); |
| 766 | 748 |
| 767 helper_->SetScheduled(false); | 749 helper_->SetScheduled(false); |
| 768 return true; | 750 return true; |
| 769 } | 751 } |
| 770 | 752 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 786 | 768 |
| 787 gfx::Size OSMesaImageTransportSurface::GetSize() { | 769 gfx::Size OSMesaImageTransportSurface::GetSize() { |
| 788 return size_; | 770 return size_; |
| 789 } | 771 } |
| 790 | 772 |
| 791 } // namespace | 773 } // namespace |
| 792 | 774 |
| 793 // static | 775 // static |
| 794 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 776 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
| 795 GpuChannelManager* manager, | 777 GpuChannelManager* manager, |
| 796 int32 render_view_id, | 778 GpuCommandBufferStub* stub, |
| 797 int32 client_id, | |
| 798 int32 command_buffer_id, | |
| 799 gfx::PluginWindowHandle handle) { | 779 gfx::PluginWindowHandle handle) { |
| 800 scoped_refptr<gfx::GLSurface> surface; | 780 scoped_refptr<gfx::GLSurface> surface; |
| 801 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | 781 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
| 802 switch (gfx::GetGLImplementation()) { | 782 switch (gfx::GetGLImplementation()) { |
| 803 case gfx::kGLImplementationDesktopGL: | 783 case gfx::kGLImplementationDesktopGL: |
| 804 surface = new GLXImageTransportSurface(manager, | 784 surface = new GLXImageTransportSurface(manager, stub); |
| 805 render_view_id, | |
| 806 client_id, | |
| 807 command_buffer_id); | |
| 808 break; | 785 break; |
| 809 case gfx::kGLImplementationEGLGLES2: | 786 case gfx::kGLImplementationEGLGLES2: |
| 810 surface = new EGLImageTransportSurface(manager, | 787 surface = new EGLImageTransportSurface(manager, stub); |
| 811 render_view_id, | |
| 812 client_id, | |
| 813 command_buffer_id); | |
| 814 break; | 788 break; |
| 815 case gfx::kGLImplementationOSMesaGL: | 789 case gfx::kGLImplementationOSMesaGL: |
| 816 surface = new OSMesaImageTransportSurface(manager, | 790 surface = new OSMesaImageTransportSurface(manager, stub); |
| 817 render_view_id, | |
| 818 client_id, | |
| 819 command_buffer_id); | |
| 820 break; | 791 break; |
| 821 default: | 792 default: |
| 822 NOTREACHED(); | 793 NOTREACHED(); |
| 823 return NULL; | 794 return NULL; |
| 824 } | 795 } |
| 825 #else | 796 #else |
| 826 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); | 797 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); |
| 827 if (!surface.get()) | 798 if (!surface.get()) |
| 828 return NULL; | 799 return NULL; |
| 829 | 800 |
| 830 surface = new PassThroughImageTransportSurface(manager, | 801 surface = new PassThroughImageTransportSurface(manager, stub, surface.get()); |
| 831 render_view_id, | |
| 832 client_id, | |
| 833 command_buffer_id, | |
| 834 surface.get()); | |
| 835 #endif | 802 #endif |
| 836 if (surface->Initialize()) | 803 if (surface->Initialize()) |
| 837 return surface; | 804 return surface; |
| 838 else | 805 else |
| 839 return NULL; | 806 return NULL; |
| 840 } | 807 } |
| 841 | 808 |
| 842 #endif // defined(USE_GPU) | 809 #endif // defined(USE_GPU) |
| OLD | NEW |