Chromium Code Reviews| 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 "ui/ozone/platform/cast/overlay_manager_cast.h" | 5 #include "ui/ozone/platform/cast/overlay_manager_cast.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "chromecast/media/base/media_message_loop.h" | |
| 7 #include "chromecast/public/cast_media_shlib.h" | 12 #include "chromecast/public/cast_media_shlib.h" |
| 8 #include "chromecast/public/graphics_types.h" | 13 #include "chromecast/public/graphics_types.h" |
| 9 #include "chromecast/public/video_plane.h" | 14 #include "chromecast/public/video_plane.h" |
| 10 #include "ui/gfx/geometry/rect_conversions.h" | 15 #include "ui/gfx/geometry/rect_conversions.h" |
| 11 #include "ui/ozone/public/overlay_candidates_ozone.h" | 16 #include "ui/ozone/public/overlay_candidates_ozone.h" |
| 12 | 17 |
| 13 namespace ui { | 18 namespace ui { |
| 14 namespace { | 19 namespace { |
| 15 | 20 |
| 21 void SetVideoPlaneGeometry( | |
| 22 const chromecast::RectF& display_rect, | |
| 23 chromecast::media::VideoPlane::CoordinateType coordinate_type, | |
| 24 chromecast::media::VideoPlane::Transform transform) { | |
| 25 chromecast::media::VideoPlane* video_plane = | |
| 26 chromecast::media::CastMediaShlib::GetVideoPlane(); | |
| 27 CHECK(video_plane); | |
| 28 video_plane->SetGeometry(display_rect, coordinate_type, transform); | |
| 29 } | |
| 30 | |
| 16 // Translates a gfx::OverlayTransform into a VideoPlane::Transform. | 31 // Translates a gfx::OverlayTransform into a VideoPlane::Transform. |
| 17 // Could be just a lookup table once we have unit tests for this code | 32 // Could be just a lookup table once we have unit tests for this code |
| 18 // to ensure it stays in sync with OverlayTransform. | 33 // to ensure it stays in sync with OverlayTransform. |
| 19 chromecast::media::VideoPlane::Transform ConvertTransform( | 34 chromecast::media::VideoPlane::Transform ConvertTransform( |
| 20 gfx::OverlayTransform transform) { | 35 gfx::OverlayTransform transform) { |
| 21 switch (transform) { | 36 switch (transform) { |
| 22 case gfx::OVERLAY_TRANSFORM_NONE: | 37 case gfx::OVERLAY_TRANSFORM_NONE: |
| 23 return chromecast::media::VideoPlane::TRANSFORM_NONE; | 38 return chromecast::media::VideoPlane::TRANSFORM_NONE; |
| 24 case gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: | 39 case gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: |
| 25 return chromecast::media::VideoPlane::FLIP_HORIZONTAL; | 40 return chromecast::media::VideoPlane::FLIP_HORIZONTAL; |
| 26 case gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL: | 41 case gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL: |
| 27 return chromecast::media::VideoPlane::FLIP_VERTICAL; | 42 return chromecast::media::VideoPlane::FLIP_VERTICAL; |
| 28 case gfx::OVERLAY_TRANSFORM_ROTATE_90: | 43 case gfx::OVERLAY_TRANSFORM_ROTATE_90: |
| 29 return chromecast::media::VideoPlane::ROTATE_90; | 44 return chromecast::media::VideoPlane::ROTATE_90; |
| 30 case gfx::OVERLAY_TRANSFORM_ROTATE_180: | 45 case gfx::OVERLAY_TRANSFORM_ROTATE_180: |
| 31 return chromecast::media::VideoPlane::ROTATE_180; | 46 return chromecast::media::VideoPlane::ROTATE_180; |
| 32 case gfx::OVERLAY_TRANSFORM_ROTATE_270: | 47 case gfx::OVERLAY_TRANSFORM_ROTATE_270: |
| 33 return chromecast::media::VideoPlane::ROTATE_270; | 48 return chromecast::media::VideoPlane::ROTATE_270; |
| 34 default: | 49 default: |
| 35 NOTREACHED(); | 50 NOTREACHED(); |
| 36 return chromecast::media::VideoPlane::TRANSFORM_NONE; | 51 return chromecast::media::VideoPlane::TRANSFORM_NONE; |
| 37 } | 52 } |
| 38 } | 53 } |
| 39 | 54 |
| 55 bool ExactlyEqual(const chromecast::RectF& r1, const chromecast::RectF& r2) { | |
|
erickung1
2015/07/08 17:12:33
wonder if this can become util function?
Although
halliwell
2015/07/08 17:16:41
I'm not sure how widely useful exact float compari
| |
| 56 return r1.x == r2.x && r1.y == r2.y && r1.width == r2.width && | |
| 57 r1.height == r2.height; | |
| 58 } | |
| 59 | |
| 40 class OverlayCandidatesCast : public OverlayCandidatesOzone { | 60 class OverlayCandidatesCast : public OverlayCandidatesOzone { |
| 41 public: | 61 public: |
| 62 OverlayCandidatesCast() | |
| 63 : media_task_runner_( | |
| 64 chromecast::media::MediaMessageLoop::GetTaskRunner()), | |
| 65 transform_(gfx::OVERLAY_TRANSFORM_INVALID), | |
| 66 display_rect_(0, 0, 0, 0) {} | |
| 67 | |
| 42 void CheckOverlaySupport(OverlaySurfaceCandidateList* surfaces) override { | 68 void CheckOverlaySupport(OverlaySurfaceCandidateList* surfaces) override { |
|
gunsch
2015/07/08 16:02:52
readability nit: there are now four consecutive cl
erickung1
2015/07/08 17:12:33
or
for (...) {
if (candidate.plane_z_order !=
halliwell
2015/07/08 17:16:41
Moved out of class definition and used continue as
| |
| 43 for (auto& candidate : *surfaces) { | 69 for (auto& candidate : *surfaces) { |
| 44 if (candidate.plane_z_order == -1) { | 70 if (candidate.plane_z_order == -1) { |
| 45 candidate.overlay_handled = true; | 71 candidate.overlay_handled = true; |
| 46 | 72 |
| 47 // Compositor requires all overlay rectangles to have integer coords | 73 // Compositor requires all overlay rectangles to have integer coords |
| 48 candidate.display_rect = gfx::ToEnclosedRect(candidate.display_rect); | 74 candidate.display_rect = gfx::ToEnclosedRect(candidate.display_rect); |
| 49 | 75 |
| 50 chromecast::media::VideoPlane* video_plane = | |
| 51 chromecast::media::CastMediaShlib::GetVideoPlane(); | |
| 52 | |
| 53 chromecast::RectF display_rect( | 76 chromecast::RectF display_rect( |
| 54 candidate.display_rect.x(), candidate.display_rect.y(), | 77 candidate.display_rect.x(), candidate.display_rect.y(), |
| 55 candidate.display_rect.width(), candidate.display_rect.height()); | 78 candidate.display_rect.width(), candidate.display_rect.height()); |
| 56 video_plane->SetGeometry( | 79 |
| 57 display_rect, | 80 // Update video plane geometry + transform to match compositor quad. |
| 58 chromecast::media::VideoPlane::COORDINATE_TYPE_GRAPHICS_PLANE, | 81 // This must be done on media thread - and no point doing if it hasn't |
| 59 ConvertTransform(candidate.transform)); | 82 // changed. |
| 83 if (candidate.transform != transform_ || | |
| 84 !ExactlyEqual(display_rect, display_rect_)) { | |
| 85 transform_ = candidate.transform; | |
| 86 display_rect_ = display_rect; | |
| 87 | |
| 88 media_task_runner_->PostTask( | |
| 89 FROM_HERE, | |
| 90 base::Bind( | |
| 91 &SetVideoPlaneGeometry, display_rect, | |
| 92 chromecast::media::VideoPlane::COORDINATE_TYPE_GRAPHICS_PLANE, | |
| 93 ConvertTransform(candidate.transform))); | |
| 94 } | |
| 60 return; | 95 return; |
| 61 } | 96 } |
| 62 } | 97 } |
| 63 } | 98 } |
| 99 | |
| 100 private: | |
| 101 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | |
| 102 gfx::OverlayTransform transform_; | |
| 103 chromecast::RectF display_rect_; | |
| 64 }; | 104 }; |
| 65 | 105 |
| 66 } // namespace | 106 } // namespace |
| 67 | 107 |
| 68 OverlayManagerCast::OverlayManagerCast() { | 108 OverlayManagerCast::OverlayManagerCast() { |
| 69 } | 109 } |
| 70 | 110 |
| 71 OverlayManagerCast::~OverlayManagerCast() { | 111 OverlayManagerCast::~OverlayManagerCast() { |
| 72 } | 112 } |
| 73 | 113 |
| 74 scoped_ptr<OverlayCandidatesOzone> OverlayManagerCast::CreateOverlayCandidates( | 114 scoped_ptr<OverlayCandidatesOzone> OverlayManagerCast::CreateOverlayCandidates( |
| 75 gfx::AcceleratedWidget w) { | 115 gfx::AcceleratedWidget w) { |
| 76 return make_scoped_ptr(new OverlayCandidatesCast()); | 116 return make_scoped_ptr(new OverlayCandidatesCast()); |
| 77 } | 117 } |
| 78 | 118 |
| 79 bool OverlayManagerCast::CanShowPrimaryPlaneAsOverlay() { | 119 bool OverlayManagerCast::CanShowPrimaryPlaneAsOverlay() { |
| 80 return false; | 120 return false; |
| 81 } | 121 } |
| 82 | 122 |
| 83 } // namespace ui | 123 } // namespace ui |
| OLD | NEW |