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

Unified Diff: media/remoting/remoting_interstitial_ui.cc

Issue 2538853002: Media Remoting: Draw remoting interstitial on poster image. (Closed)
Patch Set: Addressed comments. 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..d3fa3f446e51b8a43aa3ea4c0f752ba79400b866 100644
--- a/media/remoting/remoting_interstitial_ui.cc
+++ b/media/remoting/remoting_interstitial_ui.cc
@@ -12,7 +12,6 @@
#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 +20,33 @@ 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);
-}
-
-RemotingInterstitialUI::~RemotingInterstitialUI() {}
-
-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);
-
- color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic.
- SkBitmap modified_bitmap =
- SkBitmapOperations::CreateHSLShiftedBitmap(background_image, shift);
-
+scoped_refptr<VideoFrame> GetInterstitial(const SkBitmap& background_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);
+ // Draw |background_image| on the canvas.
+ if (!background_image.drawsNothing()) {
+ 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,23 +113,21 @@ scoped_refptr<VideoFrame> RemotingInterstitialUI::GetInterstitial(
return video_frame;
}
-void RemotingInterstitialUI::ShowInterstitial(bool is_remoting_successful) {
- if (!video_renderer_sink_)
- return;
+} // namespace
- // 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);
+void ShowInterstitialOnSink(VideoRendererSink* const video_renderer_sink,
+ const SkBitmap& background_image,
+ const gfx::Size& canvas_size,
+ bool is_remoting_successful) {
+ DCHECK(!canvas_size.IsEmpty());
miu 2016/12/03 01:05:31 I'm trying to remember if this can happen. Maybe a
xjz 2016/12/06 19:50:55 Add the check before this function is called.
+ DCHECK(video_renderer_sink);
const scoped_refptr<VideoFrame> interstitial =
- GetInterstitial(background_image, is_remoting_successful);
+ GetInterstitial(background_image, canvas_size, is_remoting_successful);
if (!interstitial)
return;
- video_renderer_sink_->PaintSingleFrame(interstitial);
+ video_renderer_sink->PaintSingleFrame(interstitial);
}
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698