| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/renderer/pepper_platform_context_3d_impl.h" | 5 #include "chrome/renderer/pepper_platform_context_3d_impl.h" |
| 6 | 6 |
| 7 #include "chrome/renderer/command_buffer_proxy.h" |
| 7 #include "chrome/renderer/ggl/ggl.h" | 8 #include "chrome/renderer/ggl/ggl.h" |
| 8 #include "chrome/renderer/gpu_channel_host.h" | 9 #include "chrome/renderer/gpu_channel_host.h" |
| 9 #include "chrome/renderer/render_thread.h" | 10 #include "chrome/renderer/render_thread.h" |
| 11 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 12 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 | 13 |
| 11 #ifdef ENABLE_GPU | 14 #ifdef ENABLE_GPU |
| 12 PlatformContext3DImpl::PlatformContext3DImpl(ggl::Context* parent_context) | 15 PlatformContext3DImpl::PlatformContext3DImpl(ggl::Context* parent_context) |
| 13 : parent_context_(parent_context), | 16 : parent_context_(parent_context), |
| 14 context_(NULL) { | 17 command_buffer_(NULL) { |
| 15 } | 18 } |
| 16 | 19 |
| 17 PlatformContext3DImpl::~PlatformContext3DImpl() { | 20 PlatformContext3DImpl::~PlatformContext3DImpl() { |
| 18 if (context_) { | 21 if (command_buffer_) { |
| 19 ggl::DestroyContext(context_); | 22 DCHECK(channel_.get()); |
| 20 context_ = NULL; | 23 channel_->DestroyCommandBuffer(command_buffer_); |
| 24 command_buffer_ = NULL; |
| 21 } | 25 } |
| 26 |
| 27 channel_ = NULL; |
| 28 |
| 29 if (parent_context_ && parent_texture_id_ != 0) { |
| 30 ggl::GetImplementation(parent_context_)->FreeTextureId(parent_texture_id_); |
| 31 } |
| 32 |
| 22 } | 33 } |
| 23 | 34 |
| 24 bool PlatformContext3DImpl::Init() { | 35 bool PlatformContext3DImpl::Init() { |
| 25 // Ignore initializing more than once. | 36 // Ignore initializing more than once. |
| 26 if (context_) | 37 if (command_buffer_) |
| 27 return true; | 38 return true; |
| 28 | 39 |
| 29 RenderThread* render_thread = RenderThread::current(); | 40 RenderThread* render_thread = RenderThread::current(); |
| 30 if (!render_thread) | 41 if (!render_thread) |
| 31 return false; | 42 return false; |
| 32 | 43 |
| 33 GpuChannelHost* host = render_thread->GetGpuChannel(); | 44 channel_ = render_thread->GetGpuChannel(); |
| 34 if (!host) | 45 if (!channel_.get()) |
| 35 return false; | 46 return false; |
| 36 | 47 |
| 37 DCHECK(host->state() == GpuChannelHost::kConnected); | 48 DCHECK(channel_->state() == GpuChannelHost::kConnected); |
| 49 |
| 50 // Flush any remaining commands in the parent context to make sure the |
| 51 // texture id accounting stays consistent. |
| 52 gpu::gles2::GLES2Implementation* parent_gles2 = |
| 53 ggl::GetImplementation(parent_context_); |
| 54 parent_gles2->helper()->CommandBufferHelper::Finish(); |
| 55 parent_texture_id_ = parent_gles2->MakeTextureId(); |
| 38 | 56 |
| 39 // TODO(apatrick): Let Pepper plugins configure their back buffer surface. | 57 // TODO(apatrick): Let Pepper plugins configure their back buffer surface. |
| 40 static const int32 attribs[] = { | 58 static const int32 kAttribs[] = { |
| 41 ggl::GGL_ALPHA_SIZE, 8, | 59 ggl::GGL_ALPHA_SIZE, 8, |
| 42 ggl::GGL_DEPTH_SIZE, 24, | 60 ggl::GGL_DEPTH_SIZE, 24, |
| 43 ggl::GGL_STENCIL_SIZE, 8, | 61 ggl::GGL_STENCIL_SIZE, 8, |
| 44 ggl::GGL_SAMPLES, 0, | 62 ggl::GGL_SAMPLES, 0, |
| 45 ggl::GGL_SAMPLE_BUFFERS, 0, | 63 ggl::GGL_SAMPLE_BUFFERS, 0, |
| 46 ggl::GGL_NONE, | 64 ggl::GGL_NONE, |
| 47 }; | 65 }; |
| 66 std::vector<int32> attribs(kAttribs, kAttribs + ARRAYSIZE_UNSAFE(kAttribs)); |
| 67 CommandBufferProxy* parent_command_buffer = |
| 68 ggl::GetCommandBufferProxy(parent_context_); |
| 69 command_buffer_ = channel_->CreateOffscreenCommandBuffer( |
| 70 parent_command_buffer, |
| 71 gfx::Size(1, 1), |
| 72 "", |
| 73 attribs, |
| 74 parent_texture_id_); |
| 48 | 75 |
| 49 // TODO(apatrick): Decide which extensions to expose to Pepper plugins. | 76 if (!command_buffer_) |
| 50 // Currently they get only core GLES2. | |
| 51 context_ = ggl::CreateOffscreenContext(host, | |
| 52 parent_context_, | |
| 53 gfx::Size(1, 1), | |
| 54 "", | |
| 55 attribs); | |
| 56 if (!context_) | |
| 57 return false; | 77 return false; |
| 58 | 78 |
| 59 return true; | 79 return true; |
| 60 } | 80 } |
| 61 | 81 |
| 62 bool PlatformContext3DImpl::SwapBuffers() { | |
| 63 DCHECK(context_); | |
| 64 return ggl::SwapBuffers(context_); | |
| 65 } | |
| 66 | |
| 67 unsigned PlatformContext3DImpl::GetError() { | |
| 68 DCHECK(context_); | |
| 69 return ggl::GetError(context_); | |
| 70 } | |
| 71 | |
| 72 void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) { | 82 void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) { |
| 73 DCHECK(context_); | 83 DCHECK(command_buffer_); |
| 74 ggl::SetSwapBuffersCallback(context_, callback); | 84 command_buffer_->SetSwapBuffersCallback(callback); |
| 75 } | 85 } |
| 76 | 86 |
| 77 unsigned PlatformContext3DImpl::GetBackingTextureId() { | 87 unsigned PlatformContext3DImpl::GetBackingTextureId() { |
| 78 DCHECK(context_); | 88 DCHECK(command_buffer_); |
| 79 return ggl::GetParentTextureId(context_); | 89 return parent_texture_id_; |
| 80 } | 90 } |
| 81 | 91 |
| 82 gpu::gles2::GLES2Implementation* | 92 gpu::CommandBuffer* |
| 83 PlatformContext3DImpl::GetGLES2Implementation() { | 93 PlatformContext3DImpl::GetCommandBuffer() { |
| 84 DCHECK(context_); | 94 return command_buffer_; |
| 85 return ggl::GetImplementation(context_); | |
| 86 } | 95 } |
| 87 | 96 |
| 88 #endif // ENABLE_GPU | 97 #endif // ENABLE_GPU |
| 89 | 98 |
| OLD | NEW |