blob: 0936024f65e7d7eee9789cbdca3029fce8ad98c5 [file] [log] [blame]
Jamie Madilld2b50a02016-06-09 00:13:35 -07001//
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 Madilldcc9b512017-06-05 15:28:45 -040015#include <limits>
Jamie Madilld2b50a02016-06-09 00:13:35 -070016#include <map>
17
Jamie Madillfb05bcb2017-06-07 15:43:18 -040018#include "common/angleutils.h"
Jamie Madilld2b50a02016-06-09 00:13:35 -070019#include "libANGLE/angletypes.h"
20
Jamie Madill86e0b7f2016-08-09 11:10:29 -040021namespace angle
22{
23struct Format;
24}
25
Jamie Madilld2b50a02016-06-09 00:13:35 -070026namespace gl
27{
28struct FormatType;
29struct InternalFormat;
30}
31
32namespace rx
33{
34
Jamie Madilldcc9b512017-06-05 15:28:45 -040035class ResourceSerial
36{
37 public:
38 constexpr ResourceSerial() : mValue(kDirty) {}
39 constexpr ResourceSerial(uintptr_t value) : mValue(value) {}
40 constexpr bool operator==(ResourceSerial other) const { return mValue == other.mValue; }
41 constexpr bool operator!=(ResourceSerial other) const { return mValue != other.mValue; }
42
43 void dirty() { mValue = kDirty; }
44
45 private:
46 constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max();
47
48 uintptr_t mValue;
49};
50
Jamie Madillfb05bcb2017-06-07 15:43:18 -040051class SerialFactory;
52
53class Serial final
54{
55 public:
56 constexpr Serial() : mValue(0) {}
57 constexpr Serial(const Serial &other) = default;
58 Serial &operator=(const Serial &other) = default;
59
60 constexpr bool operator==(const Serial &other) const { return mValue == other.mValue; }
61 constexpr bool operator!=(const Serial &other) const { return mValue != other.mValue; }
62 constexpr bool operator>(const Serial &other) const { return mValue > other.mValue; }
63 constexpr bool operator>=(const Serial &other) const { return mValue >= other.mValue; }
64 constexpr bool operator<(const Serial &other) const { return mValue < other.mValue; }
65 constexpr bool operator<=(const Serial &other) const { return mValue <= other.mValue; }
66
67 private:
68 friend class SerialFactory;
69 constexpr explicit Serial(uint64_t value) : mValue(value) {}
70 uint64_t mValue;
71};
72
73class SerialFactory final : angle::NonCopyable
74{
75 public:
76 SerialFactory() : mSerial(1) {}
77
78 Serial generate()
79 {
80 ASSERT(mSerial != std::numeric_limits<uint64_t>::max());
81 return Serial(mSerial++);
82 }
83
84 private:
85 uint64_t mSerial;
86};
87
Jamie Madilla5b15612016-08-09 11:10:27 -040088using MipGenerationFunction = void (*)(size_t sourceWidth,
89 size_t sourceHeight,
90 size_t sourceDepth,
91 const uint8_t *sourceData,
92 size_t sourceRowPitch,
93 size_t sourceDepthPitch,
94 uint8_t *destData,
95 size_t destRowPitch,
96 size_t destDepthPitch);
97
Jamie Madilld2b50a02016-06-09 00:13:35 -070098typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest);
99typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest);
100typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest);
101
Jamie Madill4f57e5f2016-10-27 17:36:53 -0400102class FastCopyFunctionMap
103{
104 public:
105 struct Entry
106 {
107 GLenum format;
108 GLenum type;
109 ColorCopyFunction func;
110 };
111
112 constexpr FastCopyFunctionMap() : FastCopyFunctionMap(nullptr, 0) {}
113
114 constexpr FastCopyFunctionMap(const Entry *data, size_t size) : mSize(size), mData(data) {}
115
116 bool has(const gl::FormatType &formatType) const;
117 ColorCopyFunction get(const gl::FormatType &formatType) const;
118
119 private:
120 size_t mSize;
121 const Entry *mData;
122};
Jamie Madilld2b50a02016-06-09 00:13:35 -0700123
124struct PackPixelsParams
125{
126 PackPixelsParams();
127 PackPixelsParams(const gl::Rectangle &area,
128 GLenum format,
129 GLenum type,
130 GLuint outputPitch,
131 const gl::PixelPackState &pack,
132 ptrdiff_t offset);
133
134 gl::Rectangle area;
135 GLenum format;
136 GLenum type;
137 GLuint outputPitch;
138 gl::Buffer *packBuffer;
139 gl::PixelPackState pack;
140 ptrdiff_t offset;
141};
142
143void PackPixels(const PackPixelsParams &params,
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400144 const angle::Format &sourceFormat,
Jamie Madilld2b50a02016-06-09 00:13:35 -0700145 int inputPitch,
146 const uint8_t *source,
147 uint8_t *destination);
148
149ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType);
150ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
151 const gl::FormatType &formatType);
152
Jamie Madillabaab232017-01-10 12:37:37 -0500153using InitializeTextureDataFunction = void (*)(size_t width,
154 size_t height,
155 size_t depth,
156 uint8_t *output,
157 size_t outputRowPitch,
158 size_t outputDepthPitch);
159
Jamie Madillb2e48632016-08-09 18:08:03 -0400160using LoadImageFunction = void (*)(size_t width,
161 size_t height,
162 size_t depth,
163 const uint8_t *input,
164 size_t inputRowPitch,
165 size_t inputDepthPitch,
166 uint8_t *output,
167 size_t outputRowPitch,
168 size_t outputDepthPitch);
169
170struct LoadImageFunctionInfo
171{
172 LoadImageFunctionInfo() : loadFunction(nullptr), requiresConversion(false) {}
173 LoadImageFunctionInfo(LoadImageFunction loadFunction, bool requiresConversion)
174 : loadFunction(loadFunction), requiresConversion(requiresConversion)
175 {
176 }
177
178 LoadImageFunction loadFunction;
179 bool requiresConversion;
180};
181
182using LoadFunctionMap = LoadImageFunctionInfo (*)(GLenum);
183
Jamie Madilld2b50a02016-06-09 00:13:35 -0700184} // namespace rx
185
186#endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_