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

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: Changes per xjz@'s comments. 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,
miu 2016/11/04 22:02:30 Is |canvas_size| ever different from existing_fram
apacible 2016/11/05 01:12:52 Updated to use the |existing_frame_canvas| size.
19 SkCanvas* existing_frame_canvas,
20 bool isRemotingSuccessful) {
miu 2016/11/04 22:02:30 ditto: (underscore_naming)
apacible 2016/11/05 01:12:51 Done.
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));
miu 2016/11/04 22:02:30 I don't know for sure (maybe you already looked in
apacible 2016/11/05 01:12:51 This line is actually a no-op, so removed.
49 canvas.restore();
50
51 // Write text over the image.
52 SkPaint paint;
53 int text_size = SkIntToScalar(30);
54 paint.setAntiAlias(true);
55 paint.setFilterQuality(kHigh_SkFilterQuality);
56 paint.setColor(SK_ColorLTGRAY);
57 paint.setTypeface(SkTypeface::MakeFromName(
58 "sans", SkFontStyle::FromOldStyle(SkTypeface::kNormal)));
59 paint.setTextSize(text_size);
60
61 const std::string remote_playback_message =
62 isRemotingSuccessful
63 ? GetLocalizedStringUTF8(MEDIA_REMOTING_CASTING_VIDEO_TEXT)
64 : GetLocalizedStringUTF8(MEDIA_REMOTING_CAST_ERROR_TEXT);
65
66 // Center the text horizontally in the canvas.
miu 2016/11/04 22:02:30 The comment says "horizontally," but the next line
xjz 2016/11/04 22:10:24 It is only centered horizontally, not vertically.
apacible 2016/11/05 01:12:52 I removed this and added a general comment.
67 SkScalar sk_text_offset_y = (canvas_size.height() / 2.0) + text_size;
68 size_t display_text_width = paint.measureText(remote_playback_message.c_str(),
miu 2016/11/04 22:02:30 Avoid using c_str() where possible. Since the leng
apacible 2016/11/05 01:12:52 Done.
69 remote_playback_message.size());
70 SkScalar sk_text_offset_x = (canvas_size.width() - display_text_width) / 2.0;
71 canvas.drawText(remote_playback_message.c_str(),
miu 2016/11/04 22:02:30 s/c_str/data/
apacible 2016/11/05 01:12:52 Done.
72 remote_playback_message.size(), sk_text_offset_x,
73 sk_text_offset_y, paint);
74
75 // Draw the appropriate Cast icon.
76 gfx::VectorIconId current_icon = isRemotingSuccessful
77 ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE
78 : gfx::VectorIconId::MEDIA_ROUTER_ERROR;
79 // gfx::ImageSkia and SkBitmap have the same width.
miu 2016/11/04 22:02:30 Was this comment meant to be placed just before li
apacible 2016/11/05 01:12:52 This was more a note for myself. Removed.
80 gfx::ImageSkia icon_image =
81 gfx::CreateVectorIcon(current_icon, 65, SK_ColorLTGRAY);
82 const SkBitmap* icon_bitmap = icon_image.bitmap();
83 SkScalar sk_image_offset_x = (canvas_size.width() - icon_image.width()) / 2.0;
84 SkScalar sk_image_offset_y =
85 (canvas_size.height() / 2.0) - icon_image.height();
86 canvas.drawBitmap(*icon_bitmap, sk_image_offset_x, sk_image_offset_y, &paint);
87
88 // Create a new VideoFrame, copy the bitmap, then return it.
89 const gfx::Rect region_in_frame =
miu 2016/11/04 22:02:30 Is |region_in_frame| a different size than the can
apacible 2016/11/05 01:12:52 Done.
90 gfx::Rect(modified_bitmap.width(), modified_bitmap.height());
91 scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame(
92 media::PIXEL_FORMAT_I420, canvas_size, gfx::Rect(canvas_size),
93 canvas_size, base::TimeDelta());
94 media::CopyRGBToVideoFrame(
miu 2016/11/04 22:02:30 I think you have to lock the pixels while reading
apacible 2016/11/05 01:12:52 Done.
95 reinterpret_cast<uint8_t*>(modified_bitmap.getPixels()),
96 modified_bitmap.rowBytes(), region_in_frame, video_frame.get());
97 return video_frame;
98 }
99
100 } // namespace media
OLDNEW
« media/remoting/remoting_interstitial_ui.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