Index: ui/gl/android/gl_image_stream.cc |
diff --git a/ui/gl/android/gl_image_stream.cc b/ui/gl/android/gl_image_stream.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f3af689e7732e0f66d5bfdd66b3b96f4f3cb2145 |
--- /dev/null |
+++ b/ui/gl/android/gl_image_stream.cc |
@@ -0,0 +1,70 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/gl/android/gl_image_stream.h" |
+ |
+#include "base/bind.h" |
+#include "ui/gfx/size.h" |
+#include "ui/gl/android/surface_texture_bridge.h" |
+#include "ui/gl/gl_bindings.h" |
+ |
+namespace gfx { |
+ |
+GLImageStream::GLImageStream(uint32 texture_id) |
+ : has_updated_(false), |
+ surface_texture_bridge_(new gfx::SurfaceTextureBridge(texture_id)) { |
+ memset(¤t_matrix_, 0, sizeof(current_matrix_)); |
+} |
+ |
+GLImageStream::~GLImageStream() {} |
+ |
+void GLImageStream::Destroy() { |
+} |
+ |
+gfx::Size GLImageStream::GetSize() { |
+ return size_; |
+} |
+ |
+void GLImageStream::UpdateTexImage() { |
+ surface_texture_bridge_->UpdateTexImage(); |
+ if (matrix_callback_.is_null()) |
+ return; |
+ |
+ Matrix new_matrix; |
+ surface_texture_bridge_->GetTransformMatrix(new_matrix.components); |
+ |
+ // Only query the matrix once we have bound a valid frame. |
+ if (has_updated_ && |
+ memcmp(¤t_matrix_, &new_matrix, sizeof(new_matrix)) != 0) { |
+ memcpy(¤t_matrix_, &new_matrix, sizeof(new_matrix)); |
+ matrix_callback_.Run(new_matrix); |
+ } |
+} |
+ |
+SurfaceTextureBridge* GLImageStream::GetSurfaceTexture() |
+{ |
+ return surface_texture_bridge_; |
+} |
+ |
+void GLImageStream::SetFrameAvailableCallback(const base::Closure& callback) { |
+ frame_callback_ = callback; |
+ base::Closure frame_cb = base::Bind(&GLImageStream::OnFrameAvailable, this); |
+ surface_texture_bridge_->SetFrameAvailableCallback(frame_cb); |
+} |
+ |
+void GLImageStream::OnFrameAvailable() { |
+ has_updated_ = true; |
+ frame_callback_.Run(); |
+} |
+ |
+bool GLImageStream::BindTexImageExternal() { |
+ surface_texture_bridge_->AttachToGLContext(); |
+ return true; |
+} |
+ |
+void GLImageStream::ReleaseTexImageExternal() { |
+ surface_texture_bridge_->DetachFromGLContext(); |
+} |
+ |
+} // namespace gfx |