Index: media/gpu/avda_shared_state.cc |
diff --git a/media/gpu/avda_shared_state.cc b/media/gpu/avda_shared_state.cc |
index 1309dabe2385dc409b8c3a7c395257a1b5bba9c1..6f55f1a6f1d1512ab7b881367e30af62f5a15dc4 100644 |
--- a/media/gpu/avda_shared_state.cc |
+++ b/media/gpu/avda_shared_state.cc |
@@ -61,7 +61,8 @@ class AVDASharedState::OnFrameAvailableHandler |
DISALLOW_COPY_AND_ASSIGN(OnFrameAvailableHandler); |
}; |
-AVDASharedState::AVDASharedState() |
+AVDASharedState::AVDASharedState( |
+ scoped_refptr<AVDASurfaceBundle> surface_bundle) |
: frame_available_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
base::WaitableEvent::InitialState::NOT_SIGNALED), |
@@ -70,10 +71,26 @@ AVDASharedState::AVDASharedState() |
0, 1, 0, 0, // matrix on the first call. Will be Y-flipped later. |
0, 0, 1, 0, // |
0, 0, 0, 1, // Comment preserves 4x4 formatting. |
- } {} |
+ }, |
+ surface_bundle_(surface_bundle), |
+ weak_this_factory_(this) { |
+ // If the surface bundle has a surface texture, then register to receive |
+ // OnFrameAvailable notifications. |
+ if (surface_texture()) { |
+ on_frame_available_handler_ = |
tguilbert
2017/05/16 20:41:59
Curiosity: Do you know why this is a scoped ptr an
liberato (no reviews please)
2017/05/16 20:59:53
both |this| and the callback own a reference to it
|
+ new OnFrameAvailableHandler(this, surface_texture()); |
+ } |
+ |
+ // If we're holding a reference to an overlay, then register to drop it if the |
+ // overlay's surface is destroyed. |
+ if (surface_bundle_ && surface_bundle_->overlay) { |
watk
2017/05/17 19:45:14
surface_bundle_ can't be null here right?
if (ove
liberato (no reviews please)
2017/05/17 20:19:33
good point, done.
|
+ surface_bundle_->overlay->AddSurfaceDestroyedCallback(base::Bind( |
+ &AVDASharedState::OnSurfaceDestroyed, weak_this_factory_.GetWeakPtr())); |
+ } |
+} |
AVDASharedState::~AVDASharedState() { |
- if (!surface_texture_) |
+ if (!surface_texture()) |
watk
2017/05/17 19:45:14
this is bizarre looking, haha
We should have writ
liberato (no reviews please)
2017/05/17 20:19:33
good point!
|
return; |
on_frame_available_handler_->ClearListener(); |
@@ -113,14 +130,6 @@ void AVDASharedState::WaitForFrameAvailable() { |
} |
} |
-void AVDASharedState::SetSurfaceTexture( |
- scoped_refptr<SurfaceTextureGLOwner> surface_texture) { |
- DCHECK(surface_texture); |
- surface_texture_ = surface_texture; |
- on_frame_available_handler_ = |
- new OnFrameAvailableHandler(this, surface_texture_.get()); |
-} |
- |
void AVDASharedState::RenderCodecBufferToSurfaceTexture( |
MediaCodecBridge* codec, |
int codec_buffer_index) { |
@@ -131,13 +140,18 @@ void AVDASharedState::RenderCodecBufferToSurfaceTexture( |
} |
void AVDASharedState::UpdateTexImage() { |
- surface_texture_->UpdateTexImage(); |
+ surface_texture()->UpdateTexImage(); |
// Helpfully, this is already column major. |
- surface_texture_->GetTransformMatrix(gl_matrix_); |
+ surface_texture()->GetTransformMatrix(gl_matrix_); |
} |
void AVDASharedState::GetTransformMatrix(float matrix[16]) const { |
memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); |
} |
+void AVDASharedState::OnSurfaceDestroyed(AndroidOverlay* overlay) { |
+ if (surface_bundle_ && surface_bundle_->overlay.get() == overlay) |
watk
2017/05/17 19:45:14
if (overlay() == overlay)?
liberato (no reviews please)
2017/05/17 20:19:32
oooohhhhh. done. yes, i originally just compared
|
+ surface_bundle_ = nullptr; |
+} |
+ |
} // namespace media |