diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-12-19 14:25:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-26 09:39:20 +0100 |
commit | 3b2ded1d4405fc51acb8bbbd24e06cf00198dac8 (patch) | |
tree | 35ac8663e9db5c60515f3d5417180b28dd575563 /Userland/Libraries/LibGPU | |
parent | dc8be499e6e55404a329fac93c663a00961e81bf (diff) | |
download | serenity-3b2ded1d4405fc51acb8bbbd24e06cf00198dac8.zip |
LibGPU+LibSoftGPU: Move size and pixel format information to GPU::Image
Size and format information are the same for every implementation and do
not need to be virtual. This removes the need to reimplement them for
each driver.
Diffstat (limited to 'Userland/Libraries/LibGPU')
-rw-r--r-- | Userland/Libraries/LibGPU/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGPU/Image.cpp | 32 | ||||
-rw-r--r-- | Userland/Libraries/LibGPU/Image.h | 20 |
3 files changed, 44 insertions, 9 deletions
diff --git a/Userland/Libraries/LibGPU/CMakeLists.txt b/Userland/Libraries/LibGPU/CMakeLists.txt index 030c5b2f86..cf4fdbd1f1 100644 --- a/Userland/Libraries/LibGPU/CMakeLists.txt +++ b/Userland/Libraries/LibGPU/CMakeLists.txt @@ -1,5 +1,6 @@ set(SOURCES Driver.cpp + Image.cpp ) serenity_lib(LibGPU gpu) diff --git a/Userland/Libraries/LibGPU/Image.cpp b/Userland/Libraries/LibGPU/Image.cpp new file mode 100644 index 0000000000..62106ccbdf --- /dev/null +++ b/Userland/Libraries/LibGPU/Image.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/Math.h> +#include <LibGPU/Image.h> + +namespace GPU { + +Image::Image(void const* ownership_token, GPU::PixelFormat const& pixel_format, u32 width, u32 height, u32 depth, u32 max_levels) + : m_ownership_token { ownership_token } + , m_pixel_format { pixel_format } +{ + VERIFY(width > 0); + VERIFY(height > 0); + VERIFY(depth > 0); + VERIFY(max_levels > 0); + + u32 number_of_levels_in_full_chain = max(max(AK::log2(width), AK::log2(height)), AK::log2(depth)) + 1; + m_mipmap_sizes.resize(min(max_levels, number_of_levels_in_full_chain)); + + for (u32 level = 0; level < m_mipmap_sizes.size(); ++level) { + m_mipmap_sizes[level] = { width, height, depth }; + width = max(width / 2, 1); + height = max(height / 2, 1); + depth = max(depth / 2, 1); + } +} + +} diff --git a/Userland/Libraries/LibGPU/Image.h b/Userland/Libraries/LibGPU/Image.h index aed3f581c4..25096990d3 100644 --- a/Userland/Libraries/LibGPU/Image.h +++ b/Userland/Libraries/LibGPU/Image.h @@ -8,24 +8,24 @@ #pragma once #include <AK/RefCounted.h> +#include <AK/Vector.h> #include <LibGPU/ImageDataLayout.h> +#include <LibGPU/ImageFormat.h> #include <LibGfx/Vector3.h> namespace GPU { class Image : public RefCounted<Image> { public: - Image(void const* ownership_token) - : m_ownership_token { ownership_token } - { - } - + Image(void const* ownership_token, PixelFormat const&, u32 width, u32 height, u32 depth, u32 max_levels); virtual ~Image() { } - virtual u32 width_at_level(u32 level) const = 0; - virtual u32 height_at_level(u32 level) const = 0; - virtual u32 depth_at_level(u32 level) const = 0; - virtual u32 number_of_levels() const = 0; + u32 width_at_level(u32 level) const { return m_mipmap_sizes[level].x(); } + u32 height_at_level(u32 level) const { return m_mipmap_sizes[level].y(); } + u32 depth_at_level(u32 level) const { return m_mipmap_sizes[level].z(); } + u32 number_of_levels() const { return m_mipmap_sizes.size(); } + + PixelFormat pixel_format() const { return m_pixel_format; } virtual void regenerate_mipmaps() = 0; @@ -38,6 +38,8 @@ public: private: void const* const m_ownership_token { nullptr }; + Vector<Vector3<u32>> m_mipmap_sizes; + PixelFormat m_pixel_format; }; } |