| 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" | 9 #include "platform/graphics/GraphicsContext.h" |
| 10 #include "platform/graphics/ImageObserver.h" | 10 #include "platform/graphics/ImageObserver.h" |
| 11 #include "platform/graphics/paint/SkPictureBuilder.h" | 11 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "third_party/skia/include/core/SkPaint.h" | 14 #include "third_party/skia/include/core/SkPaint.h" |
| 15 #include "third_party/skia/include/core/SkPicture.h" | 15 #include "third_party/skia/include/core/SkPicture.h" |
| 16 #include "third_party/skia/include/core/SkRect.h" | 16 #include "third_party/skia/include/core/SkRect.h" |
| 17 #include "third_party/skia/include/core/SkSize.h" | 17 #include "third_party/skia/include/core/SkSize.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Gray with 40% opacity. | 23 // Gray with 40% opacity. |
| 24 const RGBA32 kFillColor = 0x66808080; | 24 const RGBA32 kFillColor = 0x66808080; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 PlaceholderImage::~PlaceholderImage() {} | 28 PlaceholderImage::~PlaceholderImage() {} |
| 29 | 29 |
| 30 sk_sp<SkImage> PlaceholderImage::imageForCurrentFrame() { | 30 sk_sp<SkImage> PlaceholderImage::imageForCurrentFrame( |
| 31 const ColorBehavior& colorBehavior) { |
| 32 // TODO(ccameron): This function should not ignore |colorBehavior|. |
| 33 // https://crbug.com/672306 |
| 31 if (m_imageForCurrentFrame) | 34 if (m_imageForCurrentFrame) |
| 32 return m_imageForCurrentFrame; | 35 return m_imageForCurrentFrame; |
| 33 | 36 |
| 34 const FloatRect destRect(0.0f, 0.0f, static_cast<float>(m_size.width()), | 37 const FloatRect destRect(0.0f, 0.0f, static_cast<float>(m_size.width()), |
| 35 static_cast<float>(m_size.height())); | 38 static_cast<float>(m_size.height())); |
| 36 SkPictureBuilder builder(destRect); | 39 SkPictureBuilder builder(destRect); |
| 37 GraphicsContext& context = builder.context(); | 40 GraphicsContext& context = builder.context(); |
| 38 context.beginRecording(destRect); | 41 context.beginRecording(destRect); |
| 39 | 42 |
| 40 context.setFillColor(kFillColor); | 43 context.setFillColor(kFillColor); |
| 41 context.fillRect(destRect); | 44 context.fillRect(destRect); |
| 42 | 45 |
| 43 m_imageForCurrentFrame = SkImage::MakeFromPicture( | 46 m_imageForCurrentFrame = SkImage::MakeFromPicture( |
| 44 builder.endRecording(), SkISize::Make(m_size.width(), m_size.height()), | 47 builder.endRecording(), SkISize::Make(m_size.width(), m_size.height()), |
| 45 nullptr, nullptr); | 48 nullptr, nullptr); |
| 46 | 49 |
| 47 return m_imageForCurrentFrame; | 50 return m_imageForCurrentFrame; |
| 48 } | 51 } |
| 49 | 52 |
| 50 void PlaceholderImage::draw(SkCanvas* canvas, | 53 void PlaceholderImage::draw(SkCanvas* canvas, |
| 51 const SkPaint& basePaint, | 54 const SkPaint& basePaint, |
| 52 const FloatRect& destRect, | 55 const FloatRect& destRect, |
| 53 const FloatRect& srcRect, | 56 const FloatRect& srcRect, |
| 54 RespectImageOrientationEnum, | 57 RespectImageOrientationEnum, |
| 55 ImageClampingMode) { | 58 ImageClampingMode, |
| 59 const ColorBehavior& colorBehavior) { |
| 60 // TODO(ccameron): This function should not ignore |colorBehavior|. |
| 61 // https://crbug.com/672306 |
| 56 if (!srcRect.intersects(FloatRect(0.0f, 0.0f, | 62 if (!srcRect.intersects(FloatRect(0.0f, 0.0f, |
| 57 static_cast<float>(m_size.width()), | 63 static_cast<float>(m_size.width()), |
| 58 static_cast<float>(m_size.height())))) { | 64 static_cast<float>(m_size.height())))) { |
| 59 return; | 65 return; |
| 60 } | 66 } |
| 61 | 67 |
| 62 SkPaint paint(basePaint); | 68 SkPaint paint(basePaint); |
| 63 paint.setStyle(SkPaint::kFill_Style); | 69 paint.setStyle(SkPaint::kFill_Style); |
| 64 paint.setColor(kFillColor); | 70 paint.setColor(kFillColor); |
| 65 canvas->drawRect(destRect, paint); | 71 canvas->drawRect(destRect, paint); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void PlaceholderImage::destroyDecodedData() { | 74 void PlaceholderImage::destroyDecodedData() { |
| 69 m_imageForCurrentFrame.reset(); | 75 m_imageForCurrentFrame.reset(); |
| 70 } | 76 } |
| 71 | 77 |
| 72 } // namespace blink | 78 } // namespace blink |
| OLD | NEW |