OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gl/android/gl_image_stream.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "ui/gfx/size.h" |
| 9 #include "ui/gl/android/surface_texture_bridge.h" |
| 10 #include "ui/gl/gl_bindings.h" |
| 11 |
| 12 namespace gfx { |
| 13 |
| 14 GLImageStream::GLImageStream(uint32 texture_id) |
| 15 : has_updated_(false), |
| 16 surface_texture_bridge_(new gfx::SurfaceTextureBridge(texture_id)), |
| 17 weak_factory_(this) { |
| 18 memset(¤t_matrix_, 0, sizeof(current_matrix_)); |
| 19 } |
| 20 |
| 21 GLImageStream::~GLImageStream() {} |
| 22 |
| 23 void GLImageStream::Destroy() { |
| 24 } |
| 25 |
| 26 gfx::Size GLImageStream::GetSize() { |
| 27 return size_; |
| 28 } |
| 29 |
| 30 void GLImageStream::WillUseTexImage() { |
| 31 GLint texture_id = 0; |
| 32 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
| 33 surface_texture_bridge_->UpdateTexImage(); |
| 34 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id); |
| 35 if (matrix_callback_.is_null()) |
| 36 return; |
| 37 |
| 38 Matrix new_matrix; |
| 39 surface_texture_bridge_->GetTransformMatrix(new_matrix.components); |
| 40 |
| 41 // Only query the matrix once we have bound a valid frame. |
| 42 if (has_updated_ && |
| 43 memcmp(¤t_matrix_, &new_matrix, sizeof(new_matrix)) != 0) { |
| 44 memcpy(¤t_matrix_, &new_matrix, sizeof(new_matrix)); |
| 45 matrix_callback_.Run(new_matrix); |
| 46 } |
| 47 } |
| 48 |
| 49 GLImageStream* GLImageStream::AsGLImageStream() { |
| 50 return this; |
| 51 } |
| 52 |
| 53 SurfaceTextureBridge* GLImageStream::GetSurfaceTexture() { |
| 54 return surface_texture_bridge_; |
| 55 } |
| 56 |
| 57 void GLImageStream::SetFrameAvailableCallback(const base::Closure& callback) { |
| 58 frame_callback_ = callback; |
| 59 // Use a weak pointer here to avoid a circular reference between |
| 60 // |this| and surface_texture_bridge_. |
| 61 base::Closure frame_cb = |
| 62 base::Bind(&GLImageStream::OnFrameAvailable, weak_factory_.GetWeakPtr()); |
| 63 surface_texture_bridge_->SetFrameAvailableCallback(frame_cb); |
| 64 } |
| 65 |
| 66 void GLImageStream::OnFrameAvailable() { |
| 67 has_updated_ = true; |
| 68 frame_callback_.Run(); |
| 69 } |
| 70 |
| 71 bool GLImageStream::BindTexImageExternal() { |
| 72 surface_texture_bridge_->AttachToGLContext(); |
| 73 return true; |
| 74 } |
| 75 |
| 76 void GLImageStream::ReleaseTexImageExternal() { |
| 77 surface_texture_bridge_->DetachFromGLContext(); |
| 78 } |
| 79 |
| 80 } // namespace gfx |
OLD | NEW |