Index: gpu/command_buffer/service/stream_texture_manager_in_process_android.cc |
diff --git a/gpu/command_buffer/service/stream_texture_manager_in_process_android.cc b/gpu/command_buffer/service/stream_texture_manager_in_process_android.cc |
index 7cf814a0cc0287660ef418b0cf28aaf6d915f7e4..e823cfcb3891aea15396df81c197fc6e39ab14ac 100644 |
--- a/gpu/command_buffer/service/stream_texture_manager_in_process_android.cc |
+++ b/gpu/command_buffer/service/stream_texture_manager_in_process_android.cc |
@@ -14,142 +14,102 @@ |
namespace gpu { |
-namespace { |
- |
// Simply wraps a SurfaceTexture reference as a GLImage. |
-class GLImageImpl : public gl::GLImage { |
+class StreamTextureManagerInProcess::GLImage : public gl::GLImage { |
public: |
- GLImageImpl(uint32 texture_id, |
- gles2::TextureManager* texture_manager, |
- const scoped_refptr<gfx::SurfaceTexture>& surface_texture, |
- const base::Closure& release_callback); |
+ GLImage(uint32 texture_id, |
+ gles2::TextureManager* texture_manager, |
+ const scoped_refptr<gfx::SurfaceTexture>& surface_texture, |
+ const base::Closure& release_callback) |
+ : texture_id_(texture_id), |
+ texture_manager_(texture_manager), |
+ surface_texture_(surface_texture), |
+ release_callback_(release_callback) {} |
+ |
+ void SetSize(const gfx::Size& size) { size_ = size; } |
+ scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture() { |
+ return surface_texture_; |
+ } |
// implement gl::GLImage |
- void Destroy(bool have_context) override; |
- gfx::Size GetSize() override; |
- unsigned GetInternalFormat() override; |
- bool BindTexImage(unsigned target) override; |
- void ReleaseTexImage(unsigned target) override; |
- bool CopyTexImage(unsigned target) override; |
+ void Destroy(bool have_context) override { NOTREACHED(); } |
+ gfx::Size GetSize() override { return gfx::Size(); } |
+ unsigned GetInternalFormat() override { return GL_RGBA; } |
+ bool BindTexImage(unsigned target) override { |
+ NOTREACHED(); |
+ return false; |
+ } |
+ void ReleaseTexImage(unsigned target) override { NOTREACHED(); } |
+ bool CopyTexImage(unsigned target) override { |
+ if (target != GL_TEXTURE_EXTERNAL_OES) |
+ return false; |
+ |
+ GLint texture_id; |
+ glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
+ DCHECK(texture_id); |
+ |
+ // The following code only works if we're being asked to copy into |
+ // |texture_id_|. Copying into a different texture is not supported. |
+ if (static_cast<unsigned>(texture_id) != texture_id_) |
+ return false; |
+ |
+ surface_texture_->UpdateTexImage(); |
+ |
+ gles2::Texture* texture = |
+ texture_manager_->GetTextureForServiceId(texture_id_); |
+ if (texture) { |
+ // By setting image state to UNBOUND instead of COPIED we ensure that |
+ // CopyTexImage() is called each time the surface texture is used for |
+ // drawing. |
+ texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
+ gles2::Texture::UNBOUND); |
+ } |
+ return true; |
+ } |
bool CopyTexSubImage(unsigned target, |
const gfx::Point& offset, |
- const gfx::Rect& rect) override; |
+ const gfx::Rect& rect) override { |
+ return false; |
+ } |
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
int z_order, |
gfx::OverlayTransform transform, |
const gfx::Rect& bounds_rect, |
- const gfx::RectF& crop_rect) override; |
+ const gfx::RectF& crop_rect) override { |
+ NOTREACHED(); |
+ return false; |
+ } |
void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
uint64_t process_tracing_id, |
- const std::string& dump_name) override; |
+ const std::string& dump_name) override { |
+ // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 |
+ } |
private: |
- ~GLImageImpl() override; |
+ ~GLImage() override { release_callback_.Run(); } |
uint32 texture_id_; |
gles2::TextureManager* texture_manager_; |
scoped_refptr<gfx::SurfaceTexture> surface_texture_; |
base::Closure release_callback_; |
+ gfx::Size size_; |
- DISALLOW_COPY_AND_ASSIGN(GLImageImpl); |
+ DISALLOW_COPY_AND_ASSIGN(GLImage); |
}; |
-GLImageImpl::GLImageImpl( |
- uint32 texture_id, |
- gles2::TextureManager* texture_manager, |
- const scoped_refptr<gfx::SurfaceTexture>& surface_texture, |
- const base::Closure& release_callback) |
- : texture_id_(texture_id), |
- texture_manager_(texture_manager), |
- surface_texture_(surface_texture), |
- release_callback_(release_callback) {} |
- |
-GLImageImpl::~GLImageImpl() { |
- release_callback_.Run(); |
-} |
- |
-void GLImageImpl::Destroy(bool have_context) { |
- NOTREACHED(); |
-} |
- |
-gfx::Size GLImageImpl::GetSize() { |
- return gfx::Size(); |
-} |
- |
-unsigned GLImageImpl::GetInternalFormat() { |
- return GL_RGBA; |
-} |
- |
-bool GLImageImpl::BindTexImage(unsigned target) { |
- NOTREACHED(); |
- return false; |
-} |
- |
-void GLImageImpl::ReleaseTexImage(unsigned target) { |
- NOTREACHED(); |
-} |
- |
-bool GLImageImpl::CopyTexImage(unsigned target) { |
- if (target != GL_TEXTURE_EXTERNAL_OES) |
- return false; |
- |
- GLint texture_id; |
- glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
- DCHECK(texture_id); |
- |
- // The following code only works if we're being asked to copy into |
- // |texture_id_|. Copying into a different texture is not supported. |
- if (static_cast<unsigned>(texture_id) != texture_id_) |
- return false; |
- |
- surface_texture_->UpdateTexImage(); |
- |
- gles2::Texture* texture = |
- texture_manager_->GetTextureForServiceId(texture_id_); |
- if (texture) { |
- // By setting image state to UNBOUND instead of COPIED we ensure that |
- // CopyTexImage() is called each time the surface texture is used for |
- // drawing. |
- texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
- gles2::Texture::UNBOUND); |
- } |
- return true; |
-} |
- |
-bool GLImageImpl::CopyTexSubImage(unsigned target, |
- const gfx::Point& offset, |
- const gfx::Rect& rect) { |
- return false; |
-} |
- |
-bool GLImageImpl::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
- int z_order, |
- gfx::OverlayTransform transform, |
- const gfx::Rect& bounds_rect, |
- const gfx::RectF& crop_rect) { |
- NOTREACHED(); |
- return false; |
-} |
- |
-void GLImageImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
- uint64_t process_tracing_id, |
- const std::string& dump_name) { |
- // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 |
-} |
- |
-} // anonymous namespace |
- |
StreamTextureManagerInProcess::StreamTextureManagerInProcess() |
- : next_id_(1), weak_factory_(this) {} |
+ : weak_factory_(this) { |
+ next_id_.GetNext(); |
+} |
StreamTextureManagerInProcess::~StreamTextureManagerInProcess() { |
- if (!textures_.empty()) { |
+ if (!images_.empty()) { |
LOG(WARNING) << "Undestroyed surface textures while tearing down " |
"StreamTextureManager."; |
} |
} |
-GLuint StreamTextureManagerInProcess::CreateStreamTexture( |
+GLint StreamTextureManagerInProcess::CreateStreamTexture( |
uint32 client_texture_id, |
gles2::TextureManager* texture_manager) { |
CalledOnValidThread(); |
@@ -164,13 +124,13 @@ GLuint StreamTextureManagerInProcess::CreateStreamTexture( |
scoped_refptr<gfx::SurfaceTexture> surface_texture( |
gfx::SurfaceTexture::Create(texture->service_id())); |
- uint32 stream_id = next_id_++; |
+ int32 stream_id = next_id_.GetNext(); |
base::Closure release_callback = |
base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture, |
weak_factory_.GetWeakPtr(), stream_id); |
- scoped_refptr<gl::GLImage> gl_image( |
- new GLImageImpl(texture->service_id(), texture_manager, surface_texture, |
- release_callback)); |
+ scoped_refptr<GLImage> gl_image(new GLImage(texture->service_id(), |
+ texture_manager, surface_texture, |
+ release_callback)); |
gfx::Size size = gl_image->GetSize(); |
texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); |
@@ -182,30 +142,61 @@ GLuint StreamTextureManagerInProcess::CreateStreamTexture( |
{ |
base::AutoLock lock(map_lock_); |
- textures_[stream_id] = surface_texture; |
+ DCHECK_EQ(static_cast<size_t>(0), images_.count(stream_id)); |
+ images_[stream_id] = gl_image.get(); |
} |
- if (next_id_ == 0) |
- next_id_++; |
- |
return stream_id; |
} |
-void StreamTextureManagerInProcess::OnReleaseStreamTexture(uint32 stream_id) { |
+void StreamTextureManagerInProcess::SetStreamTextureSize( |
+ uint32 client_texture_id, |
+ int32 stream_id, |
+ size_t width, |
+ size_t height, |
+ gles2::TextureManager* texture_manager) { |
+ CalledOnValidThread(); |
+ |
+ gles2::TextureRef* texture = texture_manager->GetTexture(client_texture_id); |
+ |
+ if (!texture || (texture->texture()->target() && |
+ texture->texture()->target() != GL_TEXTURE_EXTERNAL_OES)) { |
+ return; |
+ } |
+ |
+ scoped_refptr<GLImage> gl_image; |
+ { |
+ base::AutoLock lock(map_lock_); |
+ if (!images_.count(stream_id)) |
+ return; |
+ gl_image = images_[stream_id]; |
+ } |
+ |
+ gl_image->SetSize(gfx::Size(width, height)); |
+ gfx::Size size = gl_image->GetSize(); |
+ texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, |
+ width, height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
+ gfx::Rect(size)); |
+ texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, |
+ gl_image.get(), gles2::Texture::UNBOUND); |
+} |
+ |
+void StreamTextureManagerInProcess::OnReleaseStreamTexture(int32 stream_id) { |
CalledOnValidThread(); |
base::AutoLock lock(map_lock_); |
- textures_.erase(stream_id); |
+ DCHECK_EQ(static_cast<size_t>(1), images_.count(stream_id)); |
+ images_.erase(stream_id); |
} |
// This can get called from any thread. |
scoped_refptr<gfx::SurfaceTexture> |
-StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) { |
+StreamTextureManagerInProcess::GetSurfaceTexture(int32 stream_id) { |
base::AutoLock lock(map_lock_); |
- TextureMap::const_iterator it = textures_.find(stream_id); |
- if (it != textures_.end()) |
- return it->second; |
+ ImageMap::const_iterator it = images_.find(stream_id); |
+ if (it != images_.end()) |
+ return it->second->GetSurfaceTexture(); |
- return NULL; |
+ return nullptr; |
} |
} // namespace gpu |