Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp

Issue 2423683002: Add Blink support for showing image placeholders using range requests. (Closed)
Patch Set: Addressed comments and fixed bugs Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "platform/graphics/PlaceholderImage.h"
6
7 #include "platform/geometry/FloatRect.h"
8 #include "platform/graphics/Color.h"
9 #include "platform/graphics/GraphicsContext.h"
10 #include "platform/graphics/ImageObserver.h"
11 #include "platform/graphics/paint/SkPictureBuilder.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkColor.h"
14 #include "third_party/skia/include/core/SkPaint.h"
15 #include "third_party/skia/include/core/SkPicture.h"
16 #include "third_party/skia/include/core/SkRect.h"
17 #include "third_party/skia/include/core/SkSize.h"
18
19 namespace blink {
20
21 namespace {
22
23 // Gray with 40% opacity.
24 const RGBA32 kFillColor = 0x66808080;
25
26 } // namespace
27
28 PlaceholderImage::~PlaceholderImage() {}
29
30 sk_sp<SkImage> PlaceholderImage::imageForCurrentFrame() {
31 if (m_imageForCurrentFrame)
32 return m_imageForCurrentFrame;
33
34 const FloatRect destRect(0.0f, 0.0f, static_cast<float>(m_size.width()),
35 static_cast<float>(m_size.height()));
36 SkPictureBuilder builder(destRect);
37 GraphicsContext& context = builder.context();
38 context.beginRecording(destRect);
39
40 context.setFillColor(kFillColor);
41 context.fillRect(destRect);
42
43 m_imageForCurrentFrame = SkImage::MakeFromPicture(
44 builder.endRecording(), SkISize::Make(m_size.width(), m_size.height()),
45 nullptr, nullptr);
46
47 return m_imageForCurrentFrame;
48 }
49
50 void PlaceholderImage::draw(SkCanvas* canvas,
51 const SkPaint& basePaint,
52 const FloatRect& destRect,
53 const FloatRect& srcRect,
54 RespectImageOrientationEnum,
55 ImageClampingMode) {
56 if (!srcRect.intersects(FloatRect(0.0f, 0.0f,
57 static_cast<float>(m_size.width()),
58 static_cast<float>(m_size.height())))) {
59 return;
60 }
61
62 SkPaint paint(basePaint);
63 paint.setStyle(SkPaint::kFill_Style);
64 paint.setColor(kFillColor);
65 canvas->drawRect(destRect, paint);
66
67 if (getImageObserver())
68 getImageObserver()->didDraw(this);
69 }
70
71 void PlaceholderImage::drawPattern(GraphicsContext& destContext,
72 const FloatRect& srcRect,
73 const FloatSize& scale,
74 const FloatPoint& phase,
75 SkXfermode::Mode compositeOp,
76 const FloatRect& destRect,
77 const FloatSize& repeatSpacing) {
78 Image::drawPattern(destContext, srcRect, scale, phase, compositeOp, destRect,
79 repeatSpacing);
80
81 if (getImageObserver())
82 getImageObserver()->didDraw(this);
83 }
84
85 void PlaceholderImage::destroyDecodedData() {
86 m_imageForCurrentFrame.reset();
87 }
88
89 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698