Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: content/renderer/pepper/pepper_platform_context_3d_impl.cc

Issue 16290005: Move Pepper to using mailboxes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_ &&
131 !parent_context_provider_->DestroyedOnMainThread() &&
132 parent_texture_id_)
133 return true;
134
135 parent_context_provider_ =
136 RenderThreadImpl::current()->OffscreenContextProviderForMainThread();
137 parent_texture_id_ = 0;
138 if (!parent_context_provider_)
139 return false;
140
141 gpu::gles2::GLES2Implementation* parent_gles2 =
142 parent_context_provider_->Context3d()->GetImplementation();
143 parent_gles2->GenTextures(1, &parent_texture_id_);
144 parent_gles2->BindTexture(GL_TEXTURE_2D, parent_texture_id_);
145 parent_gles2->ConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_.name);
146 parent_gles2->ShallowFlushCHROMIUM();
147 return true; 123 return true;
148 } 124 }
149 125
150 void PlatformContext3DImpl::DestroyParentContextProviderAndBackingTexture() { 126 void PlatformContext3DImpl::GetBackingMailbox(gpu::Mailbox* mailbox) {
151 if (!parent_context_provider_) 127 *mailbox = mailbox_;
152 return;
153
154 if (parent_texture_id_) {
155 gpu::gles2::GLES2Implementation* parent_gles2 =
156 parent_context_provider_->Context3d()->GetImplementation();
157 parent_gles2->DeleteTextures(1, &parent_texture_id_);
158 parent_gles2->ShallowFlushCHROMIUM();
159 parent_texture_id_ = 0;
160 }
161
162 parent_context_provider_ = NULL;
163 }
164
165 unsigned PlatformContext3DImpl::GetBackingTextureId() {
166 DCHECK(command_buffer_);
167 return parent_texture_id_;
168 }
169
170 WebKit::WebGraphicsContext3D* PlatformContext3DImpl::GetParentContext() {
171 if (!parent_context_provider_)
172 return NULL;
173 return parent_context_provider_->Context3d();
174 } 128 }
175 129
176 bool PlatformContext3DImpl::IsOpaque() { 130 bool PlatformContext3DImpl::IsOpaque() {
177 DCHECK(command_buffer_); 131 DCHECK(command_buffer_);
178 return !has_alpha_; 132 return !has_alpha_;
179 } 133 }
180 134
181 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() { 135 gpu::CommandBuffer* PlatformContext3DImpl::GetCommandBuffer() {
182 return command_buffer_; 136 return command_buffer_;
183 } 137 }
(...skipping 26 matching lines...) Expand all
210 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { 164 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) {
211 DCHECK(command_buffer_); 165 DCHECK(command_buffer_);
212 166
213 if (!console_message_callback_.is_null()) 167 if (!console_message_callback_.is_null())
214 console_message_callback_.Run(msg, id); 168 console_message_callback_.Run(msg, id);
215 } 169 }
216 170
217 } // namespace content 171 } // namespace content
218 172
219 #endif // ENABLE_GPU 173 #endif // ENABLE_GPU
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698