blob: 9ff85269c2ae6b5eaf5fa3ddc79597e5b4b11d4b [file] [log] [blame]
// Copyright 2024 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#pragma once
#include <cstdint>
#include "pw_geometry/size.h"
/// @defgroup pw_framebuffer
namespace pw::framebuffer {
/// @ingroup pw_framebuffer
///
/// Enum for framebuffer pixel format.
enum class PixelFormat {
None,
RGB565,
};
/// @ingroup pw_framebuffer
///
/// A Framebuffer refers to a buffer of pixel data and the various attributes of
/// that pixel data (such as dimensions, rowbytes, etc.).
class Framebuffer {
public:
/// Construct a default invalid framebuffer.
Framebuffer();
/// Construct a framebuffer of the specified dimensions which *does not* own
/// the |data| - i.e. this instance will never attempt to free it.
Framebuffer(void* data,
PixelFormat pixel_format,
pw::geometry::Size<uint16_t> size,
uint16_t row_bytes);
Framebuffer(const Framebuffer&) = delete;
Framebuffer(Framebuffer&& other);
Framebuffer& operator=(const Framebuffer&) = delete;
Framebuffer& operator=(Framebuffer&&);
/// Has the framebuffer been properly initialized?
bool is_valid() const { return pixel_data_ != nullptr; }
/// Return a pointer to the framebuffer pixel buffer.
void* data() const { return pixel_data_; }
/// Return the format of all pixels managed by this framebuffer.
PixelFormat pixel_format() const { return pixel_format_; }
/// Return the framebuffer size which is the width and height of the
/// framebuffer in pixels.
pw::geometry::Size<uint16_t> size() const { return size_; }
/// Return the number of bytes per row of pixel data.
uint16_t row_bytes() const { return row_bytes_; }
private:
/// The pixel buffer.
void* pixel_data_;
/// The pixel format.
PixelFormat pixel_format_;
/// width/height (in pixels) of |pixel_data_|.
pw::geometry::Size<uint16_t> size_;
/// The number of bytes in each row.
uint16_t row_bytes_;
};
} // namespace pw::framebuffer