| 1 | // Copyright 2021 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "VideoBackends/Software/SWBoundingBox.h" |
| 5 | |
| 6 | #include <algorithm> |
| 7 | #include <array> |
| 8 | |
| 9 | #include "Common/CommonTypes.h" |
| 10 | |
| 11 | namespace BBoxManager |
| 12 | { |
| 13 | namespace |
| 14 | { |
| 15 | // Current bounding box coordinates. |
| 16 | std::array<u16, 4> s_coordinates{}; |
| 17 | } // Anonymous namespace |
| 18 | |
| 19 | u16 GetCoordinate(Coordinate coordinate) |
| 20 | { |
| 21 | return s_coordinates[static_cast<u32>(coordinate)]; |
| 22 | } |
| 23 | |
| 24 | void SetCoordinate(Coordinate coordinate, u16 value) |
| 25 | { |
| 26 | s_coordinates[static_cast<u32>(coordinate)] = value; |
| 27 | } |
| 28 | |
| 29 | void Update(u16 left, u16 right, u16 top, u16 bottom) |
| 30 | { |
| 31 | const u16 new_left = std::min(left, GetCoordinate(Coordinate::Left)); |
| 32 | const u16 new_right = std::max(right, GetCoordinate(Coordinate::Right)); |
| 33 | const u16 new_top = std::min(top, GetCoordinate(Coordinate::Top)); |
| 34 | const u16 new_bottom = std::max(bottom, GetCoordinate(Coordinate::Bottom)); |
| 35 | |
| 36 | SetCoordinate(Coordinate::Left, new_left); |
| 37 | SetCoordinate(Coordinate::Right, new_right); |
| 38 | SetCoordinate(Coordinate::Top, new_top); |
| 39 | SetCoordinate(Coordinate::Bottom, new_bottom); |
| 40 | } |
| 41 | |
| 42 | } // namespace BBoxManager |
| 43 | |
| 44 | namespace SW |
| 45 | { |
| 46 | std::vector<BBoxType> SWBoundingBox::Read(u32 index, u32 length) |
| 47 | { |
| 48 | std::vector<BBoxType> values(length); |
| 49 | |
| 50 | for (u32 i = 0; i < length; i++) |
| 51 | { |
| 52 | values[i] = BBoxManager::GetCoordinate(static_cast<BBoxManager::Coordinate>(index + i)); |
| 53 | } |
| 54 | |
| 55 | return values; |
| 56 | } |
| 57 | |
| 58 | void SWBoundingBox::Write(u32 index, std::span<const BBoxType> values) |
| 59 | { |
| 60 | for (size_t i = 0; i < values.size(); i++) |
| 61 | { |
| 62 | BBoxManager::SetCoordinate(static_cast<BBoxManager::Coordinate>(index + i), values[i]); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } // namespace SW |