blob: d6d001c456d05a24b8c7c8c41093aa240ff57b43 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef sw_Surface_hpp
16#define sw_Surface_hpp
17
18#include "Color.hpp"
19#include "Main/Config.hpp"
20#include "Common/Resource.hpp"
21
22namespace sw
23{
24 class Resource;
25
Alexis Hetu10c74a62017-11-29 14:00:32 -050026 template <typename T> struct RectT
Nicolas Capens0bac2852016-05-07 06:09:58 -040027 {
Alexis Hetu10c74a62017-11-29 14:00:32 -050028 RectT() {}
29 RectT(T x0i, T y0i, T x1i, T y1i) : x0(x0i), y0(y0i), x1(x1i), y1(y1i) {}
Nicolas Capens0bac2852016-05-07 06:09:58 -040030
Alexis Hetu10c74a62017-11-29 14:00:32 -050031 void clip(T minX, T minY, T maxX, T maxY)
32 {
33 x0 = clamp(x0, minX, maxX);
34 y0 = clamp(y0, minY, maxY);
35 x1 = clamp(x1, minX, maxX);
36 y1 = clamp(y1, minY, maxY);
37 }
Nicolas Capens0bac2852016-05-07 06:09:58 -040038
Alexis Hetu10c74a62017-11-29 14:00:32 -050039 T width() const { return x1 - x0; }
40 T height() const { return y1 - y0; }
Nicolas Capens0bac2852016-05-07 06:09:58 -040041
Alexis Hetu10c74a62017-11-29 14:00:32 -050042 T x0; // Inclusive
43 T y0; // Inclusive
44 T x1; // Exclusive
45 T y1; // Exclusive
Nicolas Capens0bac2852016-05-07 06:09:58 -040046 };
47
Alexis Hetu10c74a62017-11-29 14:00:32 -050048 typedef RectT<int> Rect;
49 typedef RectT<float> RectF;
50
Nicolas Capensbfa23b32017-12-11 10:06:37 -050051 template<typename T> struct SliceRectT : public RectT<T>
Nicolas Capens0bac2852016-05-07 06:09:58 -040052 {
Alexis Hetu10c74a62017-11-29 14:00:32 -050053 SliceRectT() : slice(0) {}
54 SliceRectT(const RectT<T>& rect) : RectT<T>(rect), slice(0) {}
55 SliceRectT(const RectT<T>& rect, int s) : RectT<T>(rect), slice(s) {}
56 SliceRectT(T x0, T y0, T x1, T y1, int s) : RectT<T>(x0, y0, x1, y1), slice(s) {}
Nicolas Capens0bac2852016-05-07 06:09:58 -040057 int slice;
58 };
59
Alexis Hetu10c74a62017-11-29 14:00:32 -050060 typedef SliceRectT<int> SliceRect;
61 typedef SliceRectT<float> SliceRectF;
62
Nicolas Capenscd0af642020-07-11 03:43:58 -040063 enum Format ENUM_UNDERLYING_TYPE_UNSIGNED_INT
Nicolas Capens0bac2852016-05-07 06:09:58 -040064 {
65 FORMAT_NULL,
66
67 FORMAT_A8,
68 FORMAT_R8I,
69 FORMAT_R8UI,
Nicolas Capens975adb72017-12-19 15:34:20 -050070 FORMAT_R8_SNORM,
71 FORMAT_R8,
Nicolas Capens0bac2852016-05-07 06:09:58 -040072 FORMAT_R16I,
73 FORMAT_R16UI,
74 FORMAT_R32I,
75 FORMAT_R32UI,
76 FORMAT_R3G3B2,
77 FORMAT_A8R3G3B2,
78 FORMAT_X4R4G4B4,
79 FORMAT_A4R4G4B4,
80 FORMAT_R4G4B4A4,
81 FORMAT_R5G6B5,
82 FORMAT_R8G8B8,
83 FORMAT_B8G8R8,
84 FORMAT_X8R8G8B8,
85 FORMAT_A8R8G8B8,
86 FORMAT_X8B8G8R8I,
87 FORMAT_X8B8G8R8UI,
Nicolas Capens975adb72017-12-19 15:34:20 -050088 FORMAT_X8B8G8R8_SNORM,
89 FORMAT_X8B8G8R8,
Nicolas Capens0bac2852016-05-07 06:09:58 -040090 FORMAT_A8B8G8R8I,
91 FORMAT_A8B8G8R8UI,
Nicolas Capens975adb72017-12-19 15:34:20 -050092 FORMAT_A8B8G8R8_SNORM,
93 FORMAT_A8B8G8R8,
Nicolas Capens0bac2852016-05-07 06:09:58 -040094 FORMAT_SRGB8_X8,
95 FORMAT_SRGB8_A8,
96 FORMAT_X1R5G5B5,
97 FORMAT_A1R5G5B5,
98 FORMAT_R5G5B5A1,
99 FORMAT_G8R8I,
100 FORMAT_G8R8UI,
Nicolas Capens975adb72017-12-19 15:34:20 -0500101 FORMAT_G8R8_SNORM,
102 FORMAT_G8R8,
103 FORMAT_G16R16,
Nicolas Capens0bac2852016-05-07 06:09:58 -0400104 FORMAT_G16R16I,
105 FORMAT_G16R16UI,
106 FORMAT_G32R32I,
107 FORMAT_G32R32UI,
108 FORMAT_A2R10G10B10,
109 FORMAT_A2B10G10R10,
Nicolas Capens5555af42017-12-14 13:14:03 -0500110 FORMAT_A2B10G10R10UI,
Nicolas Capens975adb72017-12-19 15:34:20 -0500111 FORMAT_A16B16G16R16,
Nicolas Capens0bac2852016-05-07 06:09:58 -0400112 FORMAT_X16B16G16R16I,
113 FORMAT_X16B16G16R16UI,
114 FORMAT_A16B16G16R16I,
115 FORMAT_A16B16G16R16UI,
116 FORMAT_X32B32G32R32I,
117 FORMAT_X32B32G32R32UI,
118 FORMAT_A32B32G32R32I,
119 FORMAT_A32B32G32R32UI,
120 // Paletted formats
121 FORMAT_P8,
122 FORMAT_A8P8,
123 // Compressed formats
124 FORMAT_DXT1,
125 FORMAT_DXT3,
126 FORMAT_DXT5,
127 FORMAT_ATI1,
128 FORMAT_ATI2,
129 FORMAT_ETC1,
130 FORMAT_R11_EAC,
131 FORMAT_SIGNED_R11_EAC,
132 FORMAT_RG11_EAC,
133 FORMAT_SIGNED_RG11_EAC,
134 FORMAT_RGB8_ETC2,
135 FORMAT_SRGB8_ETC2,
136 FORMAT_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
137 FORMAT_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
138 FORMAT_RGBA8_ETC2_EAC,
139 FORMAT_SRGB8_ALPHA8_ETC2_EAC,
Nicolas Capens0bac2852016-05-07 06:09:58 -0400140 // Floating-point formats
141 FORMAT_A16F,
142 FORMAT_R16F,
143 FORMAT_G16R16F,
144 FORMAT_B16G16R16F,
Nicolas Capensa6bc61d2017-12-20 11:07:45 -0500145 FORMAT_X16B16G16R16F,
Nicolas Capens0bac2852016-05-07 06:09:58 -0400146 FORMAT_A16B16G16R16F,
Nicolas Capens67fdd832017-12-21 11:20:54 -0500147 FORMAT_X16B16G16R16F_UNSIGNED,
Nicolas Capens0bac2852016-05-07 06:09:58 -0400148 FORMAT_A32F,
149 FORMAT_R32F,
150 FORMAT_G32R32F,
151 FORMAT_B32G32R32F,
152 FORMAT_X32B32G32R32F,
153 FORMAT_A32B32G32R32F,
Nicolas Capens67fdd832017-12-21 11:20:54 -0500154 FORMAT_X32B32G32R32F_UNSIGNED,
Nicolas Capens0bac2852016-05-07 06:09:58 -0400155 // Bump map formats
156 FORMAT_V8U8,
157 FORMAT_L6V5U5,
158 FORMAT_Q8W8V8U8,
159 FORMAT_X8L8V8U8,
160 FORMAT_A2W10V10U10,
161 FORMAT_V16U16,
162 FORMAT_A16W16V16U16,
163 FORMAT_Q16W16V16U16,
164 // Luminance formats
165 FORMAT_L8,
166 FORMAT_A4L4,
167 FORMAT_L16,
168 FORMAT_A8L8,
169 FORMAT_L16F,
170 FORMAT_A16L16F,
171 FORMAT_L32F,
172 FORMAT_A32L32F,
173 // Depth/stencil formats
174 FORMAT_D16,
175 FORMAT_D32,
176 FORMAT_D24X8,
177 FORMAT_D24S8,
178 FORMAT_D24FS8,
179 FORMAT_D32F, // Quad layout
Nicolas Capens57e7cea2017-12-13 22:25:04 -0500180 FORMAT_D32FS8, // Quad layout
Nicolas Capens0bac2852016-05-07 06:09:58 -0400181 FORMAT_D32F_COMPLEMENTARY, // Quad layout, 1 - z
Nicolas Capens57e7cea2017-12-13 22:25:04 -0500182 FORMAT_D32FS8_COMPLEMENTARY, // Quad layout, 1 - z
Nicolas Capens0bac2852016-05-07 06:09:58 -0400183 FORMAT_D32F_LOCKABLE, // Linear layout
184 FORMAT_D32FS8_TEXTURE, // Linear layout, no PCF
Nicolas Capens57e7cea2017-12-13 22:25:04 -0500185 FORMAT_D32F_SHADOW, // Linear layout, PCF
Nicolas Capens0bac2852016-05-07 06:09:58 -0400186 FORMAT_D32FS8_SHADOW, // Linear layout, PCF
187 FORMAT_DF24S8,
188 FORMAT_DF16S8,
189 FORMAT_INTZ,
190 FORMAT_S8,
191 // Quad layout framebuffer
192 FORMAT_X8G8R8B8Q,
193 FORMAT_A8G8R8B8Q,
194 // YUV formats
195 FORMAT_YV12_BT601,
196 FORMAT_YV12_BT709,
197 FORMAT_YV12_JFIF, // Full-swing BT.601
198
199 FORMAT_LAST = FORMAT_YV12_JFIF
200 };
201
202 enum Lock
203 {
204 LOCK_UNLOCKED,
205 LOCK_READONLY,
206 LOCK_WRITEONLY,
207 LOCK_READWRITE,
Nicolas Capensae7756e2018-02-22 16:13:01 -0500208 LOCK_DISCARD,
209 LOCK_UPDATE // Write access which doesn't dirty the buffer, because it's being updated with the sibling's data.
Nicolas Capens0bac2852016-05-07 06:09:58 -0400210 };
211
Nicolas Capens9ed48ba2017-05-11 11:25:00 -0400212 class [[clang::lto_visibility_public]] Surface
Nicolas Capens0bac2852016-05-07 06:09:58 -0400213 {
214 private:
215 struct Buffer
216 {
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500217 friend Surface;
218
219 private:
Nicolas Capens0bac2852016-05-07 06:09:58 -0400220 void write(int x, int y, int z, const Color<float> &color);
221 void write(int x, int y, const Color<float> &color);
222 void write(void *element, const Color<float> &color);
223 Color<float> read(int x, int y, int z) const;
224 Color<float> read(int x, int y) const;
225 Color<float> read(void *element) const;
226 Color<float> sample(float x, float y, float z) const;
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500227 Color<float> sample(float x, float y, int layer) const;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400228
229 void *lockRect(int x, int y, int z, Lock lock);
230 void unlockRect();
231
232 void *buffer;
233 int width;
234 int height;
235 int depth;
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500236 short border;
237 short samples;
238
Nicolas Capens0bac2852016-05-07 06:09:58 -0400239 int bytes;
240 int pitchB;
241 int pitchP;
242 int sliceB;
243 int sliceP;
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500244
Nicolas Capens0bac2852016-05-07 06:09:58 -0400245 Format format;
Alexis Hetu6b164c32017-09-20 11:24:52 -0400246 AtomicInt lock;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400247
Nicolas Capens73e18c12017-11-28 13:31:35 -0500248 bool dirty; // Sibling internal/external buffer doesn't match.
Nicolas Capens0bac2852016-05-07 06:09:58 -0400249 };
250
Nicolas Capensf41f0332017-05-30 15:25:50 -0400251 protected:
Nicolas Capens0bac2852016-05-07 06:09:58 -0400252 Surface(int width, int height, int depth, Format format, void *pixels, int pitch, int slice);
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500253 Surface(Resource *texture, int width, int height, int depth, int border, int samples, Format format, bool lockable, bool renderTarget, int pitchP = 0);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400254
Nicolas Capensf41f0332017-05-30 15:25:50 -0400255 public:
256 static Surface *create(int width, int height, int depth, Format format, void *pixels, int pitch, int slice);
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500257 static Surface *create(Resource *texture, int width, int height, int depth, int border, int samples, Format format, bool lockable, bool renderTarget, int pitchP = 0);
Nicolas Capensf41f0332017-05-30 15:25:50 -0400258
259 virtual ~Surface() = 0;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400260
261 inline void *lock(int x, int y, int z, Lock lock, Accessor client, bool internal = false);
262 inline void unlock(bool internal = false);
263 inline int getWidth() const;
264 inline int getHeight() const;
265 inline int getDepth() const;
Alexis Hetu9c6d5222016-11-29 17:02:14 -0500266 inline int getBorder() const;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400267 inline Format getFormat(bool internal = false) const;
268 inline int getPitchB(bool internal = false) const;
269 inline int getPitchP(bool internal = false) const;
270 inline int getSliceB(bool internal = false) const;
271 inline int getSliceP(bool internal = false) const;
272
273 void *lockExternal(int x, int y, int z, Lock lock, Accessor client);
274 void unlockExternal();
275 inline Format getExternalFormat() const;
276 inline int getExternalPitchB() const;
277 inline int getExternalPitchP() const;
278 inline int getExternalSliceB() const;
279 inline int getExternalSliceP() const;
280
Nicolas Capensf41f0332017-05-30 15:25:50 -0400281 virtual void *lockInternal(int x, int y, int z, Lock lock, Accessor client) = 0;
282 virtual void unlockInternal() = 0;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400283 inline Format getInternalFormat() const;
284 inline int getInternalPitchB() const;
285 inline int getInternalPitchP() const;
286 inline int getInternalSliceB() const;
287 inline int getInternalSliceP() const;
288
Alexis Hetua52dfbd2016-10-05 17:03:30 -0400289 void *lockStencil(int x, int y, int front, Accessor client);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400290 void unlockStencil();
Alexis Hetua52dfbd2016-10-05 17:03:30 -0400291 inline Format getStencilFormat() const;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400292 inline int getStencilPitchB() const;
293 inline int getStencilSliceB() const;
294
Antoine Labourfc2b84d2017-06-09 18:14:05 -0700295 void sync(); // Wait for lock(s) to be released.
Alexis Hetu88482c32018-06-05 17:05:17 -0400296 virtual bool requiresSync() const { return false; }
Antoine Labourfc2b84d2017-06-09 18:14:05 -0700297 inline bool isUnlocked() const; // Only reliable after sync().
Nicolas Capensbf7a8142017-05-19 10:57:28 -0400298
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500299 inline int getSamples() const;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400300 inline int getMultiSampleCount() const;
301 inline int getSuperSampleCount() const;
302
Nicolas Capens426cb5e2017-07-20 14:14:09 -0400303 bool isEntire(const Rect& rect) const;
304 Rect getRect() const;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400305 void clearDepth(float depth, int x0, int y0, int width, int height);
306 void clearStencil(unsigned char stencil, unsigned char mask, int x0, int y0, int width, int height);
307 void fill(const Color<float> &color, int x0, int y0, int width, int height);
308
309 Color<float> readExternal(int x, int y, int z) const;
310 Color<float> readExternal(int x, int y) const;
311 Color<float> sampleExternal(float x, float y, float z) const;
312 Color<float> sampleExternal(float x, float y) const;
313 void writeExternal(int x, int y, int z, const Color<float> &color);
314 void writeExternal(int x, int y, const Color<float> &color);
315
316 void copyInternal(const Surface* src, int x, int y, float srcX, float srcY, bool filter);
317 void copyInternal(const Surface* src, int x, int y, int z, float srcX, float srcY, float srcZ, bool filter);
318
Alexis Hetua76a1bf2016-11-29 17:17:26 -0500319 enum Edge { TOP, BOTTOM, RIGHT, LEFT };
320 void copyCubeEdge(Edge dstEdge, Surface *src, Edge srcEdge);
321 void computeCubeCorner(int x0, int y0, int x1, int y1);
322
Nicolas Capens0bac2852016-05-07 06:09:58 -0400323 bool hasStencil() const;
324 bool hasDepth() const;
325 bool hasPalette() const;
326 bool isRenderTarget() const;
327
Nicolas Capens73e18c12017-11-28 13:31:35 -0500328 bool hasDirtyContents() const;
329 void markContentsClean();
Nicolas Capens0bac2852016-05-07 06:09:58 -0400330 inline bool isExternalDirty() const;
331 Resource *getResource();
332
333 static int bytes(Format format);
Alexis Hetu9c6d5222016-11-29 17:02:14 -0500334 static int pitchB(int width, int border, Format format, bool target);
335 static int pitchP(int width, int border, Format format, bool target);
336 static int sliceB(int width, int height, int border, Format format, bool target);
337 static int sliceP(int width, int height, int border, Format format, bool target);
Nicolas Capens419a5802018-05-08 17:20:50 -0400338 static size_t size(int width, int height, int depth, int border, int samples, Format format);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400339
340 static bool isStencil(Format format);
341 static bool isDepth(Format format);
Alexis Hetub9dda642016-10-06 11:25:32 -0400342 static bool hasQuadLayout(Format format);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400343 static bool isPalette(Format format);
344
345 static bool isFloatFormat(Format format);
346 static bool isUnsignedComponent(Format format, int component);
347 static bool isSRGBreadable(Format format);
348 static bool isSRGBwritable(Format format);
Nicolas Capens5555af42017-12-14 13:14:03 -0500349 static bool isSRGBformat(Format format);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400350 static bool isCompressed(Format format);
Nicolas Capens492887a2017-03-27 14:50:51 -0400351 static bool isSignedNonNormalizedInteger(Format format);
352 static bool isUnsignedNonNormalizedInteger(Format format);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400353 static bool isNonNormalizedInteger(Format format);
Nicolas Capens492887a2017-03-27 14:50:51 -0400354 static bool isNormalizedInteger(Format format);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400355 static int componentCount(Format format);
356
357 static void setTexturePalette(unsigned int *palette);
358
Nicolas Capensbf7a8142017-05-19 10:57:28 -0400359 private:
Nicolas Capens0bac2852016-05-07 06:09:58 -0400360 sw::Resource *resource;
361
Nicolas Capens0bac2852016-05-07 06:09:58 -0400362 typedef unsigned char byte;
363 typedef unsigned short word;
364 typedef unsigned int dword;
365 typedef uint64_t qword;
366
Nicolas Capens0bac2852016-05-07 06:09:58 -0400367 struct DXT1
368 {
369 word c0;
370 word c1;
371 dword lut;
372 };
373
374 struct DXT3
375 {
376 qword a;
377
378 word c0;
379 word c1;
380 dword lut;
381 };
382
383 struct DXT5
384 {
385 union
386 {
387 struct
388 {
389 byte a0;
390 byte a1;
391 };
392
393 qword alut; // Skip first 16 bit
394 };
395
396 word c0;
397 word c1;
398 dword clut;
399 };
Nicolas Capens0bac2852016-05-07 06:09:58 -0400400
401 struct ATI2
402 {
403 union
404 {
405 struct
406 {
407 byte y0;
408 byte y1;
409 };
410
411 qword ylut; // Skip first 16 bit
412 };
413
414 union
415 {
416 struct
417 {
418 byte x0;
419 byte x1;
420 };
421
422 qword xlut; // Skip first 16 bit
423 };
424 };
425
426 struct ATI1
427 {
428 union
429 {
430 struct
431 {
432 byte r0;
433 byte r1;
434 };
435
436 qword rlut; // Skip first 16 bit
437 };
438 };
439
Alexis Hetu9c6d5222016-11-29 17:02:14 -0500440 static void decodeR8G8B8(Buffer &destination, Buffer &source);
441 static void decodeX1R5G5B5(Buffer &destination, Buffer &source);
442 static void decodeA1R5G5B5(Buffer &destination, Buffer &source);
443 static void decodeX4R4G4B4(Buffer &destination, Buffer &source);
444 static void decodeA4R4G4B4(Buffer &destination, Buffer &source);
445 static void decodeP8(Buffer &destination, Buffer &source);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400446
Alexis Hetu9c6d5222016-11-29 17:02:14 -0500447 static void decodeDXT1(Buffer &internal, Buffer &external);
448 static void decodeDXT3(Buffer &internal, Buffer &external);
449 static void decodeDXT5(Buffer &internal, Buffer &external);
Alexis Hetu9c6d5222016-11-29 17:02:14 -0500450 static void decodeATI1(Buffer &internal, Buffer &external);
451 static void decodeATI2(Buffer &internal, Buffer &external);
452 static void decodeEAC(Buffer &internal, Buffer &external, int nbChannels, bool isSigned);
453 static void decodeETC2(Buffer &internal, Buffer &external, int nbAlphaBits, bool isSRGB);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400454
455 static void update(Buffer &destination, Buffer &source);
456 static void genericUpdate(Buffer &destination, Buffer &source);
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500457 static void *allocateBuffer(int width, int height, int depth, int border, int samples, Format format);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400458 static void memfill4(void *buffer, int pattern, int bytes);
459
Nicolas Capens539468c2018-06-28 11:28:40 -0400460 bool identicalBuffers() const;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400461 Format selectInternalFormat(Format format) const;
462
463 void resolve();
464
465 Buffer external;
466 Buffer internal;
467 Buffer stencil;
468
469 const bool lockable;
470 const bool renderTarget;
471
Nicolas Capens73e18c12017-11-28 13:31:35 -0500472 bool dirtyContents; // Sibling surfaces need updating (mipmaps / cube borders).
Nicolas Capens0bac2852016-05-07 06:09:58 -0400473 unsigned int paletteUsed;
474
475 static unsigned int *palette; // FIXME: Not multi-device safe
476 static unsigned int paletteID;
477
478 bool hasParent;
479 bool ownExternal;
480 };
481}
482
483#undef min
484#undef max
485
486namespace sw
487{
488 void *Surface::lock(int x, int y, int z, Lock lock, Accessor client, bool internal)
489 {
490 return internal ? lockInternal(x, y, z, lock, client) : lockExternal(x, y, z, lock, client);
491 }
492
493 void Surface::unlock(bool internal)
494 {
495 return internal ? unlockInternal() : unlockExternal();
496 }
497
498 int Surface::getWidth() const
499 {
500 return external.width;
501 }
502
503 int Surface::getHeight() const
504 {
505 return external.height;
506 }
507
508 int Surface::getDepth() const
509 {
510 return external.depth;
511 }
512
Alexis Hetu9c6d5222016-11-29 17:02:14 -0500513 int Surface::getBorder() const
514 {
515 return internal.border;
516 }
517
Nicolas Capens0bac2852016-05-07 06:09:58 -0400518 Format Surface::getFormat(bool internal) const
519 {
520 return internal ? getInternalFormat() : getExternalFormat();
521 }
522
523 int Surface::getPitchB(bool internal) const
524 {
525 return internal ? getInternalPitchB() : getExternalPitchB();
526 }
527
528 int Surface::getPitchP(bool internal) const
529 {
Nicolas Capens26b41162017-02-14 22:42:58 -0500530 return internal ? getInternalPitchP() : getExternalPitchP();
Nicolas Capens0bac2852016-05-07 06:09:58 -0400531 }
532
533 int Surface::getSliceB(bool internal) const
534 {
535 return internal ? getInternalSliceB() : getExternalSliceB();
536 }
537
538 int Surface::getSliceP(bool internal) const
539 {
Nicolas Capens26b41162017-02-14 22:42:58 -0500540 return internal ? getInternalSliceP() : getExternalSliceP();
Nicolas Capens0bac2852016-05-07 06:09:58 -0400541 }
542
543 Format Surface::getExternalFormat() const
544 {
545 return external.format;
546 }
547
548 int Surface::getExternalPitchB() const
549 {
550 return external.pitchB;
551 }
552
553 int Surface::getExternalPitchP() const
554 {
555 return external.pitchP;
556 }
557
558 int Surface::getExternalSliceB() const
559 {
560 return external.sliceB;
561 }
562
563 int Surface::getExternalSliceP() const
564 {
565 return external.sliceP;
566 }
567
568 Format Surface::getInternalFormat() const
569 {
570 return internal.format;
571 }
572
573 int Surface::getInternalPitchB() const
574 {
575 return internal.pitchB;
576 }
577
578 int Surface::getInternalPitchP() const
579 {
580 return internal.pitchP;
581 }
582
583 int Surface::getInternalSliceB() const
584 {
585 return internal.sliceB;
586 }
587
588 int Surface::getInternalSliceP() const
589 {
590 return internal.sliceP;
591 }
592
Alexis Hetua52dfbd2016-10-05 17:03:30 -0400593 Format Surface::getStencilFormat() const
594 {
595 return stencil.format;
596 }
597
Nicolas Capens0bac2852016-05-07 06:09:58 -0400598 int Surface::getStencilPitchB() const
599 {
600 return stencil.pitchB;
601 }
602
603 int Surface::getStencilSliceB() const
604 {
605 return stencil.sliceB;
606 }
607
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500608 int Surface::getSamples() const
609 {
610 return internal.samples;
611 }
612
Nicolas Capens0bac2852016-05-07 06:09:58 -0400613 int Surface::getMultiSampleCount() const
614 {
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500615 return sw::min((int)internal.samples, 4);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400616 }
617
618 int Surface::getSuperSampleCount() const
619 {
Nicolas Capensbfa23b32017-12-11 10:06:37 -0500620 return internal.samples > 4 ? internal.samples / 4 : 1;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400621 }
622
Antoine Labourfc2b84d2017-06-09 18:14:05 -0700623 bool Surface::isUnlocked() const
624 {
625 return external.lock == LOCK_UNLOCKED &&
626 internal.lock == LOCK_UNLOCKED &&
627 stencil.lock == LOCK_UNLOCKED;
628 }
629
Nicolas Capens0bac2852016-05-07 06:09:58 -0400630 bool Surface::isExternalDirty() const
631 {
632 return external.buffer && external.buffer != internal.buffer && external.dirty;
633 }
634}
635
636#endif // sw_Surface_hpp