annotate src/graph_engine_skia.cpp @ 1535:9aff42a7e2b9 tip

Fix issue of add/remove a frame at a scene before all key frames of a layer. When you added or removed a frame at a scene before all key frames of a layer, frameline was not updated correctly. It seems nothing happened, but domview is updated. This changeset fix this issue by correcting logic for boundary case.
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 30 Sep 2011 22:07:28 +0800
parents 74635b07a83a
children
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
2 // vim: sw=4:ts=8:sts=4
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
3 /*! \page ge_layer Graphic Engine Layer
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
4 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
5 * Graphic Engine Layer is an abstract of graphic engine; likes Cairo
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
6 * and Skia. It provides portability for the rest of MadButterfly.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
7 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
8 * The basic stratage of interface of graphic engine layer is defined
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
9 * according purpose of MadButterfly. For example, MadButterfly wants
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
10 * a function that can clear a canvas, we define a clear function.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
11 * Never define a indirectly way to finish the function. Never define
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
12 * a way to finish the function for the reason that some engine
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
13 * require you to finish the task in that procedure. It avoids
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
14 * binding graphic engine layer with any behavior of a graphic engine,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
15 * and provides more compatible with other engines, to define
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
16 * interface of graphic engine layer according purpose of
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
17 * MadButterfly.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
18 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
19 * \section ge_mem Graphic Engine Layer Memory Management
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
20 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
21 * MadButterfly is responsible for management of objects and memory
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
22 * blocks returned by graphic engine layer, even for graphic engines
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
23 * that have management model. MadButterfly supposes memory blocks
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
24 * only be released when they are no more used. MadBufferfly is
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
25 * responsible for release them. So, even a graphic engine has
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
26 * reference count with objects, MadButterfly still keep a reference
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
27 * for every object returned by the engine until no one will use it.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
28 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
29 * \section ge_transform Transformation of Coordination System
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
30 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
31 * Points of pathes are transformed when it is added to the canvas
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
32 * with the transformation matrix at the time. So, changes of
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
33 * transformation matrix of an canvas will not affect points that had
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
34 * been added. It only affects points been added when the matrix is
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
35 * setted.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
36 */
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
37 #include <stdio.h>
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
38 #include <stdlib.h>
479
9a867333018b mbe_create() and mbe_destroy() pass the compilation.
Thinker K.F. Li <thinker@branda.to>
parents: 473
diff changeset
39 #include <SkCanvas.h>
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
40 #include <SkBitmap.h>
495
9e36e06fcc18 Include SkRegion.h for graph_engine_skia.cpp
Thinker K.F. Li <thinker@branda.to>
parents: 483
diff changeset
41 #include <SkRegion.h>
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
42 #include <SkShader.h>
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
43 #include <SkDevice.h>
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
44 #include <SkGradientShader.h>
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
45 #include <SkXfermode.h>
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
46 #include <SkColorFilter.h>
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
47
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
48 #define C_START extern "C" {
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
49 #define C_END }
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
50
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
51 C_START
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
52
468
ae784a86ba82 C++ instead of C to bridge to Skia
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 #include "mb_graph_engine_skia.h"
ae784a86ba82 C++ instead of C to bridge to Skia
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 #include "mb_shapes.h"
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
55 #include "mb_img_ldr.h"
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
56
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
57 /*! \brief Source pattern
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
58 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
59 * For Skia, source pattern is SkShader with some decoration. Since
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
60 * SkShade will repeative tiling or extenting edge color, it can not
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
61 * stop tiling and extenting for fixed size bitmap. So, we need to
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
62 * translate mbe_paint() into a drawing of a rectangle.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
63 */
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
64 struct _mbe_pattern_t {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
65 SkShader *shader;
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
66 SkBitmap *bitmap;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
67 int w, h;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
68 int has_size;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
69 co_aix matrix[6];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
70 };
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
71
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
72 struct _mbe_scaled_font_t {
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
73 struct _mb_font_face_t *face;
473
ba64f928542b Remove mbe_matrix_t type.
Thinker K.F. Li <thinker@branda.to>
parents: 472
diff changeset
74 co_aix fnt_mtx[6];
ba64f928542b Remove mbe_matrix_t type.
Thinker K.F. Li <thinker@branda.to>
parents: 472
diff changeset
75 co_aix ctm[6];
479
9a867333018b mbe_create() and mbe_destroy() pass the compilation.
Thinker K.F. Li <thinker@branda.to>
parents: 473
diff changeset
76 };
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
77 struct _mbe_font_face_t {};
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
78 /*! \brief MadButterfly Graphic Engine Context.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
79 *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
80 * A context comprises source pattern, target surface, path,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
81 * line-width, and transform matrix.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
82 */
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
83 struct _mbe_t {
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
84 SkCanvas *canvas;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
85 SkPath *path, *subpath;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
86 SkPaint *paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
87 SkRegion *saved_region;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
88
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
89 struct _mbe_states_t *states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
90 };
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
91
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
92 struct _mbe_states_t {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
93 mbe_pattern_t *ptn;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
94 int ptn_owned;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
95 co_aix line_width;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
96 co_aix matrix[6];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
97 struct _mbe_states_t *next;
469
4dc0be6c044a Add copy and clear graphic engine functions.
Thinker K.F. Li <thinker@branda.to>
parents: 468
diff changeset
98 };
468
ae784a86ba82 C++ instead of C to bridge to Skia
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99
ae784a86ba82 C++ instead of C to bridge to Skia
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 #ifndef ASSERT
ae784a86ba82 C++ instead of C to bridge to Skia
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 #define ASSERT(x)
ae784a86ba82 C++ instead of C to bridge to Skia
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 #endif
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
103
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
104 #define PI 3.1415926535897931
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
105
483
d984a6672be7 Fix bug of translate between co_aix and SkScalar.
Thinker K.F. Li <thinker@branda.to>
parents: 482
diff changeset
106 #define CO_AIX_2_SKSCALAR(a) ((SkScalar)a)
d984a6672be7 Fix bug of translate between co_aix and SkScalar.
Thinker K.F. Li <thinker@branda.to>
parents: 482
diff changeset
107 #define SKSCALAR_2_CO_AIX(a) ((co_aix)(a))
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
108 #define MB_MATRIX_2_SKMATRIX(sk, mb) { \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
109 (sk).setScaleX(CO_AIX_2_SKSCALAR((mb)[0])); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
110 (sk).setSkewX(CO_AIX_2_SKSCALAR((mb)[1])); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
111 (sk).setTranslateX(CO_AIX_2_SKSCALAR((mb)[2])); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
112 (sk).setSkewY(CO_AIX_2_SKSCALAR((mb)[3])); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
113 (sk).setScaleY(CO_AIX_2_SKSCALAR((mb)[4])); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
114 (sk).setTranslateY(CO_AIX_2_SKSCALAR((mb)[5])); \
514
663d361eb3b8 Set perspective of 3x3 matrix when translate MB matrix to SkMatrix.
Thinker K.F. Li <thinker@branda.to>
parents: 513
diff changeset
115 (sk).setPerspX(0); \
663d361eb3b8 Set perspective of 3x3 matrix when translate MB matrix to SkMatrix.
Thinker K.F. Li <thinker@branda.to>
parents: 513
diff changeset
116 (sk).setPerspY(0); \
663d361eb3b8 Set perspective of 3x3 matrix when translate MB matrix to SkMatrix.
Thinker K.F. Li <thinker@branda.to>
parents: 513
diff changeset
117 (sk).set(SkMatrix::kMPersp2, 1); \
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
118 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
119 #define SKMATRIX_2_MB_MATRIX(mb, sk) { \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
120 (mb)[0] = SKSCALAR_2_CO_AIX((sk).getScaleX()); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
121 (mb)[1] = SKSCALAR_2_CO_AIX((sk).getSkewX()); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
122 (mb)[2] = SKSCALAR_2_CO_AIX((sk).getTranslateX()); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
123 (mb)[3] = SKSCALAR_2_CO_AIX((sk).getSkewY()); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
124 (mb)[4] = SKSCALAR_2_CO_AIX((sk).getScaleY()); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
125 (mb)[5] = SKSCALAR_2_CO_AIX((sk).getTranslateY()); \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
126 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
127 #define MBSTOP_2_SKCOLOR(c) \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
128 ((((int)((c)->a * 255)) << 24) | \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
129 (((int)((c)->r * 255)) << 16) | \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
130 (((int)((c)->g * 255)) << 8) | \
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
131 (((int)((c)->b * 255))))
508
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
132 #define MB_CO_COMP_2_SK(c) (((int)((c) * 255)) & 0xff)
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
133
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
134 static const co_aix id_matrix[6] = { 1, 0, 0, 0, 1, 0 };
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
135
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
136 static void
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
137 _prepare_sized_pattern(mbe_t *mbe, mbe_pattern_t *ptn) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
138 SkCanvas *canvas = mbe->canvas;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
139 SkPath path;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
140 co_aix x, y;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
141 co_aix reverse[6];
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
142
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
143 *mbe->saved_region = canvas->getTotalClip();
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
144
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
145 compute_reverse(ptn->matrix, reverse);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
146 x = 0; y = 0;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
147 matrix_trans_pos(reverse, &x, &y);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
148 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
149 x = 0; y = ptn->h;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
150 matrix_trans_pos(reverse, &x, &y);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
151 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
152 x = ptn->w; y = ptn->h;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
153 matrix_trans_pos(reverse, &x, &y);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
154 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
155 path.close();
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
156
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
157 canvas->clipPath(path, SkRegion::kIntersect_Op);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
158 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
159
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
160 static void
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
161 _finish_sized_pattern(mbe_t *mbe) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
162 SkCanvas *canvas = mbe->canvas;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
163
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
164 canvas->setClipRegion(*mbe->saved_region);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
165 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
166
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
167 static void
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
168 _canvas_device_region(SkCanvas *canvas, SkRegion *region) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
169 SkDevice *device;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
170 int w, h;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
171
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
172 device = canvas->getDevice();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
173 w = device->width();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
174 h = device->height();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
175 region->setRect(0, 0, w, h);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
176 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
177
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
178 static void
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
179 _update_path(mbe_t *mbe) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
180 SkPath *path = mbe->path;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
181 SkPath *subpath = mbe->subpath;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
182 SkMatrix canvas_matrix;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
183 SkPoint point;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
184
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
185 MB_MATRIX_2_SKMATRIX(canvas_matrix, mbe->states->matrix);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
186 path->addPath(*subpath, canvas_matrix);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
187
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
188 subpath->getLastPt(&point);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
189 subpath->rewind();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
190 subpath->moveTo(point);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
191 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
192
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
193 /*
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
194 * When a function want to use the paint associated with a canvas to
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
195 * draw, it should call _prepare_paint() can make the paint ready.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
196 * And, call _finish_paint() when the paint is no more used.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
197 */
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
198 static void
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
199 _prepare_paint(mbe_t *mbe, SkPaint::Style style) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
200 SkPaint *paint = mbe->paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
201 mbe_pattern_t *ptn = mbe->states->ptn;
511
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
202 SkShader *shader;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
203 co_aix matrix[6];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
204 SkMatrix skmatrix;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
205
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
206 paint->setStyle(style);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
207
511
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
208 if(ptn != NULL) {
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
209 /* Local matrix of SkShader is a mapping from source pattern to
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
210 * user space. Unlikely, for Cairo is a mapping from user space
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
211 * to source pattern.
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
212 */
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
213 shader = ptn->shader;
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
214 matrix_mul(mbe->states->matrix, ptn->matrix, matrix);
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
215 MB_MATRIX_2_SKMATRIX(skmatrix, matrix);
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
216 shader->setLocalMatrix(skmatrix);
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
217 paint->setShader(shader);
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
218 }
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
219
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
220 if(style == SkPaint::kStroke_Style)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
221 paint->setStrokeWidth(CO_AIX_2_SKSCALAR(mbe->states->line_width));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
222
511
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
223 if(ptn != NULL && ptn->has_size)
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
224 _prepare_sized_pattern(mbe, ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
225 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
226
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
227 static void
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
228 _finish_paint(mbe_t *mbe) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
229 mbe_pattern_t *ptn = mbe->states->ptn;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
230
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
231 mbe->paint->reset();
511
caa087976b17 Fix the issue of segmentation fault when the pattern of a mbe is not setted.
Thinker K.F. Li <thinker@branda.to>
parents: 508
diff changeset
232 if(ptn != NULL && ptn->has_size)
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
233 _finish_sized_pattern(mbe);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
234 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
235
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
236 mbe_pattern_t *mbe_pattern_create_for_surface(mbe_surface_t *surface) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
237 mbe_pattern_t *ptn;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
238 SkBitmap *bitmap = (SkBitmap *)surface;
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
239
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
240 ptn = (mbe_pattern_t *)malloc(sizeof(mbe_pattern_t));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
241 ptn->shader = SkShader::CreateBitmapShader(*bitmap,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
242 SkShader::kClamp_TileMode,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
243 SkShader::kClamp_TileMode);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
244 if(ptn->shader == NULL) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
245 free(ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
246 return NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
247 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
248
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
249 ptn->has_size = 1;
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
250 ptn->bitmap = NULL;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
251 ptn->w = bitmap->width();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
252 ptn->h = bitmap->height();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
253
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
254 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
255
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
256 return ptn;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
257 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
258
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
259 mbe_pattern_t *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
260 mbe_pattern_create_radial(co_aix cx0, co_aix cy0, co_aix radius0,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
261 co_aix cx1, co_aix cy1, co_aix radius1,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
262 grad_stop_t *stops, int stop_cnt) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
263 mbe_pattern_t *ptn;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
264 SkColor *colors;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
265 SkScalar *poses;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
266 grad_stop_t *stop;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
267 SkPoint center;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
268 int i;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
269
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
270 ptn = (mbe_pattern_t *)malloc(sizeof(mbe_pattern_t));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
271 colors = new SkColor[stop_cnt];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
272 poses = new SkScalar[stop_cnt];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
273 if(ptn == NULL || colors == NULL || poses == NULL)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
274 goto fail;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
275
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
276 center.set(CO_AIX_2_SKSCALAR(cx1), CO_AIX_2_SKSCALAR(cy1));
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
277
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
278 stop = stops;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
279 for(i = 0; i < stop_cnt; i++) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
280 colors[i] = MBSTOP_2_SKCOLOR(stop);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
281 poses[i] = CO_AIX_2_SKSCALAR(stop->offset);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
282 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
283
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
284 /*
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
285 * cx0, cy0 and radius0 is not used. Since Skia is still not
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
286 * support two circles radial. And, SVG 1.2 is also not support
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
287 * two circles.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
288 */
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
289 ptn->shader =
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
290 SkGradientShader::CreateRadial(center, CO_AIX_2_SKSCALAR(radius1),
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
291 colors, poses, stop_cnt,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
292 SkShader::kClamp_TileMode);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
293 if(ptn->shader == NULL)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
294 goto fail;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
295
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
296 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6);
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
297
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
298 ptn->bitmap = NULL;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
299
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
300 delete colors;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
301 delete poses;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
302 return ptn;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
303
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
304 fail:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
305 if(ptn) free(ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
306 if(colors) delete colors;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
307 if(poses) delete poses;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
308 return NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
309 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
310
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
311 mbe_pattern_t *
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
312 mbe_pattern_create_linear(co_aix x0, co_aix y0,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
313 co_aix x1, co_aix y1,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
314 grad_stop_t *stops, int stop_cnt) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
315 mbe_pattern_t *ptn;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
316 SkColor *colors;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
317 SkScalar *poses;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
318 grad_stop_t *stop;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
319 SkPoint points[2];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
320 int i;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
321
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
322 ptn = (mbe_pattern_t *)malloc(sizeof(mbe_pattern_t));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
323 colors = new SkColor[stop_cnt];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
324 poses = new SkScalar[stop_cnt];
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
325 if(ptn == NULL || colors == NULL || poses == NULL)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
326 goto fail;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
327
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
328 points[0].set(CO_AIX_2_SKSCALAR(x0), CO_AIX_2_SKSCALAR(y0));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
329 points[1].set(CO_AIX_2_SKSCALAR(x1), CO_AIX_2_SKSCALAR(y1));
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
330
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
331 stop = stops;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
332 for(i = 0; i < stop_cnt; i++) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
333 colors[i] = MBSTOP_2_SKCOLOR(stop);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
334 poses[i] = CO_AIX_2_SKSCALAR(stop->offset);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
335 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
336
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
337 /*
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
338 * cx0, cy0 and radius0 is not used. Since Skia is still not
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
339 * support two circles radial. And, SVG 1.2 is also not support
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
340 * two circles.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
341 */
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
342 ptn->shader =
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
343 SkGradientShader::CreateLinear(points, colors, poses, stop_cnt,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
344 SkShader::kClamp_TileMode);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
345 if(ptn->shader == NULL)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
346 goto fail;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
347
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
348 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
349
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
350 ptn->bitmap = NULL;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
351
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
352 delete colors;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
353 delete poses;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
354 return ptn;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
355
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
356 fail:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
357 if(ptn) free(ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
358 if(colors) delete colors;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
359 if(poses) delete poses;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
360 return NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
361 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
362
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
363 void mbe_pattern_set_matrix(mbe_pattern_t *ptn, const co_aix matrix[6]) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
364 SkMatrix skmatrix;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
365
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
366 MB_MATRIX_2_SKMATRIX(skmatrix, matrix);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
367
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
368 ptn->shader->setLocalMatrix(skmatrix);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
369 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
370
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
371 void mbe_pattern_destroy(mbe_pattern_t *ptn) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
372 if(ptn->shader)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
373 delete ptn->shader;
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
374 if(ptn->bitmap)
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
375 delete ptn->bitmap;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
376 free(ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
377 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
378
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
379 int mbe_image_surface_get_stride(mbe_surface_t *surface) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
380 return ((SkBitmap *)surface)->rowBytes();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
381 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
382
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
383 int mbe_image_surface_get_height(mbe_surface_t *surface) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
384 return ((SkBitmap *)surface)->height();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
385 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
386
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
387 int mbe_image_surface_get_width(mbe_surface_t *surface) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
388 return ((SkBitmap *)surface)->width();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
389 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
390
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
391 unsigned char *mbe_image_surface_get_data(mbe_surface_t *surface) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
392 return (unsigned char *)((SkBitmap *)surface)->getPixels();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
393 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
394
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
395 mbe_surface_t *mbe_image_surface_create_from_png(const char *filename) {}
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
396
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
397 static SkBitmap *
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
398 _mbe_bitmap_create_for_data(unsigned char *data, mb_img_fmt_t fmt,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
399 int width, int height, int stride) {
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
400 SkBitmap *bitmap;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
401 SkBitmap::Config cfg;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
402
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
403 switch(fmt) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
404 case MB_IFMT_ARGB32:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
405 cfg = SkBitmap::kARGB_8888_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
406
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
407 case MB_IFMT_A8:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
408 cfg = SkBitmap::kA8_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
409
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
410 case MB_IFMT_A1:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
411 cfg = SkBitmap::kA1_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
412
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
413 case MB_IFMT_RGB16_565:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
414 cfg = SkBitmap::kRGB_565_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
415
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
416 case MB_IFMT_RGB24:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
417 default:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
418 return NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
419 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
420
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
421 bitmap = new SkBitmap();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
422 if(bitmap == NULL)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
423 return NULL;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
424
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
425 bitmap->setConfig(cfg, width, height, stride);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
426 bitmap->setPixels(data);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
427
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
428 return bitmap;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
429 }
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
430
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
431 mbe_surface_t *
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
432 mbe_image_surface_create_for_data(unsigned char *data,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
433 mb_img_fmt_t fmt,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
434 int width, int height,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
435 int stride) {
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
436 SkBitmap *bitmap;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
437
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
438 bitmap = _mbe_bitmap_create_for_data(data, fmt, width, height, stride);
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
439 return (mbe_surface_t *)bitmap;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
440 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
441
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
442 mb_img_fmt_t mbe_image_surface_get_format(mbe_surface_t *surface) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
443 SkBitmap *bitmap = (SkBitmap *)surface;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
444 mb_img_fmt_t fmt;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
445 SkBitmap::Config cfg;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
446
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
447 cfg = bitmap->getConfig();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
448 switch(cfg) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
449 case SkBitmap::kARGB_8888_Config:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
450 fmt = MB_IFMT_ARGB32; break;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
451
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
452 case SkBitmap::kA8_Config:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
453 fmt = MB_IFMT_A8; break;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
454
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
455 case SkBitmap::kA1_Config:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
456 fmt = MB_IFMT_A1; break;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
457
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
458 case SkBitmap::kRGB_565_Config:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
459 fmt = MB_IFMT_RGB16_565; break;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
460
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
461 default:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
462 fmt = MB_IFMT_DUMMY;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
463 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
464
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
465 return fmt;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
466 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
467
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
468 mbe_surface_t *
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
469 mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
470 SkBitmap *bitmap;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
471 SkBitmap::Config cfg;
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
472
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
473 switch(fmt) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
474 case MB_IFMT_ARGB32:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
475 cfg = SkBitmap::kARGB_8888_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
476
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
477 case MB_IFMT_A8:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
478 cfg = SkBitmap::kA8_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
479
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
480 case MB_IFMT_A1:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
481 cfg = SkBitmap::kA1_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
482
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
483 case MB_IFMT_RGB16_565:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
484 cfg = SkBitmap::kRGB_565_Config; break;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
485
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
486 case MB_IFMT_RGB24:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
487 default:
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
488 return NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
489 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
490
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
491 bitmap = new SkBitmap();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
492 if(bitmap == NULL)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
493 return NULL;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
494
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
495 bitmap->setConfig(cfg, width, height);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
496 bitmap->allocPixels();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
497
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
498 return (mbe_surface_t *)bitmap;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
499 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
500
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
501 mbe_scaled_font_t *mbe_scaled_font_reference(mbe_scaled_font_t *scaled) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
502 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
503
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
504 void mbe_scaled_font_destroy(mbe_scaled_font_t *scaled) {}
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
505 mbe_font_face_t *mbe_font_face_reference(mbe_font_face_t *face) {}
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
506 mbe_scaled_font_t *
473
ba64f928542b Remove mbe_matrix_t type.
Thinker K.F. Li <thinker@branda.to>
parents: 472
diff changeset
507 mbe_scaled_font_create(mbe_font_face_t *face, co_aix fnt_mtx[6],
ba64f928542b Remove mbe_matrix_t type.
Thinker K.F. Li <thinker@branda.to>
parents: 472
diff changeset
508 co_aix ctm[6]) {}
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
509 mbe_scaled_font_t *mbe_get_scaled_font(mbe_t *canvas) {}
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
510 void mbe_scaled_font_text_extents(mbe_scaled_font_t *scaled,
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
511 const char *txt,
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
512 mbe_text_extents_t *extents) {}
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
513
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
514 void mbe_font_face_destroy(mbe_font_face_t *face) {}
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
515
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
516 void mbe_paint_with_alpha(mbe_t *canvas, co_aix alpha) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
517 SkPaint *paint = canvas->paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
518 SkColorFilter *filter;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
519 SkColor color;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
520
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
521 color = ((uint32_t)(alpha * 255)) << 24;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
522 filter =
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
523 SkColorFilter::CreateModeFilter(color,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
524 SkXfermode::kSrcOver_Mode);
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
525 mbe_paint(canvas);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
526
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
527 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
528
508
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
529 void mbe_surface_destroy(mbe_surface_t *surface) {
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
530 SkBitmap *bmap = (SkBitmap *)surface;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
531
508
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
532 delete bmap;
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
533 }
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
534
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
535 void mbe_set_source_rgba(mbe_t *canvas,
508
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
536 co_aix r, co_aix g, co_aix b, co_aix a) {
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
537 canvas->paint->setARGB(MB_CO_COMP_2_SK(a),
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
538 MB_CO_COMP_2_SK(r),
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
539 MB_CO_COMP_2_SK(g),
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
540 MB_CO_COMP_2_SK(b));
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
541 canvas->states->ptn = NULL;
508
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
542 }
b106fa78a090 Add functions of mbe_set_source_rgba() and mbe_surface_destroy().
Thinker K.F. Li <thinker@branda.to>
parents: 497
diff changeset
543
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
544 void mbe_set_scaled_font(mbe_t *canvas,
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
545 const mbe_scaled_font_t *scaled) {}
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
546 void mbe_set_source_rgb(mbe_t *canvas, co_aix r, co_aix g, co_aix b) {}
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
547
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
548 void mbe_set_line_width(mbe_t *canvas, co_aix width) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
549 canvas->states->line_width = width;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
550 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
551
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
552 mbe_font_face_t *mbe_get_font_face(mbe_t *canvas) {}
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
553
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
554 void mbe_fill_preserve(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
555 mbe_pattern_t *ptn = canvas->states->ptn;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
556 SkPaint *paint = canvas->paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
557 SkPath *path = canvas->path;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
558 SkRegion *saved_clip = NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
559 co_aix x, y;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
560
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
561 ASSERT(paint);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
562 ASSERT(ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
563 ASSERT(path);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
564
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
565 if(!canvas->subpath->isEmpty())
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
566 _update_path(canvas);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
567
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
568 _prepare_paint(canvas, SkPaint::kFill_Style);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
569
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
570 canvas->canvas->drawPath(*path, *paint);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
571
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
572 _finish_paint(canvas);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
573 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
574
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
575 void mbe_set_source(mbe_t *canvas, mbe_pattern_t *source) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
576 canvas->states->ptn = source;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
577 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
578
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
579 void mbe_reset_scissoring(mbe_t *canvas) {
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
580 SkRegion clip;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
581
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
582 _canvas_device_region(canvas->canvas, &clip);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
583 canvas->canvas->setClipRegion(clip);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
584 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
585
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
586 mbe_surface_t *mbe_get_target(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
587 return (mbe_surface_t *)&canvas->canvas->getDevice()->accessBitmap(false);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
588 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
589
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
590 void mbe_close_path(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
591 canvas->subpath->close();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
592 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
593
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
594 void mbe_text_path(mbe_t *canvas, const char *txt) {}
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
595
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
596 void mbe_rectangle(mbe_t *canvas, co_aix x, co_aix y,
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
597 co_aix width, co_aix height) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
598 SkPath *subpath = canvas->subpath;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
599
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
600 subpath->addRect(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y),
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
601 CO_AIX_2_SKSCALAR(x + width),
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
602 CO_AIX_2_SKSCALAR(y + height));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
603 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
604
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
605 int mbe_in_stroke(mbe_t *canvas, co_aix x, co_aix y) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
606 return 0;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
607 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
608
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
609 void mbe_new_path(mbe_t *canvas) {
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
610 canvas->subpath->rewind();
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
611 canvas->path->rewind();
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
612 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
613
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
614 void mbe_curve_to(mbe_t *canvas, co_aix x1, co_aix y1,
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
615 co_aix x2, co_aix y2,
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
616 co_aix x3, co_aix y3) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
617 SkPath *subpath = canvas->subpath;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
618
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
619 subpath->cubicTo(CO_AIX_2_SKSCALAR(x1), CO_AIX_2_SKSCALAR(y1),
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
620 CO_AIX_2_SKSCALAR(x2), CO_AIX_2_SKSCALAR(y2),
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
621 CO_AIX_2_SKSCALAR(x3), CO_AIX_2_SKSCALAR(y3));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
622 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
623
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
624 void mbe_restore(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
625 struct _mbe_states_t *states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
626
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
627 _update_path(canvas);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
628
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
629 states = canvas->states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
630 ASSERT(states->next);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
631 canvas->states = states->next;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
632 free(states);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
633 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
634
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
635 void mbe_move_to(mbe_t *canvas, co_aix x, co_aix y) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
636 canvas->subpath->moveTo(CO_AIX_2_SKSCALAR(x),
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
637 CO_AIX_2_SKSCALAR(y));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
638 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
639
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
640 void mbe_line_to(mbe_t *canvas, co_aix x, co_aix y) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
641 canvas->subpath->lineTo(CO_AIX_2_SKSCALAR(x),
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
642 CO_AIX_2_SKSCALAR(y));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
643 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
644
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
645 int mbe_in_fill(mbe_t *canvas, co_aix x, co_aix y) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
646 SkRegion region, dev_region;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
647 bool in_fill;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
648
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
649 if(!canvas->subpath->isEmpty())
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
650 _update_path(canvas);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
651
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
652 _canvas_device_region(canvas->canvas, &dev_region);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
653 region.setPath(*canvas->path, dev_region);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
654
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
655 in_fill = region.contains(x, y);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
656
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
657 return in_fill;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
658 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
659
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
660 void mbe_stroke(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
661 SkPath *path = canvas->path;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
662 SkPaint *paint = canvas->paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
663
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
664 ASSERT(ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
665 ASSERT(path);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
666 ASSERT(paint);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
667
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
668 if(!canvas->subpath->isEmpty())
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
669 _update_path(canvas);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
670
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
671 _prepare_paint(canvas, SkPaint::kStroke_Style);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
672
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
673 canvas->canvas->drawPath(*path, *paint);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
674
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
675 _finish_paint(canvas);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
676
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
677 path->rewind();
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
678 canvas->subpath->rewind();
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
679 }
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
680
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
681 /*! \brief Create a mbe from a SkCanvas.
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
682 *
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
683 * It is only used for Android JNI. It is used to create mbe_t from a
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
684 * SkCanvas created by Canvas class of Android Java application.
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
685 */
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
686 mbe_t *skia_mbe_create_by_canvas(SkCanvas *canvas) {
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
687 mbe_t *mbe;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
688 struct _mbe_states_t *states;
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
689
479
9a867333018b mbe_create() and mbe_destroy() pass the compilation.
Thinker K.F. Li <thinker@branda.to>
parents: 473
diff changeset
690 mbe = (mbe_t *)malloc(sizeof(mbe_t));
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
691 if(mbe == NULL)
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
692 return NULL;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
693
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
694 mbe->states = (struct _mbe_states_t *)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
695 malloc(sizeof(struct _mbe_states_t));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
696 states = mbe->states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
697 if(states == NULL) {
479
9a867333018b mbe_create() and mbe_destroy() pass the compilation.
Thinker K.F. Li <thinker@branda.to>
parents: 473
diff changeset
698 free(mbe);
9a867333018b mbe_create() and mbe_destroy() pass the compilation.
Thinker K.F. Li <thinker@branda.to>
parents: 473
diff changeset
699 return NULL;
9a867333018b mbe_create() and mbe_destroy() pass the compilation.
Thinker K.F. Li <thinker@branda.to>
parents: 473
diff changeset
700 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
701
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
702 canvas->ref();
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
703 mbe->canvas = canvas;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
704 mbe->path = new SkPath();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
705 mbe->subpath = new SkPath();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
706 mbe->saved_region = new SkRegion();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
707 mbe->paint = new SkPaint();
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
708 states->ptn = NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
709 states->ptn_owned = 0;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
710 states->line_width = 0;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
711 states->next = NULL;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
712
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
713 if(mbe->path == NULL ||
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
714 mbe->subpath == NULL || mbe->paint == NULL ||
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
715 mbe->saved_region == NULL)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
716 goto fail;
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
717
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
718 memcpy(states->matrix, id_matrix, sizeof(co_aix) * 6);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
719
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
720 return mbe;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
721
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
722 fail:
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
723 canvas->unref();
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
724 if(mbe->path) delete mbe->path;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
725 if(mbe->subpath) delete mbe->subpath;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
726 if(mbe->paint) delete mbe->paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
727 if(mbe->saved_region) delete mbe->saved_region;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
728 free(states);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
729 free(mbe);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
730
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
731 return NULL;
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
732 }
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
733
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
734 mbe_t *mbe_create(mbe_surface_t *target) {
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
735 mbe_t *mbe;
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
736 SkBitmap *bitmap = (SkBitmap *)target;
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
737 SkCanvas *canvas;
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
738
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
739 canvas = new SkCanvas(*bitmap);
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
740 if(canvas == NULL) {
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
741 delete bitmap;
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
742 return NULL;
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
743 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
744
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
745 mbe = skia_mbe_create_by_canvas(canvas);
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
746 canvas->unref();
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
747
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
748 if(mbe == NULL) {
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
749 delete bitmap;
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
750 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
751
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
752 return mbe;
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
753 }
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
754
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
755 void mbe_destroy(mbe_t *canvas) {
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
756 struct _mbe_states_t *states;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
757
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
758 canvas->canvas->unref();
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
759 delete canvas->path;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
760 delete canvas->subpath;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
761 delete canvas->paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
762 delete canvas->saved_region;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
763 while(canvas->states) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
764 states = canvas->states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
765 canvas->states = states->next;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
766
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
767 if(states->ptn && states->ptn_owned)
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
768 mbe_pattern_destroy(states->ptn);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
769 free(states);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
770 }
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
771 free(canvas);
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
772 }
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
773
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
774 void mbe_paint(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
775 SkPaint *paint = canvas->paint;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
776
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
777 ASSERT(paint);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
778
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
779 _prepare_paint(canvas, SkPaint::kFill_Style);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
780
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
781 canvas->canvas->drawPaint(*paint);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
782
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
783 _finish_paint(canvas);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
784 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
785
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
786 void mbe_save(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
787 struct _mbe_states_t *states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
788
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
789 states = (struct _mbe_states_t *)malloc(sizeof(struct _mbe_states_t));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
790 ASSERT(states);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
791
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
792 memcpy(states, canvas->states, sizeof(struct _mbe_states_t));
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
793 states->next = canvas->states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
794 canvas->states = states;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
795 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
796
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
797 void mbe_fill(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
798 mbe_fill_preserve(canvas);
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
799 canvas->path->rewind();
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
800 canvas->subpath->rewind();
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
801 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
802
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
803 void mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) {
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
804 SkRegion region;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
805 area_t *area;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
806 co_aix right, bottom;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
807 int i;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
808
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
809 for(i = 0; i < n_areas; i++) {
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
810 area = areas[i];
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
811 right = area->x + area->w;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
812 bottom = area->y + area->h;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
813 region.setRect(area->x, area->y, right, bottom);
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
814 canvas->canvas->clipRegion(region, SkRegion::kIntersect_Op);
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
815 }
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
816 }
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
817
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
818 void mbe_clip(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
819 if(!canvas->subpath->isEmpty())
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
820 _update_path(canvas);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
821
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
822 canvas->canvas->clipPath(*canvas->path, SkRegion::kIntersect_Op);
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
823 canvas->path->rewind();
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
824 canvas->subpath->rewind();
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
825 }
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
826
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
827 mbe_font_face_t * mbe_query_font_face(const char *family,
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
828 int slant, int weight) {}
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
829 void mbe_free_font_face(mbe_font_face_t *face) {}
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
830
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
831 mbe_pattern_t *mbe_pattern_create_image(mb_img_data_t *img) {
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
832 mbe_pattern_t *ptn;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
833 SkBitmap *bitmap;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
834
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
835 bitmap = _mbe_bitmap_create_for_data((unsigned char *)img->content,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
836 img->fmt,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
837 img->w, img->h, img->stride);
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
838 ptn = (mbe_pattern_t *)malloc(sizeof(mbe_pattern_t));
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
839 ptn->shader = SkShader::CreateBitmapShader(*bitmap,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
840 SkShader::kClamp_TileMode,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
841 SkShader::kClamp_TileMode);
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
842 if(ptn->shader == NULL) {
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
843 free(ptn);
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
844 delete bitmap;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
845 return NULL;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
846 }
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
847
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
848 ptn->has_size = 1;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
849 ptn->w = bitmap->width();
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
850 ptn->h = bitmap->height();
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
851 ptn->bitmap = NULL;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
852
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
853 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6);
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
854
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
855 return ptn;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
856 }
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
857
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
858 void mbe_clear(mbe_t *canvas) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
859 SkColor color = 0;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
860
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
861 canvas->canvas->drawColor(color, SkXfermode::kClear_Mode);
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
862 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
863
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
864 void mbe_copy_source(mbe_t *src, mbe_t *dst) {
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
865 SkPaint *paint = dst->paint;
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
866 const SkBitmap *bmap;
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
867 SkXfermode *mode;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
868
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
869 /* _prepare_paint(dst, SkPaint::kFill_Style); */
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
870 mode = SkXfermode::Create(SkXfermode::kSrc_Mode);
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
871 paint->setXfermode(mode);
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
872 bmap = &src->canvas->getDevice()->accessBitmap(false);
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
873
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
874 dst->canvas->drawBitmap(*bmap, 0, 0, paint);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
875
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
876 paint->reset();
512
d186d1e24458 Change prototype of mbe_copy_source().
Thinker K.F. Li <thinker@branda.to>
parents: 511
diff changeset
877 mode->unref();
513
6394a1e33b2f Rewind/reset path and subpath.
Thinker K.F. Li <thinker@branda.to>
parents: 512
diff changeset
878 /* _finish_paint(dst); */
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
879 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
880
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
881 void mbe_transform(mbe_t *mbe, co_aix matrix[6]) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
882 _update_path(mbe);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
883
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
884 matrix_mul(matrix, mbe->states->matrix, mbe->states->matrix);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
885 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
886
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
887 void mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius,
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
888 co_aix angle_start, co_aix angle_stop) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
889 SkPoint point;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
890 SkPath *subpath = mbe->subpath;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
891 SkRect rect;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
892 SkScalar x0, y0;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
893 SkScalar ang_start, ang_stop;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
894 SkScalar sweep;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
895 SkScalar r; /* radius */
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
896
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
897 subpath->getLastPt(&point);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
898 x0 = point.fX;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
899 y0 = point.fX;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
900 r = CO_AIX_2_SKSCALAR(radius);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
901 ang_start = CO_AIX_2_SKSCALAR(angle_start * 180 / PI);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
902 ang_stop = CO_AIX_2_SKSCALAR(angle_stop * 180 / PI);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
903
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
904 /* Skia can only draw an arc in clockwise directly. We negative
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
905 * start and stop point to draw the arc in the mirror along x-axis
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
906 * in a sub-path. Then, the sub-path are reflected along x-axis,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
907 * again. We get a right path, and add it to the path of mbe_t.
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
908 */
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
909 if(ang_start > ang_stop) {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
910 SkPath tmppath;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
911 SkMatrix matrix;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
912 co_aix reflect[6] = { 1, 0, 0,
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
913 0, -1, 0};
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 514
diff changeset
914
482
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
915 rect.set(-r, -r, r, r);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
916 sweep = ang_start - ang_stop;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
917 tmppath.arcTo(rect, -ang_start, sweep, false);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
918
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
919 reflect[2] = x;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
920 reflect[5] = y;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
921 MB_MATRIX_2_SKMATRIX(matrix, reflect);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
922 subpath->addPath(tmppath, matrix);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
923 } else {
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
924 rect.set(x0 - r, y0 - r, x0 + r, y0 + r);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
925 sweep = ang_stop - ang_start;
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
926 subpath->arcTo(rect, ang_start, sweep, false);
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
927 }
d38aca825822 Import more functions for Skia graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents: 479
diff changeset
928 }
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
929
1519
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
930 mbe_surface_t *
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
931 mbe_win_surface_create(void *display, void *drawable,
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
932 int fmt, int width, int height) {
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
933 fprintf(stderr, "%s:%d:mbe_win_surface_create: not implemented!\n",
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
934 __FILE__, __LINE__);
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
935 abort();
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
936 return NULL;
74635b07a83a Porting Skia backend to latest version and with X
Thinker K.F. Li <thinker@codemud.net>
parents: 1067
diff changeset
937 }
472
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
938
4254eaa699d0 Declare functions that should be implemented by Skia graphic engine
Thinker K.F. Li <thinker@branda.to>
parents: 469
diff changeset
939 C_END