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

Side by Side Diff: content/common/gpu/stream_texture_android.cc

Issue 1129943006: Implement StreamTexture::BindTexImage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/common/gpu/stream_texture_android.h" 5 #include "content/common/gpu/stream_texture_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/common/android/surface_texture_peer.h" 8 #include "content/common/android/surface_texture_peer.h"
9 #include "content/common/gpu/gpu_channel.h" 9 #include "content/common/gpu/gpu_channel.h"
10 #include "content/common/gpu/gpu_messages.h" 10 #include "content/common/gpu/gpu_messages.h"
11 #include "gpu/command_buffer/service/context_group.h" 11 #include "gpu/command_buffer/service/context_group.h"
12 #include "gpu/command_buffer/service/context_state.h" 12 #include "gpu/command_buffer/service/context_state.h"
13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
14 #include "gpu/command_buffer/service/image_manager.h"
14 #include "gpu/command_buffer/service/texture_manager.h" 15 #include "gpu/command_buffer/service/texture_manager.h"
15 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
16 #include "ui/gl/gl_context.h" 17 #include "ui/gl/gl_context.h"
17 #include "ui/gl/scoped_make_current.h" 18 #include "ui/gl/scoped_make_current.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 using gpu::gles2::ContextGroup; 22 using gpu::gles2::ContextGroup;
22 using gpu::gles2::GLES2Decoder; 23 using gpu::gles2::GLES2Decoder;
24 using gpu::gles2::ImageManager;
23 using gpu::gles2::TextureManager; 25 using gpu::gles2::TextureManager;
24 using gpu::gles2::TextureRef; 26 using gpu::gles2::TextureRef;
25 27
26 // static 28 // static
27 bool StreamTexture::Create( 29 bool StreamTexture::CreateStreamTextureImage(GpuCommandBufferStub* owner_stub,
28 GpuCommandBufferStub* owner_stub, 30 int32 image_id,
29 uint32 client_texture_id, 31 int32 stream_id) {
30 int stream_id) { 32 DCHECK(owner_stub);
33 GLES2Decoder* decoder = owner_stub->decoder();
34 DCHECK(decoder);
35 ImageManager* image_manager = decoder->GetImageManager();
36 DCHECK(image_manager);
37 scoped_refptr<StreamTexture> image(
38 new StreamTexture(owner_stub, stream_id, 0));
39 image_manager->AddImage(image.get(), image_id);
40 return true;
41 }
42
43 // static
44 bool StreamTexture::CreateStreamTexture(GpuCommandBufferStub* owner_stub,
45 uint32 client_texture_id,
46 int stream_id) {
31 GLES2Decoder* decoder = owner_stub->decoder(); 47 GLES2Decoder* decoder = owner_stub->decoder();
32 TextureManager* texture_manager = 48 TextureManager* texture_manager =
33 decoder->GetContextGroup()->texture_manager(); 49 decoder->GetContextGroup()->texture_manager();
34 TextureRef* texture = texture_manager->GetTexture(client_texture_id); 50 TextureRef* texture = texture_manager->GetTexture(client_texture_id);
35 51
36 if (texture && (!texture->texture()->target() || 52 if (texture && (!texture->texture()->target() ||
37 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) { 53 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) {
38 54
39 // TODO: Ideally a valid image id was returned to the client so that 55 // TODO: Ideally a valid image id was returned to the client so that
40 // it could then call glBindTexImage2D() for doing the following. 56 // it could then call glBindTexImage2D() for doing the following.
41 scoped_refptr<gfx::GLImage> gl_image( 57 scoped_refptr<gfx::GLImage> gl_image(
42 new StreamTexture(owner_stub, stream_id, texture->service_id())); 58 new StreamTexture(owner_stub, stream_id, texture->service_id()));
43 gfx::Size size = gl_image->GetSize(); 59 gfx::Size size = gl_image->GetSize();
44 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); 60 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES);
45 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, 61 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA,
46 size.width(), size.height(), 1, 0, GL_RGBA, 62 size.width(), size.height(), 1, 0, GL_RGBA,
47 GL_UNSIGNED_BYTE, gfx::Rect(size)); 63 GL_UNSIGNED_BYTE, gfx::Rect(size));
48 texture_manager->SetLevelImage( 64 texture_manager->SetLevelImage(
49 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get()); 65 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get());
50 return true; 66 return true;
51 } 67 }
52 68
53 return false; 69 return false;
54 } 70 }
55 71
56 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, 72 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
57 int32 route_id, 73 int32 route_id,
58 uint32 texture_id) 74 int32 texture_id)
59 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), 75 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)),
60 size_(0, 0), 76 size_(0, 0),
61 has_valid_frame_(false), 77 has_valid_frame_(false),
62 has_pending_frame_(false), 78 has_pending_frame_(false),
63 owner_stub_(owner_stub), 79 owner_stub_(owner_stub),
64 route_id_(route_id), 80 route_id_(route_id),
65 has_listener_(false), 81 has_listener_(false),
82 texture_id_(texture_id),
66 weak_factory_(this) { 83 weak_factory_(this) {
67 owner_stub->AddDestructionObserver(this); 84 owner_stub->AddDestructionObserver(this);
68 memset(current_matrix_, 0, sizeof(current_matrix_)); 85 memset(current_matrix_, 0, sizeof(current_matrix_));
69 owner_stub->channel()->AddRoute(route_id, this); 86 owner_stub->channel()->AddRoute(route_id, this);
70 surface_texture_->SetFrameAvailableCallback(base::Bind( 87 surface_texture_->SetFrameAvailableCallback(base::Bind(
71 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); 88 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr()));
72 } 89 }
73 90
74 StreamTexture::~StreamTexture() { 91 StreamTexture::~StreamTexture() {
75 if (owner_stub_) { 92 if (owner_stub_) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (!owner_stub_) 201 if (!owner_stub_)
185 return; 202 return;
186 203
187 base::ProcessHandle process = owner_stub_->channel()->renderer_pid(); 204 base::ProcessHandle process = owner_stub_->channel()->renderer_pid();
188 205
189 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( 206 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer(
190 process, surface_texture_, primary_id, secondary_id); 207 process, surface_texture_, primary_id, secondary_id);
191 } 208 }
192 209
193 bool StreamTexture::BindTexImage(unsigned target) { 210 bool StreamTexture::BindTexImage(unsigned target) {
194 NOTREACHED(); 211 TRACE_EVENT0("gpu", "StreamTexture::BindTexImage");
195 return false; 212 DCHECK(surface_texture_.get());
213 if (!owner_stub_ || !surface_texture_.get())
214 return false;
215
216 if (target != GL_TEXTURE_EXTERNAL_OES) {
217 LOG(ERROR)
218 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target";
219 return false;
220 }
221
222 GLint texture_id;
223 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
224 DCHECK(texture_id);
225 if (!texture_id_)
226 texture_id_ = texture_id;
227 if (texture_id_ && texture_id_ != texture_id) {
228 LOG(ERROR) << "Surface texture can only be bound to one texture ID";
229 return false;
230 }
231 // Note: Surface textures used as gpu memory buffers are created with an
232 // initial dummy texture id of 0. We need to call DetachFromGLContext() here
233 // to detach from the dummy texture before we can attach to a real texture
234 // id. DetachFromGLContext() will delete the texture for the current
235 // attachment point so it's important that this is never called when
236 // attached to a real texture id. Detaching from the dummy texture id should
237 // not cause any problems as the GL should silently ignore 0 when passed to
238 // glDeleteTextures.
239 surface_texture_->DetachFromGLContext();
240 // This will attach the surface texture to the texture currently bound to
241 // GL_TEXTURE_EXTERNAL_OES target.
242 surface_texture_->AttachToGLContext();
243
244 surface_texture_->UpdateTexImage();
245 return true;
196 } 246 }
197 247
198 void StreamTexture::ReleaseTexImage(unsigned target) { 248 void StreamTexture::ReleaseTexImage(unsigned target) {
199 NOTREACHED(); 249 NOTREACHED();
200 } 250 }
201 251
202 bool StreamTexture::CopyTexSubImage(unsigned target, 252 bool StreamTexture::CopyTexSubImage(unsigned target,
203 const gfx::Point& offset, 253 const gfx::Point& offset,
204 const gfx::Rect& rect) { 254 const gfx::Rect& rect) {
205 return false; 255 return false;
206 } 256 }
207 257
208 bool StreamTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, 258 bool StreamTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
209 int z_order, 259 int z_order,
210 gfx::OverlayTransform transform, 260 gfx::OverlayTransform transform,
211 const gfx::Rect& bounds_rect, 261 const gfx::Rect& bounds_rect,
212 const gfx::RectF& crop_rect) { 262 const gfx::RectF& crop_rect) {
213 NOTREACHED(); 263 NOTREACHED();
214 return false; 264 return false;
215 } 265 }
216 266
217 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698