-
Notifications
You must be signed in to change notification settings - Fork 4
/
HACKING
110 lines (82 loc) · 4.04 KB
/
HACKING
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Adding New Tests
================
Tests are easy to add. Decide a name for the test, then implement these
three routines in cairo-tests/${name}.cpp:
* ca_setup_${name}
* ca_teardown_${name}
* ca_test_${name}
The setup routine is executed just once, before the main iterations
begin. For tests that are directly measuring low level drawing
operations, you may not have much - if any - setup. But you could use
this for one-time setup or precalculations that would be expensive to do
in the test proper and that shouldn't be charged against performance.
Now reimplement the same test for skia (and any other drawing
libraries), with the same three routines but prefixed with sk_*.
Adding New Rendering Backends
=============================
Tasks for adding another backend:
* cairo-[backend].cpp - surface creation/update/destruction
* skia-[backend].cpp - surface creation/update/destruction
* [backend].cpp - shared code for both of the above
* caskbench-context.cpp - register your backend
* caskbench.cpp - add command line options you need
Adding New Drawing Library Backends
===================================
Adding a new drawing library is a bit more involved:
* config.h.cmake
* CMakeScripts/Modules/FindXxx.cmake
* CMakeLists.txt - add library to build system
* caskbench.cpp - add command line options, etc.
* caskbench_context.* - register your drawing library
* [drawlib]-[backend].cpp - surface creation/update/deletion
* [drawlib]-shapes.* - implement shape drawing
* [drawlib]-utils.cpp - misc. routines
* [drawlib]-tests/*.cpp - reimplement all tests
Start by adding your library to the build system via the cmake files.
The FindXxx.cmake module searches through lists of paths where your
drawing library might be, and figures out the XXX_LIBRARIES path and
XXX_INCLUDE_DIR. It should set XXX_FOUND to "YES" if the library was
detected. Use the cairo and skia modules as examples. Now add a USE_XXX
for your library to config.h.cmake, and then register your library in
CMakeLists.txt - you can basically just copy the logic for cairo. Run
cmake and verify things get detected correctly.
With the actual coding, the easiest place to start is probably the
command line arguments in caskbench.cpp. Add your library to
print_drawing_libs_available() and update process_drawing_libs() to
check for your drawing library's name. You should now be able to invoke
caskbench with your drawing library specified, and it'll bail out when
it can't find the matching tests.
We can go ahead and stub in all the tests at this point. Create a
directory src/xxx-tests/ and add the following code to line.cpp:
#include <config.h>
int xx_setup_line() { return 1; }
void xx_teardown_line() { }
int xx_test_line { return 1; }
Copy this file to all the other tests, substituting the test name for
'line' in the filename and the above three lines.
Then in the generate_tests bash script, add code to write the
declarations for these tests, and to set up the perf_tests data
structure. To test this part is working, run:
$ src/generate_tests src/ /dev/stdout
Now go back to caskbench.cpp and extend populate_user_tests() with your
drawing library.
Next, enable your new drawing library in caskbench_context.cpp by adding
definitions for these routines:
context_setup_xxx()
context_destroy_xxx()
context_update_xxx()
These three routines are called indirectly from caskbench.cpp's main
routine; it will probably help to review the DESIGN document to learn
how all these bits interoperate. As you implement these three routines,
you'll add your own xxx-egl.cpp and xxx-image.cpp with your
backend-specific code. Use cairo-egl.cpp and cairo-image.cpp as
examples.
Also add these two routines to xxx-util.cpp:
[Maybe all the drawing lib context routines should be moved to -utils?]
context_clear_xxx()
write_image_file_xxx()
Now you're ready to create a shapes library, xxx-shapes.cpp. This
should be a pretty paint-by-numbers reimplementing of the cairo or
skia shape library.
Finally, go through and fill in all the tests. This should also be
pretty straightforward.