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

Side by Side Diff: media/gpu/avda_shared_state.cc

Issue 2889603005: Position overlays in AVDACodecImage (Closed)
Patch Set: rebased Created 3 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/gpu/avda_shared_state.h" 5 #include "media/gpu/avda_shared_state.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "media/gpu/avda_codec_image.h" 9 #include "media/gpu/avda_codec_image.h"
10 #include "ui/gl/android/surface_texture.h" 10 #include "ui/gl/android/surface_texture.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Protects changes to listener_. 55 // Protects changes to listener_.
56 base::Lock lock_; 56 base::Lock lock_;
57 57
58 // The AVDASharedState that wants the OnFrameAvailable callback. 58 // The AVDASharedState that wants the OnFrameAvailable callback.
59 AVDASharedState* listener_; 59 AVDASharedState* listener_;
60 60
61 DISALLOW_COPY_AND_ASSIGN(OnFrameAvailableHandler); 61 DISALLOW_COPY_AND_ASSIGN(OnFrameAvailableHandler);
62 }; 62 };
63 63
64 AVDASharedState::AVDASharedState() 64 AVDASharedState::AVDASharedState(
65 scoped_refptr<AVDASurfaceBundle> surface_bundle)
65 : frame_available_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 66 : frame_available_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
66 base::WaitableEvent::InitialState::NOT_SIGNALED), 67 base::WaitableEvent::InitialState::NOT_SIGNALED),
67 68
68 gl_matrix_{ 69 gl_matrix_{
69 1, 0, 0, 0, // Default to a sane guess just in case we can't get the 70 1, 0, 0, 0, // Default to a sane guess just in case we can't get the
70 0, 1, 0, 0, // matrix on the first call. Will be Y-flipped later. 71 0, 1, 0, 0, // matrix on the first call. Will be Y-flipped later.
71 0, 0, 1, 0, // 72 0, 0, 1, 0, //
72 0, 0, 0, 1, // Comment preserves 4x4 formatting. 73 0, 0, 0, 1, // Comment preserves 4x4 formatting.
73 } {} 74 },
75 surface_bundle_(surface_bundle),
76 weak_this_factory_(this) {
77 // If the surface bundle has a surface texture, then register to receive
78 // OnFrameAvailable notifications.
79 if (surface_texture()) {
80 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
81 new OnFrameAvailableHandler(this, surface_texture());
82 }
83
84 // If we're holding a reference to an overlay, then register to drop it if the
85 // overlay's surface is destroyed.
86 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.
87 surface_bundle_->overlay->AddSurfaceDestroyedCallback(base::Bind(
88 &AVDASharedState::OnSurfaceDestroyed, weak_this_factory_.GetWeakPtr()));
89 }
90 }
74 91
75 AVDASharedState::~AVDASharedState() { 92 AVDASharedState::~AVDASharedState() {
76 if (!surface_texture_) 93 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!
77 return; 94 return;
78 95
79 on_frame_available_handler_->ClearListener(); 96 on_frame_available_handler_->ClearListener();
80 } 97 }
81 98
82 void AVDASharedState::SignalFrameAvailable() { 99 void AVDASharedState::SignalFrameAvailable() {
83 frame_available_event_.Signal(); 100 frame_available_event_.Signal();
84 } 101 }
85 102
86 void AVDASharedState::WaitForFrameAvailable() { 103 void AVDASharedState::WaitForFrameAvailable() {
(...skipping 19 matching lines...) Expand all
106 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame"); 123 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame");
107 if (!frame_available_event_.TimedWait(remaining)) { 124 if (!frame_available_event_.TimedWait(remaining)) {
108 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " 125 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: "
109 << elapsed.InMillisecondsF() 126 << elapsed.InMillisecondsF()
110 << "ms, additionally waited: " << remaining.InMillisecondsF() 127 << "ms, additionally waited: " << remaining.InMillisecondsF()
111 << "ms, total: " << (elapsed + remaining).InMillisecondsF() 128 << "ms, total: " << (elapsed + remaining).InMillisecondsF()
112 << "ms"; 129 << "ms";
113 } 130 }
114 } 131 }
115 132
116 void AVDASharedState::SetSurfaceTexture(
117 scoped_refptr<SurfaceTextureGLOwner> surface_texture) {
118 DCHECK(surface_texture);
119 surface_texture_ = surface_texture;
120 on_frame_available_handler_ =
121 new OnFrameAvailableHandler(this, surface_texture_.get());
122 }
123
124 void AVDASharedState::RenderCodecBufferToSurfaceTexture( 133 void AVDASharedState::RenderCodecBufferToSurfaceTexture(
125 MediaCodecBridge* codec, 134 MediaCodecBridge* codec,
126 int codec_buffer_index) { 135 int codec_buffer_index) {
127 if (!release_time_.is_null()) 136 if (!release_time_.is_null())
128 WaitForFrameAvailable(); 137 WaitForFrameAvailable();
129 codec->ReleaseOutputBuffer(codec_buffer_index, true); 138 codec->ReleaseOutputBuffer(codec_buffer_index, true);
130 release_time_ = base::TimeTicks::Now(); 139 release_time_ = base::TimeTicks::Now();
131 } 140 }
132 141
133 void AVDASharedState::UpdateTexImage() { 142 void AVDASharedState::UpdateTexImage() {
134 surface_texture_->UpdateTexImage(); 143 surface_texture()->UpdateTexImage();
135 // Helpfully, this is already column major. 144 // Helpfully, this is already column major.
136 surface_texture_->GetTransformMatrix(gl_matrix_); 145 surface_texture()->GetTransformMatrix(gl_matrix_);
137 } 146 }
138 147
139 void AVDASharedState::GetTransformMatrix(float matrix[16]) const { 148 void AVDASharedState::GetTransformMatrix(float matrix[16]) const {
140 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); 149 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_));
141 } 150 }
142 151
152 void AVDASharedState::OnSurfaceDestroyed(AndroidOverlay* overlay) {
153 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
154 surface_bundle_ = nullptr;
155 }
156
143 } // namespace media 157 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698