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

Unified 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 side-by-side diff with in-line comments
Download patch
« media/base/media_resources.h ('K') | « media/remoting/remoting_interstitial_ui.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/remoting/remoting_interstitial_ui.cc
diff --git a/media/remoting/remoting_interstitial_ui.cc b/media/remoting/remoting_interstitial_ui.cc
new file mode 100644
index 0000000000000000000000000000000000000000..672769e66245fe9ed78e99559aeb1eec78fa1b42
--- /dev/null
+++ b/media/remoting/remoting_interstitial_ui.cc
@@ -0,0 +1,103 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/remoting/remoting_interstitial_ui.h"
+
+#include "media/base/media_resources.h"
+#include "media/base/video_util.h"
+#include "third_party/skia/include/core/SkTypeface.h"
+#include "third_party/skia/include/effects/SkBlurImageFilter.h"
+#include "ui/gfx/color_palette.h"
+#include "ui/gfx/paint_vector_icon.h"
+#include "ui/gfx/skbitmap_operations.h"
+#include "ui/gfx/vector_icons_public.h"
+
+namespace media {
+
+scoped_refptr<VideoFrame> GetInterstitial(gfx::Size canvas_size,
+ SkCanvas* existing_frame_canvas,
+ bool isRemotingSuccessful) {
+ if (!existing_frame_canvas)
+ return nullptr;
+
+ // Initial bitmap to grab the existing frame image.
+ SkBitmap bitmap;
+ bitmap.setInfo(existing_frame_canvas->imageInfo());
+
+ // Second bitmap for manipulation.
+ SkBitmap modified_bitmap;
+
+ // Reads the pixels from the current frame into |modified_bitmap|. In the
+ // case this failed, create and use a blank bitmap.
+ if (existing_frame_canvas->readPixels(&bitmap, 0, 0)) {
+ // Make monochromatic.
+ color_utils::HSL shift = {-1, 0, 0.2};
+ modified_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, shift);
+ } else {
+ modified_bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height());
+ }
+
+ SkCanvas canvas(modified_bitmap);
+
+ // Blur the background image.
+ SkScalar sigma = SkDoubleToScalar(10);
+ SkPaint paint_blur;
+ paint_blur.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
+ canvas.saveLayer(0, &paint_blur);
+ canvas.drawBitmap(modified_bitmap, SkIntToScalar(0), SkIntToScalar(0));
+ canvas.restore();
+
+ // Write text over the image.
+ 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.
+ int text_size = SkIntToScalar(30);
+ paint_text.setAntiAlias(true);
+ paint_text.setFilterQuality(kHigh_SkFilterQuality);
+ paint_text.setColor(SK_ColorLTGRAY);
+ paint_text.setTypeface(SkTypeface::MakeFromName(
+ "sans", SkFontStyle::FromOldStyle(SkTypeface::kNormal)));
+ paint_text.setTextSize(text_size);
+
+ // 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.
+ const std::string remote_playback_message =
+ isRemotingSuccessful
+ ? GetLocalizedStringUTF8(MEDIA_REMOTING_CASTING_VIDEO_TEXT)
+ : GetLocalizedStringUTF8(MEDIA_REMOTING_CAST_ERROR_TEXT);
+
+ 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.
+ size_t display_text_width = paint_text.measureText(
+ remote_playback_message.c_str(), remote_playback_message.size());
+ SkScalar sk_horizontal_text_margin =
xjz 2016/11/03 23:53:40 nit: ditto naming.
apacible 2016/11/04 01:25:38 Done.
+ (canvas_size.width() - display_text_width) / 2.0;
+ canvas.drawText(remote_playback_message.c_str(),
+ remote_playback_message.size(), sk_horizontal_text_margin,
+ sk_vertical_text_margin, paint_text);
+
+ // Draw the appropriate Cast icon.
+ gfx::VectorIconId current_icon = isRemotingSuccessful
+ ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE
+ : gfx::VectorIconId::MEDIA_ROUTER_ERROR;
+ // gfx::ImageSkia and SkBitmap have the same width.
+ gfx::ImageSkia icon_image =
+ gfx::CreateVectorIcon(current_icon, 65, SK_ColorLTGRAY);
+ const SkBitmap* icon_bitmap = icon_image.bitmap();
+ SkScalar sk_horizontal_image_margin =
xjz 2016/11/03 23:53:40 nit: naming.
apacible 2016/11/04 01:25:38 Done.
+ (canvas_size.width() - icon_image.width()) / 2.0;
+ SkScalar sk_vertical_image_margin =
xjz 2016/11/03 23:53:39 nit: naming.
apacible 2016/11/04 01:25:38 Done.
+ (canvas_size.height() / 2.0) - icon_image.height();
+ canvas.drawBitmap(*icon_bitmap, sk_horizontal_image_margin,
+ sk_vertical_image_margin, &paint_text);
+
+ // Create a new VideoFrame, copy the bitmap, then return it.
+ const gfx::Rect region_in_frame =
+ gfx::Rect(modified_bitmap.width(), modified_bitmap.height());
+ scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame(
+ media::PIXEL_FORMAT_I420, canvas_size, gfx::Rect(canvas_size),
+ canvas_size, base::TimeDelta());
+ media::CopyRGBToVideoFrame(
+ reinterpret_cast<uint8_t*>(modified_bitmap.getPixels()),
+ modified_bitmap.rowBytes(), region_in_frame, video_frame.get());
+ return video_frame;
+}
+
+} // namespace media
« 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