Matt Sarett | 7de7385 | 2016-10-25 18:36:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| 17 | namespace android { |
| 18 | namespace NinePatchUtils { |
| 19 | |
| 20 | static inline void SetLatticeDivs(SkCanvas::Lattice* lattice, const Res_png_9patch& chunk, |
| 21 | int width, int height) { |
| 22 | lattice->fXCount = chunk.numXDivs; |
| 23 | lattice->fYCount = chunk.numYDivs; |
| 24 | lattice->fXDivs = chunk.getXDivs(); |
| 25 | lattice->fYDivs = chunk.getYDivs(); |
| 26 | |
| 27 | // We'll often see ninepatches where the last div is equal to the width or height. |
| 28 | // This doesn't provide any additional information and is not supported by Skia. |
| 29 | if (lattice->fXCount > 0 && width == lattice->fXDivs[lattice->fXCount - 1]) { |
| 30 | lattice->fXCount--; |
| 31 | } |
| 32 | if (lattice->fYCount > 0 && height == lattice->fYDivs[lattice->fYCount - 1]) { |
| 33 | lattice->fYCount--; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | }; // namespace NinePatchUtils |
| 38 | }; // namespace android |