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 | |
| 18 | #include "libANGLE/angletypes.h" |
| 19 | |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 20 | namespace angle |
| 21 | { |
| 22 | struct Format; |
| 23 | } |
| 24 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 25 | namespace gl |
| 26 | { |
| 27 | struct FormatType; |
| 28 | struct InternalFormat; |
| 29 | } |
| 30 | |
| 31 | namespace rx |
| 32 | { |
| 33 | |
Jamie Madill | dcc9b51 | 2017-06-05 15:28:45 -0400 | [diff] [blame] | 34 | class ResourceSerial |
| 35 | { |
| 36 | public: |
| 37 | constexpr ResourceSerial() : mValue(kDirty) {} |
| 38 | constexpr ResourceSerial(uintptr_t value) : mValue(value) {} |
| 39 | constexpr bool operator==(ResourceSerial other) const { return mValue == other.mValue; } |
| 40 | constexpr bool operator!=(ResourceSerial other) const { return mValue != other.mValue; } |
| 41 | |
| 42 | void dirty() { mValue = kDirty; } |
| 43 | |
| 44 | private: |
| 45 | constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max(); |
| 46 | |
| 47 | uintptr_t mValue; |
| 48 | }; |
| 49 | |
Jamie Madill | a5b1561 | 2016-08-09 11:10:27 -0400 | [diff] [blame] | 50 | using MipGenerationFunction = void (*)(size_t sourceWidth, |
| 51 | size_t sourceHeight, |
| 52 | size_t sourceDepth, |
| 53 | const uint8_t *sourceData, |
| 54 | size_t sourceRowPitch, |
| 55 | size_t sourceDepthPitch, |
| 56 | uint8_t *destData, |
| 57 | size_t destRowPitch, |
| 58 | size_t destDepthPitch); |
| 59 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 60 | typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest); |
| 61 | typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest); |
| 62 | typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest); |
| 63 | |
Jamie Madill | 4f57e5f | 2016-10-27 17:36:53 -0400 | [diff] [blame] | 64 | class FastCopyFunctionMap |
| 65 | { |
| 66 | public: |
| 67 | struct Entry |
| 68 | { |
| 69 | GLenum format; |
| 70 | GLenum type; |
| 71 | ColorCopyFunction func; |
| 72 | }; |
| 73 | |
| 74 | constexpr FastCopyFunctionMap() : FastCopyFunctionMap(nullptr, 0) {} |
| 75 | |
| 76 | constexpr FastCopyFunctionMap(const Entry *data, size_t size) : mSize(size), mData(data) {} |
| 77 | |
| 78 | bool has(const gl::FormatType &formatType) const; |
| 79 | ColorCopyFunction get(const gl::FormatType &formatType) const; |
| 80 | |
| 81 | private: |
| 82 | size_t mSize; |
| 83 | const Entry *mData; |
| 84 | }; |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 85 | |
| 86 | struct PackPixelsParams |
| 87 | { |
| 88 | PackPixelsParams(); |
| 89 | PackPixelsParams(const gl::Rectangle &area, |
| 90 | GLenum format, |
| 91 | GLenum type, |
| 92 | GLuint outputPitch, |
| 93 | const gl::PixelPackState &pack, |
| 94 | ptrdiff_t offset); |
| 95 | |
| 96 | gl::Rectangle area; |
| 97 | GLenum format; |
| 98 | GLenum type; |
| 99 | GLuint outputPitch; |
| 100 | gl::Buffer *packBuffer; |
| 101 | gl::PixelPackState pack; |
| 102 | ptrdiff_t offset; |
| 103 | }; |
| 104 | |
| 105 | void PackPixels(const PackPixelsParams ¶ms, |
Jamie Madill | 86e0b7f | 2016-08-09 11:10:29 -0400 | [diff] [blame] | 106 | const angle::Format &sourceFormat, |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 107 | int inputPitch, |
| 108 | const uint8_t *source, |
| 109 | uint8_t *destination); |
| 110 | |
| 111 | ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType); |
| 112 | ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions, |
| 113 | const gl::FormatType &formatType); |
| 114 | |
Jamie Madill | abaab23 | 2017-01-10 12:37:37 -0500 | [diff] [blame] | 115 | using InitializeTextureDataFunction = void (*)(size_t width, |
| 116 | size_t height, |
| 117 | size_t depth, |
| 118 | uint8_t *output, |
| 119 | size_t outputRowPitch, |
| 120 | size_t outputDepthPitch); |
| 121 | |
Jamie Madill | b2e4863 | 2016-08-09 18:08:03 -0400 | [diff] [blame] | 122 | using LoadImageFunction = void (*)(size_t width, |
| 123 | size_t height, |
| 124 | size_t depth, |
| 125 | const uint8_t *input, |
| 126 | size_t inputRowPitch, |
| 127 | size_t inputDepthPitch, |
| 128 | uint8_t *output, |
| 129 | size_t outputRowPitch, |
| 130 | size_t outputDepthPitch); |
| 131 | |
| 132 | struct LoadImageFunctionInfo |
| 133 | { |
| 134 | LoadImageFunctionInfo() : loadFunction(nullptr), requiresConversion(false) {} |
| 135 | LoadImageFunctionInfo(LoadImageFunction loadFunction, bool requiresConversion) |
| 136 | : loadFunction(loadFunction), requiresConversion(requiresConversion) |
| 137 | { |
| 138 | } |
| 139 | |
| 140 | LoadImageFunction loadFunction; |
| 141 | bool requiresConversion; |
| 142 | }; |
| 143 | |
| 144 | using LoadFunctionMap = LoadImageFunctionInfo (*)(GLenum); |
| 145 | |
Jamie Madill | d2b50a0 | 2016-06-09 00:13:35 -0700 | [diff] [blame] | 146 | } // namespace rx |
| 147 | |
| 148 | #endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_ |