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

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

Issue 2643253003: Media Remoting Clean-up: Less-redundant naming, style consistency, etc. (Closed)
Patch Set: Created 3 years, 11 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 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/interstitial.h"
6 6
7 #include "media/base/media_resources.h" 7 #include "media/base/media_resources.h"
8 #include "media/base/video_frame.h" 8 #include "media/base/video_frame.h"
9 #include "media/base/video_renderer_sink.h" 9 #include "media/base/video_renderer_sink.h"
10 #include "media/base/video_util.h" 10 #include "media/base/video_util.h"
11 #include "skia/ext/image_operations.h" 11 #include "skia/ext/image_operations.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkTypeface.h" 14 #include "third_party/skia/include/core/SkTypeface.h"
14 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 15 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
15 #include "ui/gfx/color_palette.h" 16 #include "ui/gfx/color_palette.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 #include "ui/gfx/paint_vector_icon.h" 18 #include "ui/gfx/paint_vector_icon.h"
18 #include "ui/gfx/skbitmap_operations.h" 19 #include "ui/gfx/skbitmap_operations.h"
19 #include "ui/gfx/vector_icons_public.h" 20 #include "ui/gfx/vector_icons_public.h"
20 21
21 namespace media { 22 namespace media {
23 namespace remoting {
22 24
23 namespace { 25 namespace {
24 26
25 SkBitmap ResizeImage(const SkBitmap& image, const gfx::Size& scaled_size) { 27 SkBitmap ResizeImage(const SkBitmap& image, const gfx::Size& scaled_size) {
26 DCHECK(!scaled_size.IsEmpty()); 28 DCHECK(!scaled_size.IsEmpty());
27 29
28 if (image.width() == scaled_size.width() && 30 if (image.width() == scaled_size.width() &&
29 image.height() == scaled_size.height()) 31 image.height() == scaled_size.height())
30 return image; 32 return image;
31 33
32 return skia::ImageOperations::Resize( 34 return skia::ImageOperations::Resize(
33 image, skia::ImageOperations::RESIZE_BEST, scaled_size.width(), 35 image, skia::ImageOperations::RESIZE_BEST, scaled_size.width(),
34 scaled_size.height()); 36 scaled_size.height());
35 } 37 }
36 38
37 void RenderCastMessage(const gfx::Size& canvas_size, 39 void RenderCastMessage(const gfx::Size& canvas_size,
38 RemotingInterstitialType type, 40 InterstitialType type,
39 SkCanvas* canvas) { 41 SkCanvas* canvas) {
40 DCHECK(canvas); 42 DCHECK(canvas);
41 if (type == RemotingInterstitialType::BETWEEN_SESSIONS) 43 if (type == InterstitialType::BETWEEN_SESSIONS)
42 return; 44 return;
43 45
44 // Blur the background image. 46 // Blur the background image.
45 SkScalar sigma = SkDoubleToScalar(10); 47 SkScalar sigma = SkDoubleToScalar(10);
46 SkPaint paint_blur; 48 SkPaint paint_blur;
47 paint_blur.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr)); 49 paint_blur.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
48 canvas->saveLayer(0, &paint_blur); 50 canvas->saveLayer(0, &paint_blur);
49 canvas->restore(); 51 canvas->restore();
50 52
51 // Create SkPaint for text and icon bitmap. 53 // Create SkPaint for text and icon bitmap.
(...skipping 12 matching lines...) Expand all
64 int text_size = SkIntToScalar(30); 66 int text_size = SkIntToScalar(30);
65 paint.setAntiAlias(true); 67 paint.setAntiAlias(true);
66 paint.setFilterQuality(kHigh_SkFilterQuality); 68 paint.setFilterQuality(kHigh_SkFilterQuality);
67 paint.setColor(SK_ColorLTGRAY); 69 paint.setColor(SK_ColorLTGRAY);
68 paint.setTypeface(SkTypeface::MakeFromName( 70 paint.setTypeface(SkTypeface::MakeFromName(
69 "sans", SkFontStyle::FromOldStyle(SkTypeface::kNormal))); 71 "sans", SkFontStyle::FromOldStyle(SkTypeface::kNormal)));
70 paint.setTextSize(text_size); 72 paint.setTextSize(text_size);
71 73
72 // Draw the appropriate text. 74 // Draw the appropriate text.
73 const std::string remote_playback_message = 75 const std::string remote_playback_message =
74 (type == RemotingInterstitialType::IN_SESSION 76 (type == InterstitialType::IN_SESSION
75 ? GetLocalizedStringUTF8(MEDIA_REMOTING_CASTING_VIDEO_TEXT) 77 ? GetLocalizedStringUTF8(MEDIA_REMOTING_CASTING_VIDEO_TEXT)
76 : GetLocalizedStringUTF8(MEDIA_REMOTING_CAST_ERROR_TEXT)); 78 : GetLocalizedStringUTF8(MEDIA_REMOTING_CAST_ERROR_TEXT));
77 size_t display_text_width = paint.measureText(remote_playback_message.data(), 79 size_t display_text_width = paint.measureText(remote_playback_message.data(),
78 remote_playback_message.size()); 80 remote_playback_message.size());
79 SkScalar sk_text_offset_x = (canvas_size.width() - display_text_width) / 2.0; 81 SkScalar sk_text_offset_x = (canvas_size.width() - display_text_width) / 2.0;
80 SkScalar sk_text_offset_y = (canvas_size.height() / 2.0) + text_size; 82 SkScalar sk_text_offset_y = (canvas_size.height() / 2.0) + text_size;
81 canvas->drawText(remote_playback_message.data(), 83 canvas->drawText(remote_playback_message.data(),
82 remote_playback_message.size(), sk_text_offset_x, 84 remote_playback_message.size(), sk_text_offset_x,
83 sk_text_offset_y, paint); 85 sk_text_offset_y, paint);
84 86
85 // Draw the appropriate Cast icon. 87 // Draw the appropriate Cast icon.
86 gfx::VectorIconId current_icon = 88 gfx::VectorIconId current_icon =
87 (type == RemotingInterstitialType::IN_SESSION 89 (type == InterstitialType::IN_SESSION
88 ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE 90 ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE
89 : gfx::VectorIconId::MEDIA_ROUTER_WARNING); 91 : gfx::VectorIconId::MEDIA_ROUTER_WARNING);
90 gfx::ImageSkia icon_image = 92 gfx::ImageSkia icon_image =
91 gfx::CreateVectorIcon(current_icon, 65, SK_ColorLTGRAY); 93 gfx::CreateVectorIcon(current_icon, 65, SK_ColorLTGRAY);
92 const SkBitmap* icon_bitmap = icon_image.bitmap(); 94 const SkBitmap* icon_bitmap = icon_image.bitmap();
93 SkScalar sk_image_offset_x = (canvas_size.width() - icon_image.width()) / 2.0; 95 SkScalar sk_image_offset_x = (canvas_size.width() - icon_image.width()) / 2.0;
94 SkScalar sk_image_offset_y = 96 SkScalar sk_image_offset_y =
95 (canvas_size.height() / 2.0) - icon_image.height(); 97 (canvas_size.height() / 2.0) - icon_image.height();
96 canvas->drawBitmap(*icon_bitmap, sk_image_offset_x, sk_image_offset_y, 98 canvas->drawBitmap(*icon_bitmap, sk_image_offset_x, sk_image_offset_y,
97 &paint); 99 &paint);
98 } 100 }
99 101
100 scoped_refptr<VideoFrame> RenderInterstitialFrame( 102 scoped_refptr<VideoFrame> RenderInterstitialFrame(const SkBitmap& image,
101 const SkBitmap& image, 103 const gfx::Size& canvas_size,
102 const gfx::Size& canvas_size, 104 InterstitialType type) {
103 RemotingInterstitialType type) {
104 SkBitmap canvas_bitmap; 105 SkBitmap canvas_bitmap;
105 canvas_bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height()); 106 canvas_bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height());
106 canvas_bitmap.eraseColor(SK_ColorBLACK); 107 canvas_bitmap.eraseColor(SK_ColorBLACK);
107 SkCanvas canvas(canvas_bitmap); 108 SkCanvas canvas(canvas_bitmap);
108 109
109 // Draw background image on the canvas. 110 // Draw background image on the canvas.
110 if (!image.drawsNothing()) { 111 if (!image.drawsNothing()) {
111 gfx::Rect centered_rect = ComputeLetterboxRegion( 112 gfx::Rect centered_rect = ComputeLetterboxRegion(
112 gfx::Rect(canvas_size), gfx::Size(image.width(), image.height())); 113 gfx::Rect(canvas_size), gfx::Size(image.width(), image.height()));
113 SkBitmap processed_image = ResizeImage(image, centered_rect.size()); 114 SkBitmap processed_image = ResizeImage(image, centered_rect.size());
114 if (type != RemotingInterstitialType::BETWEEN_SESSIONS) { 115 if (type != InterstitialType::BETWEEN_SESSIONS) {
115 color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic. 116 color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic.
116 processed_image = 117 processed_image =
117 SkBitmapOperations::CreateHSLShiftedBitmap(processed_image, shift); 118 SkBitmapOperations::CreateHSLShiftedBitmap(processed_image, shift);
118 } 119 }
119 canvas.writePixels(processed_image, centered_rect.x(), centered_rect.y()); 120 canvas.writePixels(processed_image, centered_rect.x(), centered_rect.y());
120 } 121 }
121 122
122 RenderCastMessage(canvas_size, type, &canvas); 123 RenderCastMessage(canvas_size, type, &canvas);
123 124
124 // Create a new VideoFrame, copy the bitmap, then return it. 125 // Create a new VideoFrame, copy the bitmap, then return it.
125 scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( 126 scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateFrame(
126 media::PIXEL_FORMAT_I420, canvas_size, gfx::Rect(canvas_size), 127 PIXEL_FORMAT_I420, canvas_size, gfx::Rect(canvas_size), canvas_size,
127 canvas_size, base::TimeDelta()); 128 base::TimeDelta());
128 canvas_bitmap.lockPixels(); 129 canvas_bitmap.lockPixels();
129 media::CopyRGBToVideoFrame( 130 CopyRGBToVideoFrame(reinterpret_cast<uint8_t*>(canvas_bitmap.getPixels()),
130 reinterpret_cast<uint8_t*>(canvas_bitmap.getPixels()), 131 canvas_bitmap.rowBytes(),
131 canvas_bitmap.rowBytes(), 132 gfx::Rect(canvas_size.width(), canvas_size.height()),
132 gfx::Rect(canvas_size.width(), canvas_size.height()), video_frame.get()); 133 video_frame.get());
133 canvas_bitmap.unlockPixels(); 134 canvas_bitmap.unlockPixels();
134 return video_frame; 135 return video_frame;
135 } 136 }
136 137
137 } // namespace 138 } // namespace
138 139
139 void PaintRemotingInterstitial(const SkBitmap& image, 140 void PaintInterstitial(const SkBitmap& image,
140 const gfx::Size& canvas_size, 141 const gfx::Size& canvas_size,
141 RemotingInterstitialType interstitial_type, 142 InterstitialType interstitial_type,
142 VideoRendererSink* video_renderer_sink) { 143 VideoRendererSink* video_renderer_sink) {
143 if (canvas_size.IsEmpty()) 144 if (canvas_size.IsEmpty())
144 return; 145 return;
145 146
146 const scoped_refptr<VideoFrame> interstitial = 147 const scoped_refptr<VideoFrame> interstitial =
147 RenderInterstitialFrame(image, canvas_size, interstitial_type); 148 RenderInterstitialFrame(image, canvas_size, interstitial_type);
148 149
149 if (!interstitial) 150 if (!interstitial)
150 return; 151 return;
151 video_renderer_sink->PaintSingleFrame(interstitial); 152 video_renderer_sink->PaintSingleFrame(interstitial);
152 } 153 }
153 154
155 } // namespace remoting
154 } // namespace media 156 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698