Chromium Code Reviews| Index: third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp |
| diff --git a/third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp b/third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3ca5ff9c147d4c822d2538ea25bbff2e61ea5b0b |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "platform/graphics/PlaceholderImage.h" |
| + |
| +#include "platform/geometry/FloatRect.h" |
| +#include "platform/graphics/Color.h" |
| +#include "platform/graphics/GraphicsContext.h" |
| +#include "platform/graphics/ImageObserver.h" |
| +#include "platform/graphics/paint/SkPictureBuilder.h" |
| +#include "third_party/skia/include/core/SkCanvas.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| +#include "third_party/skia/include/core/SkImage.h" |
| +#include "third_party/skia/include/core/SkPaint.h" |
| +#include "third_party/skia/include/core/SkPicture.h" |
| +#include "third_party/skia/include/core/SkRect.h" |
| +#include "third_party/skia/include/core/SkSize.h" |
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +// Gray with 40% opacity. |
| +const RGBA32 kFillColor = 0x66808080; |
| + |
| +} // namespace |
| + |
| +PlaceholderImage::~PlaceholderImage() {} |
| + |
| +sk_sp<SkImage> PlaceholderImage::imageForCurrentFrame() { |
|
Stephen Chennney
2016/10/17 18:09:17
You're always creating a new image here, but my un
sclittle
2016/10/18 00:54:11
Done.
|
| + const FloatRect destRect(0.0f, 0.0f, static_cast<float>(m_size.width()), |
| + static_cast<float>(m_size.height())); |
| + SkPictureBuilder builder(destRect); |
| + GraphicsContext& context = builder.context(); |
| + context.beginRecording(destRect); |
| + |
| + context.setFillColor(kFillColor); |
| + context.fillRect(destRect); |
| + |
| + return SkImage::MakeFromPicture( |
| + builder.endRecording(), SkISize::Make(m_size.width(), m_size.height()), |
| + nullptr, nullptr); |
| +} |
| + |
| +void PlaceholderImage::draw(SkCanvas* canvas, |
| + const SkPaint& basePaint, |
| + const FloatRect& destRect, |
| + const FloatRect& srcRect, |
| + RespectImageOrientationEnum, |
| + ImageClampingMode) { |
| + if (!srcRect.intersects(FloatRect(0.0f, 0.0f, |
| + static_cast<float>(m_size.width()), |
| + static_cast<float>(m_size.height())))) { |
| + return; |
| + } |
| + |
| + SkPaint paint(basePaint); |
| + paint.setStyle(SkPaint::kFill_Style); |
| + paint.setColor(kFillColor); |
| + canvas->drawRect(destRect, paint); |
| + |
| + if (getImageObserver()) |
| + getImageObserver()->didDraw(this); |
| +} |
| + |
| +void PlaceholderImage::drawPattern(GraphicsContext& destContext, |
| + const FloatRect& srcRect, |
| + const FloatSize& scale, |
| + const FloatPoint& phase, |
| + SkXfermode::Mode compositeOp, |
| + const FloatRect& destRect, |
| + const FloatSize& repeatSpacing) { |
| + Image::drawPattern(destContext, srcRect, scale, phase, compositeOp, destRect, |
| + repeatSpacing); |
| + |
| + if (getImageObserver()) |
| + getImageObserver()->didDraw(this); |
| +} |
| + |
| +} // namespace blink |