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 #include "content/renderer/pepper/pepper_platform_context_3d_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_context_3d_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/common/gpu/client/context_provider_command_buffer.h" | 8 #include "content/common/gpu/client/context_provider_command_buffer.h" |
9 #include "content/common/gpu/client/gpu_channel_host.h" | 9 #include "content/common/gpu/client/gpu_channel_host.h" |
10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 10 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return true; | 46 return true; |
47 | 47 |
48 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 48 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
49 if (!render_thread) | 49 if (!render_thread) |
50 return false; | 50 return false; |
51 | 51 |
52 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 52 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
53 | 53 |
54 channel_ = render_thread->EstablishGpuChannelSync( | 54 channel_ = render_thread->EstablishGpuChannelSync( |
55 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); | 55 CAUSE_FOR_GPU_LAUNCH_PEPPERPLATFORMCONTEXT3DIMPL_INITIALIZE); |
56 if (!channel_) | 56 if (!channel_.get()) |
57 return false; | 57 return false; |
58 DCHECK(channel_->state() == GpuChannelHost::kConnected); | 58 DCHECK(channel_->state() == GpuChannelHost::kConnected); |
59 | 59 |
60 gfx::Size surface_size; | 60 gfx::Size surface_size; |
61 std::vector<int32> attribs; | 61 std::vector<int32> attribs; |
62 // TODO(alokp): Change GpuChannelHost::CreateOffscreenCommandBuffer() | 62 // TODO(alokp): Change GpuChannelHost::CreateOffscreenCommandBuffer() |
63 // interface to accept width and height in the attrib_list so that | 63 // interface to accept width and height in the attrib_list so that |
64 // we do not need to filter for width and height here. | 64 // we do not need to filter for width and height here. |
65 if (attrib_list) { | 65 if (attrib_list) { |
66 for (const int32_t* attr = attrib_list; | 66 for (const int32_t* attr = attrib_list; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 base::Bind(&PlatformContext3DImpl::OnContextLost, | 113 base::Bind(&PlatformContext3DImpl::OnContextLost, |
114 weak_ptr_factory_.GetWeakPtr())); | 114 weak_ptr_factory_.GetWeakPtr())); |
115 command_buffer_->SetOnConsoleMessageCallback( | 115 command_buffer_->SetOnConsoleMessageCallback( |
116 base::Bind(&PlatformContext3DImpl::OnConsoleMessage, | 116 base::Bind(&PlatformContext3DImpl::OnConsoleMessage, |
117 weak_ptr_factory_.GetWeakPtr())); | 117 weak_ptr_factory_.GetWeakPtr())); |
118 | 118 |
119 return SetParentAndCreateBackingTextureIfNeeded(); | 119 return SetParentAndCreateBackingTextureIfNeeded(); |
120 } | 120 } |
121 | 121 |
122 bool PlatformContext3DImpl::SetParentAndCreateBackingTextureIfNeeded() { | 122 bool PlatformContext3DImpl::SetParentAndCreateBackingTextureIfNeeded() { |
123 if (parent_context_provider_ && | 123 if (parent_context_provider_.get() && |
124 !parent_context_provider_->DestroyedOnMainThread() && | 124 !parent_context_provider_->DestroyedOnMainThread() && parent_texture_id_) |
125 parent_texture_id_) | |
126 return true; | 125 return true; |
127 | 126 |
128 parent_context_provider_ = | 127 parent_context_provider_ = |
129 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); | 128 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); |
130 parent_texture_id_ = 0; | 129 parent_texture_id_ = 0; |
131 if (!parent_context_provider_) | 130 if (!parent_context_provider_.get()) |
132 return false; | 131 return false; |
133 | 132 |
134 // Flush any remaining commands in the parent context to make sure the | 133 // Flush any remaining commands in the parent context to make sure the |
135 // texture id accounting stays consistent. | 134 // texture id accounting stays consistent. |
136 gpu::gles2::GLES2Implementation* parent_gles2 = | 135 gpu::gles2::GLES2Implementation* parent_gles2 = |
137 parent_context_provider_->Context3d()->GetImplementation(); | 136 parent_context_provider_->Context3d()->GetImplementation(); |
138 parent_gles2->helper()->CommandBufferHelper::Finish(); | 137 parent_gles2->helper()->CommandBufferHelper::Finish(); |
139 parent_texture_id_ = parent_gles2->MakeTextureId(); | 138 parent_texture_id_ = parent_gles2->MakeTextureId(); |
140 | 139 |
141 CommandBufferProxyImpl* parent_command_buffer = | 140 CommandBufferProxyImpl* parent_command_buffer = |
142 parent_context_provider_->Context3d()->GetCommandBufferProxy(); | 141 parent_context_provider_->Context3d()->GetCommandBufferProxy(); |
143 if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_)) | 142 if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_)) |
144 return false; | 143 return false; |
145 | 144 |
146 return true; | 145 return true; |
147 } | 146 } |
148 | 147 |
149 void PlatformContext3DImpl::DestroyParentContextProviderAndBackingTexture() { | 148 void PlatformContext3DImpl::DestroyParentContextProviderAndBackingTexture() { |
150 if (!parent_context_provider_) | 149 if (!parent_context_provider_.get()) |
151 return; | 150 return; |
152 | 151 |
153 if (parent_texture_id_) { | 152 if (parent_texture_id_) { |
154 // Flush any remaining commands in the parent context to make sure the | 153 // Flush any remaining commands in the parent context to make sure the |
155 // texture id accounting stays consistent. | 154 // texture id accounting stays consistent. |
156 gpu::gles2::GLES2Implementation* parent_gles2 = | 155 gpu::gles2::GLES2Implementation* parent_gles2 = |
157 parent_context_provider_->Context3d()->GetImplementation(); | 156 parent_context_provider_->Context3d()->GetImplementation(); |
158 parent_gles2->helper()->CommandBufferHelper::Finish(); | 157 parent_gles2->helper()->CommandBufferHelper::Finish(); |
159 parent_gles2->FreeTextureId(parent_texture_id_); | 158 parent_gles2->FreeTextureId(parent_texture_id_); |
160 parent_texture_id_ = 0; | 159 parent_texture_id_ = 0; |
161 } | 160 } |
162 | 161 |
163 parent_context_provider_ = NULL; | 162 parent_context_provider_ = NULL; |
164 } | 163 } |
165 | 164 |
166 unsigned PlatformContext3DImpl::GetBackingTextureId() { | 165 unsigned PlatformContext3DImpl::GetBackingTextureId() { |
167 DCHECK(command_buffer_); | 166 DCHECK(command_buffer_); |
168 return parent_texture_id_; | 167 return parent_texture_id_; |
169 } | 168 } |
170 | 169 |
171 WebKit::WebGraphicsContext3D* PlatformContext3DImpl::GetParentContext() { | 170 WebKit::WebGraphicsContext3D* PlatformContext3DImpl::GetParentContext() { |
172 if (!parent_context_provider_) | 171 if (!parent_context_provider_.get()) |
173 return NULL; | 172 return NULL; |
174 return parent_context_provider_->Context3d(); | 173 return parent_context_provider_->Context3d(); |
175 } | 174 } |
176 | 175 |
177 bool PlatformContext3DImpl::IsOpaque() { | 176 bool PlatformContext3DImpl::IsOpaque() { |
178 DCHECK(command_buffer_); | 177 DCHECK(command_buffer_); |
179 return !has_alpha_; | 178 return !has_alpha_; |
180 } | 179 } |
181 | 180 |
182 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() { | 181 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() { |
(...skipping 28 matching lines...) Expand all Loading... |
211 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { | 210 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { |
212 DCHECK(command_buffer_); | 211 DCHECK(command_buffer_); |
213 | 212 |
214 if (!console_message_callback_.is_null()) | 213 if (!console_message_callback_.is_null()) |
215 console_message_callback_.Run(msg, id); | 214 console_message_callback_.Run(msg, id); |
216 } | 215 } |
217 | 216 |
218 } // namespace content | 217 } // namespace content |
219 | 218 |
220 #endif // ENABLE_GPU | 219 #endif // ENABLE_GPU |
OLD | NEW |