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" |
11 #include "content/renderer/render_thread_impl.h" | 11 #include "content/renderer/render_thread_impl.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 13 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
14 #include "gpu/command_buffer/client/gles2_implementation.h" | 14 #include "gpu/command_buffer/client/gles2_implementation.h" |
15 #include "gpu/ipc/command_buffer_proxy.h" | 15 #include "gpu/ipc/command_buffer_proxy.h" |
16 #include "ppapi/c/pp_graphics_3d.h" | 16 #include "ppapi/c/pp_graphics_3d.h" |
17 #include "ui/gl/gpu_preference.h" | 17 #include "ui/gl/gpu_preference.h" |
18 | 18 |
19 #ifdef ENABLE_GPU | 19 #ifdef ENABLE_GPU |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 PlatformContext3DImpl::PlatformContext3DImpl() | 23 PlatformContext3DImpl::PlatformContext3DImpl() |
24 : parent_texture_id_(0), | 24 : has_alpha_(false), |
25 has_alpha_(false), | |
26 command_buffer_(NULL), | 25 command_buffer_(NULL), |
27 weak_ptr_factory_(this) { | 26 weak_ptr_factory_(this) { |
28 } | 27 } |
29 | 28 |
30 PlatformContext3DImpl::~PlatformContext3DImpl() { | 29 PlatformContext3DImpl::~PlatformContext3DImpl() { |
31 DestroyParentContextProviderAndBackingTexture(); | |
32 | |
33 if (command_buffer_) { | 30 if (command_buffer_) { |
34 DCHECK(channel_.get()); | 31 DCHECK(channel_.get()); |
35 channel_->DestroyCommandBuffer(command_buffer_); | 32 channel_->DestroyCommandBuffer(command_buffer_); |
36 command_buffer_ = NULL; | 33 command_buffer_ = NULL; |
37 } | 34 } |
38 | 35 |
39 channel_ = NULL; | 36 channel_ = NULL; |
40 } | 37 } |
41 | 38 |
42 bool PlatformContext3DImpl::Init(const int32* attrib_list, | 39 bool PlatformContext3DImpl::Init(const int32* attrib_list, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 GURL::EmptyGURL(), | 102 GURL::EmptyGURL(), |
106 gpu_preference); | 103 gpu_preference); |
107 if (!command_buffer_) | 104 if (!command_buffer_) |
108 return false; | 105 return false; |
109 if (!command_buffer_->Initialize()) | 106 if (!command_buffer_->Initialize()) |
110 return false; | 107 return false; |
111 std::vector<gpu::Mailbox> names; | 108 std::vector<gpu::Mailbox> names; |
112 if (!command_buffer_->GenerateMailboxNames(1, &names)) | 109 if (!command_buffer_->GenerateMailboxNames(1, &names)) |
113 return false; | 110 return false; |
114 DCHECK_EQ(names.size(), 1u); | 111 DCHECK_EQ(names.size(), 1u); |
| 112 if (!command_buffer_->ProduceFrontBuffer(names[0])) |
| 113 return false; |
115 mailbox_ = names[0]; | 114 mailbox_ = names[0]; |
116 if (!command_buffer_->ProduceFrontBuffer(mailbox_)) | |
117 return false; | |
118 | 115 |
119 command_buffer_->SetChannelErrorCallback( | 116 command_buffer_->SetChannelErrorCallback( |
120 base::Bind(&PlatformContext3DImpl::OnContextLost, | 117 base::Bind(&PlatformContext3DImpl::OnContextLost, |
121 weak_ptr_factory_.GetWeakPtr())); | 118 weak_ptr_factory_.GetWeakPtr())); |
122 command_buffer_->SetOnConsoleMessageCallback( | 119 command_buffer_->SetOnConsoleMessageCallback( |
123 base::Bind(&PlatformContext3DImpl::OnConsoleMessage, | 120 base::Bind(&PlatformContext3DImpl::OnConsoleMessage, |
124 weak_ptr_factory_.GetWeakPtr())); | 121 weak_ptr_factory_.GetWeakPtr())); |
125 | 122 |
126 return SetParentAndCreateBackingTextureIfNeeded(); | |
127 } | |
128 | |
129 bool PlatformContext3DImpl::SetParentAndCreateBackingTextureIfNeeded() { | |
130 if (parent_context_provider_.get() && | |
131 !parent_context_provider_->DestroyedOnMainThread() && parent_texture_id_) | |
132 return true; | |
133 | |
134 parent_context_provider_ = | |
135 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); | |
136 parent_texture_id_ = 0; | |
137 if (!parent_context_provider_.get()) | |
138 return false; | |
139 | |
140 gpu::gles2::GLES2Implementation* parent_gles2 = | |
141 parent_context_provider_->Context3d()->GetImplementation(); | |
142 parent_gles2->GenTextures(1, &parent_texture_id_); | |
143 parent_gles2->BindTexture(GL_TEXTURE_2D, parent_texture_id_); | |
144 parent_gles2->ConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_.name); | |
145 parent_gles2->ShallowFlushCHROMIUM(); | |
146 return true; | 123 return true; |
147 } | 124 } |
148 | 125 |
149 void PlatformContext3DImpl::DestroyParentContextProviderAndBackingTexture() { | 126 void PlatformContext3DImpl::GetBackingMailbox(gpu::Mailbox* mailbox) { |
150 if (!parent_context_provider_.get()) | 127 *mailbox = mailbox_; |
151 return; | |
152 | |
153 if (parent_texture_id_) { | |
154 gpu::gles2::GLES2Implementation* parent_gles2 = | |
155 parent_context_provider_->Context3d()->GetImplementation(); | |
156 parent_gles2->DeleteTextures(1, &parent_texture_id_); | |
157 parent_gles2->ShallowFlushCHROMIUM(); | |
158 parent_texture_id_ = 0; | |
159 } | |
160 | |
161 parent_context_provider_ = NULL; | |
162 } | |
163 | |
164 unsigned PlatformContext3DImpl::GetBackingTextureId() { | |
165 DCHECK(command_buffer_); | |
166 return parent_texture_id_; | |
167 } | |
168 | |
169 WebKit::WebGraphicsContext3D* PlatformContext3DImpl::GetParentContext() { | |
170 if (!parent_context_provider_.get()) | |
171 return NULL; | |
172 return parent_context_provider_->Context3d(); | |
173 } | 128 } |
174 | 129 |
175 bool PlatformContext3DImpl::IsOpaque() { | 130 bool PlatformContext3DImpl::IsOpaque() { |
176 DCHECK(command_buffer_); | 131 DCHECK(command_buffer_); |
177 return !has_alpha_; | 132 return !has_alpha_; |
178 } | 133 } |
179 | 134 |
180 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() { | 135 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() { |
181 return command_buffer_; | 136 return command_buffer_; |
182 } | 137 } |
(...skipping 26 matching lines...) Expand all Loading... |
209 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { | 164 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { |
210 DCHECK(command_buffer_); | 165 DCHECK(command_buffer_); |
211 | 166 |
212 if (!console_message_callback_.is_null()) | 167 if (!console_message_callback_.is_null()) |
213 console_message_callback_.Run(msg, id); | 168 console_message_callback_.Run(msg, id); |
214 } | 169 } |
215 | 170 |
216 } // namespace content | 171 } // namespace content |
217 | 172 |
218 #endif // ENABLE_GPU | 173 #endif // ENABLE_GPU |
OLD | NEW |