| OLD | NEW |
| 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 "chromecast/media/base/video_plane_controller.h" | 5 #include "chromecast/media/base/video_plane_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 size_t sample_counter_; | 135 size_t sample_counter_; |
| 136 | 136 |
| 137 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 137 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 138 | 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(RateLimitedSetVideoPlaneGeometry); | 139 DISALLOW_COPY_AND_ASSIGN(RateLimitedSetVideoPlaneGeometry); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 VideoPlaneController::VideoPlaneController( | 142 VideoPlaneController::VideoPlaneController( |
| 143 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner) | 143 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner) |
| 144 : is_paused_(false), | 144 : is_paused_(false), |
| 145 have_output_res_(false), | 145 have_screen_res_(false), |
| 146 have_graphics_res_(false), | 146 have_graphics_plane_res_(false), |
| 147 output_res_(0, 0), | 147 screen_res_(0, 0), |
| 148 graphics_res_(0, 0), | 148 graphics_plane_res_(0, 0), |
| 149 have_video_plane_geometry_(false), | 149 have_video_plane_geometry_(false), |
| 150 video_plane_display_rect_(0, 0), | 150 video_plane_display_rect_(0, 0), |
| 151 video_plane_transform_(VideoPlane::TRANSFORM_NONE), | 151 video_plane_transform_(VideoPlane::TRANSFORM_NONE), |
| 152 media_task_runner_(media_task_runner), | 152 media_task_runner_(media_task_runner), |
| 153 video_plane_wrapper_( | 153 video_plane_wrapper_( |
| 154 new RateLimitedSetVideoPlaneGeometry(media_task_runner_)) {} | 154 new RateLimitedSetVideoPlaneGeometry(media_task_runner_)) {} |
| 155 | 155 |
| 156 VideoPlaneController::~VideoPlaneController() {} | 156 VideoPlaneController::~VideoPlaneController() {} |
| 157 | 157 |
| 158 // TODO(esum): SetGeometry, SetDeviceResolution, and SetGraphicsPlaneResolution | |
| 159 // follow the same pattern (copy/paste). Currently it's not worth modularizing | |
| 160 // since there are only 3 fields. If more fields are needed in the future, | |
| 161 // consider making a generic method to implement this pattern. | |
| 162 void VideoPlaneController::SetGeometry(const RectF& display_rect, | 158 void VideoPlaneController::SetGeometry(const RectF& display_rect, |
| 163 VideoPlane::Transform transform) { | 159 VideoPlane::Transform transform) { |
| 164 DCHECK(thread_checker_.CalledOnValidThread()); | 160 DCHECK(thread_checker_.CalledOnValidThread()); |
| 165 DCHECK(DisplayRectFValid(display_rect)); | 161 DCHECK(DisplayRectFValid(display_rect)); |
| 166 if (have_video_plane_geometry_ && | 162 if (have_video_plane_geometry_ && |
| 167 RectFEqual(display_rect, video_plane_display_rect_) && | 163 RectFEqual(display_rect, video_plane_display_rect_) && |
| 168 transform == video_plane_transform_) { | 164 transform == video_plane_transform_) { |
| 169 VLOG(2) << "No change found in geometry parameters."; | 165 VLOG(2) << "No change found in geometry parameters."; |
| 170 return; | 166 return; |
| 171 } | 167 } |
| 172 | 168 |
| 173 VLOG(1) << "New geometry parameters " | 169 VLOG(1) << "New geometry parameters " |
| 174 << " rect=" << display_rect.width << "x" << display_rect.height | 170 << " rect=" << display_rect.width << "x" << display_rect.height |
| 175 << " @" << display_rect.x << "," << display_rect.y << " transform " | 171 << " @" << display_rect.x << "," << display_rect.y << " transform " |
| 176 << transform; | 172 << transform; |
| 177 | 173 |
| 178 have_video_plane_geometry_ = true; | 174 have_video_plane_geometry_ = true; |
| 179 video_plane_display_rect_ = display_rect; | 175 video_plane_display_rect_ = display_rect; |
| 180 video_plane_transform_ = transform; | 176 video_plane_transform_ = transform; |
| 181 | 177 |
| 182 MaybeRunSetGeometry(); | 178 MaybeRunSetGeometry(); |
| 183 } | 179 } |
| 184 | 180 |
| 185 void VideoPlaneController::SetDeviceResolution(const Size& resolution) { | 181 void VideoPlaneController::SetScreenResolution(const Size& resolution) { |
| 186 DCHECK(thread_checker_.CalledOnValidThread()); | 182 DCHECK(thread_checker_.CalledOnValidThread()); |
| 187 DCHECK(ResolutionSizeValid(resolution)); | 183 DCHECK(ResolutionSizeValid(resolution)); |
| 188 if (have_output_res_ && SizeEqual(resolution, output_res_)) { | 184 if (have_screen_res_ && SizeEqual(resolution, screen_res_)) { |
| 189 VLOG(2) << "No change found in output resolution."; | 185 VLOG(2) << "No change found in screen resolution."; |
| 190 return; | 186 return; |
| 191 } | 187 } |
| 192 | 188 |
| 193 VLOG(1) << "New output resolution " << resolution.width << "x" | 189 VLOG(1) << "New screen resolution " << resolution.width << "x" |
| 194 << resolution.height; | 190 << resolution.height; |
| 195 | 191 |
| 196 have_output_res_ = true; | 192 have_screen_res_ = true; |
| 197 output_res_ = resolution; | 193 screen_res_ = resolution; |
| 198 | 194 |
| 199 MaybeRunSetGeometry(); | 195 MaybeRunSetGeometry(); |
| 200 } | 196 } |
| 201 | 197 |
| 202 void VideoPlaneController::SetGraphicsPlaneResolution(const Size& resolution) { | 198 void VideoPlaneController::SetGraphicsPlaneResolution(const Size& resolution) { |
| 203 DCHECK(thread_checker_.CalledOnValidThread()); | 199 DCHECK(thread_checker_.CalledOnValidThread()); |
| 204 DCHECK(ResolutionSizeValid(resolution)); | 200 DCHECK(ResolutionSizeValid(resolution)); |
| 205 if (have_graphics_res_ && SizeEqual(resolution, graphics_res_)) { | 201 if (have_graphics_plane_res_ && SizeEqual(resolution, graphics_plane_res_)) { |
| 206 VLOG(2) << "No change found in graphics resolution."; | 202 VLOG(2) << "No change found in graphics plane resolution."; |
| 207 return; | 203 return; |
| 208 } | 204 } |
| 209 | 205 |
| 210 VLOG(1) << "New graphics resolution " << resolution.width << "x" | 206 VLOG(1) << "New graphics plane resolution " << resolution.width << "x" |
| 211 << resolution.height; | 207 << resolution.height; |
| 212 | 208 |
| 213 have_graphics_res_ = true; | 209 have_graphics_plane_res_ = true; |
| 214 graphics_res_ = resolution; | 210 graphics_plane_res_ = resolution; |
| 215 | 211 |
| 216 MaybeRunSetGeometry(); | 212 // Any cached video plane geometry parameters are no longer valid since they |
| 213 // were relative to the PREVIOUS graphics plane resolution. Thus, the cached |
| 214 // parameters are cleared, and it's the caller's responsibility to call |
| 215 // SetGeometry() with arguments relative to the NEW graphics plane if needed. |
| 216 ClearVideoPlaneGeometry(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void VideoPlaneController::Pause() { | 219 void VideoPlaneController::Pause() { |
| 220 DCHECK(thread_checker_.CalledOnValidThread()); | 220 DCHECK(thread_checker_.CalledOnValidThread()); |
| 221 VLOG(1) << "Pausing controller. No more VideoPlane SetGeometry calls."; | 221 VLOG(1) << "Pausing controller. No more VideoPlane SetGeometry calls."; |
| 222 is_paused_ = true; | 222 is_paused_ = true; |
| 223 } | 223 } |
| 224 | 224 |
| 225 void VideoPlaneController::Resume() { | 225 void VideoPlaneController::Resume() { |
| 226 DCHECK(thread_checker_.CalledOnValidThread()); | 226 DCHECK(thread_checker_.CalledOnValidThread()); |
| 227 VLOG(1) << "Resuming controller. VideoPlane SetGeometry calls are active."; | 227 VLOG(1) << "Resuming controller. VideoPlane SetGeometry calls are active."; |
| 228 is_paused_ = false; | 228 is_paused_ = false; |
| 229 MaybeRunSetGeometry(); | 229 ClearVideoPlaneGeometry(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool VideoPlaneController::is_paused() const { | 232 bool VideoPlaneController::is_paused() const { |
| 233 DCHECK(thread_checker_.CalledOnValidThread()); | 233 DCHECK(thread_checker_.CalledOnValidThread()); |
| 234 return is_paused_; | 234 return is_paused_; |
| 235 } | 235 } |
| 236 | 236 |
| 237 void VideoPlaneController::MaybeRunSetGeometry() { | 237 void VideoPlaneController::MaybeRunSetGeometry() { |
| 238 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 239 if (is_paused_) { | 238 if (is_paused_) { |
| 240 VLOG(2) << "All VideoPlane SetGeometry calls are paused. Ignoring request."; | 239 VLOG(2) << "All VideoPlane SetGeometry calls are paused. Ignoring request."; |
| 241 return; | 240 return; |
| 242 } | 241 } |
| 243 | 242 |
| 244 if (!HaveDataForSetGeometry()) { | 243 if (!HaveDataForSetGeometry()) { |
| 245 VLOG(2) << "Don't have all VideoPlane SetGeometry data. Ignoring request."; | 244 VLOG(2) << "Don't have all VideoPlane SetGeometry data. Ignoring request."; |
| 246 return; | 245 return; |
| 247 } | 246 } |
| 248 | 247 |
| 249 DCHECK(graphics_res_.width != 0 && graphics_res_.height != 0); | 248 DCHECK(graphics_plane_res_.width != 0 && graphics_plane_res_.height != 0); |
| 250 | 249 |
| 251 RectF scaled_rect = video_plane_display_rect_; | 250 RectF scaled_rect = video_plane_display_rect_; |
| 252 if (graphics_res_.width != output_res_.width || | 251 if (graphics_plane_res_.width != screen_res_.width || |
| 253 graphics_res_.height != output_res_.height) { | 252 graphics_plane_res_.height != screen_res_.height) { |
| 254 float sx = static_cast<float>(output_res_.width) / graphics_res_.width; | 253 float sx = |
| 255 float sy = static_cast<float>(output_res_.height) / graphics_res_.height; | 254 static_cast<float>(screen_res_.width) / graphics_plane_res_.width; |
| 255 float sy = |
| 256 static_cast<float>(screen_res_.height) / graphics_plane_res_.height; |
| 256 scaled_rect.x *= sx; | 257 scaled_rect.x *= sx; |
| 257 scaled_rect.y *= sy; | 258 scaled_rect.y *= sy; |
| 258 scaled_rect.width *= sx; | 259 scaled_rect.width *= sx; |
| 259 scaled_rect.height *= sy; | 260 scaled_rect.height *= sy; |
| 260 } | 261 } |
| 261 | 262 |
| 262 media_task_runner_->PostTask( | 263 media_task_runner_->PostTask( |
| 263 FROM_HERE, | 264 FROM_HERE, |
| 264 base::Bind(&RateLimitedSetVideoPlaneGeometry::SetGeometry, | 265 base::Bind(&RateLimitedSetVideoPlaneGeometry::SetGeometry, |
| 265 video_plane_wrapper_, scaled_rect, video_plane_transform_)); | 266 video_plane_wrapper_, scaled_rect, video_plane_transform_)); |
| 266 } | 267 } |
| 267 | 268 |
| 268 bool VideoPlaneController::HaveDataForSetGeometry() const { | 269 bool VideoPlaneController::HaveDataForSetGeometry() const { |
| 269 DCHECK(thread_checker_.CalledOnValidThread()); | 270 return have_screen_res_ && have_graphics_plane_res_ && |
| 270 return have_output_res_ && have_graphics_res_ && have_video_plane_geometry_; | 271 have_video_plane_geometry_; |
| 272 } |
| 273 |
| 274 void VideoPlaneController::ClearVideoPlaneGeometry() { |
| 275 have_video_plane_geometry_ = false; |
| 276 video_plane_display_rect_ = RectF(0, 0); |
| 277 video_plane_transform_ = VideoPlane::TRANSFORM_NONE; |
| 271 } | 278 } |
| 272 | 279 |
| 273 } // namespace media | 280 } // namespace media |
| 274 } // namespace chromecast | 281 } // namespace chromecast |
| OLD | NEW |