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