Chromium Code Reviews| 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 memset(¤t_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::UpdateTexImage() { | |
| 30 surface_texture_bridge_->UpdateTexImage(); | |
| 31 if (matrix_callback_.is_null()) | |
| 32 return; | |
| 33 | |
| 34 Matrix new_matrix; | |
| 35 surface_texture_bridge_->GetTransformMatrix(new_matrix.components); | |
| 36 | |
| 37 // Only query the matrix once we have bound a valid frame. | |
| 38 if (has_updated_ && | |
| 39 memcmp(¤t_matrix_, &new_matrix, sizeof(new_matrix)) != 0) { | |
| 40 memcpy(¤t_matrix_, &new_matrix, sizeof(new_matrix)); | |
| 41 matrix_callback_.Run(new_matrix); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 SurfaceTextureBridge* GLImageStream::GetSurfaceTexture() | |
| 46 { | |
|
piman
2013/08/13 00:52:04
nit: { on previous line
no sievers
2013/08/14 04:01:23
Done.
| |
| 47 return surface_texture_bridge_; | |
| 48 } | |
| 49 | |
| 50 void GLImageStream::SetFrameAvailableCallback(const base::Closure& callback) { | |
| 51 frame_callback_ = callback; | |
| 52 base::Closure frame_cb = base::Bind(&GLImageStream::OnFrameAvailable, this); | |
| 53 surface_texture_bridge_->SetFrameAvailableCallback(frame_cb); | |
|
piman
2013/08/13 00:52:04
Doesn't this cause a reference cycle?
frame_cb ref
no sievers
2013/08/14 04:01:23
Thanks, no point for the callback to add a ref bac
| |
| 54 } | |
| 55 | |
| 56 void GLImageStream::OnFrameAvailable() { | |
| 57 has_updated_ = true; | |
| 58 frame_callback_.Run(); | |
| 59 } | |
| 60 | |
| 61 bool GLImageStream::BindTexImageExternal() { | |
| 62 surface_texture_bridge_->AttachToGLContext(); | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 void GLImageStream::ReleaseTexImageExternal() { | |
| 67 surface_texture_bridge_->DetachFromGLContext(); | |
| 68 } | |
| 69 | |
| 70 } // namespace gfx | |
| OLD | NEW |