blob: 0aa7875647ccac833cff33a204150326cc4a295e [file] [log] [blame]
Cody Schuffelen134ff032019-11-22 00:25:32 -08001#pragma once
2
3/*
4 * Copyright (C) 2017 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19// Memory layout for primitive graphics types.
20
21// The vsoc::layout namespace indicates that these are shared memory structure
22// definitions. The #include's given above are strictly limited, as are the
23// types that can be referenced below.
24
25#include <cstdint>
26
27#include "common/vsoc/shm/base.h"
28
29namespace vsoc {
30
31// The enumerations for VSoC pixel formats are laid out so that hardware to
32// parse bytes per pixel without relying an a exhaustive list of pixel formats.
33// These constants define the fields involved.
34namespace PixelFormatConst {
35 static const uint32_t BytesPerPixelSize = 3;
36 static const uint32_t SubformatSize = 3;
37 static const uint32_t MaxBytesPerPixel = (1 << BytesPerPixelSize);
38 static const uint32_t MaxSubformat = (1 << SubformatSize) - 1;
39};
40
41
42// Builds (statically) a new pixel format enumeration value given constant
43// bytes per pixel.
44template <uint32_t BYTES, uint32_t SUB_FORMAT>
45struct PixelFormatBuilder {
46 static_assert(BYTES > 0, "Too few bytes");
47 static_assert(BYTES <= PixelFormatConst::MaxBytesPerPixel, "Too many bytes");
48 static_assert(SUB_FORMAT <= PixelFormatConst::MaxSubformat,
49 "Too many subformats");
50 static const uint32_t value = ((BYTES - 1) << PixelFormatConst::SubformatSize) | SUB_FORMAT;
51};
52
53template <uint32_t FORMAT>
54struct PixelFormatProperties {
55 // No static asserts since all int32_t values are (technically) valid pixel formats?
56 static const uint32_t bytes_per_pixel = (FORMAT >> PixelFormatConst::SubformatSize) + 1;
57};
58
59// Contains all of the pixel formats currently supported by this VSoC. The
60// enumeration serves multiple purposes:
61//
62// * The compile will warn (or error) if we switch on PixelFormat and don't
63// handly all of the cases.
64//
65// * Code can use PixelFormat to describe paramaters, making APIs a bit more
66// self-documenting.
67//
68// * Observant reviewers can verify that the same pixel value is not assigned
69// to multiple formats. Keep the enums in numerical order below to
70// make this easier.
71enum PixelFormat : uint32_t {
72 VSOC_PIXEL_FORMAT_UNINITIALIZED = PixelFormatBuilder<1,0>::value,
73 VSOC_PIXEL_FORMAT_BLOB = PixelFormatBuilder<1,1>::value,
74
75 VSOC_PIXEL_FORMAT_RGB_565 = PixelFormatBuilder<2,0>::value,
76 VSOC_PIXEL_FORMAT_YV12 = PixelFormatBuilder<2,1>::value,
77 VSOC_PIXEL_FORMAT_YCbCr_420_888 = PixelFormatBuilder<2,2>::value,
78
79 VSOC_PIXEL_FORMAT_RGB_888 = PixelFormatBuilder<3,0>::value,
80
81 VSOC_PIXEL_FORMAT_RGBA_8888 = PixelFormatBuilder<4,0>::value,
82 VSOC_PIXEL_FORMAT_RGBX_8888 = PixelFormatBuilder<4,1>::value,
83 VSOC_PIXEL_FORMAT_BGRA_8888 = PixelFormatBuilder<4,2>::value,
84
85 VSOC_PIXEL_FORMAT_RGBA_FP16 = PixelFormatBuilder<8,0>::value,
86
87 // VSOC_PIXEL_FORMAT_IMPLEMENTATION_DEFINED intentionally left out. The HALs
88 // should choose one of the defined contrete types.
89 //
90 // The following formats are defined in various platform versions, but don't
91 // seem to be used. If we encounter them it's ok to add them to the table.
92 // This does not necessitate a version change.
93 //
94 // The following have been in the framework for a long time:
95 //
96 // VSOC_PIXEL_FORMAT_YCrCb_420_SP
97 // VSOC_PIXEL_FORMAT_YCbCr_422_SP
98 //
99 // The following were added in JB_MR2:
100 //
101 // VSOC_PIXEL_FORMAT_YCbCr_420_888
102 // VSOC_PIXEL_FORMAT_Y8
103 // VSOC_PIXEL_FORMAT_Y16
104 //
105 // The following were added in L:
106 //
107 // VSOC_PIXEL_FORMAT_RAW_OPAQUE
108 // VSOC_PIXEL_FORMAT_RAW16 (also known as RAW_SENSOR. Define only RAW16)
109 // VSOC_PIXEL_FORMAT_RAW10
110 //
111 // The following were added in L MR1:
112 //
113 // VSOC_PIXEL_FORMAT_YCbCr_444_888
114 // VSOC_PIXEL_FORMAT_YCbCr_422_888
115 // VSOC_PIXEL_FORMAT_RAW12
116 // VSOC_PIXEL_FORMAT_FLEX_RGBA_8888
117 // VSOC_PIXEL_FORMAT_FLEX_RGB_888
118 //
119 // These pixel formats were removed in later framework versions. Implement
120 // only if absolutely necessary.
121 //
122 // Support was dropped in K for:
123 //
124 // VSOC_PIXEL_FORMAT_RGBA_5551
125 // VSOC_PIXEL_FORMAT_RGBA_4444
126 //
127 // Supported only in K, L, and LMR1:
128 //
129 // VSOC_PIXEL_FORMAT_sRGB_X_8888
130 // VSOC_PIXEL_FORMAT_sRGB_A_8888
131};
132// Enums can't have static members, so can't use the macro here.
133static_assert(ShmTypeValidator<PixelFormat, 4>::valid,
134 "Compilation error. Please fix above errors and retry.");
135
136namespace layout {
137
138// VSoC memory layout for a register that accepts a single pixel format.
139// The value is volatile to ensure that the compiler does not eliminate stores.
140struct PixelFormatRegister {
141 static constexpr size_t layout_size = 4;
142
143 volatile PixelFormat value_;
144};
145ASSERT_SHM_COMPATIBLE(PixelFormatRegister);
146
147// Register layout for a mask giving different PixelFormats. Reserve enough
148// space to allow for future expansion. For example, we may well end with
149// a 12 bit per channel format in the future.
150struct PixelFormatMaskRegister {
151 static constexpr size_t layout_size = 8;
152
153 volatile uint64_t value_;
154
155 bool HasValue(PixelFormat in) {
156 return !!(value_ & (uint64_t(1) << in));
157 }
158};
159ASSERT_SHM_COMPATIBLE(PixelFormatMaskRegister);
160
161// Ensure that the mask is large enough to hold the highest encodable
162// pixel format.
163static_assert(PixelFormatBuilder<
164 PixelFormatConst::MaxBytesPerPixel,
165 PixelFormatConst::MaxSubformat>::value <
166 8 * sizeof(PixelFormatMaskRegister),
167 "Largest pixel format does not fit in mask");
168} // layout
169} // vsoc