| 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 "platform/graphics/paint/ClipDisplayItem.h" | 5 #include "platform/graphics/paint/ClipDisplayItem.h" |
| 6 | 6 |
| 7 #include "platform/geometry/FloatRoundedRect.h" | 7 #include "platform/geometry/FloatRoundedRect.h" |
| 8 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "public/platform/WebDisplayItemList.h" | 9 #include "public/platform/WebDisplayItemList.h" |
| 10 #include "third_party/skia/include/core/SkScalar.h" | 10 #include "third_party/skia/include/core/SkScalar.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 void ClipDisplayItem::replay(GraphicsContext& context) const | 14 void ClipDisplayItem::replay(GraphicsContext& context) const |
| 15 { | 15 { |
| 16 context.save(); | 16 context.save(); |
| 17 context.clipRect(m_clipRect, AntiAliased); | 17 |
| 18 // RoundedInnerRectClipper only cares about rounded-rect clips, |
| 19 // and passes an "infinite" rect clip; there is no reason to apply this clip
. |
| 20 // TODO(fmalita): convert RoundedInnerRectClipper to a better suited |
| 21 // DisplayItem so we don't have to special-case its semantics. |
| 22 if (m_clipRect != LayoutRect::infiniteIntRect()) |
| 23 context.clipRect(m_clipRect, AntiAliased); |
| 18 | 24 |
| 19 for (const FloatRoundedRect& roundedRect : m_roundedRectClips) | 25 for (const FloatRoundedRect& roundedRect : m_roundedRectClips) |
| 20 context.clipRoundedRect(roundedRect); | 26 context.clipRoundedRect(roundedRect); |
| 21 } | 27 } |
| 22 | 28 |
| 23 void ClipDisplayItem::appendToWebDisplayItemList(const IntRect& visualRect, WebD
isplayItemList* list) const | 29 void ClipDisplayItem::appendToWebDisplayItemList(const IntRect& visualRect, WebD
isplayItemList* list) const |
| 24 { | 30 { |
| 25 WebVector<SkRRect> webRoundedRects(m_roundedRectClips.size()); | 31 WebVector<SkRRect> webRoundedRects(m_roundedRectClips.size()); |
| 26 for (size_t i = 0; i < m_roundedRectClips.size(); ++i) { | 32 for (size_t i = 0; i < m_roundedRectClips.size(); ++i) |
| 27 FloatRoundedRect::Radii rectRadii = m_roundedRectClips[i].getRadii(); | 33 webRoundedRects[i] = m_roundedRectClips[i]; |
| 28 SkVector skRadii[4]; | 34 |
| 29 skRadii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(rectRadii.topLeft(
).width()), | |
| 30 SkIntToScalar(rectRadii.topLeft().height())); | |
| 31 skRadii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(rectRadii.topRigh
t().width()), | |
| 32 SkIntToScalar(rectRadii.topRight().height())); | |
| 33 skRadii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(rectRadii.bottomR
ight().width()), | |
| 34 SkIntToScalar(rectRadii.bottomRight().height())); | |
| 35 skRadii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(rectRadii.bottomLe
ft().width()), | |
| 36 SkIntToScalar(rectRadii.bottomLeft().height())); | |
| 37 SkRRect skRoundedRect; | |
| 38 skRoundedRect.setRectRadii(m_roundedRectClips[i].rect(), skRadii); | |
| 39 webRoundedRects[i] = skRoundedRect; | |
| 40 } | |
| 41 list->appendClipItem(visualRect, m_clipRect, webRoundedRects); | 35 list->appendClipItem(visualRect, m_clipRect, webRoundedRects); |
| 42 } | 36 } |
| 43 | 37 |
| 44 void EndClipDisplayItem::replay(GraphicsContext& context) const | 38 void EndClipDisplayItem::replay(GraphicsContext& context) const |
| 45 { | 39 { |
| 46 context.restore(); | 40 context.restore(); |
| 47 } | 41 } |
| 48 | 42 |
| 49 void EndClipDisplayItem::appendToWebDisplayItemList(const IntRect& visualRect, W
ebDisplayItemList* list) const | 43 void EndClipDisplayItem::appendToWebDisplayItemList(const IntRect& visualRect, W
ebDisplayItemList* list) const |
| 50 { | 44 { |
| 51 list->appendEndClipItem(visualRect); | 45 list->appendEndClipItem(visualRect); |
| 52 } | 46 } |
| 53 | 47 |
| 54 #ifndef NDEBUG | 48 #ifndef NDEBUG |
| 55 void ClipDisplayItem::dumpPropertiesAsDebugString(WTF::StringBuilder& stringBuil
der) const | 49 void ClipDisplayItem::dumpPropertiesAsDebugString(WTF::StringBuilder& stringBuil
der) const |
| 56 { | 50 { |
| 57 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); | 51 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); |
| 58 stringBuilder.append(WTF::String::format(", clipRect: [%d,%d,%d,%d]", | 52 stringBuilder.append(WTF::String::format(", clipRect: [%d,%d,%d,%d]", |
| 59 m_clipRect.x(), m_clipRect.y(), m_clipRect.width(), m_clipRect.height())
); | 53 m_clipRect.x(), m_clipRect.y(), m_clipRect.width(), m_clipRect.height())
); |
| 60 } | 54 } |
| 61 #endif | 55 #endif |
| 62 | 56 |
| 63 } // namespace blink | 57 } // namespace blink |
| OLD | NEW |