blob: fa0ae03a69f7a96cf1b5ef935f4c862bce84b707 [file] [log] [blame]
Tom Hudson8dfaa492014-12-09 15:03:44 -05001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef PAINT_UTILS_H
17#define PAINT_UTILS_H
18
19namespace android {
20namespace uirenderer {
21
22class PaintUtils {
23public:
24
25 /**
26 * Safely retrieves the mode from the specified xfermode. If the specified
27 * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
28 */
29 static inline SkXfermode::Mode getXfermode(SkXfermode* mode) {
30 SkXfermode::Mode resultMode;
31 if (!SkXfermode::AsMode(mode, &resultMode)) {
32 resultMode = SkXfermode::kSrcOver_Mode;
33 }
34 return resultMode;
35 }
36
37 // TODO: move to a method on android:Paint? replace with SkPaint::nothingToDraw()?
38 static inline bool paintWillNotDraw(const SkPaint& paint) {
39 return paint.getAlpha() == 0
40 && !paint.getColorFilter()
41 && getXfermode(paint.getXfermode()) == SkXfermode::kSrcOver_Mode;
42 }
43
44 // TODO: move to a method on android:Paint? replace with SkPaint::nothingToDraw()?
45 static inline bool paintWillNotDrawText(const SkPaint& paint) {
46 return paint.getAlpha() == 0
Chris Craikd41c4d82015-01-05 15:51:13 -080047 && paint.getLooper() == nullptr
Tom Hudson8dfaa492014-12-09 15:03:44 -050048 && !paint.getColorFilter()
49 && getXfermode(paint.getXfermode()) == SkXfermode::kSrcOver_Mode;
50 }
51
52 static bool isBlendedColorFilter(const SkColorFilter* filter) {
Chris Craikd41c4d82015-01-05 15:51:13 -080053 if (filter == nullptr) {
Tom Hudson8dfaa492014-12-09 15:03:44 -050054 return false;
55 }
56 return (filter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag) == 0;
57 }
58
59}; // class PaintUtils
60
61} /* namespace uirenderer */
62} /* namespace android */
63
64#endif /* PAINT_UTILS_H */