blob: 94a189079b18cb9ce17f1520f379ae3202528c40 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// 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 Capensd022e412016-09-26 13:30:14 -040018#include "Reactor/Reactor.hpp"
Nicolas Capens0bac2852016-05-07 06:09:58 -040019#include "Renderer/Surface.hpp"
20#include "Common/Thread.hpp"
21
22namespace sw
23{
Nicolas Capens48461502018-08-06 14:20:45 -040024 using namespace rr;
25
Nicolas Capens0bac2852016-05-07 06:09:58 -040026 class Surface;
27
28 struct BlitState
29 {
30 int width;
31 int height;
32 Format destFormat;
33 Format sourceFormat;
Nicolas Capensd3206e62015-12-28 11:13:48 -050034 int destStride;
35 int sourceStride;
Nicolas Capens0bac2852016-05-07 06:09:58 -040036 int cursorWidth;
37 int cursorHeight;
38 };
39
Nicolas Capens9ed48ba2017-05-11 11:25:00 -040040 class [[clang::lto_visibility_public]] FrameBuffer
Nicolas Capens0bac2852016-05-07 06:09:58 -040041 {
42 public:
43 FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin);
44
Nicolas Capens6016a142017-05-29 17:20:36 -040045 virtual ~FrameBuffer() = 0;
Nicolas Capens0bac2852016-05-07 06:09:58 -040046
Nicolas Capens241f7892015-12-30 23:40:45 -050047 virtual void flip(sw::Surface *source) = 0;
48 virtual void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) = 0;
Nicolas Capens0bac2852016-05-07 06:09:58 -040049
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 Clayton6897e9b2019-07-16 17:27:27 +010057 static std::shared_ptr<Routine> copyRoutine(const BlitState &state);
Nicolas Capens0bac2852016-05-07 06:09:58 -040058
59 protected:
Nicolas Capens241f7892015-12-30 23:40:45 -050060 void copy(sw::Surface *source);
Nicolas Capense5a96372017-08-11 15:14:25 -040061
Nicolas Capens0bac2852016-05-07 06:09:58 -040062 bool windowed;
63
Nicolas Capense5a96372017-08-11 15:14:25 -040064 void *framebuffer; // Native window buffer.
65 int width;
66 int height;
67 int stride;
68 Format format;
Nicolas Capens0bac2852016-05-07 06:09:58 -040069
70 private:
71 void copyLocked();
72
73 static void threadFunction(void *parameters);
74
Nicolas Capense5a96372017-08-11 15:14:25 -040075 void *renderbuffer; // Render target buffer.
Nicolas Capens0bac2852016-05-07 06:09:58 -040076
Nicolas Capensa29d6532016-12-05 21:38:09 -050077 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 Clayton6897e9b2019-07-16 17:27:27 +010093 std::shared_ptr<Routine> blitRoutine;
Nicolas Capense5a96372017-08-11 15:14:25 -040094 BlitState blitState; // State of the current blitRoutine.
95 BlitState updateState; // State of the routine to be generated.
Nicolas Capens0bac2852016-05-07 06:09:58 -040096
97 static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c);
98
Nicolas Capens0bac2852016-05-07 06:09:58 -040099 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