Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/remoting/remoting_interstitial_ui.h" | 5 #include "media/remoting/remoting_interstitial_ui.h" |
| 6 | 6 |
| 7 #include "media/base/media_resources.h" | 7 #include "media/base/media_resources.h" |
| 8 #include "media/base/video_frame.h" | 8 #include "media/base/video_frame.h" |
| 9 #include "media/base/video_renderer_sink.h" | 9 #include "media/base/video_renderer_sink.h" |
| 10 #include "media/base/video_util.h" | 10 #include "media/base/video_util.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "third_party/skia/include/core/SkTypeface.h" | 12 #include "third_party/skia/include/core/SkTypeface.h" |
| 13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 14 #include "ui/gfx/color_palette.h" | 14 #include "ui/gfx/color_palette.h" |
| 15 #include "ui/gfx/geometry/size.h" | |
| 16 #include "ui/gfx/paint_vector_icon.h" | 15 #include "ui/gfx/paint_vector_icon.h" |
| 17 #include "ui/gfx/skbitmap_operations.h" | 16 #include "ui/gfx/skbitmap_operations.h" |
| 18 #include "ui/gfx/vector_icons_public.h" | 17 #include "ui/gfx/vector_icons_public.h" |
| 19 | 18 |
| 20 namespace media { | 19 namespace media { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { | 23 scoped_refptr<VideoFrame> GetInterstitial(const SkBitmap& background_image, |
| 25 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) | 24 const gfx::Size& canvas_size, |
| 26 return gfx::Size(natural_size.height(), natural_size.width()); | 25 bool is_remoting_successful) { |
| 27 return natural_size; | 26 SkBitmap modified_bitmap; |
| 28 } | 27 modified_bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height()); |
| 28 modified_bitmap.eraseColor(SK_ColorBLACK); | |
| 29 SkCanvas canvas(modified_bitmap); | |
| 29 | 30 |
| 30 } // namespace | 31 // Draw |background_image| on the canvas. |
| 32 if (!background_image.drawsNothing()) { | |
| 33 color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic. | |
| 34 SkBitmap monochromatic_image = | |
| 35 SkBitmapOperations::CreateHSLShiftedBitmap(background_image, shift); | |
| 31 | 36 |
| 32 RemotingInterstitialUI::RemotingInterstitialUI( | 37 const gfx::Size image_size = |
| 33 VideoRendererSink* video_renderer_sink, | 38 gfx::Size(background_image.width(), background_image.height()); |
| 34 const PipelineMetadata& pipeline_metadata) | 39 if (image_size != canvas_size) { |
| 35 : video_renderer_sink_(video_renderer_sink), | 40 // Centered the background image. |
| 36 pipeline_metadata_(pipeline_metadata) { | 41 gfx::Rect centered_rect = |
| 37 DCHECK(pipeline_metadata_.has_video); | 42 ComputeLetterboxRegion(gfx::Rect(canvas_size), image_size); |
| 38 pipeline_metadata_.natural_size = GetRotatedVideoSize( | 43 canvas.writePixels(monochromatic_image, centered_rect.x(), |
| 39 pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size); | 44 centered_rect.y()); |
| 40 } | 45 } else { |
| 41 | 46 canvas.writePixels(monochromatic_image, 0, 0); |
| 42 RemotingInterstitialUI::~RemotingInterstitialUI() {} | 47 } |
| 43 | 48 } |
| 44 scoped_refptr<VideoFrame> RemotingInterstitialUI::GetInterstitial( | |
| 45 const SkBitmap& background_image, | |
| 46 bool is_remoting_successful) { | |
| 47 const gfx::Size canvas_size = | |
| 48 gfx::Size(background_image.width(), background_image.height()); | |
| 49 DCHECK(canvas_size == pipeline_metadata_.natural_size); | |
| 50 | |
| 51 color_utils::HSL shift = {-1, 0, 0.2}; // Make monochromatic. | |
| 52 SkBitmap modified_bitmap = | |
| 53 SkBitmapOperations::CreateHSLShiftedBitmap(background_image, shift); | |
| 54 | |
| 55 SkCanvas canvas(modified_bitmap); | |
| 56 | 49 |
| 57 // Blur the background image. | 50 // Blur the background image. |
| 58 SkScalar sigma = SkDoubleToScalar(10); | 51 SkScalar sigma = SkDoubleToScalar(10); |
| 59 SkPaint paint_blur; | 52 SkPaint paint_blur; |
| 60 paint_blur.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr)); | 53 paint_blur.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr)); |
| 61 canvas.saveLayer(0, &paint_blur); | 54 canvas.saveLayer(0, &paint_blur); |
| 62 canvas.restore(); | 55 canvas.restore(); |
| 63 | 56 |
| 64 // Create SkPaint for text and icon bitmap. | 57 // Create SkPaint for text and icon bitmap. |
| 65 // After |paint| draws, the new canvas should look like this: | 58 // After |paint| draws, the new canvas should look like this: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 canvas_size, base::TimeDelta()); | 106 canvas_size, base::TimeDelta()); |
| 114 modified_bitmap.lockPixels(); | 107 modified_bitmap.lockPixels(); |
| 115 media::CopyRGBToVideoFrame( | 108 media::CopyRGBToVideoFrame( |
| 116 reinterpret_cast<uint8_t*>(modified_bitmap.getPixels()), | 109 reinterpret_cast<uint8_t*>(modified_bitmap.getPixels()), |
| 117 modified_bitmap.rowBytes(), | 110 modified_bitmap.rowBytes(), |
| 118 gfx::Rect(canvas_size.width(), canvas_size.height()), video_frame.get()); | 111 gfx::Rect(canvas_size.width(), canvas_size.height()), video_frame.get()); |
| 119 modified_bitmap.unlockPixels(); | 112 modified_bitmap.unlockPixels(); |
| 120 return video_frame; | 113 return video_frame; |
| 121 } | 114 } |
| 122 | 115 |
| 123 void RemotingInterstitialUI::ShowInterstitial(bool is_remoting_successful) { | 116 } // namespace |
| 124 if (!video_renderer_sink_) | |
| 125 return; | |
| 126 | 117 |
| 127 // TODO(xjz): Provide poster image, if available, rather than a blank, black | 118 void ShowInterstitialOnSink(VideoRendererSink* const video_renderer_sink, |
| 128 // image. | 119 const SkBitmap& background_image, |
| 129 SkBitmap background_image; | 120 const gfx::Size& canvas_size, |
| 130 const gfx::Size size = pipeline_metadata_.natural_size; | 121 bool is_remoting_successful) { |
| 131 background_image.allocN32Pixels(size.width(), size.height()); | 122 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.
| |
| 132 background_image.eraseColor(SK_ColorBLACK); | 123 DCHECK(video_renderer_sink); |
| 133 | 124 |
| 134 const scoped_refptr<VideoFrame> interstitial = | 125 const scoped_refptr<VideoFrame> interstitial = |
| 135 GetInterstitial(background_image, is_remoting_successful); | 126 GetInterstitial(background_image, canvas_size, is_remoting_successful); |
| 136 if (!interstitial) | 127 if (!interstitial) |
| 137 return; | 128 return; |
| 138 | 129 |
| 139 video_renderer_sink_->PaintSingleFrame(interstitial); | 130 video_renderer_sink->PaintSingleFrame(interstitial); |
| 140 } | 131 } |
| 141 | 132 |
| 142 } // namespace media | 133 } // namespace media |
| OLD | NEW |