2 * Copyright 2014 Google Inc.
3 * Copyright 2015 Xamarin Inc.
4 * Copyright 2017 Microsoft Corporation. All rights reserved.
6 * Use of this source code is governed by a BSD-style license that can be
7 * found in the LICENSE file.
10 #include "SkTypes.h" // required to make sure SK_SUPPORT_GPU is defined
14 #include "GrContext.h"
15 #include "gl/GrGLInterface.h"
16 #include "gl/GrGLAssembleInterface.h"
18 #include "gr_context.h"
20 #include "sk_types_priv.h"
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)));
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));
30 void gr_context_unref(gr_context_t* context) {
31 SkSafeUnref(AsGrContext(context));
34 void gr_context_abandon_context(gr_context_t* context) {
35 AsGrContext(context)->abandonContext();
38 void gr_context_release_resources_and_abandon_context(gr_context_t* context) {
39 AsGrContext(context)->releaseResourcesAndAbandonContext();
42 void gr_context_get_resource_cache_limits(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
43 AsGrContext(context)->getResourceCacheLimits(maxResources, maxResourceBytes);
46 void gr_context_set_resource_cache_limits(gr_context_t* context, int maxResources, size_t maxResourceBytes) {
47 AsGrContext(context)->setResourceCacheLimits(maxResources, maxResourceBytes);
50 void gr_context_get_resource_cache_usage(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
51 AsGrContext(context)->getResourceCacheUsage(maxResources, maxResourceBytes);
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);
58 void gr_context_flush(gr_context_t* context) {
59 AsGrContext(context)->flush();
62 void gr_context_reset_context(gr_context_t* context, uint32_t state) {
63 AsGrContext(context)->resetContext(state);
67 const gr_glinterface_t* gr_glinterface_default_interface() {
68 return ToGrGLInterface(GrGLDefaultInterface());
71 const gr_glinterface_t* gr_glinterface_create_native_interface() {
72 return ToGrGLInterface(GrGLCreateNativeInterface());
75 const gr_glinterface_t* gr_glinterface_assemble_interface(void* ctx, gr_gl_get_proc get) {
76 return ToGrGLInterface(GrGLAssembleInterface(ctx, get));
79 const gr_glinterface_t* gr_glinterface_assemble_gl_interface(void* ctx, gr_gl_get_proc get) {
80 return ToGrGLInterface(GrGLAssembleGLInterface(ctx, get));
83 const gr_glinterface_t* gr_glinterface_assemble_gles_interface(void* ctx, gr_gl_get_proc get) {
84 return ToGrGLInterface(GrGLAssembleGLESInterface(ctx, get));
87 void gr_glinterface_unref(gr_glinterface_t* glInterface) {
88 SkSafeUnref(AsGrGLInterface(glInterface));
91 gr_glinterface_t* gr_glinterface_clone(gr_glinterface_t* glInterface) {
92 return ToGrGLInterface(GrGLInterface::NewClone(AsGrGLInterface(glInterface)));
95 bool gr_glinterface_validate(gr_glinterface_t* glInterface) {
96 return AsGrGLInterface(glInterface)->validate();
99 bool gr_glinterface_has_extension(gr_glinterface_t* glInterface, const char* extension) {
100 return AsGrGLInterface(glInterface)->hasExtension(extension);
103 #else // !SK_SUPPORT_GPU
105 #include "gr_context.h"
106 #include "sk_types_priv.h"
108 gr_context_t* gr_context_create(gr_backend_t backend, gr_backendcontext_t backendContext, const gr_context_options_t* options) {
112 gr_context_t* gr_context_create_with_defaults(gr_backend_t backend, gr_backendcontext_t backendContext) {
116 void gr_context_unref(gr_context_t* context) {
119 void gr_context_abandon_context(gr_context_t* context) {
122 void gr_context_release_resources_and_abandon_context(gr_context_t* context) {
125 void gr_context_get_resource_cache_limits(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
128 void gr_context_set_resource_cache_limits(gr_context_t* context, int maxResources, size_t maxResourceBytes) {
131 void gr_context_get_resource_cache_usage(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
134 int gr_context_get_recommended_sample_count(gr_context_t* context, gr_pixelconfig_t config, float dpi) {
138 void gr_context_flush(gr_context_t* context) {
141 const gr_glinterface_t* gr_glinterface_default_interface() {
145 const gr_glinterface_t* gr_glinterface_create_native_interface() {
149 const gr_glinterface_t* gr_glinterface_assemble_interface(void* ctx, gr_gl_get_proc get) {
153 const gr_glinterface_t* gr_glinterface_assemble_gl_interface(void* ctx, gr_gl_get_proc get) {
157 const gr_glinterface_t* gr_glinterface_assemble_gles_interface(void* ctx, gr_gl_get_proc get) {
161 void gr_glinterface_unref(gr_glinterface_t* glInterface) {
164 gr_glinterface_t* gr_glinterface_clone(gr_glinterface_t* glInterface) {
168 bool gr_glinterface_validate(gr_glinterface_t* glInterface) {
172 bool gr_glinterface_has_extension(gr_glinterface_t* glInterface, const char* extension) {
176 #endif // SK_SUPPORT_GPU