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