Merge from google/chrome/m55
[platform/upstream/libSkiaSharp.git] / src / c / sk_surface.cpp
1 /*
2  * Copyright 2014 Google 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 "SkCanvas.h"
9 #include "SkData.h"
10 #include "SkImage.h"
11 #include "SkMaskFilter.h"
12 #include "SkMatrix.h"
13 #include "SkPaint.h"
14 #include "SkPath.h"
15 #include "SkPictureRecorder.h"
16 #include "SkSurface.h"
17
18 #include "sk_canvas.h"
19 #include "sk_data.h"
20 #include "sk_image.h"
21 #include "sk_paint.h"
22 #include "sk_path.h"
23 #include "sk_picture.h"
24 #include "sk_surface.h"
25
26 #include "sk_types_priv.h"
27
28 sk_colortype_t sk_colortype_get_default_8888() {
29     return (sk_colortype_t)SkColorType::kN32_SkColorType;
30 }
31
32 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo, const sk_surfaceprops_t* props) {
33     SkImageInfo info;
34     from_c(*cinfo, &info);
35     SkSurfaceProps* surfProps = nullptr;
36     if (props) {
37         from_c(props, surfProps);
38     }
39     return ToSurface(SkSurface::MakeRaster(info, surfProps).release());
40 }
41
42 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_surfaceprops_t* props) {
43     SkImageInfo info;
44     from_c(*cinfo, &info);
45     SkSurfaceProps* surfProps = nullptr;
46     if (props) {
47         from_c(props, surfProps);
48     }
49     return ToSurface(SkSurface::MakeRasterDirect(info, pixels, rowBytes, surfProps).release());
50 }
51
52 void sk_surface_unref(sk_surface_t* csurf) {
53     SkSafeUnref(AsSurface(csurf));
54 }
55
56 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
57     return ToCanvas(AsSurface(csurf)->getCanvas());
58 }
59
60 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) {
61     return ToImage(AsSurface(csurf)->makeImageSnapshot().release());
62 }
63
64 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) {
65     SkSurfaceProps* surfProps = nullptr;
66     if (props) {
67         from_c(props, surfProps);
68     }
69     return ToSurface(SkSurface::MakeFromBackendRenderTarget(AsGrContext(context), AsGrBackendRenderTargetDesc(*desc), surfProps).release());
70 }
71
72 sk_surface_t* sk_surface_new_backend_texture(gr_context_t* context, const gr_backend_texture_desc_t* desc, const sk_surfaceprops_t* props) {
73     SkSurfaceProps* surfProps = nullptr;
74     if (props) {
75         from_c(props, surfProps);
76     }
77     return ToSurface(SkSurface::MakeFromBackendTexture(AsGrContext(context), AsGrBackendTextureDesc(*desc), surfProps).release());
78 }
79
80 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) {
81     SkSurfaceProps* surfProps = nullptr;
82     if (props) {
83         from_c(props, surfProps);
84     }
85     return ToSurface(SkSurface::MakeFromBackendTextureAsRenderTarget(AsGrContext(context), AsGrBackendTextureDesc(*desc), surfProps).release());
86 }
87
88 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) {
89     SkImageInfo info;
90     from_c(*cinfo, &info);
91     SkSurfaceProps* surfProps = nullptr;
92     if (props) {
93         from_c(props, surfProps);
94     }
95     return ToSurface(SkSurface::MakeRenderTarget(AsGrContext(context), (SkBudgeted)budgeted, info, sampleCount, surfProps).release());
96 }