• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2009, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 // must include config.h first for webkit to fiddle with new/delete
27 #include "config.h"
28 #include "SkANP.h"
29 
anp_newPath()30 static ANPPath* anp_newPath() {
31     return new ANPPath;
32 }
33 
anp_deletePath(ANPPath * path)34 static void anp_deletePath(ANPPath* path) {
35     delete path;
36 }
37 
anp_copy(ANPPath * dst,const ANPPath * src)38 static void anp_copy(ANPPath* dst, const ANPPath* src) {
39     *dst = *src;
40 }
41 
anp_equal(const ANPPath * p0,const ANPPath * p1)42 static bool anp_equal(const ANPPath* p0, const ANPPath* p1) {
43     return *p0 == *p1;
44 }
45 
anp_reset(ANPPath * path)46 static void anp_reset(ANPPath* path) {
47     path->reset();
48 }
49 
anp_isEmpty(const ANPPath * path)50 static bool anp_isEmpty(const ANPPath* path) {
51     return path->isEmpty();
52 }
53 
anp_getBounds(const ANPPath * path,ANPRectF * bounds)54 static void anp_getBounds(const ANPPath* path, ANPRectF* bounds) {
55     SkANP::SetRect(bounds, path->getBounds());
56 }
57 
anp_moveTo(ANPPath * path,float x,float y)58 static void anp_moveTo(ANPPath* path, float x, float y) {
59     path->moveTo(SkFloatToScalar(x), SkFloatToScalar(y));
60 }
61 
anp_lineTo(ANPPath * path,float x,float y)62 static void anp_lineTo(ANPPath* path, float x, float y) {
63     path->lineTo(SkFloatToScalar(x), SkFloatToScalar(y));
64 }
65 
anp_quadTo(ANPPath * path,float x0,float y0,float x1,float y1)66 static void anp_quadTo(ANPPath* path, float x0, float y0, float x1, float y1) {
67     path->quadTo(SkFloatToScalar(x0), SkFloatToScalar(y0),
68                  SkFloatToScalar(x1), SkFloatToScalar(y1));
69 }
70 
anp_cubicTo(ANPPath * path,float x0,float y0,float x1,float y1,float x2,float y2)71 static void anp_cubicTo(ANPPath* path, float x0, float y0,
72                         float x1, float y1, float x2, float y2) {
73     path->cubicTo(SkFloatToScalar(x0), SkFloatToScalar(y0),
74                   SkFloatToScalar(x1), SkFloatToScalar(y1),
75                   SkFloatToScalar(x2), SkFloatToScalar(y2));
76 }
77 
anp_close(ANPPath * path)78 static void anp_close(ANPPath* path) {
79     path->close();
80 }
81 
anp_offset(ANPPath * path,float dx,float dy,ANPPath * dst)82 static void anp_offset(ANPPath* path, float dx, float dy, ANPPath* dst) {
83     path->offset(SkFloatToScalar(dx), SkFloatToScalar(dy), dst);
84 }
85 
anp_transform(ANPPath * src,const ANPMatrix * matrix,ANPPath * dst)86 static void anp_transform(ANPPath* src, const ANPMatrix* matrix,
87                           ANPPath* dst) {
88     src->transform(*matrix, dst);
89 }
90 
91 ///////////////////////////////////////////////////////////////////////////////
92 
93 #define ASSIGN(obj, name)   (obj)->name = anp_##name
94 
ANPPathInterfaceV0_Init(ANPInterface * value)95 void ANPPathInterfaceV0_Init(ANPInterface* value) {
96     ANPPathInterfaceV0* i = reinterpret_cast<ANPPathInterfaceV0*>(value);
97 
98     ASSIGN(i, newPath);
99     ASSIGN(i, deletePath);
100     ASSIGN(i, copy);
101     ASSIGN(i, equal);
102     ASSIGN(i, reset);
103     ASSIGN(i, isEmpty);
104     ASSIGN(i, getBounds);
105     ASSIGN(i, moveTo);
106     ASSIGN(i, lineTo);
107     ASSIGN(i, quadTo);
108     ASSIGN(i, cubicTo);
109     ASSIGN(i, close);
110     ASSIGN(i, offset);
111     ASSIGN(i, transform);
112 }
113