Anthony DiGirolamo | d1b0bbb | 2024-04-10 20:15:41 +0000 | [diff] [blame] | 1 | // Copyright 2024 The Pigweed Authors |
AnthonyDiGirolamo | f1aa141 | 2022-05-21 08:44:24 -0700 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | // use this file except in compliance with the License. You may obtain a copy of |
| 5 | // the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | // License for the specific language governing permissions and limitations under |
| 13 | // the License. |
Chris Mumford | cad52c5 | 2023-02-16 18:56:43 +0000 | [diff] [blame] | 14 | #include "public/pw_framebuffer/framebuffer.h" |
AnthonyDiGirolamo | f1aa141 | 2022-05-21 08:44:24 -0700 | [diff] [blame] | 15 | |
| 16 | #include <cstddef> |
| 17 | |
Chris Mumford | 70a1399 | 2022-10-12 16:20:15 +0000 | [diff] [blame] | 18 | #include "pw_assert/assert.h" |
AnthonyDiGirolamo | f1aa141 | 2022-05-21 08:44:24 -0700 | [diff] [blame] | 19 | |
AnthonyDiGirolamo | f1aa141 | 2022-05-21 08:44:24 -0700 | [diff] [blame] | 20 | namespace pw::framebuffer { |
| 21 | |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 22 | Framebuffer::Framebuffer() |
| 23 | : pixel_data_(nullptr), |
| 24 | pixel_format_(PixelFormat::None), |
| 25 | size_{0, 0}, |
| 26 | row_bytes_(0) {} |
AnthonyDiGirolamo | f1aa141 | 2022-05-21 08:44:24 -0700 | [diff] [blame] | 27 | |
Chris Mumford | 23c47b8 | 2023-03-08 19:18:33 +0000 | [diff] [blame] | 28 | Framebuffer::Framebuffer(void* data, |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 29 | PixelFormat pixel_format, |
Anthony DiGirolamo | d1b0bbb | 2024-04-10 20:15:41 +0000 | [diff] [blame] | 30 | pw::geometry::Size<uint16_t> size, |
Chris Mumford | 79baf95 | 2023-03-08 16:32:16 +0000 | [diff] [blame] | 31 | uint16_t row_bytes) |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 32 | : pixel_data_(data), |
| 33 | pixel_format_(pixel_format), |
| 34 | size_(size), |
| 35 | row_bytes_(row_bytes) { |
| 36 | PW_ASSERT(data != nullptr); |
| 37 | PW_ASSERT(pixel_format != PixelFormat::None); |
| 38 | } |
AnthonyDiGirolamo | f1aa141 | 2022-05-21 08:44:24 -0700 | [diff] [blame] | 39 | |
Chris Mumford | cad52c5 | 2023-02-16 18:56:43 +0000 | [diff] [blame] | 40 | Framebuffer::Framebuffer(Framebuffer&& other) |
Chris Mumford | f9cc798 | 2022-12-14 20:09:16 +0000 | [diff] [blame] | 41 | : pixel_data_(other.pixel_data_), |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 42 | pixel_format_(other.pixel_format_), |
Chris Mumford | d2d3d7e | 2023-02-23 17:15:44 +0000 | [diff] [blame] | 43 | size_(other.size_), |
Chris Mumford | f9cc798 | 2022-12-14 20:09:16 +0000 | [diff] [blame] | 44 | row_bytes_(other.row_bytes_) { |
| 45 | other.pixel_data_ = nullptr; |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 46 | other.pixel_format_ = PixelFormat::None; |
Chris Mumford | f9cc798 | 2022-12-14 20:09:16 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Chris Mumford | cad52c5 | 2023-02-16 18:56:43 +0000 | [diff] [blame] | 49 | Framebuffer& Framebuffer::operator=(Framebuffer&& rhs) { |
Chris Mumford | f9cc798 | 2022-12-14 20:09:16 +0000 | [diff] [blame] | 50 | pixel_data_ = rhs.pixel_data_; |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 51 | pixel_format_ = rhs.pixel_format_; |
Chris Mumford | d2d3d7e | 2023-02-23 17:15:44 +0000 | [diff] [blame] | 52 | size_ = rhs.size_; |
Chris Mumford | f9cc798 | 2022-12-14 20:09:16 +0000 | [diff] [blame] | 53 | row_bytes_ = rhs.row_bytes_; |
| 54 | rhs.pixel_data_ = nullptr; |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 55 | rhs.pixel_format_ = PixelFormat::None; |
Chris Mumford | f9cc798 | 2022-12-14 20:09:16 +0000 | [diff] [blame] | 56 | return *this; |
| 57 | } |
| 58 | |
AnthonyDiGirolamo | f1aa141 | 2022-05-21 08:44:24 -0700 | [diff] [blame] | 59 | } // namespace pw::framebuffer |