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

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: 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/SkImage.h"
15 #include "third_party/skia/include/core/SkPaint.h"
16 #include "third_party/skia/include/core/SkPicture.h"
17 #include "third_party/skia/include/core/SkRect.h"
18 #include "third_party/skia/include/core/SkSize.h"
19
20 namespace blink {
21
22 namespace {
23
24 // Gray with 40% opacity.
25 const RGBA32 kFillColor = 0x66808080;
26
27 } // namespace
28
29 PlaceholderImage::~PlaceholderImage() {}
30
31 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.
32 const FloatRect destRect(0.0f, 0.0f, static_cast<float>(m_size.width()),
33 static_cast<float>(m_size.height()));
34 SkPictureBuilder builder(destRect);
35 GraphicsContext& context = builder.context();
36 context.beginRecording(destRect);
37
38 context.setFillColor(kFillColor);
39 context.fillRect(destRect);
40
41 return SkImage::MakeFromPicture(
42 builder.endRecording(), SkISize::Make(m_size.width(), m_size.height()),
43 nullptr, nullptr);
44 }
45
46 void PlaceholderImage::draw(SkCanvas* canvas,
47 const SkPaint& basePaint,
48 const FloatRect& destRect,
49 const FloatRect& srcRect,
50 RespectImageOrientationEnum,
51 ImageClampingMode) {
52 if (!srcRect.intersects(FloatRect(0.0f, 0.0f,
53 static_cast<float>(m_size.width()),
54 static_cast<float>(m_size.height())))) {
55 return;
56 }
57
58 SkPaint paint(basePaint);
59 paint.setStyle(SkPaint::kFill_Style);
60 paint.setColor(kFillColor);
61 canvas->drawRect(destRect, paint);
62
63 if (getImageObserver())
64 getImageObserver()->didDraw(this);
65 }
66
67 void PlaceholderImage::drawPattern(GraphicsContext& destContext,
68 const FloatRect& srcRect,
69 const FloatSize& scale,
70 const FloatPoint& phase,
71 SkXfermode::Mode compositeOp,
72 const FloatRect& destRect,
73 const FloatSize& repeatSpacing) {
74 Image::drawPattern(destContext, srcRect, scale, phase, compositeOp, destRect,
75 repeatSpacing);
76
77 if (getImageObserver())
78 getImageObserver()->didDraw(this);
79 }
80
81 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698