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

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

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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
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 "skia/ext/cdl_picture.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 if (m_imageForCurrentFrame) 31 if (m_imageForCurrentFrame)
32 return m_imageForCurrentFrame; 32 return m_imageForCurrentFrame;
33 33
34 const FloatRect destRect(0.0f, 0.0f, static_cast<float>(m_size.width()), 34 const FloatRect destRect(0.0f, 0.0f, static_cast<float>(m_size.width()),
35 static_cast<float>(m_size.height())); 35 static_cast<float>(m_size.height()));
36 SkPictureBuilder builder(destRect); 36 SkPictureBuilder builder(destRect);
37 GraphicsContext& context = builder.context(); 37 GraphicsContext& context = builder.context();
38 context.beginRecording(destRect); 38 context.beginRecording(destRect);
39 39
40 context.setFillColor(kFillColor); 40 context.setFillColor(kFillColor);
41 context.fillRect(destRect); 41 context.fillRect(destRect);
42 42
43 m_imageForCurrentFrame = SkImage::MakeFromPicture( 43 m_imageForCurrentFrame = SkImage::MakeFromPicture(
44 builder.endRecording(), SkISize::Make(m_size.width(), m_size.height()), 44 ToSkPicture(builder.endRecording().get()),
45 nullptr, nullptr); 45 SkISize::Make(m_size.width(), m_size.height()), nullptr, nullptr);
46 46
47 return m_imageForCurrentFrame; 47 return m_imageForCurrentFrame;
48 } 48 }
49 49
50 void PlaceholderImage::draw(SkCanvas* canvas, 50 void PlaceholderImage::draw(CdlCanvas* canvas,
51 const SkPaint& basePaint, 51 const CdlPaint& basePaint,
52 const FloatRect& destRect, 52 const FloatRect& destRect,
53 const FloatRect& srcRect, 53 const FloatRect& srcRect,
54 RespectImageOrientationEnum, 54 RespectImageOrientationEnum,
55 ImageClampingMode) { 55 ImageClampingMode) {
56 if (!srcRect.intersects(FloatRect(0.0f, 0.0f, 56 if (!srcRect.intersects(FloatRect(0.0f, 0.0f,
57 static_cast<float>(m_size.width()), 57 static_cast<float>(m_size.width()),
58 static_cast<float>(m_size.height())))) { 58 static_cast<float>(m_size.height())))) {
59 return; 59 return;
60 } 60 }
61 61
62 SkPaint paint(basePaint); 62 CdlPaint paint(basePaint);
63 paint.setStyle(SkPaint::kFill_Style); 63 paint.setStyle(CdlPaint::kFill_Style);
64 paint.setColor(kFillColor); 64 paint.setColor(kFillColor);
65 canvas->drawRect(destRect, paint); 65 canvas->drawRect(destRect, paint);
66 } 66 }
67 67
68 void PlaceholderImage::destroyDecodedData() { 68 void PlaceholderImage::destroyDecodedData() {
69 m_imageForCurrentFrame.reset(); 69 m_imageForCurrentFrame.reset();
70 } 70 }
71 71
72 } // namespace blink 72 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698