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