blob: a146d0fc2f8ac9b72f6274c2c36312ac3baf1fad [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
18#include "libANGLE/angletypes.h"
19
Jamie Madill86e0b7f2016-08-09 11:10:29 -040020namespace angle
21{
22struct Format;
23}
24
Jamie Madilld2b50a02016-06-09 00:13:35 -070025namespace gl
26{
27struct FormatType;
28struct InternalFormat;
29}
30
31namespace rx
32{
33
Jamie Madilldcc9b512017-06-05 15:28:45 -040034class 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 Madilla5b15612016-08-09 11:10:27 -040050using 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 Madilld2b50a02016-06-09 00:13:35 -070060typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest);
61typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest);
62typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest);
63
Jamie Madill4f57e5f2016-10-27 17:36:53 -040064class 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 Madilld2b50a02016-06-09 00:13:35 -070085
86struct 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
105void PackPixels(const PackPixelsParams &params,
Jamie Madill86e0b7f2016-08-09 11:10:29 -0400106 const angle::Format &sourceFormat,
Jamie Madilld2b50a02016-06-09 00:13:35 -0700107 int inputPitch,
108 const uint8_t *source,
109 uint8_t *destination);
110
111ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType);
112ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
113 const gl::FormatType &formatType);
114
Jamie Madillabaab232017-01-10 12:37:37 -0500115using 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 Madillb2e48632016-08-09 18:08:03 -0400122using 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
132struct 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
144using LoadFunctionMap = LoadImageFunctionInfo (*)(GLenum);
145
Jamie Madilld2b50a02016-06-09 00:13:35 -0700146} // namespace rx
147
148#endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_