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