| 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..f57b1bedfd055f6b9e67dd3a66dbd0ee6e5e43e5
|
| --- /dev/null
|
| +++ b/ui/gl/android/gl_image_stream.cc
|
| @@ -0,0 +1,88 @@
|
| +// 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()
|
| + : has_updated_(false),
|
| + weak_factory_(this) {
|
| + memset(¤t_matrix_, 0, sizeof(current_matrix_));
|
| +}
|
| +
|
| +GLImageStream::~GLImageStream() {}
|
| +
|
| +void GLImageStream::Destroy() {
|
| +}
|
| +
|
| +gfx::Size GLImageStream::GetSize() {
|
| + return size_;
|
| +}
|
| +
|
| +void GLImageStream::WillUseTexImage() {
|
| + GLint texture_id = 0;
|
| + glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
|
| + surface_texture_bridge_->UpdateTexImage();
|
| + glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id);
|
| + 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);
|
| + }
|
| +}
|
| +
|
| +GLImageStream* GLImageStream::AsGLImageStream() {
|
| + return this;
|
| +}
|
| +
|
| +SurfaceTextureBridge* GLImageStream::GetSurfaceTexture() {
|
| + return surface_texture_bridge_;
|
| +}
|
| +
|
| +void GLImageStream::SetFrameAvailableCallback(const base::Closure& callback) {
|
| + frame_callback_ = callback;
|
| + // Use a weak pointer here to avoid a circular reference between
|
| + // |this| and surface_texture_bridge_.
|
| + base::Closure frame_cb =
|
| + base::Bind(&GLImageStream::OnFrameAvailable, weak_factory_.GetWeakPtr());
|
| + surface_texture_bridge_->SetFrameAvailableCallback(frame_cb);
|
| +}
|
| +
|
| +void GLImageStream::OnFrameAvailable() {
|
| + has_updated_ = true;
|
| + frame_callback_.Run();
|
| +}
|
| +
|
| +bool GLImageStream::BindTexImage() {
|
| + if (!surface_texture_bridge_) {
|
| + GLint texture_id = 0;
|
| + glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
|
| + if (!texture_id)
|
| + return false;
|
| +
|
| + surface_texture_bridge_(new gfx::SurfaceTextureBridge(texture_id));
|
| + return true;
|
| + }
|
| + surface_texture_bridge_->AttachToGLContext();
|
| + return true;
|
| +}
|
| +
|
| +void GLImageStream::ReleaseTexImage() {
|
| + surface_texture_bridge_->DetachFromGLContext();
|
| +}
|
| +
|
| +} // namespace gfx
|
|
|