OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 #include "platform/graphics/paint/ClipDisplayItem.h" | 6 #include "platform/graphics/paint/ClipDisplayItem.h" |
7 | 7 |
8 #include "platform/geometry/FloatRoundedRect.h" | 8 #include "platform/geometry/FloatRoundedRect.h" |
9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
| 10 #include "platform/graphics/paint/DisplayItems.h" |
10 #include "public/platform/WebDisplayItemList.h" | 11 #include "public/platform/WebDisplayItemList.h" |
11 #include "third_party/skia/include/core/SkScalar.h" | 12 #include "third_party/skia/include/core/SkScalar.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
15 void ClipDisplayItem::replay(GraphicsContext& context) | 16 void ClipDisplayItem::replay(GraphicsContext& context) |
16 { | 17 { |
17 context.save(); | 18 context.save(); |
18 context.clipRect(m_clipRect, NotAntiAliased, m_operation); | 19 context.clipRect(m_clipRect, NotAntiAliased, SkRegion::kIntersect_Op); |
19 for (FloatRoundedRect roundedRect : m_roundedRectClips) | 20 if (m_roundedRectClips) { |
20 context.clipRoundedRect(roundedRect, m_operation); | 21 for (const auto& roundedRect : *m_roundedRectClips) |
| 22 context.clipRoundedRect(roundedRect, SkRegion::kIntersect_Op); |
| 23 } |
21 } | 24 } |
22 | 25 |
23 void ClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) const | 26 void ClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) const |
24 { | 27 { |
25 WebVector<SkRRect> webRoundedRects(m_roundedRectClips.size()); | 28 if (!m_roundedRectClips) { |
26 for (size_t i = 0; i < m_roundedRectClips.size(); ++i) { | 29 WebVector<SkRRect> webRoundedRects; |
27 FloatRoundedRect::Radii rectRadii = m_roundedRectClips[i].radii(); | 30 list->appendClipItem(m_clipRect, webRoundedRects); |
| 31 return; |
| 32 } |
| 33 |
| 34 Vector<FloatRoundedRect>& roundedRects = *m_roundedRectClips; |
| 35 WebVector<SkRRect> webRoundedRects(roundedRects.size()); |
| 36 for (size_t i = 0; i < m_roundedRectClips->size(); ++i) { |
| 37 FloatRoundedRect::Radii rectRadii = roundedRects[i].radii(); |
28 SkVector skRadii[4]; | 38 SkVector skRadii[4]; |
29 skRadii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(rectRadii.topLeft(
).width()), | 39 skRadii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(rectRadii.topLeft(
).width()), |
30 SkIntToScalar(rectRadii.topLeft().height())); | 40 SkIntToScalar(rectRadii.topLeft().height())); |
31 skRadii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(rectRadii.topRigh
t().width()), | 41 skRadii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(rectRadii.topRigh
t().width()), |
32 SkIntToScalar(rectRadii.topRight().height())); | 42 SkIntToScalar(rectRadii.topRight().height())); |
33 skRadii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(rectRadii.bottomR
ight().width()), | 43 skRadii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(rectRadii.bottomR
ight().width()), |
34 SkIntToScalar(rectRadii.bottomRight().height())); | 44 SkIntToScalar(rectRadii.bottomRight().height())); |
35 skRadii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(rectRadii.bottomLe
ft().width()), | 45 skRadii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(rectRadii.bottomLe
ft().width()), |
36 SkIntToScalar(rectRadii.bottomLeft().height())); | 46 SkIntToScalar(rectRadii.bottomLeft().height())); |
37 SkRRect skRoundedRect; | 47 SkRRect skRoundedRect; |
38 skRoundedRect.setRectRadii(m_roundedRectClips[i].rect(), skRadii); | 48 skRoundedRect.setRectRadii(roundedRects[i].rect(), skRadii); |
39 webRoundedRects[i] = skRoundedRect; | 49 webRoundedRects[i] = skRoundedRect; |
40 } | 50 } |
41 // FIXME: needs to include the SkRegion::Op | 51 // FIXME: needs to include the SkRegion::Op |
42 list->appendClipItem(m_clipRect, webRoundedRects); | 52 list->appendClipItem(m_clipRect, webRoundedRects); |
43 } | 53 } |
44 | 54 |
| 55 void ClipDisplayItem::appendByMoving(DisplayItems& destination) |
| 56 { |
| 57 destination.emplaceBack<ClipDisplayItem>( |
| 58 DisplayItemClientWrapperHelper(*this), |
| 59 type(), |
| 60 m_clipRect, |
| 61 m_roundedRectClips.release()); |
| 62 } |
| 63 |
45 void EndClipDisplayItem::replay(GraphicsContext& context) | 64 void EndClipDisplayItem::replay(GraphicsContext& context) |
46 { | 65 { |
47 context.restore(); | 66 context.restore(); |
48 } | 67 } |
49 | 68 |
50 void EndClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) co
nst | 69 void EndClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) co
nst |
51 { | 70 { |
52 list->appendEndClipItem(); | 71 list->appendEndClipItem(); |
53 } | 72 } |
54 | 73 |
| 74 void EndClipDisplayItem::appendByMoving(DisplayItems& destination) |
| 75 { |
| 76 destination.emplaceBack<EndClipDisplayItem>( |
| 77 DisplayItemClientWrapperHelper(*this), type()); |
| 78 } |
| 79 |
55 #ifndef NDEBUG | 80 #ifndef NDEBUG |
56 void ClipDisplayItem::dumpPropertiesAsDebugString(WTF::StringBuilder& stringBuil
der) const | 81 void ClipDisplayItem::dumpPropertiesAsDebugString(WTF::StringBuilder& stringBuil
der) const |
57 { | 82 { |
58 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); | 83 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); |
59 stringBuilder.append(WTF::String::format(", clipRect: [%d,%d,%d,%d]", | 84 stringBuilder.append(WTF::String::format(", clipRect: [%d,%d,%d,%d]", |
60 m_clipRect.x(), m_clipRect.y(), m_clipRect.width(), m_clipRect.height())
); | 85 m_clipRect.x(), m_clipRect.y(), m_clipRect.width(), m_clipRect.height())
); |
61 } | 86 } |
62 #endif | 87 #endif |
63 | 88 |
64 } // namespace blink | 89 } // namespace blink |
OLD | NEW |