1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "GrOvalEffect.h"
9
10#include "GrCircleEffect.h"
11#include "GrEllipseEffect.h"
12#include "SkRect.h"
13
14std::unique_ptr<GrFragmentProcessor> GrOvalEffect::Make(GrClipEdgeType edgeType, const SkRect& oval,
15                                                        const GrShaderCaps& caps) {
16    if (GrClipEdgeType::kHairlineAA == edgeType) {
17        return nullptr;
18    }
19    SkScalar w = oval.width();
20    SkScalar h = oval.height();
21    if (SkScalarNearlyEqual(w, h)) {
22        w /= 2;
23        return GrCircleEffect::Make(edgeType, SkPoint::Make(oval.fLeft + w, oval.fTop + w),
24                                    w);
25    } else {
26        w /= 2;
27        h /= 2;
28        return GrEllipseEffect::Make(edgeType, SkPoint::Make(oval.fLeft + w, oval.fTop + h),
29                                     SkPoint::Make(w, h), caps);
30    }
31
32    return nullptr;
33}
34