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 | { |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 24 | using namespace rr; |
| 25 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 26 | class Surface; |
| 27 | |
| 28 | struct BlitState |
| 29 | { |
| 30 | int width; |
| 31 | int height; |
| 32 | Format destFormat; |
| 33 | Format sourceFormat; |
Nicolas Capens | d3206e6 | 2015-12-28 11:13:48 -0500 | [diff] [blame] | 34 | int destStride; |
| 35 | int sourceStride; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 36 | int cursorWidth; |
| 37 | int cursorHeight; |
| 38 | }; |
| 39 | |
Nicolas Capens | 9ed48ba | 2017-05-11 11:25:00 -0400 | [diff] [blame] | 40 | class [[clang::lto_visibility_public]] FrameBuffer |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 41 | { |
| 42 | public: |
| 43 | FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin); |
| 44 | |
Nicolas Capens | 6016a14 | 2017-05-29 17:20:36 -0400 | [diff] [blame] | 45 | virtual ~FrameBuffer() = 0; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 46 | |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 47 | virtual void flip(sw::Surface *source) = 0; |
| 48 | virtual void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) = 0; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 49 | |
| 50 | virtual void *lock() = 0; |
| 51 | virtual void unlock() = 0; |
| 52 | |
| 53 | static void setCursorImage(sw::Surface *cursor); |
| 54 | static void setCursorOrigin(int x0, int y0); |
| 55 | static void setCursorPosition(int x, int y); |
| 56 | |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 57 | static std::shared_ptr<Routine> copyRoutine(const BlitState &state); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 58 | |
| 59 | protected: |
Nicolas Capens | 241f789 | 2015-12-30 23:40:45 -0500 | [diff] [blame] | 60 | void copy(sw::Surface *source); |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 61 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 62 | bool windowed; |
| 63 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 64 | void *framebuffer; // Native window buffer. |
| 65 | int width; |
| 66 | int height; |
| 67 | int stride; |
| 68 | Format format; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 69 | |
| 70 | private: |
| 71 | void copyLocked(); |
| 72 | |
| 73 | static void threadFunction(void *parameters); |
| 74 | |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 75 | void *renderbuffer; // Render target buffer. |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 76 | |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 77 | struct Cursor |
| 78 | { |
| 79 | void *image; |
| 80 | int x; |
| 81 | int y; |
| 82 | int width; |
| 83 | int height; |
| 84 | int hotspotX; |
| 85 | int hotspotY; |
| 86 | int positionX; |
| 87 | int positionY; |
| 88 | }; |
| 89 | |
| 90 | static Cursor cursor; |
| 91 | |
| 92 | void (*blitFunction)(void *dst, void *src, Cursor *cursor); |
Ben Clayton | 6897e9b | 2019-07-16 17:27:27 +0100 | [diff] [blame] | 93 | std::shared_ptr<Routine> blitRoutine; |
Nicolas Capens | e5a9637 | 2017-08-11 15:14:25 -0400 | [diff] [blame] | 94 | BlitState blitState; // State of the current blitRoutine. |
| 95 | BlitState updateState; // State of the routine to be generated. |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 96 | |
| 97 | static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c); |
| 98 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 99 | Thread *blitThread; |
| 100 | Event syncEvent; |
| 101 | Event blitEvent; |
| 102 | volatile bool terminate; |
| 103 | |
| 104 | static bool topLeftOrigin; |
| 105 | }; |
| 106 | } |
| 107 | |
| 108 | #endif // sw_FrameBuffer_hpp |