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..74477092623b217273625a9a144cddd012a5b556 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_ = |
+ 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) { |
+ surface_bundle_->overlay->AddDestructionCallback(base::Bind( |
+ &AVDASharedState::OnSurfaceDestroyed, weak_this_factory_.GetWeakPtr())); |
+ } |
+} |
AVDASharedState::~AVDASharedState() { |
- if (!surface_texture_) |
+ if (!surface_texture()) |
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(); |
tguilbert
2017/05/16 20:41:59
Is there ever a risk of a nullptr deref?
liberato (no reviews please)
2017/05/16 20:59:52
shouldn't be. i think the only path here (UpdateS
|
// 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) |
tguilbert
2017/05/16 20:41:59
Equivalent to overlay() == overlay?
liberato (no reviews please)
2017/05/16 20:59:52
was my first choice too. didn't compile, with "no
watk
2017/05/17 19:46:40
Oh, I commented on this as well.
overlay() == ove
|
+ surface_bundle_ = nullptr; |
+} |
+ |
} // namespace media |