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 #include "content/renderer/pepper_platform_context_3d_impl.h" | 5 #include "content/renderer/pepper_platform_context_3d_impl.h" |
| 6 | 6 |
| 7 #include "content/renderer/render_thread.h" | 7 #include "content/renderer/render_thread.h" |
| 8 #include "content/renderer/gpu/renderer_gl_context.h" | 8 #include "content/renderer/gpu/renderer_gl_context.h" |
| 9 #include "content/renderer/gpu/gpu_channel_host.h" | 9 #include "content/renderer/gpu/gpu_channel_host.h" |
| 10 #include "content/renderer/gpu/command_buffer_proxy.h" | 10 #include "content/renderer/gpu/command_buffer_proxy.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 if (command_buffer_) { | 34 if (command_buffer_) { |
| 35 DCHECK(channel_.get()); | 35 DCHECK(channel_.get()); |
| 36 channel_->DestroyCommandBuffer(command_buffer_); | 36 channel_->DestroyCommandBuffer(command_buffer_); |
| 37 command_buffer_ = NULL; | 37 command_buffer_ = NULL; |
| 38 } | 38 } |
| 39 | 39 |
| 40 channel_ = NULL; | 40 channel_ = NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool PlatformContext3DImpl::Init() { | 43 bool PlatformContext3DImpl::Init(const int32* attrib_list) { |
| 44 // Ignore initializing more than once. | 44 // Ignore initializing more than once. |
| 45 if (command_buffer_) | 45 if (command_buffer_) |
| 46 return true; | 46 return true; |
| 47 | 47 |
| 48 // Parent may already have been deleted. | 48 // Parent may already have been deleted. |
| 49 if (!parent_context_.get()) | 49 if (!parent_context_.get()) |
| 50 return false; | 50 return false; |
| 51 | 51 |
| 52 RenderThread* render_thread = RenderThread::current(); | 52 RenderThread* render_thread = RenderThread::current(); |
| 53 if (!render_thread) | 53 if (!render_thread) |
| 54 return false; | 54 return false; |
| 55 | 55 |
| 56 channel_ = render_thread->GetGpuChannel(); | 56 channel_ = render_thread->GetGpuChannel(); |
| 57 if (!channel_.get()) | 57 if (!channel_.get()) |
| 58 return false; | 58 return false; |
| 59 | 59 |
| 60 DCHECK(channel_->state() == GpuChannelHost::kConnected); | 60 DCHECK(channel_->state() == GpuChannelHost::kConnected); |
| 61 | 61 |
| 62 // Flush any remaining commands in the parent context to make sure the | 62 // Flush any remaining commands in the parent context to make sure the |
| 63 // texture id accounting stays consistent. | 63 // texture id accounting stays consistent. |
| 64 gpu::gles2::GLES2Implementation* parent_gles2 = | 64 gpu::gles2::GLES2Implementation* parent_gles2 = |
| 65 parent_context_->GetImplementation(); | 65 parent_context_->GetImplementation(); |
| 66 parent_gles2->helper()->CommandBufferHelper::Finish(); | 66 parent_gles2->helper()->CommandBufferHelper::Finish(); |
| 67 parent_texture_id_ = parent_gles2->MakeTextureId(); | 67 parent_texture_id_ = parent_gles2->MakeTextureId(); |
| 68 | 68 |
| 69 // TODO(apatrick): Let Pepper plugins configure their back buffer surface. | 69 // TODO(alokp): Remove this when we deprecate PPB_Context3D. |
| 70 static const int32 kAttribs[] = { | 70 static const int32 kAttribs[] = { |
| 71 RendererGLContext::ALPHA_SIZE, 8, | 71 RendererGLContext::ALPHA_SIZE, 8, |
| 72 RendererGLContext::DEPTH_SIZE, 24, | 72 RendererGLContext::DEPTH_SIZE, 24, |
| 73 RendererGLContext::STENCIL_SIZE, 8, | 73 RendererGLContext::STENCIL_SIZE, 8, |
| 74 RendererGLContext::SAMPLES, 0, | 74 RendererGLContext::SAMPLES, 0, |
| 75 RendererGLContext::SAMPLE_BUFFERS, 0, | 75 RendererGLContext::SAMPLE_BUFFERS, 0, |
| 76 RendererGLContext::HEIGHT, 1, | |
| 77 RendererGLContext::WIDTH, 1, | |
| 76 RendererGLContext::NONE, | 78 RendererGLContext::NONE, |
| 77 }; | 79 }; |
|
piman
2011/07/28 23:35:06
You could move this to PPB_Context3D_Impl
alokp
2011/07/29 16:13:12
Good idea. Done.
| |
| 78 std::vector<int32> attribs(kAttribs, kAttribs + ARRAYSIZE_UNSAFE(kAttribs)); | 80 attrib_list = attrib_list ? attrib_list : kAttribs; |
| 81 | |
| 82 gfx::Size surface_size; | |
| 83 std::vector<int32> attribs; | |
| 84 for (const int32_t* attr = attrib_list; | |
| 85 attr[0] != RendererGLContext::NONE; | |
| 86 attr += 2) { | |
| 87 switch (attr[0]) { | |
| 88 case RendererGLContext::WIDTH: | |
| 89 surface_size.set_width(attr[1]); | |
| 90 break; | |
| 91 case RendererGLContext::HEIGHT: | |
| 92 surface_size.set_height(attr[1]); | |
| 93 break; | |
| 94 default: | |
| 95 attribs.push_back(attr[0]); | |
| 96 attribs.push_back(attr[1]); | |
| 97 break; | |
| 98 } | |
| 99 } | |
| 100 attribs.push_back(RendererGLContext::NONE); | |
| 101 | |
| 79 CommandBufferProxy* parent_command_buffer = | 102 CommandBufferProxy* parent_command_buffer = |
| 80 parent_context_->GetCommandBufferProxy(); | 103 parent_context_->GetCommandBufferProxy(); |
| 81 command_buffer_ = channel_->CreateOffscreenCommandBuffer( | 104 command_buffer_ = channel_->CreateOffscreenCommandBuffer( |
| 82 gfx::Size(1, 1), | 105 surface_size, |
| 83 "*", | 106 "*", |
| 84 attribs, | 107 attribs, |
| 85 GURL::EmptyGURL()); | 108 GURL::EmptyGURL()); |
| 86 if (!command_buffer_) | 109 if (!command_buffer_) |
| 87 return false; | 110 return false; |
| 88 | 111 |
| 89 if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_)) | 112 if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_)) |
| 90 return false; | 113 return false; |
| 91 | 114 |
| 92 command_buffer_->SetChannelErrorCallback(callback_factory_.NewCallback( | 115 command_buffer_->SetChannelErrorCallback(callback_factory_.NewCallback( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 119 } | 142 } |
| 120 | 143 |
| 121 void PlatformContext3DImpl::OnContextLost() { | 144 void PlatformContext3DImpl::OnContextLost() { |
| 122 DCHECK(command_buffer_); | 145 DCHECK(command_buffer_); |
| 123 | 146 |
| 124 if (context_lost_callback_.get()) | 147 if (context_lost_callback_.get()) |
| 125 context_lost_callback_->Run(); | 148 context_lost_callback_->Run(); |
| 126 } | 149 } |
| 127 | 150 |
| 128 #endif // ENABLE_GPU | 151 #endif // ENABLE_GPU |
| OLD | NEW |