Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: ui/gl/android/gl_image_stream.cc

Issue 22824009: Remove StreamTextureManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gl/android/gl_image_stream.h ('k') | ui/gl/gl.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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()
15 : has_updated_(false),
16 weak_factory_(this) {
17 memset(&current_matrix_, 0, sizeof(current_matrix_));
18 }
19
20 GLImageStream::~GLImageStream() {}
21
22 void GLImageStream::Destroy() {
23 }
24
25 gfx::Size GLImageStream::GetSize() {
26 return size_;
27 }
28
29 void GLImageStream::WillUseTexImage() {
30 GLint texture_id = 0;
31 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
32 surface_texture_bridge_->UpdateTexImage();
33 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id);
34 if (matrix_callback_.is_null())
35 return;
36
37 Matrix new_matrix;
38 surface_texture_bridge_->GetTransformMatrix(new_matrix.components);
39
40 // Only query the matrix once we have bound a valid frame.
41 if (has_updated_ &&
42 memcmp(&current_matrix_, &new_matrix, sizeof(new_matrix)) != 0) {
43 memcpy(&current_matrix_, &new_matrix, sizeof(new_matrix));
44 matrix_callback_.Run(new_matrix);
45 }
46 }
47
48 GLImageStream* GLImageStream::AsGLImageStream() {
49 return this;
50 }
51
52 SurfaceTextureBridge* GLImageStream::GetSurfaceTexture() {
53 return surface_texture_bridge_;
54 }
55
56 void GLImageStream::SetFrameAvailableCallback(const base::Closure& callback) {
57 frame_callback_ = callback;
58 // Use a weak pointer here to avoid a circular reference between
59 // |this| and surface_texture_bridge_.
60 base::Closure frame_cb =
61 base::Bind(&GLImageStream::OnFrameAvailable, weak_factory_.GetWeakPtr());
62 surface_texture_bridge_->SetFrameAvailableCallback(frame_cb);
63 }
64
65 void GLImageStream::OnFrameAvailable() {
66 has_updated_ = true;
67 frame_callback_.Run();
68 }
69
70 bool GLImageStream::BindTexImage() {
71 if (!surface_texture_bridge_) {
72 GLint texture_id = 0;
73 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
74 if (!texture_id)
75 return false;
76
77 surface_texture_bridge_(new gfx::SurfaceTextureBridge(texture_id));
78 return true;
79 }
80 surface_texture_bridge_->AttachToGLContext();
81 return true;
82 }
83
84 void GLImageStream::ReleaseTexImage() {
85 surface_texture_bridge_->DetachFromGLContext();
86 }
87
88 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/android/gl_image_stream.h ('k') | ui/gl/gl.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698