1
1
#ifndef CANVAS_H
2
2
#define CANVAS_H
3
3
4
+ #include < GLFW/glfw3.h>
4
5
#include < skia/include/core/SkCanvas.h>
5
6
#include < skia/include/core/SkRefCnt.h>
6
7
#include < skia/include/core/SkSurface.h>
8
+ #include < skia/include/gpu/ganesh/GrDirectContext.h>
9
+
10
+ #define DEFAULT_CANVAS_WIDTH 800
11
+ #define DEFAULT_CANVAS_HEIGHT 600
7
12
8
13
namespace Nickvision ::Cavalier::Shared::Models
9
14
{
@@ -14,18 +19,27 @@ namespace Nickvision::Cavalier::Shared::Models
14
19
{
15
20
public:
16
21
/* *
17
- * @brief Creates a Canvas.
22
+ * @brief Constructs a Canvas.
18
23
* @param width The width of the canvas
19
24
* @param height The height of the canvas
20
25
*/
21
26
Canvas (int width, int height);
22
27
/* *
23
- * @brief Creates a Cavnas.
24
- * @param The surface to adapt
25
- * @param width The width of the canvas
26
- * @param height The height of the canvas
28
+ * @brief Destructs a Canvas.
29
+ */
30
+ ~Canvas ();
31
+ /* *
32
+ * @brief Gets whether or not the Canvas is properly initalized.
33
+ * @return True if properly initalized
34
+ * @return False if not properly initalized
35
+ */
36
+ bool isValid () const ;
37
+ /* *
38
+ * @brief Gets whether or not the canvas is using the GPU.
39
+ * @return True if using GPU
40
+ * @return False if using CPU
27
41
*/
28
- Canvas ( const sk_sp<SkSurface>& surface, int width, int height) ;
42
+ bool isGPUCanvas () const ;
29
43
/* *
30
44
* @brief Gets the skia surface object.
31
45
* @return SkSurface
@@ -36,6 +50,11 @@ namespace Nickvision::Cavalier::Shared::Models
36
50
* @return SkCanvas
37
51
*/
38
52
SkCanvas* getSkiaCanvas () const ;
53
+ /* *
54
+ * @brief Gets the skia gpu context object.
55
+ * @return GrDirectContext
56
+ */
57
+ GrDirectContext* getSkiaContext () const ;
39
58
/* *
40
59
* @brief Gets the width of the canvas.
41
60
* @return The width of the canvas
@@ -46,14 +65,27 @@ namespace Nickvision::Cavalier::Shared::Models
46
65
* @return The height of the canvas
47
66
*/
48
67
int getHeight () const ;
68
+ /* *
69
+ * @brief Flushes the canvas.
70
+ */
71
+ void flush ();
49
72
/* *
50
73
* @brief Gets the backing skia canvas object.
51
74
* @return SkCanvas
52
75
*/
53
76
SkCanvas* operator ->();
77
+ /* *
78
+ * @brief Gets whether or not the Canvas is properly initalized.
79
+ * @return True if properly initalized
80
+ * @return False if not properly initalized
81
+ */
82
+ operator bool () const ;
54
83
55
84
private:
85
+ GLFWwindow* m_glfw;
56
86
sk_sp<SkSurface> m_surface;
87
+ sk_sp<GrDirectContext> m_context;
88
+ bool m_isGPUCanvas;
57
89
int m_width;
58
90
int m_height;
59
91
};
0 commit comments