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

Side by Side Diff: content/renderer/gpu/renderer_gl_context.cc

Issue 7529015: Allow the renderer process to map textures from one context into another. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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) 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/gpu/renderer_gl_context.h" 5 #include "content/renderer/gpu/renderer_gl_context.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 attrib_list, 127 attrib_list,
128 active_url)) 128 active_url))
129 return NULL; 129 return NULL;
130 130
131 return context.release(); 131 return context.release();
132 #else 132 #else
133 return NULL; 133 return NULL;
134 #endif 134 #endif
135 } 135 }
136 136
137 bool RendererGLContext::MapExternalResource(
138 gpu::resource_type::ResourceType resource_type,
139 uint32 resource_source_id,
140 RendererGLContext* source_context,
141 uint32 resource_dest_id) {
142 if (!command_buffer_)
143 return false;
144
145 return command_buffer_->MapExternalResource(
146 resource_type,
147 resource_source_id,
148 source_context ? source_context->command_buffer_ : NULL,
149 resource_dest_id);
150 }
151
152 bool RendererGLContext::MapExternalResourceToParent(
153 gpu::resource_type::ResourceType resource_type,
154 uint32 resource_source_id,
155 uint32 resource_dest_id) {
156 if (!command_buffer_)
157 return false;
158
159 if (!parent_.get())
160 return false;
161
162 return parent_->MapExternalResource(
163 resource_type,
164 resource_source_id,
165 this,
166 resource_dest_id);
167 }
168
137 bool RendererGLContext::SetParent(RendererGLContext* new_parent) { 169 bool RendererGLContext::SetParent(RendererGLContext* new_parent) {
138 if (parent_.get() == new_parent) 170 if (parent_.get() == new_parent)
139 return true; 171 return true;
140 172
141 // Allocate a texture ID with respect to the parent and change the parent. 173 // Allocate a texture ID with respect to the parent and change the parent.
142 uint32 new_parent_texture_id = 0; 174 uint32 new_parent_texture_id = 0;
143 if (command_buffer_) { 175 if (command_buffer_) {
144 if (new_parent) { 176 if (new_parent) {
145 TRACE_EVENT0("gpu", "RendererGLContext::SetParent::flushParent"); 177 TRACE_EVENT0("gpu", "RendererGLContext::SetParent::flushParent");
146 // Flush any remaining commands in the parent context to make sure the 178 // Flush any remaining commands in the parent context to make sure the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 command_buffer_->ResizeOffscreenFrameBuffer(size); 220 command_buffer_->ResizeOffscreenFrameBuffer(size);
189 size_ = size; 221 size_ = size;
190 } 222 }
191 } 223 }
192 224
193 uint32 RendererGLContext::GetParentTextureId() { 225 uint32 RendererGLContext::GetParentTextureId() {
194 return parent_texture_id_; 226 return parent_texture_id_;
195 } 227 }
196 228
197 uint32 RendererGLContext::CreateParentTexture(const gfx::Size& size) { 229 uint32 RendererGLContext::CreateParentTexture(const gfx::Size& size) {
198 // Allocate a texture ID with respect to the parent.
199 if (parent_.get()) { 230 if (parent_.get()) {
200 if (!MakeCurrent(parent_.get())) 231 // Reserve a parent texture ID on the client side.
201 return 0; 232 uint32 parent_texture_id = 0;
202 uint32 texture_id = parent_->gles2_implementation_->MakeTextureId(); 233 parent_->gles2_implementation_->GenTextures(1, &parent_texture_id);
203 parent_->gles2_implementation_->BindTexture(GL_TEXTURE_2D, texture_id); 234 return parent_texture_id;
204 parent_->gles2_implementation_->TexParameteri(
205 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
206 parent_->gles2_implementation_->TexParameteri(
207 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
208 parent_->gles2_implementation_->TexParameteri(
209 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
210 parent_->gles2_implementation_->TexParameteri(
211 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
212
213 parent_->gles2_implementation_->TexImage2D(GL_TEXTURE_2D,
214 0, // mip level
215 GL_RGBA,
216 size.width(),
217 size.height(),
218 0, // border
219 GL_RGBA,
220 GL_UNSIGNED_BYTE,
221 NULL);
222 // Make sure that the parent texture's storage is allocated before we let
223 // the caller attempt to use it.
224 int32 token = parent_->gles2_helper_->InsertToken();
225 parent_->gles2_helper_->WaitForToken(token);
226 return texture_id;
227 } 235 }
228 return 0; 236 return 0;
229 } 237 }
230 238
231 void RendererGLContext::DeleteParentTexture(uint32 texture) { 239 void RendererGLContext::DeleteParentTexture(uint32 texture) {
232 if (parent_.get()) { 240 if (parent_.get())
233 if (!MakeCurrent(parent_.get()))
234 return;
235 parent_->gles2_implementation_->DeleteTextures(1, &texture); 241 parent_->gles2_implementation_->DeleteTextures(1, &texture);
236 }
237 } 242 }
238 243
239 void RendererGLContext::SetSwapBuffersCallback(Callback0::Type* callback) { 244 void RendererGLContext::SetSwapBuffersCallback(Callback0::Type* callback) {
240 swap_buffers_callback_.reset(callback); 245 swap_buffers_callback_.reset(callback);
241 } 246 }
242 247
243 void RendererGLContext::SetContextLostCallback( 248 void RendererGLContext::SetContextLostCallback(
244 Callback1<ContextLostReason>::Type* callback) { 249 Callback1<ContextLostReason>::Type* callback) {
245 context_lost_callback_.reset(callback); 250 context_lost_callback_.reset(callback);
246 } 251 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 void RendererGLContext::OnContextLost() { 484 void RendererGLContext::OnContextLost() {
480 if (context_lost_callback_.get()) { 485 if (context_lost_callback_.get()) {
481 RendererGLContext::ContextLostReason reason = kUnknown; 486 RendererGLContext::ContextLostReason reason = kUnknown;
482 if (command_buffer_) { 487 if (command_buffer_) {
483 reason = ConvertReason( 488 reason = ConvertReason(
484 command_buffer_->GetLastState().context_lost_reason); 489 command_buffer_->GetLastState().context_lost_reason);
485 } 490 }
486 context_lost_callback_->Run(reason); 491 context_lost_callback_->Run(reason);
487 } 492 }
488 } 493 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698