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

Side by Side Diff: media/remoting/remoting_interstitial_ui.cc

Issue 2538853002: Media Remoting: Draw remoting interstitial on poster image. (Closed)
Patch Set: Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/remoting/remoting_interstitial_ui.h" 5 #include "media/remoting/remoting_interstitial_ui.h"
6 6
7 #include "media/base/media_resources.h" 7 #include "media/base/media_resources.h"
8 #include "media/base/pipeline_metadata.h"
8 #include "media/base/video_frame.h" 9 #include "media/base/video_frame.h"
9 #include "media/base/video_renderer_sink.h" 10 #include "media/base/video_renderer_sink.h"
10 #include "media/base/video_util.h" 11 #include "media/base/video_util.h"
12 #include "media/remoting/remoting_renderer_controller.h"
13 #include "skia/ext/image_operations.h"
11 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "third_party/skia/include/core/SkTypeface.h" 15 #include "third_party/skia/include/core/SkTypeface.h"
13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 16 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
14 #include "ui/gfx/color_palette.h" 17 #include "ui/gfx/color_palette.h"
15 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/paint_vector_icon.h" 19 #include "ui/gfx/paint_vector_icon.h"
17 #include "ui/gfx/skbitmap_operations.h" 20 #include "ui/gfx/skbitmap_operations.h"
18 #include "ui/gfx/vector_icons_public.h" 21 #include "ui/gfx/vector_icons_public.h"
19 22
20 namespace media { 23 namespace media {
21 24
22 namespace { 25 namespace {
23 26
24 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { 27 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) {
25 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) 28 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270)
26 return gfx::Size(natural_size.height(), natural_size.width()); 29 return gfx::Size(natural_size.height(), natural_size.width());
27 return natural_size; 30 return natural_size;
28 } 31 }
29 32
33 SkBitmap ResizeImage(const SkBitmap& image, int width, int height) {
34 DCHECK(width && height);
35 if (image.width() == width && image.height() == height)
36 return image;
37 return skia::ImageOperations::Resize(
miu 2016/11/29 22:56:08 This will stretch (not preserving aspect ratio). I
xjz 2016/12/02 19:23:10 Didn't find any specific in the W3C spec. But with
38 image, skia::ImageOperations::RESIZE_BEST, width, height);
39 }
40
30 } // namespace 41 } // namespace
31 42
32 RemotingInterstitialUI::RemotingInterstitialUI( 43 RemotingInterstitialUI::RemotingInterstitialUI(
33 VideoRendererSink* video_renderer_sink, 44 VideoRendererSink* video_renderer_sink,
34 const PipelineMetadata& pipeline_metadata) 45 const base::WeakPtr<RemotingRendererController>&
46 remoting_renderer_controller)
35 : video_renderer_sink_(video_renderer_sink), 47 : video_renderer_sink_(video_renderer_sink),
36 pipeline_metadata_(pipeline_metadata) { 48 remoting_renderer_controller_(remoting_renderer_controller),
37 DCHECK(pipeline_metadata_.has_video); 49 weak_factory_(this) {}
38 pipeline_metadata_.natural_size = GetRotatedVideoSize(
39 pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size);
40 }
41 50
42 RemotingInterstitialUI::~RemotingInterstitialUI() {} 51 RemotingInterstitialUI::~RemotingInterstitialUI() {}
43 52
44 scoped_refptr<VideoFrame> RemotingInterstitialUI::GetInterstitial( 53 scoped_refptr<VideoFrame> RemotingInterstitialUI::GetInterstitial(
45 const SkBitmap& background_image, 54 const SkBitmap& background_image,
46 bool is_remoting_successful) { 55 bool is_remoting_successful) {
47 const gfx::Size canvas_size = 56 const gfx::Size canvas_size =
48 gfx::Size(background_image.width(), background_image.height()); 57 gfx::Size(background_image.width(), background_image.height());
49 DCHECK(canvas_size == pipeline_metadata_.natural_size);
50 58
51 color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic. 59 color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic.
52 SkBitmap modified_bitmap = 60 SkBitmap modified_bitmap =
53 SkBitmapOperations::CreateHSLShiftedBitmap(background_image, shift); 61 SkBitmapOperations::CreateHSLShiftedBitmap(background_image, shift);
54 62
55 SkCanvas canvas(modified_bitmap); 63 SkCanvas canvas(modified_bitmap);
56 64
57 // Blur the background image. 65 // Blur the background image.
58 SkScalar sigma = SkDoubleToScalar(10); 66 SkScalar sigma = SkDoubleToScalar(10);
59 SkPaint paint_blur; 67 SkPaint paint_blur;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 modified_bitmap.rowBytes(), 125 modified_bitmap.rowBytes(),
118 gfx::Rect(canvas_size.width(), canvas_size.height()), video_frame.get()); 126 gfx::Rect(canvas_size.width(), canvas_size.height()), video_frame.get());
119 modified_bitmap.unlockPixels(); 127 modified_bitmap.unlockPixels();
120 return video_frame; 128 return video_frame;
121 } 129 }
122 130
123 void RemotingInterstitialUI::ShowInterstitial(bool is_remoting_successful) { 131 void RemotingInterstitialUI::ShowInterstitial(bool is_remoting_successful) {
124 if (!video_renderer_sink_) 132 if (!video_renderer_sink_)
125 return; 133 return;
126 134
127 // TODO(xjz): Provide poster image, if available, rather than a blank, black 135 // Draw interstial on a blank, black background image before poster image is
128 // image. 136 // downloaded.
137 DisplayInterstitial(SkBitmap(), is_remoting_successful);
miu 2016/11/29 22:56:08 Instead of a blank bitmap, it's possible the poste
xjz 2016/12/02 19:23:10 Done.
138
139 GURL poster = remoting_renderer_controller_->poster();
140 RemotingRendererController::DownloadPosterCallback cb =
141 remoting_renderer_controller_->download_poster_cb();
142 if (poster.is_empty() || cb.is_null())
143 return;
144
145 cb.Run(poster,
146 base::Bind(&RemotingInterstitialUI::PosterDownloaded,
147 weak_factory_.GetWeakPtr(), is_remoting_successful));
miu 2016/11/29 22:56:08 What if |is_remoting_successful| changes before th
xjz 2016/12/02 19:23:10 Done.
148 }
149
150 void RemotingInterstitialUI::PosterDownloaded(bool is_remoting_successful,
151 const SkBitmap& poster_image) {
152 if (poster_image.drawsNothing())
153 return;
154
155 DisplayInterstitial(poster_image, is_remoting_successful);
156 }
157
158 void RemotingInterstitialUI::DisplayInterstitial(const SkBitmap& poster_image,
159 bool is_remoting_successful) {
160 const PipelineMetadata pipeline_metadata =
161 remoting_renderer_controller_->pipeline_metadata();
162 DCHECK(pipeline_metadata.has_video);
163 const gfx::Size size = GetRotatedVideoSize(pipeline_metadata.video_rotation,
164 pipeline_metadata.natural_size);
129 SkBitmap background_image; 165 SkBitmap background_image;
130 const gfx::Size size = pipeline_metadata_.natural_size; 166 if (poster_image.drawsNothing()) {
131 background_image.allocN32Pixels(size.width(), size.height()); 167 background_image.allocN32Pixels(size.width(), size.height());
132 background_image.eraseColor(SK_ColorBLACK); 168 background_image.eraseColor(SK_ColorBLACK);
169 } else {
170 background_image = ResizeImage(poster_image, size.width(), size.height());
171 }
133 172
134 const scoped_refptr<VideoFrame> interstitial = 173 const scoped_refptr<VideoFrame> interstitial =
135 GetInterstitial(background_image, is_remoting_successful); 174 GetInterstitial(background_image, is_remoting_successful);
136 if (!interstitial) 175 if (!interstitial)
137 return; 176 return;
138 177
139 video_renderer_sink_->PaintSingleFrame(interstitial); 178 video_renderer_sink_->PaintSingleFrame(interstitial);
140 } 179 }
141 180
142 } // namespace media 181 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698