blob: 440548e9c0cf9a0a1796db976d5376f4d44653f2 [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
15#include <map>
16
17#include "libANGLE/angletypes.h"
18
Jamie Madill86e0b7f2016-08-09 11:10:29 -040019namespace angle
20{
21struct Format;
22}
23
Jamie Madilld2b50a02016-06-09 00:13:35 -070024namespace gl
25{
26struct FormatType;
27struct InternalFormat;
28}
29
30namespace rx
31{
32
Jamie Madilla5b15612016-08-09 11:10:27 -040033using MipGenerationFunction = void (*)(size_t sourceWidth,
34 size_t sourceHeight,
35 size_t sourceDepth,
36 const uint8_t *sourceData,
37 size_t sourceRowPitch,
38 size_t sourceDepthPitch,
39 uint8_t *destData,
40 size_t destRowPitch,
41 size_t destDepthPitch);
42
Jamie Madilld2b50a02016-06-09 00:13:35 -070043typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest);
44typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest);
45typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest);
46
Jamie Madill4f57e5f2016-10-27 17:36:53 -040047class FastCopyFunctionMap
48{
49 public:
50 struct Entry
51 {
52 GLenum format;
53 GLenum type;
54 ColorCopyFunction func;
55 };
56
57 constexpr FastCopyFunctionMap() : FastCopyFunctionMap(nullptr, 0) {}
58
59 constexpr FastCopyFunctionMap(const Entry *data, size_t size) : mSize(size), mData(data) {}
60
61 bool has(const gl::FormatType &formatType) const;
62 ColorCopyFunction get(const gl::FormatType &formatType) const;
63
64 private:
65 size_t mSize;
66 const Entry *mData;
67};
Jamie Madilld2b50a02016-06-09 00:13:35 -070068
69struct PackPixelsParams
70{
71 PackPixelsParams();
72 PackPixelsParams(const gl::Rectangle &area,
73 GLenum format,
74 GLenum type,
75 GLuint outputPitch,
76 const gl::PixelPackState &pack,
77 ptrdiff_t offset);
78
79 gl::Rectangle area;
80 GLenum format;
81 GLenum type;
82 GLuint outputPitch;
83 gl::Buffer *packBuffer;
84 gl::PixelPackState pack;
85 ptrdiff_t offset;
86};
87
88void PackPixels(const PackPixelsParams &params,
Jamie Madill86e0b7f2016-08-09 11:10:29 -040089 const angle::Format &sourceFormat,
Jamie Madilld2b50a02016-06-09 00:13:35 -070090 int inputPitch,
91 const uint8_t *source,
92 uint8_t *destination);
93
94ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType);
95ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
96 const gl::FormatType &formatType);
97
Jamie Madillb2e48632016-08-09 18:08:03 -040098using LoadImageFunction = void (*)(size_t width,
99 size_t height,
100 size_t depth,
101 const uint8_t *input,
102 size_t inputRowPitch,
103 size_t inputDepthPitch,
104 uint8_t *output,
105 size_t outputRowPitch,
106 size_t outputDepthPitch);
107
108struct LoadImageFunctionInfo
109{
110 LoadImageFunctionInfo() : loadFunction(nullptr), requiresConversion(false) {}
111 LoadImageFunctionInfo(LoadImageFunction loadFunction, bool requiresConversion)
112 : loadFunction(loadFunction), requiresConversion(requiresConversion)
113 {
114 }
115
116 LoadImageFunction loadFunction;
117 bool requiresConversion;
118};
119
120using LoadFunctionMap = LoadImageFunctionInfo (*)(GLenum);
121
Jamie Madilld2b50a02016-06-09 00:13:35 -0700122} // namespace rx
123
124#endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_