Updating Xamarin/Microsoft file headers
[platform/upstream/libSkiaSharp.git] / src / c / sk_surface.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 "SkCanvas.h"
11 #include "SkData.h"
12 #include "SkImage.h"
13 #include "SkMaskFilter.h"
14 #include "SkMatrix.h"
15 #include "SkPaint.h"
16 #include "SkPath.h"
17 #include "SkPictureRecorder.h"
18 #include "SkSurface.h"
19
20 #include "sk_canvas.h"
21 #include "sk_data.h"
22 #include "sk_image.h"
23 #include "sk_paint.h"
24 #include "sk_path.h"
25 #include "sk_picture.h"
26 #include "sk_surface.h"
27
28 #include "sk_types_priv.h"
29
30 sk_colortype_t sk_colortype_get_default_8888() {
31     return (sk_colortype_t)SkColorType::kN32_SkColorType;
32 }
33
34 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo, const sk_surfaceprops_t* props) {
35     SkImageInfo info;
36     from_c(*cinfo, &info);
37     SkSurfaceProps* surfProps = nullptr;
38     if (props) {
39         from_c(props, surfProps);
40     }
41     return ToSurface(SkSurface::MakeRaster(info, surfProps).release());
42 }
43
44 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_surfaceprops_t* props) {
45     SkImageInfo info;
46     from_c(*cinfo, &info);
47     SkSurfaceProps* surfProps = nullptr;
48     if (props) {
49         from_c(props, surfProps);
50     }
51     return ToSurface(SkSurface::MakeRasterDirect(info, pixels, rowBytes, surfProps).release());
52 }
53
54 void sk_surface_unref(sk_surface_t* csurf) {
55     SkSafeUnref(AsSurface(csurf));
56 }
57
58 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
59     return ToCanvas(AsSurface(csurf)->getCanvas());
60 }
61
62 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) {
63     return ToImage(AsSurface(csurf)->makeImageSnapshot().release());
64 }
65
66 sk_surface_t* sk_surface_new_backend_render_target(gr_context_t* context, const gr_backend_rendertarget_desc_t* desc, const sk_surfaceprops_t* props) {
67     SkSurfaceProps* surfProps = nullptr;
68     if (props) {
69         from_c(props, surfProps);
70     }
71     return ToSurface(SkSurface::MakeFromBackendRenderTarget(AsGrContext(context), AsGrBackendRenderTargetDesc(*desc), surfProps).release());
72 }
73
74 sk_surface_t* sk_surface_new_backend_texture(gr_context_t* context, const gr_backend_texture_desc_t* desc, const sk_surfaceprops_t* props) {
75     SkSurfaceProps* surfProps = nullptr;
76     if (props) {
77         from_c(props, surfProps);
78     }
79     return ToSurface(SkSurface::MakeFromBackendTexture(AsGrContext(context), AsGrBackendTextureDesc(*desc), surfProps).release());
80 }
81
82 sk_surface_t* sk_surface_new_backend_texture_as_render_target(gr_context_t* context, const gr_backend_texture_desc_t* desc, const sk_surfaceprops_t* props) {
83     SkSurfaceProps* surfProps = nullptr;
84     if (props) {
85         from_c(props, surfProps);
86     }
87     return ToSurface(SkSurface::MakeFromBackendTextureAsRenderTarget(AsGrContext(context), AsGrBackendTextureDesc(*desc), surfProps).release());
88 }
89
90 sk_surface_t* sk_surface_new_render_target(gr_context_t* context, bool budgeted, const sk_imageinfo_t* cinfo, int sampleCount, const sk_surfaceprops_t* props) {
91     SkImageInfo info;
92     from_c(*cinfo, &info);
93     SkSurfaceProps* surfProps = nullptr;
94     if (props) {
95         from_c(props, surfProps);
96     }
97     return ToSurface(SkSurface::MakeRenderTarget(AsGrContext(context), (SkBudgeted)budgeted, info, sampleCount, surfProps).release());
98 }
99
100 void sk_surface_draw(sk_surface_t* surface, sk_canvas_t* canvas, float x, float y, const sk_paint_t* paint) {
101     AsSurface(surface)->draw(AsCanvas(canvas), x, y, AsPaint(paint));
102 }
103
104 bool sk_surface_peek_pixels(sk_surface_t* surface, sk_pixmap_t* pixmap) {
105     return AsSurface(surface)->peekPixels(AsPixmap(pixmap));
106 }
107
108 bool sk_surface_read_pixels(sk_surface_t* surface, sk_imageinfo_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY) {
109     SkImageInfo info;
110     from_c(*dstInfo, &info);
111     return AsSurface(surface)->readPixels(info, dstPixels, dstRowBytes, srcX, srcY);
112 }
113
114 void sk_surface_get_props(sk_surface_t* surface, sk_surfaceprops_t* props) {
115     SkSurfaceProps skProps = AsSurface(surface)->props();
116     from_sk(&skProps, props);
117 }