Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef sw_FrameBuffer_hpp |
| 16 | #define sw_FrameBuffer_hpp |
| 17 | |
Nicolas Capens | d022e41 | 2016-09-26 13:30:14 -0400 | [diff] [blame] | 18 | #include "Reactor/Reactor.hpp" |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 19 | #include "Renderer/Surface.hpp" |
| 20 | #include "Common/Thread.hpp" |
| 21 | |
| 22 | namespace sw |
| 23 | { |
| 24 | class Surface; |
| 25 | |
| 26 | struct BlitState |
| 27 | { |
| 28 | int width; |
| 29 | int height; |
| 30 | Format destFormat; |
| 31 | Format sourceFormat; |
Nicolas Capens | d3206e6 | 2015-12-28 11:13:48 -0500 | [diff] [blame^] | 32 | int destStride; |
| 33 | int sourceStride; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 34 | int cursorWidth; |
| 35 | int cursorHeight; |
| 36 | }; |
| 37 | |
Nicolas Capens | 9ed48ba | 2017-05-11 11:25:00 -0400 | [diff] [blame] | 38 | class [[clang::lto_visibility_public]] FrameBuffer |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 39 | { |
| 40 | public: |
| 41 | FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin); |
| 42 | |
Nicolas Capens | 6016a14 | 2017-05-29 17:20:36 -0400 | [diff] [blame] | 43 | virtual ~FrameBuffer() = 0; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 44 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 45 | virtual void flip(void *source, Format sourceFormat, size_t sourceStride) = 0; |
| 46 | virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) = 0; |
| 47 | |
| 48 | virtual void *lock() = 0; |
| 49 | virtual void unlock() = 0; |
| 50 | |
| 51 | static void setCursorImage(sw::Surface *cursor); |
| 52 | static void setCursorOrigin(int x0, int y0); |
| 53 | static void setCursorPosition(int x, int y); |
| 54 | |
| 55 | static Routine *copyRoutine(const BlitState &state); |
| 56 | |
| 57 | protected: |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 58 | void copy(void *source, Format sourceFormat, size_t sourceStride); |
| 59 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 60 | bool windowed; |
| 61 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 62 | void *framebuffer; // Native window buffer. |
| 63 | int width; |
| 64 | int height; |
| 65 | int stride; |
| 66 | Format format; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 67 | |
| 68 | private: |
| 69 | void copyLocked(); |
| 70 | |
| 71 | static void threadFunction(void *parameters); |
| 72 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 73 | void *renderbuffer; // Render target buffer. |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 74 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 75 | struct Cursor |
| 76 | { |
| 77 | void *image; |
| 78 | int x; |
| 79 | int y; |
| 80 | int width; |
| 81 | int height; |
| 82 | int hotspotX; |
| 83 | int hotspotY; |
| 84 | int positionX; |
| 85 | int positionY; |
| 86 | }; |
| 87 | |
| 88 | static Cursor cursor; |
| 89 | |
| 90 | void (*blitFunction)(void *dst, void *src, Cursor *cursor); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 91 | Routine *blitRoutine; |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 92 | BlitState blitState; // State of the current blitRoutine. |
| 93 | BlitState updateState; // State of the routine to be generated. |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 94 | |
| 95 | static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c); |
| 96 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 97 | Thread *blitThread; |
| 98 | Event syncEvent; |
| 99 | Event blitEvent; |
| 100 | volatile bool terminate; |
| 101 | |
| 102 | static bool topLeftOrigin; |
| 103 | }; |
| 104 | } |
| 105 | |
| 106 | #endif // sw_FrameBuffer_hpp |