OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/renderer/pepper_platform_context_3d_impl.h" |
| 6 |
| 7 #include "chrome/renderer/ggl/ggl.h" |
| 8 #include "chrome/renderer/gpu_channel_host.h" |
| 9 #include "chrome/renderer/render_thread.h" |
| 10 |
| 11 #ifdef ENABLE_GPU |
| 12 PlatformContext3DImpl::PlatformContext3DImpl(ggl::Context* parent_context) |
| 13 : parent_context_(parent_context), |
| 14 context_(NULL) { |
| 15 } |
| 16 |
| 17 PlatformContext3DImpl::~PlatformContext3DImpl() { |
| 18 if (context_) { |
| 19 ggl::DestroyContext(context_); |
| 20 context_ = NULL; |
| 21 } |
| 22 } |
| 23 |
| 24 bool PlatformContext3DImpl::Init() { |
| 25 // Ignore initializing more than once. |
| 26 if (context_) |
| 27 return true; |
| 28 |
| 29 RenderThread* render_thread = RenderThread::current(); |
| 30 if (!render_thread) |
| 31 return false; |
| 32 |
| 33 GpuChannelHost* host = render_thread->GetGpuChannel(); |
| 34 if (!host) |
| 35 return false; |
| 36 |
| 37 DCHECK(host->state() == GpuChannelHost::kConnected); |
| 38 |
| 39 // TODO(apatrick): Let Pepper plugins configure their back buffer surface. |
| 40 static const int32 attribs[] = { |
| 41 ggl::GGL_ALPHA_SIZE, 8, |
| 42 ggl::GGL_DEPTH_SIZE, 24, |
| 43 ggl::GGL_STENCIL_SIZE, 8, |
| 44 ggl::GGL_SAMPLES, 0, |
| 45 ggl::GGL_SAMPLE_BUFFERS, 0, |
| 46 ggl::GGL_NONE, |
| 47 }; |
| 48 |
| 49 // TODO(apatrick): Decide which extensions to expose to Pepper plugins. |
| 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; |
| 58 |
| 59 return true; |
| 60 } |
| 61 |
| 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::ResizeBackingTexture(const gfx::Size& size) { |
| 73 DCHECK(context_); |
| 74 ggl::ResizeOffscreenContext(context_, size); |
| 75 } |
| 76 |
| 77 void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) { |
| 78 DCHECK(context_); |
| 79 ggl::SetSwapBuffersCallback(context_, callback); |
| 80 } |
| 81 |
| 82 unsigned PlatformContext3DImpl::GetBackingTextureId() { |
| 83 DCHECK(context_); |
| 84 return ggl::GetParentTextureId(context_); |
| 85 } |
| 86 |
| 87 gpu::gles2::GLES2Implementation* |
| 88 PlatformContext3DImpl::GetGLES2Implementation() { |
| 89 DCHECK(context_); |
| 90 return ggl::GetImplementation(context_); |
| 91 } |
| 92 |
| 93 #endif // ENABLE_GPU |
| 94 |
OLD | NEW |