blob: fbb2a790ab1760eac4b1fc9a7aa162b4f4513125 [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{
24 class Surface;
25
26 struct BlitState
27 {
28 int width;
29 int height;
30 Format destFormat;
31 Format sourceFormat;
Nicolas Capensd3206e62015-12-28 11:13:48 -050032 int destStride;
33 int sourceStride;
Nicolas Capens0bac2852016-05-07 06:09:58 -040034 int cursorWidth;
35 int cursorHeight;
36 };
37
Nicolas Capens9ed48ba2017-05-11 11:25:00 -040038 class [[clang::lto_visibility_public]] FrameBuffer
Nicolas Capens0bac2852016-05-07 06:09:58 -040039 {
40 public:
41 FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin);
42
Nicolas Capens6016a142017-05-29 17:20:36 -040043 virtual ~FrameBuffer() = 0;
Nicolas Capens0bac2852016-05-07 06:09:58 -040044
Nicolas Capens0bac2852016-05-07 06:09:58 -040045 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 Capense5a96372017-08-11 15:14:25 -040058 void copy(void *source, Format sourceFormat, size_t sourceStride);
59
Nicolas Capens0bac2852016-05-07 06:09:58 -040060 bool windowed;
61
Nicolas Capense5a96372017-08-11 15:14:25 -040062 void *framebuffer; // Native window buffer.
63 int width;
64 int height;
65 int stride;
66 Format format;
Nicolas Capens0bac2852016-05-07 06:09:58 -040067
68 private:
69 void copyLocked();
70
71 static void threadFunction(void *parameters);
72
Nicolas Capense5a96372017-08-11 15:14:25 -040073 void *renderbuffer; // Render target buffer.
Nicolas Capens0bac2852016-05-07 06:09:58 -040074
Nicolas Capensa29d6532016-12-05 21:38:09 -050075 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 Capens0bac2852016-05-07 06:09:58 -040091 Routine *blitRoutine;
Nicolas Capense5a96372017-08-11 15:14:25 -040092 BlitState blitState; // State of the current blitRoutine.
93 BlitState updateState; // State of the routine to be generated.
Nicolas Capens0bac2852016-05-07 06:09:58 -040094
95 static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c);
96
Nicolas Capens0bac2852016-05-07 06:09:58 -040097 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