3712e8dc2338a012625058eb1a87c87250d0a3b2
[platform/upstream/libSkiaSharp.git] / src / c / gr_context.cpp
1 /*
2  * Copyright 2016 Xamarin Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #include "GrContext.h"
9 #include "gl/GrGLInterface.h"
10 #include "gl/GrGLAssembleInterface.h"
11
12 #include "gr_context.h"
13
14 #include "sk_types_priv.h"
15
16 gr_context_t* gr_context_create(gr_backend_t backend, gr_backendcontext_t backendContext, const gr_context_options_t* options) {
17     return ToGrContext(GrContext::Create((GrBackend)backend, backendContext, AsGrContextOptions(*options)));
18 }
19
20 gr_context_t* gr_context_create_with_defaults(gr_backend_t backend, gr_backendcontext_t backendContext) {
21     return ToGrContext(GrContext::Create((GrBackend)backend, backendContext));
22 }
23
24 void gr_context_unref(gr_context_t* context) {
25     SkSafeUnref(AsGrContext(context));
26 }
27
28 void gr_context_abandon_context(gr_context_t* context) {
29     AsGrContext(context)->abandonContext();
30 }
31
32 void gr_context_release_resources_and_abandon_context(gr_context_t* context) {
33     AsGrContext(context)->releaseResourcesAndAbandonContext();
34 }
35
36 void gr_context_get_resource_cache_limits(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
37     AsGrContext(context)->getResourceCacheLimits(maxResources, maxResourceBytes);
38 }
39
40 void gr_context_set_resource_cache_limits(gr_context_t* context, int maxResources, size_t maxResourceBytes) {
41     AsGrContext(context)->setResourceCacheLimits(maxResources, maxResourceBytes);
42 }
43
44 void gr_context_get_resource_cache_usage(gr_context_t* context, int* maxResources, size_t* maxResourceBytes) {
45     AsGrContext(context)->getResourceCacheUsage(maxResources, maxResourceBytes);
46 }
47
48 int gr_context_get_recommended_sample_count(gr_context_t* context, gr_pixelconfig_t config, float dpi) {
49     return AsGrContext(context)->getRecommendedSampleCount((GrPixelConfig)config, dpi);
50 }
51
52 void gr_context_flush(gr_context_t* context) {
53     AsGrContext(context)->flush();
54 }
55
56
57 const gr_glinterface_t* gr_glinterface_default_interface() {
58     return ToGrGLInterface(GrGLDefaultInterface());
59 }
60
61 const gr_glinterface_t* gr_glinterface_create_native_interface() {
62     return ToGrGLInterface(GrGLCreateNativeInterface());
63 }
64
65 const gr_glinterface_t* gr_glinterface_assemble_interface(void* ctx, gr_gl_get_proc get) {
66     return ToGrGLInterface(GrGLAssembleInterface(ctx, get));
67 }
68
69 const gr_glinterface_t* gr_glinterface_assemble_gl_interface(void* ctx, gr_gl_get_proc get) {
70     return ToGrGLInterface(GrGLAssembleGLInterface(ctx, get));
71 }
72
73 const gr_glinterface_t* gr_glinterface_assemble_gles_interface(void* ctx, gr_gl_get_proc get) {
74     return ToGrGLInterface(GrGLAssembleGLESInterface(ctx, get));
75 }
76
77 void gr_glinterface_unref(gr_glinterface_t* glInterface) {
78     SkSafeUnref(AsGrGLInterface(glInterface));
79 }
80
81 gr_glinterface_t* gr_glinterface_clone(gr_glinterface_t* glInterface) {
82     return ToGrGLInterface(GrGLInterface::NewClone(AsGrGLInterface(glInterface)));
83 }
84
85 bool gr_glinterface_validate(gr_glinterface_t* glInterface) {
86     return AsGrGLInterface(glInterface)->validate();
87 }
88
89 bool gr_glinterface_has_extension(gr_glinterface_t* glInterface, const char* extension) {
90     return AsGrGLInterface(glInterface)->hasExtension(extension);
91 }