blob: 217156e2c003e5717945ff0f7d0cfc4584a71905 [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;
Jamie Madill222c5172017-07-19 16:15:42 -040024} // namespace angle
Jamie Madill86e0b7f2016-08-09 11:10:29 -040025
Jamie Madilld2b50a02016-06-09 00:13:35 -070026namespace gl
27{
28struct FormatType;
29struct InternalFormat;
Jamie Madill222c5172017-07-19 16:15:42 -040030} // namespace gl
31
32namespace egl
33{
34class AttributeMap;
35} // namespace egl
Jamie Madilld2b50a02016-06-09 00:13:35 -070036
37namespace rx
38{
39
Jamie Madilldcc9b512017-06-05 15:28:45 -040040class ResourceSerial
41{
42 public:
43 constexpr ResourceSerial() : mValue(kDirty) {}
44 constexpr ResourceSerial(uintptr_t value) : mValue(value) {}
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; }
49
50 private:
51 constexpr static uintptr_t kDirty = std::numeric_limits<uintptr_t>::max();
52
53 uintptr_t mValue;
54};
55
Jamie Madillfb05bcb2017-06-07 15:43:18 -040056class SerialFactory;
57
58class Serial final
59{
60 public:
61 constexpr Serial() : mValue(0) {}
62 constexpr Serial(const Serial &other) = default;
63 Serial &operator=(const Serial &other) = default;
64
65 constexpr bool operator==(const Serial &other) const { return mValue == other.mValue; }
66 constexpr bool operator!=(const Serial &other) const { return mValue != other.mValue; }
67 constexpr bool operator>(const Serial &other) const { return mValue > other.mValue; }
68 constexpr bool operator>=(const Serial &other) const { return mValue >= other.mValue; }
69 constexpr bool operator<(const Serial &other) const { return mValue < other.mValue; }
70 constexpr bool operator<=(const Serial &other) const { return mValue <= other.mValue; }
71
72 private:
73 friend class SerialFactory;
74 constexpr explicit Serial(uint64_t value) : mValue(value) {}
75 uint64_t mValue;
76};
77
78class SerialFactory final : angle::NonCopyable
79{
80 public:
81 SerialFactory() : mSerial(1) {}
82
83 Serial generate()
84 {
85 ASSERT(mSerial != std::numeric_limits<uint64_t>::max());
86 return Serial(mSerial++);
87 }
88
89 private:
90 uint64_t mSerial;
91};
92
Jamie Madilla5b15612016-08-09 11:10:27 -040093using MipGenerationFunction = void (*)(size_t sourceWidth,
94 size_t sourceHeight,
95 size_t sourceDepth,
96 const uint8_t *sourceData,
97 size_t sourceRowPitch,
98 size_t sourceDepthPitch,
99 uint8_t *destData,
100 size_t destRowPitch,
101 size_t destDepthPitch);
102
Jamie Madilld2b50a02016-06-09 00:13:35 -0700103typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest);
104typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest);
105typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest);
106
Jamie Madill4f57e5f2016-10-27 17:36:53 -0400107class FastCopyFunctionMap
108{
109 public:
110 struct Entry
111 {
112 GLenum format;
113 GLenum type;
114 ColorCopyFunction func;
115 };
116
117 constexpr FastCopyFunctionMap() : FastCopyFunctionMap(nullptr, 0) {}
118
119 constexpr FastCopyFunctionMap(const Entry *data, size_t size) : mSize(size), mData(data) {}
120
121 bool has(const gl::FormatType &formatType) const;
122 ColorCopyFunction get(const gl::FormatType &formatType) const;
123
124 private:
125 size_t mSize;
126 const Entry *mData;
127};
Jamie Madilld2b50a02016-06-09 00:13:35 -0700128
Jamie Madill4928b7c2017-06-20 12:57:39 -0400129struct PackPixelsParams : private angle::NonCopyable
Jamie Madilld2b50a02016-06-09 00:13:35 -0700130{
131 PackPixelsParams();
132 PackPixelsParams(const gl::Rectangle &area,
133 GLenum format,
134 GLenum type,
135 GLuint outputPitch,
136 const gl::PixelPackState &pack,
137 ptrdiff_t offset);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400138 PackPixelsParams(const gl::Context *context, const PackPixelsParams &other);
Jamie Madilld2b50a02016-06-09 00:13:35 -0700139
140 gl::Rectangle area;
141 GLenum format;
142 GLenum type;
143 GLuint outputPitch;
144 gl::Buffer *packBuffer;
145 gl::PixelPackState pack;
146 ptrdiff_t offset;
147};
148
149void PackPixels(const PackPixelsParams &params,
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400150 const angle::Format &sourceFormat,
Jamie Madilld2b50a02016-06-09 00:13:35 -0700151 int inputPitch,
152 const uint8_t *source,
153 uint8_t *destination);
154
155ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType);
156ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
157 const gl::FormatType &formatType);
158
Jamie Madillabaab232017-01-10 12:37:37 -0500159using InitializeTextureDataFunction = void (*)(size_t width,
160 size_t height,
161 size_t depth,
162 uint8_t *output,
163 size_t outputRowPitch,
164 size_t outputDepthPitch);
165
Jamie Madillb2e48632016-08-09 18:08:03 -0400166using LoadImageFunction = void (*)(size_t width,
167 size_t height,
168 size_t depth,
169 const uint8_t *input,
170 size_t inputRowPitch,
171 size_t inputDepthPitch,
172 uint8_t *output,
173 size_t outputRowPitch,
174 size_t outputDepthPitch);
175
176struct LoadImageFunctionInfo
177{
178 LoadImageFunctionInfo() : loadFunction(nullptr), requiresConversion(false) {}
179 LoadImageFunctionInfo(LoadImageFunction loadFunction, bool requiresConversion)
180 : loadFunction(loadFunction), requiresConversion(requiresConversion)
181 {
182 }
183
184 LoadImageFunction loadFunction;
185 bool requiresConversion;
186};
187
188using LoadFunctionMap = LoadImageFunctionInfo (*)(GLenum);
189
Jamie Madill222c5172017-07-19 16:15:42 -0400190bool ShouldUseDebugLayers(const egl::AttributeMap &attribs);
191
Geoff Langd93cd6c2017-08-11 16:32:41 -0400192void CopyImageCHROMIUM(const uint8_t *sourceData,
193 size_t sourceRowPitch,
194 size_t sourcePixelBytes,
195 ColorReadFunction readFunction,
196 uint8_t *destData,
197 size_t destRowPitch,
198 size_t destPixelBytes,
199 ColorWriteFunction colorWriteFunction,
200 GLenum destUnsizedFormat,
201 GLenum destComponentType,
202 size_t width,
203 size_t height,
204 bool unpackFlipY,
205 bool unpackPremultiplyAlpha,
206 bool unpackUnmultiplyAlpha);
207
Jamie Madilld2b50a02016-06-09 00:13:35 -0700208} // namespace rx
209
210#endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_