| Index: third_party/WebKit/Source/platform/graphics/BoxReflection.cpp
|
| diff --git a/third_party/WebKit/Source/platform/graphics/BoxReflection.cpp b/third_party/WebKit/Source/platform/graphics/BoxReflection.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f0f21cf24a71c6d5df651b739e1b568c081f3d7c
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/platform/graphics/BoxReflection.cpp
|
| @@ -0,0 +1,58 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "platform/graphics/BoxReflection.h"
|
| +
|
| +#include "platform/geometry/FloatRect.h"
|
| +#include "platform/graphics/skia/SkiaUtils.h"
|
| +#include "third_party/skia/include/core/SkImageFilter.h"
|
| +#include "third_party/skia/include/core/SkMatrix.h"
|
| +#include "third_party/skia/include/core/SkRefCnt.h"
|
| +#include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
|
| +
|
| +namespace blink {
|
| +
|
| +SkMatrix BoxReflection::reflectionMatrix() const
|
| +{
|
| + SkMatrix flipMatrix;
|
| + switch (m_direction) {
|
| + case VerticalReflection:
|
| + flipMatrix.setScale(1, -1);
|
| + flipMatrix.postTranslate(0, m_offset);
|
| + break;
|
| + case HorizontalReflection:
|
| + flipMatrix.setScale(-1, 1);
|
| + flipMatrix.postTranslate(m_offset, 0);
|
| + break;
|
| + default:
|
| + // MSVC requires that SkMatrix be initialized in this unreachable case.
|
| + NOTREACHED();
|
| + flipMatrix.reset();
|
| + break;
|
| + }
|
| + return flipMatrix;
|
| +}
|
| +
|
| +FloatRect BoxReflection::mapRect(const FloatRect& rect) const
|
| +{
|
| + SkRect reflection(rect);
|
| + reflectionMatrix().mapRect(&reflection);
|
| + FloatRect result = rect;
|
| + result.unite(reflection);
|
| + return result;
|
| +}
|
| +
|
| +PassRefPtr<SkImageFilter> BoxReflection::createImageFilter(PassRefPtr<SkImageFilter> passedInput) const
|
| +{
|
| + sk_sp<SkImageFilter> input = toSkSp(passedInput);
|
| + sk_sp<SkImageFilter> maskedInput = input;
|
| + // TODO(jbroman): If a mask image is provided, mask!
|
| +
|
| + sk_sp<SkImageFilter> flipImageFilter = SkImageFilter::MakeMatrixFilter(
|
| + reflectionMatrix(), kNone_SkFilterQuality, std::move(maskedInput));
|
| +
|
| + return fromSkSp(SkXfermodeImageFilter::Make(nullptr, std::move(flipImageFilter), std::move(input), nullptr));
|
| +}
|
| +
|
| +} // namespace blink
|
|
|