| 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 "platform/graphics/PlaceholderImage.h" | 5 #include "platform/graphics/PlaceholderImage.h" |
| 6 | 6 |
| 7 #include "platform/geometry/FloatRect.h" | 7 #include "platform/geometry/FloatRect.h" |
| 8 #include "platform/graphics/Color.h" | 8 #include "platform/graphics/Color.h" |
| 9 #include "platform/graphics/GraphicsContext.h" | |
| 10 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 11 #include "platform/graphics/paint/PaintRecord.h" | 10 #include "platform/graphics/paint/PaintRecord.h" |
| 12 #include "platform/graphics/paint/PaintRecordBuilder.h" | 11 #include "platform/graphics/paint/PaintRecorder.h" |
| 13 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "third_party/skia/include/core/SkRect.h" | 13 #include "third_party/skia/include/core/SkRect.h" |
| 15 #include "third_party/skia/include/core/SkSize.h" | 14 #include "third_party/skia/include/core/SkSize.h" |
| 16 | 15 |
| 17 namespace blink { | 16 namespace blink { |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 // Gray with 40% opacity. | 20 // Gray with 40% opacity. |
| 22 const RGBA32 kFillColor = 0x66808080; | 21 const RGBA32 kFillColor = 0x66808080; |
| 23 | 22 |
| 24 } // namespace | 23 } // namespace |
| 25 | 24 |
| 26 PlaceholderImage::~PlaceholderImage() {} | 25 PlaceholderImage::~PlaceholderImage() {} |
| 27 | 26 |
| 28 sk_sp<SkImage> PlaceholderImage::ImageForCurrentFrame() { | 27 sk_sp<SkImage> PlaceholderImage::ImageForCurrentFrame() { |
| 29 if (image_for_current_frame_) | 28 if (image_for_current_frame_) |
| 30 return image_for_current_frame_; | 29 return image_for_current_frame_; |
| 31 | 30 |
| 32 const FloatRect dest_rect(0.0f, 0.0f, static_cast<float>(size_.Width()), | 31 const FloatRect dest_rect(0.0f, 0.0f, static_cast<float>(size_.Width()), |
| 33 static_cast<float>(size_.Height())); | 32 static_cast<float>(size_.Height())); |
| 34 PaintRecordBuilder builder(dest_rect); | 33 PaintRecorder paint_recorder; |
| 35 GraphicsContext& context = builder.Context(); | 34 Draw(paint_recorder.beginRecording(dest_rect), PaintFlags(), dest_rect, |
| 36 context.BeginRecording(dest_rect); | 35 dest_rect, kDoNotRespectImageOrientation, kClampImageToSourceRect); |
| 37 | |
| 38 context.SetFillColor(kFillColor); | |
| 39 context.FillRect(dest_rect); | |
| 40 | 36 |
| 41 image_for_current_frame_ = SkImage::MakeFromPicture( | 37 image_for_current_frame_ = SkImage::MakeFromPicture( |
| 42 ToSkPicture(builder.EndRecording()), | 38 ToSkPicture(paint_recorder.finishRecordingAsPicture()), |
| 43 SkISize::Make(size_.Width(), size_.Height()), nullptr, nullptr, | 39 SkISize::Make(size_.Width(), size_.Height()), nullptr, nullptr, |
| 44 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); | 40 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); |
| 45 | 41 |
| 46 return image_for_current_frame_; | 42 return image_for_current_frame_; |
| 47 } | 43 } |
| 48 | 44 |
| 49 void PlaceholderImage::Draw(PaintCanvas* canvas, | 45 void PlaceholderImage::Draw(PaintCanvas* canvas, |
| 50 const PaintFlags& base_flags, | 46 const PaintFlags& base_flags, |
| 51 const FloatRect& dest_rect, | 47 const FloatRect& dest_rect, |
| 52 const FloatRect& src_rect, | 48 const FloatRect& src_rect, |
| 53 RespectImageOrientationEnum, | 49 RespectImageOrientationEnum, |
| 54 ImageClampingMode) { | 50 ImageClampingMode) { |
| 55 if (!src_rect.Intersects(FloatRect(0.0f, 0.0f, | 51 if (!src_rect.Intersects(FloatRect(0.0f, 0.0f, |
| 56 static_cast<float>(size_.Width()), | 52 static_cast<float>(size_.Width()), |
| 57 static_cast<float>(size_.Height())))) { | 53 static_cast<float>(size_.Height())))) { |
| 58 return; | 54 return; |
| 59 } | 55 } |
| 60 | 56 |
| 61 PaintFlags flags(base_flags); | 57 PaintFlags flags(base_flags); |
| 62 flags.setStyle(PaintFlags::kFill_Style); | 58 flags.setStyle(PaintFlags::kFill_Style); |
| 63 flags.setColor(kFillColor); | 59 flags.setColor(kFillColor); |
| 64 canvas->drawRect(dest_rect, flags); | 60 canvas->drawRect(dest_rect, flags); |
| 65 } | 61 } |
| 66 | 62 |
| 67 void PlaceholderImage::DestroyDecodedData() { | 63 void PlaceholderImage::DestroyDecodedData() { |
| 68 image_for_current_frame_.reset(); | 64 image_for_current_frame_.reset(); |
| 69 } | 65 } |
| 70 | 66 |
| 71 } // namespace blink | 67 } // namespace blink |
| OLD | NEW |