Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
| 15 | #include "FrameBuffer.hpp" |
| 16 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 17 | #include "Renderer/Surface.hpp" |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 18 | #include "Reactor/Reactor.hpp" |
Nicolas Capens | 708c24b | 2017-10-26 13:07:10 -0400 | [diff] [blame] | 19 | #include "Common/Timer.hpp" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 20 | #include "Common/Debug.hpp" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 21 | |
| 22 | #include <stdio.h> |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 23 | #include <string.h> |
| 24 | #include <time.h> |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 25 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 26 | #define ASYNCHRONOUS_BLIT false // FIXME: Currently leads to rare race conditions |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 27 | |
| 28 | namespace sw |
| 29 | { |
| 30 | extern bool forceWindowed; |
| 31 | |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 32 | FrameBuffer::Cursor FrameBuffer::cursor = {}; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 33 | bool FrameBuffer::topLeftOrigin = false; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 34 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 35 | FrameBuffer::FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 36 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 37 | this->topLeftOrigin = topLeftOrigin; |
| 38 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 39 | framebuffer = nullptr; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 40 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 41 | this->width = width; |
| 42 | this->height = height; |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 43 | format = FORMAT_X8R8G8B8; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 44 | stride = 0; |
| 45 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 46 | windowed = !fullscreen || forceWindowed; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 47 | |
Nicolas Capens | 518e41a | 2016-04-27 23:18:01 -0400 | [diff] [blame] | 48 | blitFunction = nullptr; |
| 49 | blitRoutine = nullptr; |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 50 | blitState = {}; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 51 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 52 | if(ASYNCHRONOUS_BLIT) |
| 53 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 54 | terminate = false; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 55 | FrameBuffer *parameters = this; |
| 56 | blitThread = new Thread(threadFunction, ¶meters); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 57 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | FrameBuffer::~FrameBuffer() |
| 61 | { |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 62 | if(ASYNCHRONOUS_BLIT) |
| 63 | { |
| 64 | terminate = true; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 65 | blitEvent.signal(); |
| 66 | blitThread->join(); |
| 67 | delete blitThread; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 68 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 69 | } |
| 70 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 71 | void FrameBuffer::setCursorImage(sw::Surface *cursorImage) |
| 72 | { |
| 73 | if(cursorImage) |
| 74 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 75 | cursor.image = cursorImage->lockExternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 76 | cursorImage->unlockExternal(); |
| 77 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 78 | cursor.width = cursorImage->getWidth(); |
| 79 | cursor.height = cursorImage->getHeight(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 80 | } |
| 81 | else |
| 82 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 83 | cursor.width = 0; |
| 84 | cursor.height = 0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | void FrameBuffer::setCursorOrigin(int x0, int y0) |
| 89 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 90 | cursor.hotspotX = x0; |
| 91 | cursor.hotspotY = y0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void FrameBuffer::setCursorPosition(int x, int y) |
| 95 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 96 | cursor.positionX = x; |
| 97 | cursor.positionY = y; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 100 | void FrameBuffer::copy(sw::Surface *source) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 101 | { |
| 102 | if(!source) |
| 103 | { |
| 104 | return; |
| 105 | } |
| 106 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 107 | if(!lock()) |
| 108 | { |
| 109 | return; |
| 110 | } |
| 111 | |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 112 | int sourceStride = source->getInternalPitchB(); |
| 113 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 114 | updateState = {}; |
| 115 | updateState.width = width; |
| 116 | updateState.height = height; |
| 117 | updateState.destFormat = format; |
Nicolas Capens | d3206e6 | 2015-12-28 11:13:48 -0500 | [diff] [blame] | 118 | updateState.destStride = stride; |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 119 | updateState.sourceFormat = source->getInternalFormat(); |
| 120 | updateState.sourceStride = topLeftOrigin ? sourceStride : -sourceStride; |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 121 | updateState.cursorWidth = cursor.width; |
| 122 | updateState.cursorHeight = cursor.height; |
Nicolas Capens | 8aaf671 | 2015-05-11 15:15:32 -0400 | [diff] [blame] | 123 | |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 124 | renderbuffer = source->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); |
| 125 | |
| 126 | if(!topLeftOrigin) |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 127 | { |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 128 | renderbuffer = (byte*)renderbuffer + (height - 1) * sourceStride; |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 131 | cursor.x = cursor.positionX - cursor.hotspotX; |
| 132 | cursor.y = cursor.positionY - cursor.hotspotY; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 133 | |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 134 | if(ASYNCHRONOUS_BLIT) |
| 135 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 136 | blitEvent.signal(); |
| 137 | syncEvent.wait(); |
John Bauman | 19bac1e | 2014-05-06 15:23:49 -0400 | [diff] [blame] | 138 | } |
| 139 | else |
| 140 | { |
| 141 | copyLocked(); |
| 142 | } |
Nicolas Capens | 0270476 | 2014-11-24 15:50:51 -0500 | [diff] [blame] | 143 | |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 144 | source->unlockInternal(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 145 | unlock(); |
Nicolas Capens | 6ef6d2a | 2015-02-23 14:23:11 -0500 | [diff] [blame] | 146 | |
| 147 | profiler.nextFrame(); // Assumes every copy() is a full frame |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void FrameBuffer::copyLocked() |
| 151 | { |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 152 | if(memcmp(&blitState, &updateState, sizeof(BlitState)) != 0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 153 | { |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 154 | blitState = updateState; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 155 | blitRoutine = copyRoutine(blitState); |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 156 | blitFunction = (void(*)(void*, void*, Cursor*))blitRoutine->getEntry(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 159 | blitFunction(framebuffer, renderbuffer, &cursor); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 160 | } |
| 161 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 162 | std::shared_ptr<Routine> FrameBuffer::copyRoutine(const BlitState &state) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 163 | { |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 164 | const int width = state.width; |
| 165 | const int height = state.height; |
Nicolas Capens | 10219e7 | 2014-05-07 00:17:20 -0400 | [diff] [blame] | 166 | const int dBytes = Surface::bytes(state.destFormat); |
Nicolas Capens | d3206e6 | 2015-12-28 11:13:48 -0500 | [diff] [blame] | 167 | const int dStride = state.destStride; |
Nicolas Capens | 10219e7 | 2014-05-07 00:17:20 -0400 | [diff] [blame] | 168 | const int sBytes = Surface::bytes(state.sourceFormat); |
Nicolas Capens | d3206e6 | 2015-12-28 11:13:48 -0500 | [diff] [blame] | 169 | const int sStride = state.sourceStride; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 170 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 171 | Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 172 | { |
Nicolas Capens | 81f1830 | 2016-01-14 09:32:35 -0500 | [diff] [blame] | 173 | Pointer<Byte> dst(function.Arg<0>()); |
| 174 | Pointer<Byte> src(function.Arg<1>()); |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 175 | Pointer<Byte> cursor(function.Arg<2>()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 176 | |
| 177 | For(Int y = 0, y < height, y++) |
| 178 | { |
| 179 | Pointer<Byte> d = dst + y * dStride; |
| 180 | Pointer<Byte> s = src + y * sStride; |
| 181 | |
| 182 | Int x0 = 0; |
| 183 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 184 | switch(state.destFormat) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 185 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 186 | case FORMAT_X8R8G8B8: |
| 187 | case FORMAT_A8R8G8B8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 188 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 189 | Int x = x0; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 190 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 191 | switch(state.sourceFormat) |
| 192 | { |
| 193 | case FORMAT_X8R8G8B8: |
| 194 | case FORMAT_A8R8G8B8: |
| 195 | For(, x < width - 3, x += 4) |
| 196 | { |
Nicolas Capens | c0fb8a0 | 2016-01-06 13:44:09 -0500 | [diff] [blame] | 197 | *Pointer<Int4>(d, 1) = *Pointer<Int4>(s, sStride % 16 ? 1 : 16); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 198 | |
| 199 | s += 4 * sBytes; |
| 200 | d += 4 * dBytes; |
| 201 | } |
| 202 | break; |
| 203 | case FORMAT_X8B8G8R8: |
| 204 | case FORMAT_A8B8G8R8: |
| 205 | For(, x < width - 3, x += 4) |
| 206 | { |
Nicolas Capens | c0fb8a0 | 2016-01-06 13:44:09 -0500 | [diff] [blame] | 207 | Int4 bgra = *Pointer<Int4>(s, sStride % 16 ? 1 : 16); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 208 | |
| 209 | *Pointer<Int4>(d, 1) = ((bgra & Int4(0x00FF0000)) >> 16) | |
| 210 | ((bgra & Int4(0x000000FF)) << 16) | |
| 211 | (bgra & Int4(0xFF00FF00)); |
| 212 | |
| 213 | s += 4 * sBytes; |
| 214 | d += 4 * dBytes; |
| 215 | } |
| 216 | break; |
| 217 | case FORMAT_A16B16G16R16: |
| 218 | For(, x < width - 1, x += 2) |
| 219 | { |
Ben Clayton | 8701dc4 | 2019-12-05 21:27:03 +0000 | [diff] [blame] | 220 | Short4 c0 = As<UShort4>(Swizzle(*Pointer<Short4>(s + 0), 0x2103)) >> 8; |
| 221 | Short4 c1 = As<UShort4>(Swizzle(*Pointer<Short4>(s + 8), 0x2103)) >> 8; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 222 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 223 | *Pointer<Int2>(d) = As<Int2>(PackUnsigned(c0, c1)); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 224 | |
| 225 | s += 2 * sBytes; |
| 226 | d += 2 * dBytes; |
| 227 | } |
| 228 | break; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 229 | case FORMAT_R5G6B5: |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 230 | For(, x < width - 3, x += 4) |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 231 | { |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 232 | Int4 rgb = Int4(*Pointer<Short4>(s)); |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 233 | |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 234 | *Pointer<Int4>(d) = (((rgb & Int4(0xF800)) << 8) | ((rgb & Int4(0xE01F)) << 3)) | |
| 235 | (((rgb & Int4(0x07E0)) << 5) | ((rgb & Int4(0x0600)) >> 1)) | |
| 236 | (((rgb & Int4(0x001C)) >> 2) | Int4(0xFF000000)); |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 237 | |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 238 | s += 4 * sBytes; |
| 239 | d += 4 * dBytes; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 240 | } |
| 241 | break; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 242 | default: |
| 243 | ASSERT(false); |
| 244 | break; |
| 245 | } |
| 246 | |
| 247 | For(, x < width, x++) |
| 248 | { |
| 249 | switch(state.sourceFormat) |
| 250 | { |
| 251 | case FORMAT_X8R8G8B8: |
| 252 | case FORMAT_A8R8G8B8: |
| 253 | *Pointer<Int>(d) = *Pointer<Int>(s); |
| 254 | break; |
| 255 | case FORMAT_X8B8G8R8: |
| 256 | case FORMAT_A8B8G8R8: |
| 257 | { |
| 258 | Int rgba = *Pointer<Int>(s); |
| 259 | |
| 260 | *Pointer<Int>(d) = ((rgba & Int(0x00FF0000)) >> 16) | |
| 261 | ((rgba & Int(0x000000FF)) << 16) | |
| 262 | (rgba & Int(0xFF00FF00)); |
| 263 | } |
| 264 | break; |
| 265 | case FORMAT_A16B16G16R16: |
| 266 | { |
Ben Clayton | 8701dc4 | 2019-12-05 21:27:03 +0000 | [diff] [blame] | 267 | Short4 c = As<UShort4>(Swizzle(*Pointer<Short4>(s), 0x2103)) >> 8; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 268 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 269 | *Pointer<Int>(d) = Int(As<Int2>(PackUnsigned(c, c))); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 270 | } |
| 271 | break; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 272 | case FORMAT_R5G6B5: |
| 273 | { |
| 274 | Int rgb = Int(*Pointer<Short>(s)); |
| 275 | |
| 276 | *Pointer<Int>(d) = 0xFF000000 | |
Nicolas Capens | cf0cdf6 | 2015-05-26 11:20:46 -0400 | [diff] [blame] | 277 | ((rgb & 0xF800) << 8) | ((rgb & 0xE01F) << 3) | |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 278 | ((rgb & 0x07E0) << 5) | ((rgb & 0x0600) >> 1) | |
Nicolas Capens | cf0cdf6 | 2015-05-26 11:20:46 -0400 | [diff] [blame] | 279 | ((rgb & 0x001C) >> 2); |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 280 | } |
| 281 | break; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 282 | default: |
| 283 | ASSERT(false); |
| 284 | break; |
| 285 | } |
| 286 | |
| 287 | s += sBytes; |
| 288 | d += dBytes; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 289 | } |
| 290 | } |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 291 | break; |
| 292 | case FORMAT_X8B8G8R8: |
| 293 | case FORMAT_A8B8G8R8: |
Alexis Hetu | 049a187 | 2016-04-25 16:59:58 -0400 | [diff] [blame] | 294 | case FORMAT_SRGB8_X8: |
| 295 | case FORMAT_SRGB8_A8: |
Nicolas Capens | 4e0d6f6 | 2015-03-27 21:47:49 -0400 | [diff] [blame] | 296 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 297 | Int x = x0; |
| 298 | |
| 299 | switch(state.sourceFormat) |
Nicolas Capens | 4e0d6f6 | 2015-03-27 21:47:49 -0400 | [diff] [blame] | 300 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 301 | case FORMAT_X8B8G8R8: |
| 302 | case FORMAT_A8B8G8R8: |
| 303 | For(, x < width - 3, x += 4) |
| 304 | { |
Nicolas Capens | c0fb8a0 | 2016-01-06 13:44:09 -0500 | [diff] [blame] | 305 | *Pointer<Int4>(d, 1) = *Pointer<Int4>(s, sStride % 16 ? 1 : 16); |
Nicolas Capens | 4e0d6f6 | 2015-03-27 21:47:49 -0400 | [diff] [blame] | 306 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 307 | s += 4 * sBytes; |
| 308 | d += 4 * dBytes; |
| 309 | } |
| 310 | break; |
| 311 | case FORMAT_X8R8G8B8: |
| 312 | case FORMAT_A8R8G8B8: |
| 313 | For(, x < width - 3, x += 4) |
| 314 | { |
Nicolas Capens | c0fb8a0 | 2016-01-06 13:44:09 -0500 | [diff] [blame] | 315 | Int4 bgra = *Pointer<Int4>(s, sStride % 16 ? 1 : 16); |
Nicolas Capens | 4e0d6f6 | 2015-03-27 21:47:49 -0400 | [diff] [blame] | 316 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 317 | *Pointer<Int4>(d, 1) = ((bgra & Int4(0x00FF0000)) >> 16) | |
| 318 | ((bgra & Int4(0x000000FF)) << 16) | |
| 319 | (bgra & Int4(0xFF00FF00)); |
| 320 | |
| 321 | s += 4 * sBytes; |
| 322 | d += 4 * dBytes; |
| 323 | } |
| 324 | break; |
| 325 | case FORMAT_A16B16G16R16: |
| 326 | For(, x < width - 1, x += 2) |
| 327 | { |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 328 | Short4 c0 = *Pointer<UShort4>(s + 0) >> 8; |
| 329 | Short4 c1 = *Pointer<UShort4>(s + 8) >> 8; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 330 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 331 | *Pointer<Int2>(d) = As<Int2>(PackUnsigned(c0, c1)); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 332 | |
| 333 | s += 2 * sBytes; |
| 334 | d += 2 * dBytes; |
| 335 | } |
| 336 | break; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 337 | case FORMAT_R5G6B5: |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 338 | For(, x < width - 3, x += 4) |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 339 | { |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 340 | Int4 rgb = Int4(*Pointer<Short4>(s)); |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 341 | |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 342 | *Pointer<Int4>(d) = Int4(0xFF000000) | |
| 343 | (((rgb & Int4(0x001F)) << 19) | ((rgb & Int4(0x001C)) << 14)) | |
| 344 | (((rgb & Int4(0x07E0)) << 5) | ((rgb & Int4(0x0600)) >> 1)) | |
| 345 | (((rgb & Int4(0xF800)) >> 8) | ((rgb & Int4(0xE000)) >> 13)); |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 346 | |
Nicolas Capens | f549e3b | 2017-01-24 08:53:47 -0800 | [diff] [blame] | 347 | s += 4 * sBytes; |
| 348 | d += 4 * dBytes; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 349 | } |
| 350 | break; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 351 | default: |
| 352 | ASSERT(false); |
| 353 | break; |
| 354 | } |
| 355 | |
| 356 | For(, x < width, x++) |
| 357 | { |
| 358 | switch(state.sourceFormat) |
| 359 | { |
| 360 | case FORMAT_X8B8G8R8: |
| 361 | case FORMAT_A8B8G8R8: |
| 362 | *Pointer<Int>(d) = *Pointer<Int>(s); |
| 363 | break; |
| 364 | case FORMAT_X8R8G8B8: |
| 365 | case FORMAT_A8R8G8B8: |
| 366 | { |
| 367 | Int bgra = *Pointer<Int>(s); |
| 368 | *Pointer<Int>(d) = ((bgra & Int(0x00FF0000)) >> 16) | |
| 369 | ((bgra & Int(0x000000FF)) << 16) | |
| 370 | (bgra & Int(0xFF00FF00)); |
| 371 | } |
| 372 | break; |
| 373 | case FORMAT_A16B16G16R16: |
| 374 | { |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 375 | Short4 c = *Pointer<UShort4>(s) >> 8; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 376 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 377 | *Pointer<Int>(d) = Int(As<Int2>(PackUnsigned(c, c))); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 378 | } |
| 379 | break; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 380 | case FORMAT_R5G6B5: |
| 381 | { |
| 382 | Int rgb = Int(*Pointer<Short>(s)); |
| 383 | |
| 384 | *Pointer<Int>(d) = 0xFF000000 | |
| 385 | ((rgb & 0x001F) << 19) | ((rgb & 0x001C) << 14) | |
| 386 | ((rgb & 0x07E0) << 5) | ((rgb & 0x0600) >> 1) | |
| 387 | ((rgb & 0xF800) >> 8) | ((rgb & 0xE000) >> 13); |
| 388 | } |
| 389 | break; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 390 | default: |
| 391 | ASSERT(false); |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | s += sBytes; |
| 396 | d += dBytes; |
Nicolas Capens | 4e0d6f6 | 2015-03-27 21:47:49 -0400 | [diff] [blame] | 397 | } |
| 398 | } |
Ping-Hao Wu | e04f28a | 2015-05-26 16:16:00 -0700 | [diff] [blame] | 399 | break; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 400 | case FORMAT_R8G8B8: |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 401 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 402 | For(Int x = x0, x < width, x++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 403 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 404 | switch(state.sourceFormat) |
| 405 | { |
| 406 | case FORMAT_X8R8G8B8: |
| 407 | case FORMAT_A8R8G8B8: |
| 408 | *Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 0); |
| 409 | *Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 1); |
| 410 | *Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 2); |
| 411 | break; |
| 412 | case FORMAT_X8B8G8R8: |
| 413 | case FORMAT_A8B8G8R8: |
| 414 | *Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 2); |
| 415 | *Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 1); |
| 416 | *Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 0); |
| 417 | break; |
| 418 | case FORMAT_A16B16G16R16: |
| 419 | *Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 5); |
| 420 | *Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 3); |
| 421 | *Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 1); |
| 422 | break; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 423 | case FORMAT_R5G6B5: |
| 424 | { |
| 425 | Int rgb = Int(*Pointer<Short>(s)); |
| 426 | |
| 427 | *Pointer<Byte>(d + 0) = Byte(((rgb & 0x001F) << 3) | ((rgb & 0x001C) >> 2)); |
| 428 | *Pointer<Byte>(d + 1) = Byte(((rgb & 0x07E0) << 5) | ((rgb & 0x0600) >> 1)); |
| 429 | *Pointer<Byte>(d + 2) = Byte(((rgb & 0xF800) << 8) | ((rgb & 0xE000) << 3)); |
| 430 | } |
| 431 | break; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 432 | default: |
| 433 | ASSERT(false); |
| 434 | break; |
| 435 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 436 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 437 | s += sBytes; |
| 438 | d += dBytes; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 439 | } |
| 440 | } |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 441 | break; |
| 442 | case FORMAT_R5G6B5: |
Nicolas Capens | 296e312 | 2014-05-07 00:10:55 -0400 | [diff] [blame] | 443 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 444 | For(Int x = x0, x < width, x++) |
Nicolas Capens | 296e312 | 2014-05-07 00:10:55 -0400 | [diff] [blame] | 445 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 446 | switch(state.sourceFormat) |
| 447 | { |
| 448 | case FORMAT_X8R8G8B8: |
| 449 | case FORMAT_A8R8G8B8: |
| 450 | { |
| 451 | Int c = *Pointer<Int>(s); |
Nicolas Capens | 4e0d6f6 | 2015-03-27 21:47:49 -0400 | [diff] [blame] | 452 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 453 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 8 | |
| 454 | (c & 0x0000FC00) >> 5 | |
| 455 | (c & 0x000000F8) >> 3); |
| 456 | } |
| 457 | break; |
| 458 | case FORMAT_X8B8G8R8: |
| 459 | case FORMAT_A8B8G8R8: |
| 460 | { |
| 461 | Int c = *Pointer<Int>(s); |
Nicolas Capens | 296e312 | 2014-05-07 00:10:55 -0400 | [diff] [blame] | 462 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 463 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 19 | |
| 464 | (c & 0x0000FC00) >> 5 | |
| 465 | (c & 0x000000F8) << 8); |
| 466 | } |
| 467 | break; |
| 468 | case FORMAT_A16B16G16R16: |
| 469 | { |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 470 | Short4 cc = *Pointer<UShort4>(s) >> 8; |
| 471 | Int c = Int(As<Int2>(PackUnsigned(cc, cc))); |
Nicolas Capens | 296e312 | 2014-05-07 00:10:55 -0400 | [diff] [blame] | 472 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 473 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 19 | |
| 474 | (c & 0x0000FC00) >> 5 | |
| 475 | (c & 0x000000F8) << 8); |
| 476 | } |
| 477 | break; |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 478 | case FORMAT_R5G6B5: |
| 479 | *Pointer<Short>(d) = *Pointer<Short>(s); |
| 480 | break; |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 481 | default: |
| 482 | ASSERT(false); |
| 483 | break; |
| 484 | } |
| 485 | |
| 486 | s += sBytes; |
| 487 | d += dBytes; |
| 488 | } |
Nicolas Capens | 296e312 | 2014-05-07 00:10:55 -0400 | [diff] [blame] | 489 | } |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 490 | break; |
| 491 | default: |
| 492 | ASSERT(false); |
| 493 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 494 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 497 | if(state.cursorWidth > 0 && state.cursorHeight > 0) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 498 | { |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 499 | Int x0 = *Pointer<Int>(cursor + OFFSET(Cursor,x)); |
| 500 | Int y0 = *Pointer<Int>(cursor + OFFSET(Cursor,y)); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 501 | |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 502 | For(Int y1 = 0, y1 < state.cursorHeight, y1++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 503 | { |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 504 | Int y = y0 + y1; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 505 | |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 506 | If(y >= 0 && y < height) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 507 | { |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 508 | Pointer<Byte> d = dst + y * dStride + x0 * dBytes; |
| 509 | Pointer<Byte> s = src + y * sStride + x0 * sBytes; |
| 510 | Pointer<Byte> c = *Pointer<Pointer<Byte>>(cursor + OFFSET(Cursor,image)) + y1 * state.cursorWidth * 4; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 511 | |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 512 | For(Int x1 = 0, x1 < state.cursorWidth, x1++) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 513 | { |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 514 | Int x = x0 + x1; |
Nicolas Capens | 0270476 | 2014-11-24 15:50:51 -0500 | [diff] [blame] | 515 | |
Nicolas Capens | 04f4125 | 2017-05-02 15:14:58 -0400 | [diff] [blame] | 516 | If(x >= 0 && x < width) |
| 517 | { |
| 518 | blend(state, d, s, c); |
| 519 | } |
| 520 | |
| 521 | c += 4; |
| 522 | s += sBytes; |
| 523 | d += dBytes; |
| 524 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 528 | } |
| 529 | |
Chris Forbes | 878d4b0 | 2019-01-21 10:48:35 -0800 | [diff] [blame] | 530 | return function("FrameBuffer"); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void FrameBuffer::blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c) |
| 534 | { |
| 535 | Short4 c1; |
| 536 | Short4 c2; |
| 537 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 538 | c1 = Unpack(*Pointer<Byte4>(c)); |
Nicolas Capens | 0270476 | 2014-11-24 15:50:51 -0500 | [diff] [blame] | 539 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 540 | switch(state.sourceFormat) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 541 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 542 | case FORMAT_X8R8G8B8: |
| 543 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 544 | c2 = Unpack(*Pointer<Byte4>(s)); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 545 | break; |
| 546 | case FORMAT_X8B8G8R8: |
| 547 | case FORMAT_A8B8G8R8: |
Ben Clayton | 8701dc4 | 2019-12-05 21:27:03 +0000 | [diff] [blame] | 548 | c2 = Swizzle(Unpack(*Pointer<Byte4>(s)), 0x2103); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 549 | break; |
| 550 | case FORMAT_A16B16G16R16: |
Ben Clayton | 8701dc4 | 2019-12-05 21:27:03 +0000 | [diff] [blame] | 551 | c2 = Swizzle(*Pointer<Short4>(s), 0x2103); |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 552 | break; |
| 553 | case FORMAT_R5G6B5: |
| 554 | { |
| 555 | Int rgb(*Pointer<Short>(s)); |
| 556 | rgb = 0xFF000000 | |
Nicolas Capens | 3e3f536 | 2015-05-26 16:36:35 -0400 | [diff] [blame] | 557 | ((rgb & 0xF800) << 8) | ((rgb & 0xE01F) << 3) | |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 558 | ((rgb & 0x07E0) << 5) | ((rgb & 0x0600) >> 1) | |
Nicolas Capens | 3e3f536 | 2015-05-26 16:36:35 -0400 | [diff] [blame] | 559 | ((rgb & 0x001C) >> 2); |
Nicolas Capens | e030890 | 2015-05-25 23:47:18 -0400 | [diff] [blame] | 560 | c2 = Unpack(As<Byte4>(rgb)); |
| 561 | } |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 562 | break; |
| 563 | default: |
| 564 | ASSERT(false); |
| 565 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | c1 = As<Short4>(As<UShort4>(c1) >> 9); |
| 569 | c2 = As<Short4>(As<UShort4>(c2) >> 9); |
| 570 | |
Ben Clayton | 8701dc4 | 2019-12-05 21:27:03 +0000 | [diff] [blame] | 571 | Short4 alpha = Swizzle(c1, 0x3333) & Short4(0xFFFFu, 0xFFFFu, 0xFFFFu, 0x0000); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 572 | |
| 573 | c1 = (c1 - c2) * alpha; |
| 574 | c1 = c1 >> 7; |
| 575 | c1 = c1 + c2; |
| 576 | c1 = c1 + c1; |
| 577 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 578 | switch(state.destFormat) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 579 | { |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 580 | case FORMAT_X8R8G8B8: |
| 581 | case FORMAT_A8R8G8B8: |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 582 | *Pointer<Byte4>(d) = Byte4(PackUnsigned(c1, c1)); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 583 | break; |
| 584 | case FORMAT_X8B8G8R8: |
| 585 | case FORMAT_A8B8G8R8: |
Alexis Hetu | 049a187 | 2016-04-25 16:59:58 -0400 | [diff] [blame] | 586 | case FORMAT_SRGB8_X8: |
| 587 | case FORMAT_SRGB8_A8: |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 588 | { |
Ben Clayton | 8701dc4 | 2019-12-05 21:27:03 +0000 | [diff] [blame] | 589 | c1 = Swizzle(c1, 0x2103); |
Nicolas Capens | 4e0d6f6 | 2015-03-27 21:47:49 -0400 | [diff] [blame] | 590 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 591 | *Pointer<Byte4>(d) = Byte4(PackUnsigned(c1, c1)); |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 592 | } |
| 593 | break; |
| 594 | case FORMAT_R8G8B8: |
| 595 | { |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 596 | Int c = Int(As<Int2>(PackUnsigned(c1, c1))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 597 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 598 | *Pointer<Byte>(d + 0) = Byte(c >> 0); |
| 599 | *Pointer<Byte>(d + 1) = Byte(c >> 8); |
| 600 | *Pointer<Byte>(d + 2) = Byte(c >> 16); |
| 601 | } |
| 602 | break; |
| 603 | case FORMAT_R5G6B5: |
| 604 | { |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 605 | Int c = Int(As<Int2>(PackUnsigned(c1, c1))); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 606 | |
Alexis Hetu | 3b6c9cf | 2015-05-07 11:41:43 -0400 | [diff] [blame] | 607 | *Pointer<Short>(d) = Short((c & 0x00F80000) >> 8 | |
| 608 | (c & 0x0000FC00) >> 5 | |
| 609 | (c & 0x000000F8) >> 3); |
| 610 | } |
| 611 | break; |
| 612 | default: |
| 613 | ASSERT(false); |
| 614 | break; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 615 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 616 | } |
| 617 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 618 | void FrameBuffer::threadFunction(void *parameters) |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 619 | { |
| 620 | FrameBuffer *frameBuffer = *static_cast<FrameBuffer**>(parameters); |
| 621 | |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 622 | while(!frameBuffer->terminate) |
| 623 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 624 | frameBuffer->blitEvent.wait(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 625 | |
| 626 | if(!frameBuffer->terminate) |
| 627 | { |
| 628 | frameBuffer->copyLocked(); |
| 629 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 630 | frameBuffer->syncEvent.signal(); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 631 | } |
| 632 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 633 | } |
Nicolas Capens | 0270476 | 2014-11-24 15:50:51 -0500 | [diff] [blame] | 634 | } |