| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 << " @" << display_rect.x << "," << display_rect.y << " transform " | 161 << " @" << display_rect.x << "," << display_rect.y << " transform " |
| 162 << transform; | 162 << transform; |
| 163 | 163 |
| 164 have_video_plane_geometry_ = true; | 164 have_video_plane_geometry_ = true; |
| 165 video_plane_display_rect_ = display_rect; | 165 video_plane_display_rect_ = display_rect; |
| 166 video_plane_transform_ = transform; | 166 video_plane_transform_ = transform; |
| 167 | 167 |
| 168 MaybeRunSetGeometry(); | 168 MaybeRunSetGeometry(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void VideoPlaneController::ResetGeometry() { |
| 172 DCHECK(thread_checker_.CalledOnValidThread()); |
| 173 MaybeRunSetGeometry(); |
| 174 } |
| 175 |
| 171 void VideoPlaneController::SetDeviceResolution(const Size& resolution) { | 176 void VideoPlaneController::SetDeviceResolution(const Size& resolution) { |
| 172 DCHECK(thread_checker_.CalledOnValidThread()); | 177 DCHECK(thread_checker_.CalledOnValidThread()); |
| 173 DCHECK(ResolutionSizeValid(resolution)); | 178 DCHECK(ResolutionSizeValid(resolution)); |
| 174 if (have_output_res_ && SizeEqual(resolution, output_res_)) { | 179 if (have_output_res_ && SizeEqual(resolution, output_res_)) { |
| 175 VLOG(2) << "No change found in output resolution."; | 180 VLOG(2) << "No change found in output resolution."; |
| 176 return; | 181 return; |
| 177 } | 182 } |
| 178 | 183 |
| 179 VLOG(1) << "New output resolution " << resolution.width << "x" | 184 VLOG(1) << "New output resolution " << resolution.width << "x" |
| 180 << resolution.height; | 185 << resolution.height; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 195 | 200 |
| 196 VLOG(1) << "New graphics resolution " << resolution.width << "x" | 201 VLOG(1) << "New graphics resolution " << resolution.width << "x" |
| 197 << resolution.height; | 202 << resolution.height; |
| 198 | 203 |
| 199 have_graphics_res_ = true; | 204 have_graphics_res_ = true; |
| 200 graphics_res_ = resolution; | 205 graphics_res_ = resolution; |
| 201 | 206 |
| 202 MaybeRunSetGeometry(); | 207 MaybeRunSetGeometry(); |
| 203 } | 208 } |
| 204 | 209 |
| 210 void VideoPlaneController::Pause() { |
| 211 DCHECK(thread_checker_.CalledOnValidThread()); |
| 212 VLOG(1) << "Pausing controller. No more VideoPlane SetGeometry calls."; |
| 213 is_paused_ = true; |
| 214 } |
| 215 |
| 216 void VideoPlaneController::Resume() { |
| 217 DCHECK(thread_checker_.CalledOnValidThread()); |
| 218 VLOG(1) << "Resuming controller. VideoPlane SetGeometry calls are active."; |
| 219 is_paused_ = false; |
| 220 } |
| 221 |
| 222 bool VideoPlaneController::is_paused() const { |
| 223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 224 return is_paused_; |
| 225 } |
| 226 |
| 205 VideoPlaneController::VideoPlaneController() | 227 VideoPlaneController::VideoPlaneController() |
| 206 : have_output_res_(false), | 228 : is_paused_(false), |
| 229 have_output_res_(false), |
| 207 have_graphics_res_(false), | 230 have_graphics_res_(false), |
| 208 output_res_(0, 0), | 231 output_res_(0, 0), |
| 209 graphics_res_(0, 0), | 232 graphics_res_(0, 0), |
| 210 have_video_plane_geometry_(false), | 233 have_video_plane_geometry_(false), |
| 211 video_plane_display_rect_(0, 0), | 234 video_plane_display_rect_(0, 0), |
| 212 video_plane_transform_(VideoPlane::TRANSFORM_NONE), | 235 video_plane_transform_(VideoPlane::TRANSFORM_NONE), |
| 213 media_task_runner_(MediaMessageLoop::GetTaskRunner()), | 236 media_task_runner_(MediaMessageLoop::GetTaskRunner()), |
| 214 video_plane_wrapper_( | 237 video_plane_wrapper_( |
| 215 new RateLimitedSetVideoPlaneGeometry(media_task_runner_)) {} | 238 new RateLimitedSetVideoPlaneGeometry(media_task_runner_)) {} |
| 216 | 239 |
| 217 VideoPlaneController::~VideoPlaneController() {} | 240 VideoPlaneController::~VideoPlaneController() {} |
| 218 | 241 |
| 219 void VideoPlaneController::MaybeRunSetGeometry() { | 242 void VideoPlaneController::MaybeRunSetGeometry() { |
| 220 DCHECK(thread_checker_.CalledOnValidThread()); | 243 DCHECK(thread_checker_.CalledOnValidThread()); |
| 221 if (!HaveDataForSetGeometry()) | 244 if (is_paused_) { |
| 245 VLOG(2) << "All VideoPlane SetGeometry calls are paused. Ignoring request."; |
| 222 return; | 246 return; |
| 247 } |
| 248 |
| 249 if (!HaveDataForSetGeometry()) { |
| 250 VLOG(2) << "Don't have all VideoPlane SetGeometry data. Ignoring request."; |
| 251 return; |
| 252 } |
| 223 | 253 |
| 224 DCHECK(graphics_res_.width != 0 && graphics_res_.height != 0); | 254 DCHECK(graphics_res_.width != 0 && graphics_res_.height != 0); |
| 225 | 255 |
| 226 RectF scaled_rect = video_plane_display_rect_; | 256 RectF scaled_rect = video_plane_display_rect_; |
| 227 if (graphics_res_.width != output_res_.width || | 257 if (graphics_res_.width != output_res_.width || |
| 228 graphics_res_.height != output_res_.height) { | 258 graphics_res_.height != output_res_.height) { |
| 229 float sx = static_cast<float>(output_res_.width) / graphics_res_.width; | 259 float sx = static_cast<float>(output_res_.width) / graphics_res_.width; |
| 230 float sy = static_cast<float>(output_res_.height) / graphics_res_.height; | 260 float sy = static_cast<float>(output_res_.height) / graphics_res_.height; |
| 231 scaled_rect.x *= sx; | 261 scaled_rect.x *= sx; |
| 232 scaled_rect.y *= sy; | 262 scaled_rect.y *= sy; |
| 233 scaled_rect.width *= sx; | 263 scaled_rect.width *= sx; |
| 234 scaled_rect.height *= sy; | 264 scaled_rect.height *= sy; |
| 235 } | 265 } |
| 236 | 266 |
| 237 media_task_runner_->PostTask( | 267 media_task_runner_->PostTask( |
| 238 FROM_HERE, | 268 FROM_HERE, |
| 239 base::Bind(&RateLimitedSetVideoPlaneGeometry::SetGeometry, | 269 base::Bind(&RateLimitedSetVideoPlaneGeometry::SetGeometry, |
| 240 video_plane_wrapper_, scaled_rect, video_plane_transform_)); | 270 video_plane_wrapper_, scaled_rect, video_plane_transform_)); |
| 241 } | 271 } |
| 242 | 272 |
| 243 bool VideoPlaneController::HaveDataForSetGeometry() const { | 273 bool VideoPlaneController::HaveDataForSetGeometry() const { |
| 244 DCHECK(thread_checker_.CalledOnValidThread()); | 274 DCHECK(thread_checker_.CalledOnValidThread()); |
| 245 return have_output_res_ && have_graphics_res_ && have_video_plane_geometry_; | 275 return have_output_res_ && have_graphics_res_ && have_video_plane_geometry_; |
| 246 } | 276 } |
| 247 | 277 |
| 248 } // namespace media | 278 } // namespace media |
| 249 } // namespace chromecast | 279 } // namespace chromecast |
| OLD | NEW |