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

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

Issue 2474803002: [Media Remoting] Add function to create interstitial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/remoting/remoting_interstitial_ui.h"
6
7 #include "media/base/media_resources.h"
8 #include "media/base/video_util.h"
9 #include "third_party/skia/include/core/SkTypeface.h"
10 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
11 #include "ui/gfx/color_palette.h"
12 #include "ui/gfx/paint_vector_icon.h"
13 #include "ui/gfx/skbitmap_operations.h"
14 #include "ui/gfx/vector_icons_public.h"
15
16 namespace media {
17
18 scoped_refptr<VideoFrame> GetInterstitial(gfx::Size canvas_size,
19 SkCanvas* existing_frame_canvas,
20 bool isRemotingSuccessful) {
21 if (!existing_frame_canvas)
22 return nullptr;
23
24 // Initial bitmap to grab the existing frame image.
25 SkBitmap bitmap;
26 bitmap.setInfo(existing_frame_canvas->imageInfo());
27
28 // Second bitmap for manipulation.
29 SkBitmap modified_bitmap;
30
31 // Reads the pixels from the current frame into |modified_bitmap|. In the
32 // case this failed, create and use a blank bitmap.
33 if (existing_frame_canvas->readPixels(&bitmap, 0, 0)) {
34 // Make monochromatic.
35 color_utils::HSL shift = {-1, 0, 0.2};
36 modified_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, shift);
37 } else {
38 modified_bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height());
39 }
40
41 SkCanvas canvas(modified_bitmap);
42
43 // Blur the background image.
44 SkScalar sigma = SkDoubleToScalar(10);
45 SkPaint paint_blur;
46 paint_blur.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
47 canvas.saveLayer(0, &paint_blur);
48 canvas.drawBitmap(modified_bitmap, SkIntToScalar(0), SkIntToScalar(0));
49 canvas.restore();
50
51 // Write text over the image.
52 SkPaint paint_text;
xjz 2016/11/03 23:53:39 nit: naming. This is used by both text and bitmap.
apacible 2016/11/04 01:25:38 Done.
53 int text_size = SkIntToScalar(30);
54 paint_text.setAntiAlias(true);
55 paint_text.setFilterQuality(kHigh_SkFilterQuality);
56 paint_text.setColor(SK_ColorLTGRAY);
57 paint_text.setTypeface(SkTypeface::MakeFromName(
58 "sans", SkFontStyle::FromOldStyle(SkTypeface::kNormal)));
59 paint_text.setTextSize(text_size);
60
61 // Center the text in the canvas.
xjz 2016/11/03 23:53:40 We only center the text horizontally, not vertical
apacible 2016/11/04 01:25:38 Done.
62 const std::string remote_playback_message =
63 isRemotingSuccessful
64 ? GetLocalizedStringUTF8(MEDIA_REMOTING_CASTING_VIDEO_TEXT)
65 : GetLocalizedStringUTF8(MEDIA_REMOTING_CAST_ERROR_TEXT);
66
67 SkScalar sk_vertical_text_margin = (canvas_size.height() / 2.0) + text_size;
xjz 2016/11/03 23:53:40 nit: this is only the top margin. Is this actual t
apacible 2016/11/04 01:25:38 Done.
68 size_t display_text_width = paint_text.measureText(
69 remote_playback_message.c_str(), remote_playback_message.size());
70 SkScalar sk_horizontal_text_margin =
xjz 2016/11/03 23:53:40 nit: ditto naming.
apacible 2016/11/04 01:25:38 Done.
71 (canvas_size.width() - display_text_width) / 2.0;
72 canvas.drawText(remote_playback_message.c_str(),
73 remote_playback_message.size(), sk_horizontal_text_margin,
74 sk_vertical_text_margin, paint_text);
75
76 // Draw the appropriate Cast icon.
77 gfx::VectorIconId current_icon = isRemotingSuccessful
78 ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE
79 : gfx::VectorIconId::MEDIA_ROUTER_ERROR;
80 // gfx::ImageSkia and SkBitmap have the same width.
81 gfx::ImageSkia icon_image =
82 gfx::CreateVectorIcon(current_icon, 65, SK_ColorLTGRAY);
83 const SkBitmap* icon_bitmap = icon_image.bitmap();
84 SkScalar sk_horizontal_image_margin =
xjz 2016/11/03 23:53:40 nit: naming.
apacible 2016/11/04 01:25:38 Done.
85 (canvas_size.width() - icon_image.width()) / 2.0;
86 SkScalar sk_vertical_image_margin =
xjz 2016/11/03 23:53:39 nit: naming.
apacible 2016/11/04 01:25:38 Done.
87 (canvas_size.height() / 2.0) - icon_image.height();
88 canvas.drawBitmap(*icon_bitmap, sk_horizontal_image_margin,
89 sk_vertical_image_margin, &paint_text);
90
91 // Create a new VideoFrame, copy the bitmap, then return it.
92 const gfx::Rect region_in_frame =
93 gfx::Rect(modified_bitmap.width(), modified_bitmap.height());
94 scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame(
95 media::PIXEL_FORMAT_I420, canvas_size, gfx::Rect(canvas_size),
96 canvas_size, base::TimeDelta());
97 media::CopyRGBToVideoFrame(
98 reinterpret_cast<uint8_t*>(modified_bitmap.getPixels()),
99 modified_bitmap.rowBytes(), region_in_frame, video_frame.get());
100 return video_frame;
101 }
102
103 } // namespace media
OLDNEW
« media/base/media_resources.h ('K') | « media/remoting/remoting_interstitial_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698