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

Unified Diff: media/remoting/remoting_interstitial_ui.cc

Issue 2566223005: Media Remoting: Update remoting interstitial when status changes. (Closed)
Patch Set: Removed unused declare. 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 side-by-side diff with in-line comments
Download patch
Index: media/remoting/remoting_interstitial_ui.cc
diff --git a/media/remoting/remoting_interstitial_ui.cc b/media/remoting/remoting_interstitial_ui.cc
index 9e3f01d23ea1fe55d4f598ef01ebaa02fba3b65a..333a30ff752c5749f8eef0af6f04acfe5516ef52 100644
--- a/media/remoting/remoting_interstitial_ui.cc
+++ b/media/remoting/remoting_interstitial_ui.cc
@@ -8,11 +8,11 @@
#include "media/base/video_frame.h"
#include "media/base/video_renderer_sink.h"
#include "media/base/video_util.h"
+#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkCanvas.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/geometry/size.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/gfx/vector_icons_public.h"
@@ -21,39 +21,53 @@ namespace media {
namespace {
-gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) {
- if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270)
- return gfx::Size(natural_size.height(), natural_size.width());
- return natural_size;
-}
-
-} // namespace
-
-RemotingInterstitialUI::RemotingInterstitialUI(
- VideoRendererSink* video_renderer_sink,
- const PipelineMetadata& pipeline_metadata)
- : video_renderer_sink_(video_renderer_sink),
- pipeline_metadata_(pipeline_metadata) {
- DCHECK(pipeline_metadata_.has_video);
- pipeline_metadata_.natural_size = GetRotatedVideoSize(
- pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size);
-}
+// Resizes |image| to fit in the center of |canvas_size| and preserves the
+// image's aspect ratio as close as possible.
+SkBitmap ResizeImage(const SkBitmap& image, const gfx::Size& canvas_size) {
+ DCHECK(!canvas_size.IsEmpty());
-RemotingInterstitialUI::~RemotingInterstitialUI() {}
+ const gfx::Size image_size = gfx::Size(image.width(), image.height());
+ if (image_size == canvas_size)
+ return image;
-scoped_refptr<VideoFrame> RemotingInterstitialUI::GetInterstitial(
- const SkBitmap& background_image,
- bool is_remoting_successful) {
- const gfx::Size canvas_size =
- gfx::Size(background_image.width(), background_image.height());
- DCHECK(canvas_size == pipeline_metadata_.natural_size);
+ gfx::Size scaled_size = ScaleSizeToFitWithinTarget(image_size, canvas_size);
+ if (scaled_size == image_size)
+ return image;
- color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic.
- SkBitmap modified_bitmap =
- SkBitmapOperations::CreateHSLShiftedBitmap(background_image, shift);
+ return skia::ImageOperations::Resize(
+ image, skia::ImageOperations::RESIZE_BEST, scaled_size.width(),
+ scaled_size.height());
+}
+scoped_refptr<VideoFrame> GetInterstitial(const SkBitmap& image,
+ const gfx::Size& canvas_size,
+ bool is_remoting_successful) {
+ SkBitmap modified_bitmap;
+ modified_bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height());
+ modified_bitmap.eraseColor(SK_ColorBLACK);
SkCanvas canvas(modified_bitmap);
+ SkBitmap background_image;
+ // Draw |background_image| on the canvas.
+ if (!image.drawsNothing()) {
+ background_image = ResizeImage(image, canvas_size);
+ color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic.
+ SkBitmap monochromatic_image =
+ SkBitmapOperations::CreateHSLShiftedBitmap(background_image, shift);
+
+ const gfx::Size image_size =
+ gfx::Size(background_image.width(), background_image.height());
+ if (image_size != canvas_size) {
+ // Centered the background image.
+ gfx::Rect centered_rect =
+ ComputeLetterboxRegion(gfx::Rect(canvas_size), image_size);
+ canvas.writePixels(monochromatic_image, centered_rect.x(),
+ centered_rect.y());
+ } else {
+ canvas.writePixels(monochromatic_image, 0, 0);
+ }
+ }
+
// Blur the background image.
SkScalar sigma = SkDoubleToScalar(10);
SkPaint paint_blur;
@@ -120,22 +134,34 @@ scoped_refptr<VideoFrame> RemotingInterstitialUI::GetInterstitial(
return video_frame;
}
-void RemotingInterstitialUI::ShowInterstitial(bool is_remoting_successful) {
- if (!video_renderer_sink_)
+} // namespace
+
+RemotingInterstitialUI::RemotingInterstitialUI(
+ VideoRendererSink* video_renderer_sink)
+ : video_renderer_sink_(video_renderer_sink), weak_factory_(this) {
+ DCHECK(video_renderer_sink_);
+}
+
+RemotingInterstitialUI::~RemotingInterstitialUI() {}
+
+void RemotingInterstitialUI::ShowInterstitialOnSink(
+ const SkBitmap& image,
+ const gfx::Size& canvas_size,
+ RemotingInterstitialType interstial_type) {
+ if (canvas_size.IsEmpty())
return;
- // TODO(xjz): Provide poster image, if available, rather than a blank, black
- // image.
- SkBitmap background_image;
- const gfx::Size size = pipeline_metadata_.natural_size;
- background_image.allocN32Pixels(size.width(), size.height());
- background_image.eraseColor(SK_ColorBLACK);
+ scoped_refptr<VideoFrame> interstitial =
+ VideoFrame::CreateBlackFrame(canvas_size);
+
+ if (interstial_type != RemotingInterstitialType::NONE) {
+ interstitial =
+ GetInterstitial(image, canvas_size,
+ interstial_type == RemotingInterstitialType::SUCCESS);
+ }
- const scoped_refptr<VideoFrame> interstitial =
- GetInterstitial(background_image, is_remoting_successful);
if (!interstitial)
return;
-
video_renderer_sink_->PaintSingleFrame(interstitial);
}

Powered by Google App Engine
This is Rietveld 408576698