Serenity Operating System
at master 45 lines 1.7 kB view raw
1/* 2 * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org> 3 * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <AK/RefCounted.h> 11#include <AK/Vector.h> 12#include <LibGPU/ImageDataLayout.h> 13#include <LibGPU/ImageFormat.h> 14#include <LibGfx/Vector3.h> 15 16namespace GPU { 17 18class Image : public RefCounted<Image> { 19public: 20 Image(void const* ownership_token, PixelFormat const&, u32 width, u32 height, u32 depth, u32 max_levels); 21 virtual ~Image() { } 22 23 u32 width_at_level(u32 level) const { return m_mipmap_sizes[level].x(); } 24 u32 height_at_level(u32 level) const { return m_mipmap_sizes[level].y(); } 25 u32 depth_at_level(u32 level) const { return m_mipmap_sizes[level].z(); } 26 u32 number_of_levels() const { return m_mipmap_sizes.size(); } 27 28 PixelFormat pixel_format() const { return m_pixel_format; } 29 30 virtual void regenerate_mipmaps() = 0; 31 32 virtual void write_texels(u32 level, Vector3<i32> const& output_offset, void const* input_data, ImageDataLayout const&) = 0; 33 virtual void read_texels(u32 level, Vector3<i32> const& input_offset, void* output_data, ImageDataLayout const&) const = 0; 34 virtual void copy_texels(Image const& source, u32 source_level, Vector3<u32> const& source_offset, Vector3<u32> const& size, u32 destination_level, Vector3<u32> const& destination_offset) = 0; 35 36 void const* ownership_token() const { return m_ownership_token; } 37 bool has_same_ownership_token(Image const& other) const { return other.ownership_token() == ownership_token(); } 38 39private: 40 void const* const m_ownership_token { nullptr }; 41 Vector<Vector3<u32>> m_mipmap_sizes; 42 PixelFormat m_pixel_format; 43}; 44 45}