Skip to content

Commit e405d0a

Browse files
committed
addressed PR feedback, made new UtilsAndroid files
1 parent 28118b2 commit e405d0a

File tree

6 files changed

+162
-120
lines changed

6 files changed

+162
-120
lines changed

filament/backend/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ if (FILAMENT_SUPPORTS_OPENGL AND NOT FILAMENT_USE_EXTERNAL_GLES3)
104104
if (ANDROID)
105105
list(APPEND SRCS src/opengl/platforms/ExternalStreamManagerAndroid.cpp)
106106
list(APPEND SRCS src/opengl/platforms/PlatformEGLAndroid.cpp)
107+
list(APPEND SRCS src/BackendUtilsAndroid.cpp)
107108
elseif (IOS)
108109
list(APPEND SRCS src/opengl/platforms/PlatformCocoaTouchGL.mm)
109110
list(APPEND SRCS src/opengl/platforms/CocoaTouchExternalImage.mm)

filament/backend/include/backend/DriverEnums.h

-26
Original file line numberDiff line numberDiff line change
@@ -804,32 +804,6 @@ static constexpr bool isStencilFormat(TextureFormat format) noexcept {
804804
}
805805
}
806806

807-
static constexpr bool isColorFormat(TextureFormat format) noexcept {
808-
switch (format) {
809-
// Standard color formats
810-
case TextureFormat::R8:
811-
case TextureFormat::RG8:
812-
case TextureFormat::RGBA8:
813-
case TextureFormat::R16F:
814-
case TextureFormat::RG16F:
815-
case TextureFormat::RGBA16F:
816-
case TextureFormat::R32F:
817-
case TextureFormat::RG32F:
818-
case TextureFormat::RGBA32F:
819-
case TextureFormat::RGB10_A2:
820-
case TextureFormat::R11F_G11F_B10F:
821-
case TextureFormat::SRGB8:
822-
case TextureFormat::SRGB8_A8:
823-
case TextureFormat::RGB8:
824-
case TextureFormat::RGB565:
825-
case TextureFormat::RGB5_A1:
826-
case TextureFormat::RGBA4:
827-
return true;
828-
default:
829-
return false;
830-
}
831-
}
832-
833807
static constexpr bool isUnsignedIntFormat(TextureFormat format) {
834808
switch (format) {
835809
case TextureFormat::R8UI:

filament/backend/include/private/backend/BackendUtils.h

-12
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ size_t getBlockHeight(TextureFormat format) noexcept;
7171
*/
7272
bool reshape(const PixelBufferDescriptor& data, PixelBufferDescriptor& reshaped);
7373

74-
#ifdef __ANDROID__
75-
/**
76-
* Maps AHardwareBuffer format to TextureFormat.
77-
*/
78-
TextureFormat mapToFilamentFormat(unsigned int format, bool isSrgbTransfer) noexcept;
79-
80-
/**
81-
* Maps AHardwareBuffer usage to TextureUsage.
82-
*/
83-
TextureUsage mapToFilamentUsage(unsigned int usage, TextureFormat format) noexcept;
84-
#endif //__ANDROID__
85-
8674
} // namespace filament
8775

8876
#endif // TNT_FILAMENT_BACKEND_PRIVATE_BACKENDUTILS_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (C) 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef TNT_FILAMENT_BACKEND_PRIVATE_BACKENDUTILSANDROID_H
18+
#define TNT_FILAMENT_BACKEND_PRIVATE_BACKENDUTILSANDROID_H
19+
20+
#include <backend/DriverEnums.h>
21+
22+
namespace filament::backend {
23+
24+
/**
25+
* Maps AHardwareBuffer format to TextureFormat.
26+
*/
27+
TextureFormat mapToFilamentFormat(unsigned int format, bool isSrgbTransfer) noexcept;
28+
29+
/**
30+
* Maps AHardwareBuffer usage to TextureUsage.
31+
*/
32+
TextureUsage mapToFilamentUsage(unsigned int usage, TextureFormat format) noexcept;
33+
34+
static constexpr bool isColorFormat(TextureFormat format) noexcept {
35+
switch (format) {
36+
// Standard color formats
37+
case TextureFormat::R8:
38+
case TextureFormat::RG8:
39+
case TextureFormat::RGBA8:
40+
case TextureFormat::R16F:
41+
case TextureFormat::RG16F:
42+
case TextureFormat::RGBA16F:
43+
case TextureFormat::R32F:
44+
case TextureFormat::RG32F:
45+
case TextureFormat::RGBA32F:
46+
case TextureFormat::RGB10_A2:
47+
case TextureFormat::R11F_G11F_B10F:
48+
case TextureFormat::SRGB8:
49+
case TextureFormat::SRGB8_A8:
50+
case TextureFormat::RGB8:
51+
case TextureFormat::RGB565:
52+
case TextureFormat::RGB5_A1:
53+
case TextureFormat::RGBA4:
54+
return true;
55+
default:
56+
break;
57+
}
58+
return false;
59+
}
60+
61+
} // namespace filament
62+
63+
#endif // TNT_FILAMENT_BACKEND_PRIVATE_BACKENDUTILSANDROID_H

filament/backend/src/BackendUtils.cpp

-82
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020

2121
#include <utils/CString.h>
2222

23-
#ifdef __ANDROID__
24-
#include <android/hardware_buffer.h>
25-
#include <backend/DriverEnums.h>
26-
#endif //__ANDROID__
27-
2823
#include <string_view>
2924

3025
namespace filament::backend {
@@ -541,83 +536,6 @@ bool reshape(const PixelBufferDescriptor& data, PixelBufferDescriptor& reshaped)
541536
}
542537
}
543538

544-
#ifdef __ANDROID__
545-
TextureFormat mapToFilamentFormat(unsigned int format, bool isSrgbTransfer) noexcept {
546-
if (isSrgbTransfer) {
547-
switch (format) {
548-
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
549-
return TextureFormat::SRGB8;
550-
default:
551-
return TextureFormat::SRGB8_A8;
552-
}
553-
}
554-
switch (format) {
555-
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
556-
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
557-
return TextureFormat::RGBA8;
558-
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
559-
case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
560-
return TextureFormat::RGB8;
561-
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
562-
return TextureFormat::RGB565;
563-
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
564-
return TextureFormat::RGBA16F;
565-
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
566-
return TextureFormat::RGB10_A2;
567-
case AHARDWAREBUFFER_FORMAT_D16_UNORM:
568-
return TextureFormat::DEPTH16;
569-
case AHARDWAREBUFFER_FORMAT_D24_UNORM:
570-
return TextureFormat::DEPTH24;
571-
case AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT:
572-
return TextureFormat::DEPTH24_STENCIL8;
573-
case AHARDWAREBUFFER_FORMAT_D32_FLOAT:
574-
return TextureFormat::DEPTH32F;
575-
case AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT:
576-
return TextureFormat::DEPTH32F_STENCIL8;
577-
case AHARDWAREBUFFER_FORMAT_S8_UINT:
578-
return TextureFormat::STENCIL8;
579-
case AHARDWAREBUFFER_FORMAT_R8_UNORM:
580-
return TextureFormat::R8;
581-
default:
582-
return TextureFormat::UNUSED;
583-
}
584-
}
585-
586-
TextureUsage mapToFilamentUsage(unsigned int usage, TextureFormat format) noexcept {
587-
TextureUsage usageFlags = TextureUsage::NONE;
588-
589-
if (usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE) {
590-
usageFlags |= TextureUsage::SAMPLEABLE;
591-
}
592-
593-
if (usage & AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER) {
594-
if (isDepthFormat(format)) {
595-
usageFlags |= TextureUsage::DEPTH_ATTACHMENT;
596-
}
597-
if (isStencilFormat(format)) {
598-
usageFlags |= TextureUsage::STENCIL_ATTACHMENT;
599-
}
600-
if (isColorFormat(format)) {
601-
usageFlags |= TextureUsage::COLOR_ATTACHMENT;
602-
}
603-
}
604-
605-
if (usage & AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER) {
606-
usageFlags |= TextureUsage::UPLOADABLE;
607-
}
608-
609-
if (usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) {
610-
usageFlags |= TextureUsage::PROTECTED;
611-
}
612-
613-
if (usageFlags == TextureUsage::NONE) {
614-
usageFlags = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
615-
}
616-
617-
return usageFlags;
618-
}
619-
#endif //__ANDROID__
620-
621539
} // namespace backend::filament
622540

623541

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (C) 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "private/backend/BackendUtilsAndroid.h"
18+
19+
#include <android/hardware_buffer.h>
20+
21+
namespace filament::backend {
22+
23+
TextureFormat mapToFilamentFormat(unsigned int format, bool isSrgbTransfer) noexcept {
24+
if (isSrgbTransfer) {
25+
switch (format) {
26+
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
27+
return TextureFormat::SRGB8;
28+
default:
29+
return TextureFormat::SRGB8_A8;
30+
}
31+
}
32+
switch (format) {
33+
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
34+
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
35+
return TextureFormat::RGBA8;
36+
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
37+
case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
38+
return TextureFormat::RGB8;
39+
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
40+
return TextureFormat::RGB565;
41+
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
42+
return TextureFormat::RGBA16F;
43+
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
44+
return TextureFormat::RGB10_A2;
45+
case AHARDWAREBUFFER_FORMAT_D16_UNORM:
46+
return TextureFormat::DEPTH16;
47+
case AHARDWAREBUFFER_FORMAT_D24_UNORM:
48+
return TextureFormat::DEPTH24;
49+
case AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT:
50+
return TextureFormat::DEPTH24_STENCIL8;
51+
case AHARDWAREBUFFER_FORMAT_D32_FLOAT:
52+
return TextureFormat::DEPTH32F;
53+
case AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT:
54+
return TextureFormat::DEPTH32F_STENCIL8;
55+
case AHARDWAREBUFFER_FORMAT_S8_UINT:
56+
return TextureFormat::STENCIL8;
57+
case AHARDWAREBUFFER_FORMAT_R8_UNORM:
58+
return TextureFormat::R8;
59+
default:
60+
return TextureFormat::UNUSED;
61+
}
62+
}
63+
64+
TextureUsage mapToFilamentUsage(unsigned int usage, TextureFormat format) noexcept {
65+
TextureUsage usageFlags = TextureUsage::NONE;
66+
67+
if (usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE) {
68+
usageFlags |= TextureUsage::SAMPLEABLE;
69+
}
70+
71+
if (usage & AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER) {
72+
if (isDepthFormat(format)) {
73+
usageFlags |= TextureUsage::DEPTH_ATTACHMENT;
74+
}
75+
if (isStencilFormat(format)) {
76+
usageFlags |= TextureUsage::STENCIL_ATTACHMENT;
77+
}
78+
if (isColorFormat(format)) {
79+
usageFlags |= TextureUsage::COLOR_ATTACHMENT;
80+
}
81+
}
82+
83+
if (usage & AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER) {
84+
usageFlags |= TextureUsage::UPLOADABLE;
85+
}
86+
87+
if (usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT) {
88+
usageFlags |= TextureUsage::PROTECTED;
89+
}
90+
91+
if (usageFlags == TextureUsage::NONE) {
92+
usageFlags = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
93+
}
94+
95+
return usageFlags;
96+
}
97+
98+
} // namespace backend::filament

0 commit comments

Comments
 (0)