Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/geometry/size.h" | |
| 13 #include "ui/gfx/paint_vector_icon.h" | |
| 14 #include "ui/gfx/skbitmap_operations.h" | |
| 15 #include "ui/gfx/vector_icons_public.h" | |
| 16 | |
| 17 namespace media { | |
| 18 | |
| 19 scoped_refptr<VideoFrame> GetInterstitial(SkCanvas* existing_frame_canvas, | |
|
miu
2016/11/05 04:09:52
BTW--Is it ever legal to call this function with a
apacible
2016/11/07 17:57:43
readPixels() isn't const.
| |
| 20 bool is_remoting_successful) { | |
| 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 const SkISize frame_size = existing_frame_canvas->getBaseLayerSize(); | |
| 28 const gfx::Size canvas_size = | |
| 29 gfx::Size(frame_size.width(), frame_size.height()); | |
| 30 | |
| 31 // Second bitmap for manipulation. | |
| 32 SkBitmap modified_bitmap; | |
| 33 | |
| 34 // Reads the pixels from the current frame into |modified_bitmap|. In the | |
| 35 // case this failed, create and use a blank bitmap. | |
| 36 if (existing_frame_canvas->readPixels(&bitmap, 0, 0)) { | |
| 37 // Make monochromatic. | |
| 38 color_utils::HSL shift = {-1, 0, 0.2}; | |
| 39 modified_bitmap = SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, shift); | |
| 40 } else { | |
| 41 modified_bitmap.allocN32Pixels(canvas_size.width(), canvas_size.height()); | |
| 42 } | |
| 43 | |
| 44 SkCanvas canvas(modified_bitmap); | |
| 45 | |
| 46 // Blur the background image. | |
| 47 SkScalar sigma = SkDoubleToScalar(10); | |
| 48 SkPaint paint_blur; | |
| 49 paint_blur.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr)); | |
| 50 canvas.saveLayer(0, &paint_blur); | |
| 51 canvas.restore(); | |
| 52 | |
| 53 // Create SkPaint for text and icon bitmap. | |
| 54 // After |paint| draws, the new canvas should look like this: | |
| 55 // _________________________________ | |
| 56 // | | | |
| 57 // | | | |
| 58 // | [ ] | | |
| 59 // | Casting Video... | | |
| 60 // | | | |
| 61 // |________________________________| | |
| 62 // | |
| 63 // Both text and icon are centered horizontally. Together, they are | |
|
miu
2016/11/05 04:09:52
Nice! :)
| |
| 64 // centered vertically. | |
| 65 SkPaint paint; | |
| 66 int text_size = SkIntToScalar(30); | |
| 67 paint.setAntiAlias(true); | |
| 68 paint.setFilterQuality(kHigh_SkFilterQuality); | |
| 69 paint.setColor(SK_ColorLTGRAY); | |
| 70 paint.setTypeface(SkTypeface::MakeFromName( | |
| 71 "sans", SkFontStyle::FromOldStyle(SkTypeface::kNormal))); | |
| 72 paint.setTextSize(text_size); | |
| 73 | |
| 74 // Draw the appropriate text. | |
| 75 const std::string remote_playback_message = | |
| 76 is_remoting_successful | |
| 77 ? GetLocalizedStringUTF8(MEDIA_REMOTING_CASTING_VIDEO_TEXT) | |
| 78 : GetLocalizedStringUTF8(MEDIA_REMOTING_CAST_ERROR_TEXT); | |
| 79 size_t display_text_width = paint.measureText(remote_playback_message.data(), | |
| 80 remote_playback_message.size()); | |
| 81 SkScalar sk_text_offset_x = (canvas_size.width() - display_text_width) / 2.0; | |
| 82 SkScalar sk_text_offset_y = (canvas_size.height() / 2.0) + text_size; | |
| 83 canvas.drawText(remote_playback_message.data(), | |
| 84 remote_playback_message.size(), sk_text_offset_x, | |
| 85 sk_text_offset_y, paint); | |
| 86 | |
| 87 // Draw the appropriate Cast icon. | |
| 88 gfx::VectorIconId current_icon = is_remoting_successful | |
| 89 ? gfx::VectorIconId::MEDIA_ROUTER_ACTIVE | |
| 90 : gfx::VectorIconId::MEDIA_ROUTER_ERROR; | |
| 91 gfx::ImageSkia icon_image = | |
| 92 gfx::CreateVectorIcon(current_icon, 65, SK_ColorLTGRAY); | |
| 93 const SkBitmap* icon_bitmap = icon_image.bitmap(); | |
| 94 SkScalar sk_image_offset_x = (canvas_size.width() - icon_image.width()) / 2.0; | |
| 95 SkScalar sk_image_offset_y = | |
| 96 (canvas_size.height() / 2.0) - icon_image.height(); | |
| 97 canvas.drawBitmap(*icon_bitmap, sk_image_offset_x, sk_image_offset_y, &paint); | |
| 98 | |
| 99 // Create a new VideoFrame, copy the bitmap, then return it. | |
| 100 scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame( | |
| 101 media::PIXEL_FORMAT_I420, canvas_size, gfx::Rect(canvas_size), | |
| 102 canvas_size, base::TimeDelta()); | |
| 103 modified_bitmap.lockPixels(); | |
| 104 media::CopyRGBToVideoFrame( | |
| 105 reinterpret_cast<uint8_t*>(modified_bitmap.getPixels()), | |
| 106 modified_bitmap.rowBytes(), | |
| 107 gfx::Rect(canvas_size.width(), canvas_size.height()), video_frame.get()); | |
| 108 modified_bitmap.unlockPixels(); | |
| 109 return video_frame; | |
| 110 } | |
| 111 | |
| 112 } // namespace media | |
| OLD | NEW |