| OLD | NEW |
| 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::Create(GpuCommandBufferStub* owner_stub, |
| 28 GpuCommandBufferStub* owner_stub, | 30 int32 image_id, |
| 29 uint32 client_texture_id, | 31 int32 stream_id) { |
| 30 int stream_id) { | |
| 31 GLES2Decoder* decoder = owner_stub->decoder(); | 32 GLES2Decoder* decoder = owner_stub->decoder(); |
| 32 TextureManager* texture_manager = | 33 ImageManager* image_manager = decoder->GetImageManager(); |
| 33 decoder->GetContextGroup()->texture_manager(); | 34 DCHECK(decoder); |
| 34 TextureRef* texture = texture_manager->GetTexture(client_texture_id); | 35 DCHECK(image_manager); |
| 35 | 36 image_manager->AddImage(new StreamTexture(owner_stub, stream_id, 0), |
| 36 if (texture && (!texture->texture()->target() || | 37 image_id); |
| 37 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) { | 38 return true; |
| 38 | |
| 39 // TODO: Ideally a valid image id was returned to the client so that | |
| 40 // it could then call glBindTexImage2D() for doing the following. | |
| 41 scoped_refptr<gfx::GLImage> gl_image( | |
| 42 new StreamTexture(owner_stub, stream_id, texture->service_id())); | |
| 43 gfx::Size size = gl_image->GetSize(); | |
| 44 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); | |
| 45 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, | |
| 46 size.width(), size.height(), 1, 0, GL_RGBA, | |
| 47 GL_UNSIGNED_BYTE, gfx::Rect(size)); | |
| 48 texture_manager->SetLevelImage( | |
| 49 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get()); | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 return false; | |
| 54 } | 39 } |
| 55 | 40 |
| 56 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, | 41 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, |
| 57 int32 route_id, | 42 int32 route_id, |
| 58 uint32 texture_id) | 43 int32 texture_id) |
| 59 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), | 44 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), |
| 60 size_(0, 0), | 45 size_(0, 0), |
| 61 has_valid_frame_(false), | 46 has_valid_frame_(false), |
| 62 has_pending_frame_(false), | 47 has_pending_frame_(false), |
| 63 owner_stub_(owner_stub), | 48 owner_stub_(owner_stub), |
| 64 route_id_(route_id), | 49 route_id_(route_id), |
| 65 has_listener_(false), | 50 has_listener_(false), |
| 51 texture_id_(texture_id), |
| 66 weak_factory_(this) { | 52 weak_factory_(this) { |
| 67 owner_stub->AddDestructionObserver(this); | 53 owner_stub->AddDestructionObserver(this); |
| 68 memset(current_matrix_, 0, sizeof(current_matrix_)); | 54 memset(current_matrix_, 0, sizeof(current_matrix_)); |
| 69 owner_stub->channel()->AddRoute(route_id, this); | 55 owner_stub->channel()->AddRoute(route_id, this); |
| 70 surface_texture_->SetFrameAvailableCallback(base::Bind( | 56 surface_texture_->SetFrameAvailableCallback(base::Bind( |
| 71 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); | 57 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); |
| 72 } | 58 } |
| 73 | 59 |
| 74 StreamTexture::~StreamTexture() { | 60 StreamTexture::~StreamTexture() { |
| 75 if (owner_stub_) { | 61 if (owner_stub_) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (!owner_stub_) | 170 if (!owner_stub_) |
| 185 return; | 171 return; |
| 186 | 172 |
| 187 base::ProcessHandle process = owner_stub_->channel()->renderer_pid(); | 173 base::ProcessHandle process = owner_stub_->channel()->renderer_pid(); |
| 188 | 174 |
| 189 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( | 175 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( |
| 190 process, surface_texture_, primary_id, secondary_id); | 176 process, surface_texture_, primary_id, secondary_id); |
| 191 } | 177 } |
| 192 | 178 |
| 193 bool StreamTexture::BindTexImage(unsigned target) { | 179 bool StreamTexture::BindTexImage(unsigned target) { |
| 194 NOTREACHED(); | 180 TRACE_EVENT0("gpu", "StreamTexture::BindTexImage"); |
| 195 return false; | 181 DCHECK(surface_texture_.get()); |
| 182 if (!owner_stub_ || !surface_texture_.get()) |
| 183 return false; |
| 184 |
| 185 if (target != GL_TEXTURE_EXTERNAL_OES) { |
| 186 LOG(ERROR) |
| 187 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target"; |
| 188 return false; |
| 189 } |
| 190 |
| 191 GLint texture_id; |
| 192 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
| 193 DCHECK(texture_id); |
| 194 if (texture_id_ && texture_id_ != texture_id) { |
| 195 LOG(ERROR) << "Surface texture can only be bound to one texture ID"; |
| 196 return false; |
| 197 } |
| 198 |
| 199 if (texture_id != texture_id_) { |
| 200 // Note: Surface textures used as gpu memory buffers are created with an |
| 201 // initial dummy texture id of 0. We need to call DetachFromGLContext() here |
| 202 // to detach from the dummy texture before we can attach to a real texture |
| 203 // id. DetachFromGLContext() will delete the texture for the current |
| 204 // attachment point so it's important that this is never called when |
| 205 // attached to a real texture id. Detaching from the dummy texture id should |
| 206 // not cause any problems as the GL should silently ignore 0 when passed to |
| 207 // glDeleteTextures. |
| 208 DCHECK_EQ(0, texture_id_); |
| 209 surface_texture_->DetachFromGLContext(); |
| 210 // This will attach the surface texture to the texture currently bound to |
| 211 // GL_TEXTURE_EXTERNAL_OES target. |
| 212 surface_texture_->AttachToGLContext(); |
| 213 texture_id_ = texture_id; |
| 214 } |
| 215 |
| 216 surface_texture_->UpdateTexImage(); |
| 217 return true; |
| 196 } | 218 } |
| 197 | 219 |
| 198 void StreamTexture::ReleaseTexImage(unsigned target) { | 220 void StreamTexture::ReleaseTexImage(unsigned target) { |
| 199 NOTREACHED(); | 221 NOTREACHED(); |
| 200 } | 222 } |
| 201 | 223 |
| 202 bool StreamTexture::CopyTexSubImage(unsigned target, | 224 bool StreamTexture::CopyTexSubImage(unsigned target, |
| 203 const gfx::Point& offset, | 225 const gfx::Point& offset, |
| 204 const gfx::Rect& rect) { | 226 const gfx::Rect& rect) { |
| 205 return false; | 227 return false; |
| 206 } | 228 } |
| 207 | 229 |
| 208 bool StreamTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 230 bool StreamTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 209 int z_order, | 231 int z_order, |
| 210 gfx::OverlayTransform transform, | 232 gfx::OverlayTransform transform, |
| 211 const gfx::Rect& bounds_rect, | 233 const gfx::Rect& bounds_rect, |
| 212 const gfx::RectF& crop_rect) { | 234 const gfx::RectF& crop_rect) { |
| 213 NOTREACHED(); | 235 NOTREACHED(); |
| 214 return false; | 236 return false; |
| 215 } | 237 } |
| 216 | 238 |
| 217 } // namespace content | 239 } // namespace content |
| OLD | NEW |