Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_linux.h" | 7 #include "content/common/gpu/image_transport_surface_linux.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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 virtual bool Initialize() OVERRIDE; | 43 virtual bool Initialize() OVERRIDE; |
| 44 virtual void Destroy() OVERRIDE; | 44 virtual void Destroy() OVERRIDE; |
| 45 virtual bool IsOffscreen() OVERRIDE; | 45 virtual bool IsOffscreen() OVERRIDE; |
| 46 virtual bool SwapBuffers() OVERRIDE; | 46 virtual bool SwapBuffers() OVERRIDE; |
| 47 virtual gfx::Size GetSize() OVERRIDE; | 47 virtual gfx::Size GetSize() OVERRIDE; |
| 48 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 48 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 49 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 49 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 // ImageTransportSurface implementation | 52 // ImageTransportSurface implementation |
| 53 virtual void OnSetSurfaceACK(uint64 surface_id) OVERRIDE; | 53 virtual void OnNewSurfaceACK( |
| 54 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | |
| 54 virtual void OnBuffersSwappedACK() OVERRIDE; | 55 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 55 virtual void OnResize(gfx::Size size) OVERRIDE; | 56 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 virtual ~EGLImageTransportSurface() OVERRIDE; | 59 virtual ~EGLImageTransportSurface() OVERRIDE; |
| 59 void ReleaseSurface(scoped_refptr<AcceleratedSurface>* surface); | 60 void ReleaseSurface(scoped_refptr<AcceleratedSurface>* surface); |
| 60 | 61 |
| 61 uint32 fbo_id_; | 62 uint32 fbo_id_; |
| 62 | 63 |
| 63 scoped_refptr<AcceleratedSurface> back_surface_; | 64 scoped_refptr<AcceleratedSurface> back_surface_; |
| 64 scoped_refptr<AcceleratedSurface> front_surface_; | 65 scoped_refptr<AcceleratedSurface> front_surface_; |
| 65 | 66 |
| 66 scoped_ptr<ImageTransportHelper> helper_; | 67 scoped_ptr<ImageTransportHelper> helper_; |
| 67 | 68 |
| 68 DISALLOW_COPY_AND_ASSIGN(EGLImageTransportSurface); | 69 DISALLOW_COPY_AND_ASSIGN(EGLImageTransportSurface); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 // We are backed by an Pbuffer offscreen surface for the purposes of creating a | 72 // We render to an off-screen (but mapped) window that the browser process will |
| 72 // context, but use FBOs to render to X Pixmap backed EGLImages. | 73 // read from via XComposite |
| 73 class GLXImageTransportSurface : public ImageTransportSurface, | 74 class GLXImageTransportSurface : public ImageTransportSurface, |
| 74 public gfx::NativeViewGLSurfaceGLX { | 75 public gfx::NativeViewGLSurfaceGLX { |
| 75 public: | 76 public: |
| 76 GLXImageTransportSurface(GpuChannelManager* manager, | 77 GLXImageTransportSurface(GpuChannelManager* manager, |
| 77 int32 render_view_id, | 78 int32 render_view_id, |
| 78 int32 renderer_id, | 79 int32 renderer_id, |
| 79 int32 command_buffer_id); | 80 int32 command_buffer_id); |
| 80 | 81 |
| 81 // gfx::GLSurface implementation: | 82 // gfx::GLSurface implementation: |
| 82 virtual bool Initialize() OVERRIDE; | 83 virtual bool Initialize() OVERRIDE; |
| 83 virtual void Destroy() OVERRIDE; | 84 virtual void Destroy() OVERRIDE; |
| 84 virtual bool SwapBuffers() OVERRIDE; | 85 virtual bool SwapBuffers() OVERRIDE; |
| 85 virtual gfx::Size GetSize() OVERRIDE; | 86 virtual gfx::Size GetSize() OVERRIDE; |
| 86 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 87 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 87 | 88 |
| 88 protected: | 89 protected: |
| 89 // ImageTransportSurface implementation: | 90 // ImageTransportSurface implementation: |
| 90 void OnSetSurfaceACK(uint64 surface_id) OVERRIDE; | 91 virtual void OnNewSurfaceACK( |
| 91 void OnBuffersSwappedACK() OVERRIDE; | 92 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
| 92 void OnResize(gfx::Size size) OVERRIDE; | 93 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 94 virtual void OnResize(gfx::Size size) OVERRIDE; | |
| 93 | 95 |
| 94 private: | 96 private: |
| 95 virtual ~GLXImageTransportSurface(); | 97 virtual ~GLXImageTransportSurface(); |
| 96 | 98 |
| 97 // Tell the browser to release the surface. | 99 // Tell the browser to release the surface. |
| 98 void ReleaseSurface(); | 100 void ReleaseSurface(); |
| 99 | 101 |
| 100 XID dummy_parent_; | 102 XID dummy_parent_; |
| 101 gfx::Size size_; | 103 gfx::Size size_; |
| 102 | 104 |
| 103 // Whether or not the image has been bound on the browser side. | 105 // Whether or not the image has been bound on the browser side. |
| 104 bool bound_; | 106 bool bound_; |
| 105 | 107 |
| 106 // Whether or not we've set the swap interval on the associated context. | 108 // Whether or not we've set the swap interval on the associated context. |
| 107 bool swap_interval_set_; | 109 bool swap_interval_set_; |
| 108 | 110 |
| 109 scoped_ptr<ImageTransportHelper> helper_; | 111 scoped_ptr<ImageTransportHelper> helper_; |
| 110 | 112 |
| 111 DISALLOW_COPY_AND_ASSIGN(GLXImageTransportSurface); | 113 DISALLOW_COPY_AND_ASSIGN(GLXImageTransportSurface); |
| 112 }; | 114 }; |
| 113 | 115 |
| 116 // We render to an off-screen (but mapped) window, then dump its contents | |
| 117 // into a shared memory buffer to get the memory to the browser compositor. | |
| 118 // This is to replicate the behaviour of OSMesa, without using OSMesa for now. | |
| 119 class GLXShmImageTransportSurface : public ImageTransportSurface, | |
| 120 public gfx::PbufferGLSurfaceGLX { | |
| 121 public: | |
| 122 GLXShmImageTransportSurface(GpuChannelManager* manager, | |
| 123 int32 render_view_id, | |
| 124 int32 renderer_id, | |
| 125 int32 command_buffer_id); | |
| 126 | |
| 127 // gfx::GLSurface implementation: | |
| 128 virtual bool Initialize() OVERRIDE; | |
| 129 virtual void Destroy() OVERRIDE; | |
| 130 virtual bool IsOffscreen() OVERRIDE; | |
| 131 virtual bool SwapBuffers() OVERRIDE; | |
| 132 virtual gfx::Size GetSize() OVERRIDE; | |
| 133 virtual void OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | |
| 134 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | |
| 135 | |
| 136 protected: | |
| 137 // ImageTransportSurface implementation: | |
| 138 virtual void OnNewSurfaceACK( | |
| 139 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; | |
| 140 virtual void OnBuffersSwappedACK() OVERRIDE; | |
| 141 virtual void OnResize(gfx::Size size) OVERRIDE; | |
| 142 | |
| 143 private: | |
| 144 virtual ~GLXShmImageTransportSurface(); | |
| 145 | |
| 146 // Tell the browser to release the surface. | |
| 147 void ReleaseSurface(); | |
| 148 | |
| 149 uint32 fbo_id_; | |
| 150 uint32 texture_; | |
| 151 | |
| 152 gfx::Size size_; | |
| 153 | |
| 154 scoped_ptr<TransportDIB> shared_mem_; | |
| 155 uint32 shared_id_; | |
| 156 | |
| 157 scoped_ptr<ImageTransportHelper> helper_; | |
| 158 | |
| 159 DISALLOW_COPY_AND_ASSIGN(GLXShmImageTransportSurface); | |
| 160 }; | |
| 161 | |
| 114 EGLImageTransportSurface::EGLImageTransportSurface( | 162 EGLImageTransportSurface::EGLImageTransportSurface( |
| 115 GpuChannelManager* manager, | 163 GpuChannelManager* manager, |
| 116 int32 render_view_id, | 164 int32 render_view_id, |
| 117 int32 renderer_id, | 165 int32 renderer_id, |
| 118 int32 command_buffer_id) | 166 int32 command_buffer_id) |
| 119 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), | 167 : gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1)), |
| 120 fbo_id_(0) { | 168 fbo_id_(0) { |
| 121 helper_.reset(new ImageTransportHelper(this, | 169 helper_.reset(new ImageTransportHelper(this, |
| 122 manager, | 170 manager, |
| 123 render_view_id, | 171 render_view_id, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 138 void EGLImageTransportSurface::Destroy() { | 186 void EGLImageTransportSurface::Destroy() { |
| 139 if (back_surface_.get()) | 187 if (back_surface_.get()) |
| 140 ReleaseSurface(&back_surface_); | 188 ReleaseSurface(&back_surface_); |
| 141 if (front_surface_.get()) | 189 if (front_surface_.get()) |
| 142 ReleaseSurface(&front_surface_); | 190 ReleaseSurface(&front_surface_); |
| 143 | 191 |
| 144 helper_->Destroy(); | 192 helper_->Destroy(); |
| 145 PbufferGLSurfaceEGL::Destroy(); | 193 PbufferGLSurfaceEGL::Destroy(); |
| 146 } | 194 } |
| 147 | 195 |
| 196 // Make sure that buffer swaps occur for the surface, so we can send the data | |
| 197 // to the actual onscreen surface in the browser | |
| 148 bool EGLImageTransportSurface::IsOffscreen() { | 198 bool EGLImageTransportSurface::IsOffscreen() { |
| 149 return false; | 199 return false; |
| 150 } | 200 } |
| 151 | 201 |
| 152 void EGLImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 202 void EGLImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 153 if (fbo_id_) | 203 if (fbo_id_) |
| 154 return; | 204 return; |
| 155 | 205 |
| 156 glGenFramebuffersEXT(1, &fbo_id_); | 206 glGenFramebuffersEXT(1, &fbo_id_); |
| 157 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_id_); | 207 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_id_); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 182 ReleaseSurface(&back_surface_); | 232 ReleaseSurface(&back_surface_); |
| 183 | 233 |
| 184 back_surface_ = new AcceleratedSurface(size); | 234 back_surface_ = new AcceleratedSurface(size); |
| 185 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | 235 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 186 GL_COLOR_ATTACHMENT0, | 236 GL_COLOR_ATTACHMENT0, |
| 187 GL_TEXTURE_2D, | 237 GL_TEXTURE_2D, |
| 188 back_surface_->texture(), | 238 back_surface_->texture(), |
| 189 0); | 239 0); |
| 190 glFlush(); | 240 glFlush(); |
| 191 | 241 |
| 192 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params; | 242 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 193 params.width = size.width(); | 243 params.width = size.width(); |
| 194 params.height = size.height(); | 244 params.height = size.height(); |
| 195 params.identifier = back_surface_->pixmap(); | 245 params.identifier = back_surface_->pixmap(); |
| 196 helper_->SendAcceleratedSurfaceSetIOSurface(params); | 246 helper_->SendAcceleratedSurfaceNew(params); |
| 197 | 247 |
| 198 helper_->SetScheduled(false); | 248 helper_->SetScheduled(false); |
| 199 } | 249 } |
| 200 | 250 |
| 201 bool EGLImageTransportSurface::SwapBuffers() { | 251 bool EGLImageTransportSurface::SwapBuffers() { |
| 202 front_surface_.swap(back_surface_); | 252 front_surface_.swap(back_surface_); |
| 203 DCHECK_NE(front_surface_.get(), static_cast<AcceleratedSurface*>(NULL)); | 253 DCHECK_NE(front_surface_.get(), static_cast<AcceleratedSurface*>(NULL)); |
| 204 glFlush(); | 254 glFlush(); |
| 205 | 255 |
| 206 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 256 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 218 0); | 268 0); |
| 219 } | 269 } |
| 220 helper_->SetScheduled(false); | 270 helper_->SetScheduled(false); |
| 221 return true; | 271 return true; |
| 222 } | 272 } |
| 223 | 273 |
| 224 gfx::Size EGLImageTransportSurface::GetSize() { | 274 gfx::Size EGLImageTransportSurface::GetSize() { |
| 225 return back_surface_->size(); | 275 return back_surface_->size(); |
| 226 } | 276 } |
| 227 | 277 |
| 228 void EGLImageTransportSurface::OnSetSurfaceACK( | 278 void EGLImageTransportSurface::OnNewSurfaceACK( |
| 229 uint64 surface_id) { | 279 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
| 230 DCHECK_EQ(back_surface_->pixmap(), surface_id); | 280 DCHECK_EQ(back_surface_->pixmap(), surface_id); |
| 231 helper_->SetScheduled(true); | 281 helper_->SetScheduled(true); |
| 232 } | 282 } |
| 233 | 283 |
| 234 void EGLImageTransportSurface::OnBuffersSwappedACK() { | 284 void EGLImageTransportSurface::OnBuffersSwappedACK() { |
| 235 helper_->SetScheduled(true); | 285 helper_->SetScheduled(true); |
| 236 } | 286 } |
| 237 | 287 |
| 238 GLXImageTransportSurface::GLXImageTransportSurface( | 288 GLXImageTransportSurface::GLXImageTransportSurface( |
| 239 GpuChannelManager* manager, | 289 GpuChannelManager* manager, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 size_ = size; | 374 size_ = size; |
| 325 if (bound_) { | 375 if (bound_) { |
| 326 ReleaseSurface(); | 376 ReleaseSurface(); |
| 327 bound_ = false; | 377 bound_ = false; |
| 328 } | 378 } |
| 329 | 379 |
| 330 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 380 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); |
| 331 XResizeWindow(dpy, window_, size_.width(), size_.height()); | 381 XResizeWindow(dpy, window_, size_.width(), size_.height()); |
| 332 XFlush(dpy); | 382 XFlush(dpy); |
| 333 | 383 |
| 334 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params; | 384 GpuHostMsg_AcceleratedSurfaceNew_Params params; |
| 335 params.width = size_.width(); | 385 params.width = size_.width(); |
| 336 params.height = size_.height(); | 386 params.height = size_.height(); |
| 337 params.identifier = window_; | 387 params.identifier = window_; |
| 338 helper_->SendAcceleratedSurfaceSetIOSurface(params); | 388 helper_->SendAcceleratedSurfaceNew(params); |
| 339 | 389 |
| 340 helper_->SetScheduled(false); | 390 helper_->SetScheduled(false); |
| 341 } | 391 } |
| 342 | 392 |
| 343 bool GLXImageTransportSurface::SwapBuffers() { | 393 bool GLXImageTransportSurface::SwapBuffers() { |
| 344 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); | 394 gfx::NativeViewGLSurfaceGLX::SwapBuffers(); |
| 345 glFlush(); | 395 glFlush(); |
| 346 | 396 |
| 347 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 397 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 348 params.surface_id = window_; | 398 params.surface_id = window_; |
| 349 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 399 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 350 | 400 |
| 351 helper_->SetScheduled(false); | 401 helper_->SetScheduled(false); |
| 352 return true; | 402 return true; |
| 353 } | 403 } |
| 354 | 404 |
| 355 gfx::Size GLXImageTransportSurface::GetSize() { | 405 gfx::Size GLXImageTransportSurface::GetSize() { |
| 356 return size_; | 406 return size_; |
| 357 } | 407 } |
| 358 | 408 |
| 359 void GLXImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 409 void GLXImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 360 if (!swap_interval_set_) { | 410 if (!swap_interval_set_) { |
| 361 context->SetSwapInterval(0); | 411 context->SetSwapInterval(0); |
| 362 swap_interval_set_ = true; | 412 swap_interval_set_ = true; |
| 363 } | 413 } |
| 364 } | 414 } |
| 365 | 415 |
| 366 void GLXImageTransportSurface::OnSetSurfaceACK( | 416 void GLXImageTransportSurface::OnNewSurfaceACK( |
| 367 uint64 surface_id) { | 417 uint64 surface_id, TransportDIB::Handle /*surface_handle*/) { |
| 368 DCHECK(!bound_); | 418 DCHECK(!bound_); |
| 369 bound_ = true; | 419 bound_ = true; |
| 370 helper_->SetScheduled(true); | 420 helper_->SetScheduled(true); |
| 371 } | 421 } |
| 372 | 422 |
| 373 void GLXImageTransportSurface::OnBuffersSwappedACK() { | 423 void GLXImageTransportSurface::OnBuffersSwappedACK() { |
| 374 helper_->SetScheduled(true); | 424 helper_->SetScheduled(true); |
| 375 } | 425 } |
| 376 | 426 |
| 427 GLXShmImageTransportSurface::GLXShmImageTransportSurface( | |
| 428 GpuChannelManager* manager, | |
| 429 int32 render_view_id, | |
| 430 int32 renderer_id, | |
| 431 int32 command_buffer_id) | |
| 432 : gfx::PbufferGLSurfaceGLX(gfx::Size(1,1)), | |
| 433 size_(0, 0) { | |
| 434 helper_.reset(new ImageTransportHelper(this, | |
| 435 manager, | |
| 436 render_view_id, | |
| 437 renderer_id, | |
| 438 command_buffer_id)); | |
| 439 } | |
| 440 | |
| 441 GLXShmImageTransportSurface::~GLXShmImageTransportSurface() { | |
| 442 Destroy(); | |
| 443 } | |
| 444 | |
| 445 bool GLXShmImageTransportSurface::Initialize() { | |
| 446 if (!helper_->Initialize()) | |
| 447 return false; | |
| 448 return gfx::PbufferGLSurfaceGLX::Initialize(); | |
| 449 } | |
| 450 | |
| 451 void GLXShmImageTransportSurface::Destroy() { | |
| 452 if (shared_mem_.get()) | |
| 453 ReleaseSurface(); | |
| 454 | |
| 455 helper_->Destroy(); | |
| 456 gfx::PbufferGLSurfaceGLX::Destroy(); | |
| 457 } | |
| 458 | |
| 459 // Make sure that buffer swaps occur for the surface, so we can send the data | |
| 460 // to the actual onscreen surface in the browser | |
| 461 bool GLXShmImageTransportSurface::IsOffscreen() { | |
| 462 return false; | |
| 463 } | |
| 464 | |
| 465 void GLXShmImageTransportSurface::ReleaseSurface() { | |
| 466 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | |
| 467 params.identifier = shared_id_; | |
| 468 helper_->SendAcceleratedSurfaceRelease(params); | |
| 469 | |
| 470 shared_mem_.reset(); | |
| 471 shared_id_ = 0; | |
| 472 } | |
| 473 | |
| 474 void GLXShmImageTransportSurface::OnResize(gfx::Size size) { | |
| 475 LOG(ERROR) << "OnResize *********** " << size; | |
| 476 size_ = size; | |
| 477 | |
| 478 if (shared_mem_.get()) | |
| 479 ReleaseSurface(); | |
| 480 | |
| 481 // resize the texture | |
| 482 LOG(ERROR) << std::hex << "4 GLError: " << glGetError(); | |
| 483 glBindTexture(GL_TEXTURE_2D, texture_); | |
| 484 LOG(ERROR) << std::hex << "5 GLError: " << glGetError(); | |
| 485 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, | |
| 486 size_.width(), size_.height(), 0, | |
| 487 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
| 488 LOG(ERROR) << std::hex << "6 GLError: " << glGetError(); | |
| 489 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); | |
| 490 LOG(ERROR) << std::hex << "6.1 GLError: " << glGetError(); | |
| 491 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, | |
| 492 GL_COLOR_ATTACHMENT0, | |
| 493 GL_TEXTURE_2D, | |
| 494 texture_, | |
| 495 0); | |
| 496 LOG(ERROR) << std::hex << "7 GLError: " << glGetError(); | |
| 497 glBindTexture(GL_TEXTURE_2D, 0); | |
| 498 glFlush(); | |
| 499 LOG(ERROR) << std::hex << "7.1 GLError: " << glGetError(); | |
| 500 | |
| 501 GpuHostMsg_AcceleratedSurfaceNew_Params params; | |
| 502 params.width = size_.width(); | |
| 503 params.height = size_.height(); | |
| 504 params.identifier = 0; // id comes from the browser with the shared mem | |
| 505 helper_->SendAcceleratedSurfaceNew(params); | |
| 506 | |
| 507 helper_->SetScheduled(false); | |
| 508 } | |
| 509 | |
| 510 void GLXShmImageTransportSurface::OnNewSurfaceACK( | |
| 511 uint64 surface_id, TransportDIB::Handle surface_handle) { | |
| 512 shared_id_ = surface_id; | |
| 513 shared_mem_.reset(TransportDIB::Map(surface_handle)); | |
| 514 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | |
| 515 | |
| 516 helper_->SetScheduled(true); | |
| 517 } | |
| 518 | |
| 519 bool GLXShmImageTransportSurface::SwapBuffers() { | |
| 520 DCHECK_NE(shared_mem_.get(), static_cast<void*>(NULL)); | |
| 521 | |
| 522 // grab the pixel data from the texture into the shared memory, and send | |
| 523 // it over to the browser | |
| 524 LOG(ERROR) << std::hex << "1 GLError: " << glGetError(); | |
| 525 glBindTexture(GL_TEXTURE_2D, texture_); | |
| 526 LOG(ERROR) << std::hex << "2 GLError: " << glGetError(); | |
| 527 LOG(ERROR) << "glReadPixels ***************"; | |
| 528 glReadPixels(0, 0, size_.width(), size_.height(), | |
| 529 GL_RGBA, GL_UNSIGNED_BYTE, shared_mem_->memory()); | |
| 530 LOG(ERROR) << std::hex << "3 GLError: " << glGetError(); | |
| 531 glBindTexture(GL_TEXTURE_2D, 0); | |
| 532 glFlush(); | |
| 533 LOG(ERROR) << std::hex << "3.1 GLError: " << glGetError(); | |
| 534 | |
| 535 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
| 536 params.surface_id = shared_id_; | |
| 537 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
| 538 | |
| 539 helper_->SetScheduled(false); | |
| 540 return true; | |
| 541 } | |
| 542 | |
| 543 gfx::Size GLXShmImageTransportSurface::GetSize() { | |
| 544 return size_; | |
| 545 } | |
| 546 | |
| 547 unsigned int GLXShmImageTransportSurface::GetBackingFrameBufferObject() { | |
| 548 return fbo_id_; | |
| 549 } | |
| 550 | |
| 551 void GLXShmImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | |
| 552 if (fbo_id_) | |
| 553 return; | |
| 554 | |
| 555 LOG(ERROR) << std::hex << "8 GLError: " << glGetError(); | |
| 556 glGenTextures(1, &texture_); | |
| 557 glBindTexture(GL_TEXTURE_2D, texture_); | |
|
jonathan.backer
2011/09/20 15:16:29
I think you can get rid of a bit of code duplicati
| |
| 558 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 559 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
| 560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 562 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, | |
| 563 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
| 564 glBindTexture(GL_TEXTURE_2D, 0); | |
| 565 LOG(ERROR) << std::hex << "9 GLError: " << glGetError(); | |
| 566 | |
| 567 glGenFramebuffersEXT(1, &fbo_id_); | |
| 568 LOG(ERROR) << std::hex << "10 GLError: " << glGetError(); | |
| 569 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_id_); | |
| 570 LOG(ERROR) << std::hex << "11 GLError: " << glGetError(); | |
| 571 | |
| 572 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | |
| 573 if (status != GL_FRAMEBUFFER_COMPLETE) { | |
| 574 LOG(ERROR) << "Framebuffer incomplete"; | |
| 575 } | |
| 576 LOG(ERROR) << std::hex << "12 GLError: " << glGetError(); | |
| 577 } | |
| 578 | |
| 579 void GLXShmImageTransportSurface::OnBuffersSwappedACK() { | |
| 580 helper_->SetScheduled(true); | |
| 581 } | |
| 582 | |
| 377 } // namespace | 583 } // namespace |
| 378 | 584 |
| 379 // static | 585 // static |
| 380 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 586 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
| 381 GpuChannelManager* manager, | 587 GpuChannelManager* manager, |
| 382 int32 render_view_id, | 588 int32 render_view_id, |
| 383 int32 renderer_id, | 589 int32 renderer_id, |
| 384 int32 command_buffer_id) { | 590 int32 command_buffer_id) { |
| 385 scoped_refptr<gfx::GLSurface> surface; | 591 scoped_refptr<gfx::GLSurface> surface; |
| 386 switch (gfx::GetGLImplementation()) { | 592 switch (gfx::GetGLImplementation()) { |
| 387 case gfx::kGLImplementationDesktopGL: | 593 case gfx::kGLImplementationDesktopGL: |
| 388 surface = new GLXImageTransportSurface(manager, | 594 surface = new GLXShmImageTransportSurface(manager, |
| 389 render_view_id, | 595 render_view_id, |
| 390 renderer_id, | 596 renderer_id, |
| 391 command_buffer_id); | 597 command_buffer_id); |
| 392 break; | 598 break; |
| 393 case gfx::kGLImplementationEGLGLES2: | 599 case gfx::kGLImplementationEGLGLES2: |
| 394 surface = new EGLImageTransportSurface(manager, | 600 surface = new EGLImageTransportSurface(manager, |
| 395 render_view_id, | 601 render_view_id, |
| 396 renderer_id, | 602 renderer_id, |
| 397 command_buffer_id); | 603 command_buffer_id); |
| 398 break; | 604 break; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 | 640 |
| 435 return true; | 641 return true; |
| 436 } | 642 } |
| 437 | 643 |
| 438 void ImageTransportHelper::Destroy() { | 644 void ImageTransportHelper::Destroy() { |
| 439 } | 645 } |
| 440 | 646 |
| 441 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { | 647 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
| 442 bool handled = true; | 648 bool handled = true; |
| 443 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) | 649 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
| 444 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_SetSurfaceACK, | 650 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_NewACK, |
| 445 OnSetSurfaceACK) | 651 OnNewSurfaceACK) |
| 446 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BuffersSwappedACK, | 652 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BuffersSwappedACK, |
| 447 OnBuffersSwappedACK) | 653 OnBuffersSwappedACK) |
| 448 IPC_MESSAGE_UNHANDLED(handled = false) | 654 IPC_MESSAGE_UNHANDLED(handled = false) |
| 449 IPC_END_MESSAGE_MAP() | 655 IPC_END_MESSAGE_MAP() |
| 450 return handled; | 656 return handled; |
| 451 } | 657 } |
| 452 | 658 |
| 453 void ImageTransportHelper::SendAcceleratedSurfaceRelease( | 659 void ImageTransportHelper::SendAcceleratedSurfaceRelease( |
| 454 GpuHostMsg_AcceleratedSurfaceRelease_Params params) { | 660 GpuHostMsg_AcceleratedSurfaceRelease_Params params) { |
| 455 params.renderer_id = renderer_id_; | 661 params.renderer_id = renderer_id_; |
| 456 params.render_view_id = render_view_id_; | 662 params.render_view_id = render_view_id_; |
| 457 params.route_id = route_id_; | 663 params.route_id = route_id_; |
| 458 manager_->Send(new GpuHostMsg_AcceleratedSurfaceRelease(params)); | 664 manager_->Send(new GpuHostMsg_AcceleratedSurfaceRelease(params)); |
| 459 } | 665 } |
| 460 | 666 |
| 461 void ImageTransportHelper::SendAcceleratedSurfaceSetIOSurface( | 667 void ImageTransportHelper::SendAcceleratedSurfaceNew( |
| 462 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params) { | 668 GpuHostMsg_AcceleratedSurfaceNew_Params params) { |
| 463 params.renderer_id = renderer_id_; | 669 params.renderer_id = renderer_id_; |
| 464 params.render_view_id = render_view_id_; | 670 params.render_view_id = render_view_id_; |
| 465 params.route_id = route_id_; | 671 params.route_id = route_id_; |
| 466 manager_->Send(new GpuHostMsg_AcceleratedSurfaceSetIOSurface(params)); | 672 manager_->Send(new GpuHostMsg_AcceleratedSurfaceNew(params)); |
| 467 } | 673 } |
| 468 | 674 |
| 469 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( | 675 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( |
| 470 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { | 676 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { |
| 471 params.renderer_id = renderer_id_; | 677 params.renderer_id = renderer_id_; |
| 472 params.render_view_id = render_view_id_; | 678 params.render_view_id = render_view_id_; |
| 473 params.route_id = route_id_; | 679 params.route_id = route_id_; |
| 474 manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | 680 manager_->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); |
| 475 } | 681 } |
| 476 | 682 |
| 477 void ImageTransportHelper::SetScheduled(bool is_scheduled) { | 683 void ImageTransportHelper::SetScheduled(bool is_scheduled) { |
| 478 gpu::GpuScheduler* scheduler = Scheduler(); | 684 gpu::GpuScheduler* scheduler = Scheduler(); |
| 479 if (!scheduler) | 685 if (!scheduler) |
| 480 return; | 686 return; |
| 481 | 687 |
| 482 scheduler->SetScheduled(is_scheduled); | 688 scheduler->SetScheduled(is_scheduled); |
| 483 } | 689 } |
| 484 | 690 |
| 485 void ImageTransportHelper::OnSetSurfaceACK(uint64 surface_id) { | 691 void ImageTransportHelper::OnNewSurfaceACK( |
| 486 surface_->OnSetSurfaceACK(surface_id); | 692 uint64 surface_id, TransportDIB::Handle surface_handle) { |
| 693 surface_->OnNewSurfaceACK(surface_id, surface_handle); | |
| 487 } | 694 } |
| 488 | 695 |
| 489 void ImageTransportHelper::OnBuffersSwappedACK() { | 696 void ImageTransportHelper::OnBuffersSwappedACK() { |
| 490 surface_->OnBuffersSwappedACK(); | 697 surface_->OnBuffersSwappedACK(); |
| 491 } | 698 } |
| 492 | 699 |
| 493 void ImageTransportHelper::Resize(gfx::Size size) { | 700 void ImageTransportHelper::Resize(gfx::Size size) { |
| 494 surface_->OnResize(size); | 701 surface_->OnResize(size); |
| 495 } | 702 } |
| 496 | 703 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 514 | 721 |
| 515 GpuCommandBufferStub* stub = | 722 GpuCommandBufferStub* stub = |
| 516 channel->LookupCommandBuffer(command_buffer_id_); | 723 channel->LookupCommandBuffer(command_buffer_id_); |
| 517 if (!stub) | 724 if (!stub) |
| 518 return NULL; | 725 return NULL; |
| 519 | 726 |
| 520 return stub->decoder(); | 727 return stub->decoder(); |
| 521 } | 728 } |
| 522 | 729 |
| 523 #endif // defined(USE_GPU) | 730 #endif // defined(USE_GPU) |
| OLD | NEW |