Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | namespace android { |
| 20 | namespace uirenderer { |
| 21 | |
| 22 | class PaintUtils { |
| 23 | public: |
| 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 Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame^] | 47 | && paint.getLooper() == nullptr |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 48 | && !paint.getColorFilter() |
| 49 | && getXfermode(paint.getXfermode()) == SkXfermode::kSrcOver_Mode; |
| 50 | } |
| 51 | |
| 52 | static bool isBlendedColorFilter(const SkColorFilter* filter) { |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame^] | 53 | if (filter == nullptr) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 54 | 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 */ |