| 1 | /* |
| 2 | * Copyright (c) 2020 - 2024 the ThorVG project. All rights reserved. |
| 3 | |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to deal |
| 6 | * in the Software without restriction, including without limitation the rights |
| 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | * copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | |
| 11 | * The above copyright notice and this permission notice shall be included in all |
| 12 | * copies or substantial portions of the Software. |
| 13 | |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | * SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include "tvgMath.h" |
| 24 | #include "tvgRender.h" |
| 25 | |
| 26 | /************************************************************************/ |
| 27 | /* Internal Class Implementation */ |
| 28 | /************************************************************************/ |
| 29 | |
| 30 | |
| 31 | /************************************************************************/ |
| 32 | /* External Class Implementation */ |
| 33 | /************************************************************************/ |
| 34 | |
| 35 | uint32_t RenderMethod::ref() |
| 36 | { |
| 37 | ScopedLock lock(key); |
| 38 | return (++refCnt); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | uint32_t RenderMethod::unref() |
| 43 | { |
| 44 | ScopedLock lock(key); |
| 45 | return (--refCnt); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | void RenderRegion::intersect(const RenderRegion& rhs) |
| 50 | { |
| 51 | auto x1 = x + w; |
| 52 | auto y1 = y + h; |
| 53 | auto x2 = rhs.x + rhs.w; |
| 54 | auto y2 = rhs.y + rhs.h; |
| 55 | |
| 56 | x = (x > rhs.x) ? x : rhs.x; |
| 57 | y = (y > rhs.y) ? y : rhs.y; |
| 58 | w = ((x1 < x2) ? x1 : x2) - x; |
| 59 | h = ((y1 < y2) ? y1 : y2) - y; |
| 60 | |
| 61 | if (w < 0) w = 0; |
| 62 | if (h < 0) h = 0; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | void RenderRegion::add(const RenderRegion& rhs) |
| 67 | { |
| 68 | if (rhs.x < x) { |
| 69 | w += (x - rhs.x); |
| 70 | x = rhs.x; |
| 71 | } |
| 72 | if (rhs.y < y) { |
| 73 | h += (y - rhs.y); |
| 74 | y = rhs.y; |
| 75 | } |
| 76 | if (rhs.x + rhs.w > x + w) w = (rhs.x + rhs.w) - x; |
| 77 | if (rhs.y + rhs.h > y + h) h = (rhs.y + rhs.h) - y; |
| 78 | } |