Updating Xamarin/Microsoft file headers
[platform/upstream/libSkiaSharp.git] / src / c / gr_context.cpp
1 /*
2  * Copyright 2014 Google Inc.
3  * Copyright 2015 Xamarin Inc.
4  * Copyright 2017 Microsoft Corporation. All rights reserved.
5  *
6  * Use of this source code is governed by a BSD-style license that can be
7  * found in the LICENSE file.
8  */
9
10 #include "SkTypes.h" // required to make sure SK_SUPPORT_GPU is defined
11
12 #if SK_SUPPORT_GPU
13
14 #include "GrContext.h"
15 #include "gl/GrGLInterface.h"
16 #include "gl/GrGLAssembleInterface.h"
17
18 #include "gr_context.h"
19
20 #include "sk_types_priv.h"
21
22 gr_context_t* gr_context_create(gr_backend_t backend, gr_backendcontext_t backendContext, const gr_context_options_t* options) {
23     return ToGrContext(GrContext::Create((GrBackend)backend, backendContext, AsGrContextOptions(*options)));
24 }
25
26 gr_context_t* gr_context_create_with_defaults(gr_backend_t backend, gr_backendcontext_t backendContext) {
27     return ToGrContext(GrContext::Create((GrBackend)backend, backendContext));
28 }
29
30 void gr_context_unref(gr_context_t* context) {
31     SkSafeUnref(AsGrContext(context));
32 }
33
34 void gr_context_abandon_context(gr_context_t* context) {
35     AsGrContext(context)->abandonContext();
36 }
37
38 void gr_context_release_resources_and_abandon_context(gr_context_t* context) {
39     AsGrContext(context)->releaseResourcesAndAbandonContext();
40 }
41
42 void gr_context_get_resource_cache_limits(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
43     AsGrContext(context)->getResourceCacheLimits(maxResources, maxResourceBytes);
44 }
45
46 void gr_context_set_resource_cache_limits(gr_context_t* context, int maxResources, size_t maxResourceBytes) {
47     AsGrContext(context)->setResourceCacheLimits(maxResources, maxResourceBytes);
48 }
49
50 void gr_context_get_resource_cache_usage(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
51     AsGrContext(context)->getResourceCacheUsage(maxResources, maxResourceBytes);
52 }
53
54 int gr_context_get_recommended_sample_count(gr_context_t* context, gr_pixelconfig_t config, float dpi) {
55     return AsGrContext(context)->getRecommendedSampleCount((GrPixelConfig)config, dpi);
56 }
57
58 void gr_context_flush(gr_context_t* context) {
59     AsGrContext(context)->flush();
60 }
61
62 void gr_context_reset_context(gr_context_t* context, uint32_t state) {
63     AsGrContext(context)->resetContext(state);
64 }
65
66
67 const gr_glinterface_t* gr_glinterface_default_interface() {
68     return ToGrGLInterface(GrGLDefaultInterface());
69 }
70
71 const gr_glinterface_t* gr_glinterface_create_native_interface() {
72     return ToGrGLInterface(GrGLCreateNativeInterface());
73 }
74
75 const gr_glinterface_t* gr_glinterface_assemble_interface(void* ctx, gr_gl_get_proc get) {
76     return ToGrGLInterface(GrGLAssembleInterface(ctx, get));
77 }
78
79 const gr_glinterface_t* gr_glinterface_assemble_gl_interface(void* ctx, gr_gl_get_proc get) {
80     return ToGrGLInterface(GrGLAssembleGLInterface(ctx, get));
81 }
82
83 const gr_glinterface_t* gr_glinterface_assemble_gles_interface(void* ctx, gr_gl_get_proc get) {
84     return ToGrGLInterface(GrGLAssembleGLESInterface(ctx, get));
85 }
86
87 void gr_glinterface_unref(gr_glinterface_t* glInterface) {
88     SkSafeUnref(AsGrGLInterface(glInterface));
89 }
90
91 gr_glinterface_t* gr_glinterface_clone(gr_glinterface_t* glInterface) {
92     return ToGrGLInterface(GrGLInterface::NewClone(AsGrGLInterface(glInterface)));
93 }
94
95 bool gr_glinterface_validate(gr_glinterface_t* glInterface) {
96     return AsGrGLInterface(glInterface)->validate();
97 }
98
99 bool gr_glinterface_has_extension(gr_glinterface_t* glInterface, const char* extension) {
100     return AsGrGLInterface(glInterface)->hasExtension(extension);
101 }
102
103 #else // !SK_SUPPORT_GPU
104
105 #include "gr_context.h"
106 #include "sk_types_priv.h"
107
108 gr_context_t* gr_context_create(gr_backend_t backend, gr_backendcontext_t backendContext, const gr_context_options_t* options) {
109     return nullptr;
110 }
111
112 gr_context_t* gr_context_create_with_defaults(gr_backend_t backend, gr_backendcontext_t backendContext) {
113     return nullptr;
114 }
115
116 void gr_context_unref(gr_context_t* context) {
117 }
118
119 void gr_context_abandon_context(gr_context_t* context) {
120 }
121
122 void gr_context_release_resources_and_abandon_context(gr_context_t* context) {
123 }
124
125 void gr_context_get_resource_cache_limits(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
126 }
127
128 void gr_context_set_resource_cache_limits(gr_context_t* context, int maxResources, size_t maxResourceBytes) {
129 }
130
131 void gr_context_get_resource_cache_usage(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
132 }
133
134 int gr_context_get_recommended_sample_count(gr_context_t* context, gr_pixelconfig_t config, float dpi) {
135     return 0;
136 }
137
138 void gr_context_flush(gr_context_t* context) {
139 }
140
141 const gr_glinterface_t* gr_glinterface_default_interface() {
142     return nullptr;
143 }
144
145 const gr_glinterface_t* gr_glinterface_create_native_interface() {
146     return nullptr;
147 }
148
149 const gr_glinterface_t* gr_glinterface_assemble_interface(void* ctx, gr_gl_get_proc get) {
150     return nullptr;
151 }
152
153 const gr_glinterface_t* gr_glinterface_assemble_gl_interface(void* ctx, gr_gl_get_proc get) {
154     return nullptr;
155 }
156
157 const gr_glinterface_t* gr_glinterface_assemble_gles_interface(void* ctx, gr_gl_get_proc get) {
158     return nullptr;
159 }
160
161 void gr_glinterface_unref(gr_glinterface_t* glInterface) {
162 }
163
164 gr_glinterface_t* gr_glinterface_clone(gr_glinterface_t* glInterface) {
165     return nullptr;
166 }
167
168 bool gr_glinterface_validate(gr_glinterface_t* glInterface) {
169     return false;
170 }
171
172 bool gr_glinterface_has_extension(gr_glinterface_t* glInterface, const char* extension) {
173     return false;
174 }
175
176 #endif // SK_SUPPORT_GPU