blob: 8a5ff43e144ed5618d66c4ea6c68dfae043c0955 [file] [log] [blame]
Anthony DiGirolamod1b0bbb2024-04-10 20:15:41 +00001// Copyright 2024 The Pigweed Authors
AnthonyDiGirolamof1aa1412022-05-21 08:44:24 -07002//
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 Mumfordcad52c52023-02-16 18:56:43 +000014#include "public/pw_framebuffer/framebuffer.h"
AnthonyDiGirolamof1aa1412022-05-21 08:44:24 -070015
16#include <cstddef>
17
Chris Mumford70a13992022-10-12 16:20:15 +000018#include "pw_assert/assert.h"
AnthonyDiGirolamof1aa1412022-05-21 08:44:24 -070019
AnthonyDiGirolamof1aa1412022-05-21 08:44:24 -070020namespace pw::framebuffer {
21
Chris Mumfordaa694fe2023-03-10 16:26:50 +000022Framebuffer::Framebuffer()
23 : pixel_data_(nullptr),
24 pixel_format_(PixelFormat::None),
25 size_{0, 0},
26 row_bytes_(0) {}
AnthonyDiGirolamof1aa1412022-05-21 08:44:24 -070027
Chris Mumford23c47b82023-03-08 19:18:33 +000028Framebuffer::Framebuffer(void* data,
Chris Mumfordaa694fe2023-03-10 16:26:50 +000029 PixelFormat pixel_format,
Anthony DiGirolamod1b0bbb2024-04-10 20:15:41 +000030 pw::geometry::Size<uint16_t> size,
Chris Mumford79baf952023-03-08 16:32:16 +000031 uint16_t row_bytes)
Chris Mumfordaa694fe2023-03-10 16:26:50 +000032 : 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}
AnthonyDiGirolamof1aa1412022-05-21 08:44:24 -070039
Chris Mumfordcad52c52023-02-16 18:56:43 +000040Framebuffer::Framebuffer(Framebuffer&& other)
Chris Mumfordf9cc7982022-12-14 20:09:16 +000041 : pixel_data_(other.pixel_data_),
Chris Mumfordaa694fe2023-03-10 16:26:50 +000042 pixel_format_(other.pixel_format_),
Chris Mumfordd2d3d7e2023-02-23 17:15:44 +000043 size_(other.size_),
Chris Mumfordf9cc7982022-12-14 20:09:16 +000044 row_bytes_(other.row_bytes_) {
45 other.pixel_data_ = nullptr;
Chris Mumfordaa694fe2023-03-10 16:26:50 +000046 other.pixel_format_ = PixelFormat::None;
Chris Mumfordf9cc7982022-12-14 20:09:16 +000047}
48
Chris Mumfordcad52c52023-02-16 18:56:43 +000049Framebuffer& Framebuffer::operator=(Framebuffer&& rhs) {
Chris Mumfordf9cc7982022-12-14 20:09:16 +000050 pixel_data_ = rhs.pixel_data_;
Chris Mumfordaa694fe2023-03-10 16:26:50 +000051 pixel_format_ = rhs.pixel_format_;
Chris Mumfordd2d3d7e2023-02-23 17:15:44 +000052 size_ = rhs.size_;
Chris Mumfordf9cc7982022-12-14 20:09:16 +000053 row_bytes_ = rhs.row_bytes_;
54 rhs.pixel_data_ = nullptr;
Chris Mumfordaa694fe2023-03-10 16:26:50 +000055 rhs.pixel_format_ = PixelFormat::None;
Chris Mumfordf9cc7982022-12-14 20:09:16 +000056 return *this;
57}
58
AnthonyDiGirolamof1aa1412022-05-21 08:44:24 -070059} // namespace pw::framebuffer