Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // renderer_utils: |
| 7 | // Helper methods pertaining to most or all back-ends. |
| 8 | // |
| 9 | |
| 10 | #ifndef LIBANGLE_RENDERER_RENDERER_UTILS_H_ |
| 11 | #define LIBANGLE_RENDERER_RENDERER_UTILS_H_ |
| 12 | |
| 13 | #include <cstdint> |
| 14 | |
Jamie Madill | dcc9b51 | 2017-06-05 15:28:45 -0400 | [diff] [blame] | 15 | #include <limits> |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 16 | #include <map> |
| 17 | |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 18 | #include "common/angleutils.h" |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 19 | #include "libANGLE/angletypes.h" |
| 20 | |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 21 | namespace angle |
| 22 | { |
| 23 | struct Format; |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 24 | } // namespace angle |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 25 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 26 | namespace gl |
| 27 | { |
| 28 | struct FormatType; |
| 29 | struct InternalFormat; |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 30 | } // namespace gl |
| 31 | |
| 32 | namespace egl |
| 33 | { |
| 34 | class AttributeMap; |
| 35 | } // namespace egl |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 36 | |
| 37 | namespace rx |
| 38 | { |
| 39 | |
Jamie Madill | dcc9b51 | 2017-06-05 15:28:45 -0400 | [diff] [blame] | 40 | class ResourceSerial |
| 41 | { |
| 42 | public: |
| 43 | constexpr ResourceSerial() : mValue(kDirty) {} |
Jamie Madill | 9959f54 | 2017-09-12 15:22:56 -0400 | [diff] [blame^] | 44 | explicit constexpr ResourceSerial(uintptr_t value) : mValue(value) {} |
Jamie Madill | dcc9b51 | 2017-06-05 15:28:45 -0400 | [diff] [blame] | 45 | constexpr bool operator==(ResourceSerial other) const { return mValue == other.mValue; } |
| 46 | constexpr bool operator!=(ResourceSerial other) const { return mValue != other.mValue; } |
| 47 | |
| 48 | void dirty() { mValue = kDirty; } |
Jamie Madill | 9959f54 | 2017-09-12 15:22:56 -0400 | [diff] [blame^] | 49 | void clear() { mValue = kEmpty; } |
| 50 | |
| 51 | constexpr bool valid() const { return mValue != kEmpty && mValue != kDirty; } |
| 52 | constexpr bool empty() const { return mValue == kEmpty; } |
Jamie Madill | dcc9b51 | 2017-06-05 15:28:45 -0400 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max(); |
Jamie Madill | 9959f54 | 2017-09-12 15:22:56 -0400 | [diff] [blame^] | 56 | constexpr static uintptr_t kEmpty = 0; |
Jamie Madill | dcc9b51 | 2017-06-05 15:28:45 -0400 | [diff] [blame] | 57 | |
| 58 | uintptr_t mValue; |
| 59 | }; |
| 60 | |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 61 | class SerialFactory; |
| 62 | |
| 63 | class Serial final |
| 64 | { |
| 65 | public: |
Jamie Madill | 0e7f173 | 2017-09-09 23:32:50 -0400 | [diff] [blame] | 66 | constexpr Serial() : mValue(kInvalid) {} |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 67 | constexpr Serial(const Serial &other) = default; |
| 68 | Serial &operator=(const Serial &other) = default; |
| 69 | |
Jamie Madill | 0e7f173 | 2017-09-09 23:32:50 -0400 | [diff] [blame] | 70 | constexpr bool operator==(const Serial &other) const |
| 71 | { |
| 72 | return mValue != kInvalid && mValue == other.mValue; |
| 73 | } |
| 74 | constexpr bool operator!=(const Serial &other) const |
| 75 | { |
| 76 | return mValue == kInvalid || mValue != other.mValue; |
| 77 | } |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 78 | constexpr bool operator>(const Serial &other) const { return mValue > other.mValue; } |
| 79 | constexpr bool operator>=(const Serial &other) const { return mValue >= other.mValue; } |
| 80 | constexpr bool operator<(const Serial &other) const { return mValue < other.mValue; } |
| 81 | constexpr bool operator<=(const Serial &other) const { return mValue <= other.mValue; } |
| 82 | |
| 83 | private: |
| 84 | friend class SerialFactory; |
| 85 | constexpr explicit Serial(uint64_t value) : mValue(value) {} |
| 86 | uint64_t mValue; |
Jamie Madill | 0e7f173 | 2017-09-09 23:32:50 -0400 | [diff] [blame] | 87 | static constexpr uint64_t kInvalid = 0; |
Jamie Madill | fb05bcb | 2017-06-07 15:43:18 -0400 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | class SerialFactory final : angle::NonCopyable |
| 91 | { |
| 92 | public: |
| 93 | SerialFactory() : mSerial(1) {} |
| 94 | |
| 95 | Serial generate() |
| 96 | { |
| 97 | ASSERT(mSerial != std::numeric_limits<uint64_t>::max()); |
| 98 | return Serial(mSerial++); |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | uint64_t mSerial; |
| 103 | }; |
| 104 | |
Jamie Madill | a5b1561 | 2016-08-09 11:10:27 -0400 | [diff] [blame] | 105 | using MipGenerationFunction = void (*)(size_t sourceWidth, |
| 106 | size_t sourceHeight, |
| 107 | size_t sourceDepth, |
| 108 | const uint8_t *sourceData, |
| 109 | size_t sourceRowPitch, |
| 110 | size_t sourceDepthPitch, |
| 111 | uint8_t *destData, |
| 112 | size_t destRowPitch, |
| 113 | size_t destDepthPitch); |
| 114 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 115 | typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest); |
| 116 | typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest); |
| 117 | typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest); |
| 118 | |
Jamie Madill | 4f57e5f | 2016-10-27 17:36:53 -0400 | [diff] [blame] | 119 | class FastCopyFunctionMap |
| 120 | { |
| 121 | public: |
| 122 | struct Entry |
| 123 | { |
| 124 | GLenum format; |
| 125 | GLenum type; |
| 126 | ColorCopyFunction func; |
| 127 | }; |
| 128 | |
| 129 | constexpr FastCopyFunctionMap() : FastCopyFunctionMap(nullptr, 0) {} |
| 130 | |
| 131 | constexpr FastCopyFunctionMap(const Entry *data, size_t size) : mSize(size), mData(data) {} |
| 132 | |
| 133 | bool has(const gl::FormatType &formatType) const; |
| 134 | ColorCopyFunction get(const gl::FormatType &formatType) const; |
| 135 | |
| 136 | private: |
| 137 | size_t mSize; |
| 138 | const Entry *mData; |
| 139 | }; |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 140 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 141 | struct PackPixelsParams : private angle::NonCopyable |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 142 | { |
| 143 | PackPixelsParams(); |
| 144 | PackPixelsParams(const gl::Rectangle &area, |
| 145 | GLenum format, |
| 146 | GLenum type, |
| 147 | GLuint outputPitch, |
| 148 | const gl::PixelPackState &pack, |
| 149 | ptrdiff_t offset); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 150 | PackPixelsParams(const gl::Context *context, const PackPixelsParams &other); |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 151 | |
| 152 | gl::Rectangle area; |
| 153 | GLenum format; |
| 154 | GLenum type; |
| 155 | GLuint outputPitch; |
| 156 | gl::Buffer *packBuffer; |
| 157 | gl::PixelPackState pack; |
| 158 | ptrdiff_t offset; |
| 159 | }; |
| 160 | |
| 161 | void PackPixels(const PackPixelsParams ¶ms, |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 162 | const angle::Format &sourceFormat, |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 163 | int inputPitch, |
| 164 | const uint8_t *source, |
| 165 | uint8_t *destination); |
| 166 | |
| 167 | ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType); |
| 168 | ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions, |
| 169 | const gl::FormatType &formatType); |
| 170 | |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame] | 171 | using InitializeTextureDataFunction = void (*)(size_t width, |
| 172 | size_t height, |
| 173 | size_t depth, |
| 174 | uint8_t *output, |
| 175 | size_t outputRowPitch, |
| 176 | size_t outputDepthPitch); |
| 177 | |
Jamie Madill | b2e4863 | 2016-08-09 18:08:03 -0400 | [diff] [blame] | 178 | using LoadImageFunction = void (*)(size_t width, |
| 179 | size_t height, |
| 180 | size_t depth, |
| 181 | const uint8_t *input, |
| 182 | size_t inputRowPitch, |
| 183 | size_t inputDepthPitch, |
| 184 | uint8_t *output, |
| 185 | size_t outputRowPitch, |
| 186 | size_t outputDepthPitch); |
| 187 | |
| 188 | struct LoadImageFunctionInfo |
| 189 | { |
| 190 | LoadImageFunctionInfo() : loadFunction(nullptr), requiresConversion(false) {} |
| 191 | LoadImageFunctionInfo(LoadImageFunction loadFunction, bool requiresConversion) |
| 192 | : loadFunction(loadFunction), requiresConversion(requiresConversion) |
| 193 | { |
| 194 | } |
| 195 | |
| 196 | LoadImageFunction loadFunction; |
| 197 | bool requiresConversion; |
| 198 | }; |
| 199 | |
| 200 | using LoadFunctionMap = LoadImageFunctionInfo (*)(GLenum); |
| 201 | |
Jamie Madill | 222c517 | 2017-07-19 16:15:42 -0400 | [diff] [blame] | 202 | bool ShouldUseDebugLayers(const egl::AttributeMap &attribs); |
| 203 | |
Geoff Lang | d93cd6c | 2017-08-11 16:32:41 -0400 | [diff] [blame] | 204 | void CopyImageCHROMIUM(const uint8_t *sourceData, |
| 205 | size_t sourceRowPitch, |
| 206 | size_t sourcePixelBytes, |
| 207 | ColorReadFunction readFunction, |
| 208 | uint8_t *destData, |
| 209 | size_t destRowPitch, |
| 210 | size_t destPixelBytes, |
| 211 | ColorWriteFunction colorWriteFunction, |
| 212 | GLenum destUnsizedFormat, |
| 213 | GLenum destComponentType, |
| 214 | size_t width, |
| 215 | size_t height, |
| 216 | bool unpackFlipY, |
| 217 | bool unpackPremultiplyAlpha, |
| 218 | bool unpackUnmultiplyAlpha); |
| 219 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 220 | } // namespace rx |
| 221 | |
| 222 | #endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_ |