| 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 "public/platform/WebDisplayItemList.h" | 10 #include "public/platform/WebDisplayItemList.h" |
| 11 #include "third_party/skia/include/core/SkScalar.h" | 11 #include "third_party/skia/include/core/SkScalar.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 void ClipDisplayItem::replay(GraphicsContext& context) | 15 void ClipDisplayItem::replay(GraphicsContext& context) const |
| 16 { | 16 { |
| 17 context.save(); | 17 context.save(); |
| 18 context.clipRect(m_clipRect, NotAntiAliased, SkRegion::kIntersect_Op); | 18 context.clipRect(m_clipRect, NotAntiAliased, SkRegion::kIntersect_Op); |
| 19 | 19 |
| 20 for (const FloatRoundedRect& roundedRect : m_roundedRectClips) | 20 for (const FloatRoundedRect& roundedRect : m_roundedRectClips) |
| 21 context.clipRoundedRect(roundedRect, SkRegion::kIntersect_Op); | 21 context.clipRoundedRect(roundedRect, SkRegion::kIntersect_Op); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void ClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) const | 24 void ClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) const |
| 25 { | 25 { |
| 26 WebVector<SkRRect> webRoundedRects(m_roundedRectClips.size()); | 26 WebVector<SkRRect> webRoundedRects(m_roundedRectClips.size()); |
| 27 for (size_t i = 0; i < m_roundedRectClips.size(); ++i) { | 27 for (size_t i = 0; i < m_roundedRectClips.size(); ++i) { |
| 28 FloatRoundedRect::Radii rectRadii = m_roundedRectClips[i].radii(); | 28 FloatRoundedRect::Radii rectRadii = m_roundedRectClips[i].radii(); |
| 29 SkVector skRadii[4]; | 29 SkVector skRadii[4]; |
| 30 skRadii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(rectRadii.topLeft(
).width()), | 30 skRadii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(rectRadii.topLeft(
).width()), |
| 31 SkIntToScalar(rectRadii.topLeft().height())); | 31 SkIntToScalar(rectRadii.topLeft().height())); |
| 32 skRadii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(rectRadii.topRigh
t().width()), | 32 skRadii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(rectRadii.topRigh
t().width()), |
| 33 SkIntToScalar(rectRadii.topRight().height())); | 33 SkIntToScalar(rectRadii.topRight().height())); |
| 34 skRadii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(rectRadii.bottomR
ight().width()), | 34 skRadii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(rectRadii.bottomR
ight().width()), |
| 35 SkIntToScalar(rectRadii.bottomRight().height())); | 35 SkIntToScalar(rectRadii.bottomRight().height())); |
| 36 skRadii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(rectRadii.bottomLe
ft().width()), | 36 skRadii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(rectRadii.bottomLe
ft().width()), |
| 37 SkIntToScalar(rectRadii.bottomLeft().height())); | 37 SkIntToScalar(rectRadii.bottomLeft().height())); |
| 38 SkRRect skRoundedRect; | 38 SkRRect skRoundedRect; |
| 39 skRoundedRect.setRectRadii(m_roundedRectClips[i].rect(), skRadii); | 39 skRoundedRect.setRectRadii(m_roundedRectClips[i].rect(), skRadii); |
| 40 webRoundedRects[i] = skRoundedRect; | 40 webRoundedRects[i] = skRoundedRect; |
| 41 } | 41 } |
| 42 list->appendClipItem(m_clipRect, webRoundedRects); | 42 list->appendClipItem(m_clipRect, webRoundedRects); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void EndClipDisplayItem::replay(GraphicsContext& context) | 45 void EndClipDisplayItem::replay(GraphicsContext& context) const |
| 46 { | 46 { |
| 47 context.restore(); | 47 context.restore(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void EndClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) co
nst | 50 void EndClipDisplayItem::appendToWebDisplayItemList(WebDisplayItemList* list) co
nst |
| 51 { | 51 { |
| 52 list->appendEndClipItem(); | 52 list->appendEndClipItem(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 #ifndef NDEBUG | 55 #ifndef NDEBUG |
| 56 void ClipDisplayItem::dumpPropertiesAsDebugString(WTF::StringBuilder& stringBuil
der) const | 56 void ClipDisplayItem::dumpPropertiesAsDebugString(WTF::StringBuilder& stringBuil
der) const |
| 57 { | 57 { |
| 58 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); | 58 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); |
| 59 stringBuilder.append(WTF::String::format(", clipRect: [%d,%d,%d,%d]", | 59 stringBuilder.append(WTF::String::format(", clipRect: [%d,%d,%d,%d]", |
| 60 m_clipRect.x(), m_clipRect.y(), m_clipRect.width(), m_clipRect.height())
); | 60 m_clipRect.x(), m_clipRect.y(), m_clipRect.width(), m_clipRect.height())
); |
| 61 } | 61 } |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 } // namespace blink | 64 } // namespace blink |
| OLD | NEW |