| OLD | NEW |
| (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/BoxReflection.h" |
| 6 |
| 7 #include "platform/geometry/FloatRect.h" |
| 8 #include "platform/graphics/skia/SkiaUtils.h" |
| 9 #include "third_party/skia/include/core/SkImageFilter.h" |
| 10 #include "third_party/skia/include/core/SkMatrix.h" |
| 11 #include "third_party/skia/include/core/SkRefCnt.h" |
| 12 #include "third_party/skia/include/effects/SkXfermodeImageFilter.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 SkMatrix BoxReflection::reflectionMatrix() const |
| 17 { |
| 18 SkMatrix flipMatrix; |
| 19 switch (m_direction) { |
| 20 case VerticalReflection: |
| 21 flipMatrix.setScale(1, -1); |
| 22 flipMatrix.postTranslate(0, m_offset); |
| 23 break; |
| 24 case HorizontalReflection: |
| 25 flipMatrix.setScale(-1, 1); |
| 26 flipMatrix.postTranslate(m_offset, 0); |
| 27 break; |
| 28 default: |
| 29 // MSVC requires that SkMatrix be initialized in this unreachable case. |
| 30 NOTREACHED(); |
| 31 flipMatrix.reset(); |
| 32 break; |
| 33 } |
| 34 return flipMatrix; |
| 35 } |
| 36 |
| 37 FloatRect BoxReflection::mapRect(const FloatRect& rect) const |
| 38 { |
| 39 SkRect reflection(rect); |
| 40 reflectionMatrix().mapRect(&reflection); |
| 41 FloatRect result = rect; |
| 42 result.unite(reflection); |
| 43 return result; |
| 44 } |
| 45 |
| 46 PassRefPtr<SkImageFilter> BoxReflection::createImageFilter(PassRefPtr<SkImageFil
ter> passedInput) const |
| 47 { |
| 48 sk_sp<SkImageFilter> input = toSkSp(passedInput); |
| 49 sk_sp<SkImageFilter> maskedInput = input; |
| 50 // TODO(jbroman): If a mask image is provided, mask! |
| 51 |
| 52 sk_sp<SkImageFilter> flipImageFilter = SkImageFilter::MakeMatrixFilter( |
| 53 reflectionMatrix(), kNone_SkFilterQuality, std::move(maskedInput)); |
| 54 |
| 55 return fromSkSp(SkXfermodeImageFilter::Make(nullptr, std::move(flipImageFilt
er), std::move(input), nullptr)); |
| 56 } |
| 57 |
| 58 } // namespace blink |
| OLD | NEW |