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

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

Issue 15798014: Replace context parenting by sharing through mailboxes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add test 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"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 surface_size, 101 surface_size,
102 share_buffer, 102 share_buffer,
103 "*", 103 "*",
104 attribs, 104 attribs,
105 GURL::EmptyGURL(), 105 GURL::EmptyGURL(),
106 gpu_preference); 106 gpu_preference);
107 if (!command_buffer_) 107 if (!command_buffer_)
108 return false; 108 return false;
109 if (!command_buffer_->Initialize()) 109 if (!command_buffer_->Initialize())
110 return false; 110 return false;
111 std::vector<gpu::Mailbox> names;
112 if (!command_buffer_->GenerateMailboxNames(1, &names))
113 return false;
114 DCHECK_EQ(names.size(), 1u);
115 mailbox_ = names[0];
116 if (!command_buffer_->ProduceFrontBuffer(mailbox_))
117 return false;
111 118
112 command_buffer_->SetChannelErrorCallback( 119 command_buffer_->SetChannelErrorCallback(
113 base::Bind(&PlatformContext3DImpl::OnContextLost, 120 base::Bind(&PlatformContext3DImpl::OnContextLost,
114 weak_ptr_factory_.GetWeakPtr())); 121 weak_ptr_factory_.GetWeakPtr()));
115 command_buffer_->SetOnConsoleMessageCallback( 122 command_buffer_->SetOnConsoleMessageCallback(
116 base::Bind(&PlatformContext3DImpl::OnConsoleMessage, 123 base::Bind(&PlatformContext3DImpl::OnConsoleMessage,
117 weak_ptr_factory_.GetWeakPtr())); 124 weak_ptr_factory_.GetWeakPtr()));
118 125
119 return SetParentAndCreateBackingTextureIfNeeded(); 126 return SetParentAndCreateBackingTextureIfNeeded();
120 } 127 }
121 128
122 bool PlatformContext3DImpl::SetParentAndCreateBackingTextureIfNeeded() { 129 bool PlatformContext3DImpl::SetParentAndCreateBackingTextureIfNeeded() {
123 if (parent_context_provider_.get() && 130 if (parent_context_provider_.get() &&
124 !parent_context_provider_->DestroyedOnMainThread() && parent_texture_id_) 131 !parent_context_provider_->DestroyedOnMainThread() && parent_texture_id_)
125 return true; 132 return true;
126 133
127 parent_context_provider_ = 134 parent_context_provider_ =
128 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); 135 RenderThreadImpl::current()->OffscreenContextProviderForMainThread();
129 parent_texture_id_ = 0; 136 parent_texture_id_ = 0;
130 if (!parent_context_provider_.get()) 137 if (!parent_context_provider_.get())
131 return false; 138 return false;
132 139
133 // Flush any remaining commands in the parent context to make sure the
134 // texture id accounting stays consistent.
135 gpu::gles2::GLES2Implementation* parent_gles2 = 140 gpu::gles2::GLES2Implementation* parent_gles2 =
136 parent_context_provider_->Context3d()->GetImplementation(); 141 parent_context_provider_->Context3d()->GetImplementation();
137 parent_gles2->helper()->CommandBufferHelper::Finish(); 142 parent_gles2->GenTextures(1, &parent_texture_id_);
138 parent_texture_id_ = parent_gles2->MakeTextureId(); 143 parent_gles2->BindTexture(GL_TEXTURE_2D, parent_texture_id_);
139 144 parent_gles2->ConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_.name);
140 CommandBufferProxyImpl* parent_command_buffer = 145 parent_gles2->ShallowFlushCHROMIUM();
141 parent_context_provider_->Context3d()->GetCommandBufferProxy();
142 if (!command_buffer_->SetParent(parent_command_buffer, parent_texture_id_))
143 return false;
144
145 return true; 146 return true;
146 } 147 }
147 148
148 void PlatformContext3DImpl::DestroyParentContextProviderAndBackingTexture() { 149 void PlatformContext3DImpl::DestroyParentContextProviderAndBackingTexture() {
149 if (!parent_context_provider_.get()) 150 if (!parent_context_provider_.get())
150 return; 151 return;
151 152
152 if (parent_texture_id_) { 153 if (parent_texture_id_) {
153 // Flush any remaining commands in the parent context to make sure the
154 // texture id accounting stays consistent.
155 gpu::gles2::GLES2Implementation* parent_gles2 = 154 gpu::gles2::GLES2Implementation* parent_gles2 =
156 parent_context_provider_->Context3d()->GetImplementation(); 155 parent_context_provider_->Context3d()->GetImplementation();
157 parent_gles2->helper()->CommandBufferHelper::Finish(); 156 parent_gles2->DeleteTextures(1, &parent_texture_id_);
158 parent_gles2->FreeTextureId(parent_texture_id_); 157 parent_gles2->ShallowFlushCHROMIUM();
159 parent_texture_id_ = 0; 158 parent_texture_id_ = 0;
160 } 159 }
161 160
162 parent_context_provider_ = NULL; 161 parent_context_provider_ = NULL;
163 } 162 }
164 163
165 unsigned PlatformContext3DImpl::GetBackingTextureId() { 164 unsigned PlatformContext3DImpl::GetBackingTextureId() {
166 DCHECK(command_buffer_); 165 DCHECK(command_buffer_);
167 return parent_texture_id_; 166 return parent_texture_id_;
168 } 167 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) { 209 void PlatformContext3DImpl::OnConsoleMessage(const std::string& msg, int id) {
211 DCHECK(command_buffer_); 210 DCHECK(command_buffer_);
212 211
213 if (!console_message_callback_.is_null()) 212 if (!console_message_callback_.is_null())
214 console_message_callback_.Run(msg, id); 213 console_message_callback_.Run(msg, id);
215 } 214 }
216 215
217 } // namespace content 216 } // namespace content
218 217
219 #endif // ENABLE_GPU 218 #endif // ENABLE_GPU
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698