|
2 | 2 |
|
3 | 3 |
|
4 | 4 | Backend::Backend(string name, int width, int height)
|
5 |
| - : name(name) |
6 |
| - , width(width) |
7 |
| - , height(height) |
8 |
| - , surface(NULL) |
9 |
| - , canvas(NULL) |
10 |
| - , _closure(NULL) |
| 5 | + : name(name) |
| 6 | + , width(width) |
| 7 | + , height(height) |
| 8 | + , surface(NULL) |
| 9 | + , canvas(NULL) |
| 10 | + , _closure(NULL) |
11 | 11 | {}
|
12 | 12 |
|
13 | 13 | Backend::~Backend()
|
14 | 14 | {
|
15 |
| - this->destroySurface(); |
| 15 | + this->destroySurface(); |
16 | 16 | }
|
17 | 17 |
|
18 | 18 |
|
19 | 19 | void Backend::setCanvas(Canvas* _canvas)
|
20 | 20 | {
|
21 |
| - this->canvas = _canvas; |
| 21 | + this->canvas = _canvas; |
22 | 22 | }
|
23 | 23 |
|
24 | 24 |
|
25 | 25 | cairo_surface_t* Backend::recreateSurface()
|
26 | 26 | {
|
27 |
| - this->destroySurface(); |
| 27 | + this->destroySurface(); |
28 | 28 |
|
29 |
| - return this->createSurface(); |
| 29 | + return this->createSurface(); |
30 | 30 | }
|
31 | 31 |
|
32 | 32 | cairo_surface_t* Backend::getSurface() {
|
33 |
| - if (!surface) createSurface(); |
34 |
| - return surface; |
| 33 | + if (!surface) createSurface(); |
| 34 | + return surface; |
35 | 35 | }
|
36 | 36 |
|
37 | 37 | void Backend::destroySurface()
|
38 | 38 | {
|
39 |
| - if(this->surface) |
40 |
| - { |
41 |
| - cairo_surface_destroy(this->surface); |
42 |
| - this->surface = NULL; |
43 |
| - } |
| 39 | + if(this->surface) |
| 40 | + { |
| 41 | + cairo_surface_destroy(this->surface); |
| 42 | + this->surface = NULL; |
| 43 | + } |
44 | 44 | }
|
45 | 45 |
|
46 | 46 |
|
47 | 47 | string Backend::getName()
|
48 | 48 | {
|
49 |
| - return name; |
| 49 | + return name; |
50 | 50 | }
|
51 | 51 |
|
52 | 52 | int Backend::getWidth()
|
53 | 53 | {
|
54 |
| - return this->width; |
| 54 | + return this->width; |
55 | 55 | }
|
56 | 56 | void Backend::setWidth(int width_)
|
57 | 57 | {
|
58 |
| - this->width = width_; |
59 |
| - this->recreateSurface(); |
| 58 | + this->width = width_; |
| 59 | + this->recreateSurface(); |
60 | 60 | }
|
61 | 61 |
|
62 | 62 | int Backend::getHeight()
|
63 | 63 | {
|
64 |
| - return this->height; |
| 64 | + return this->height; |
65 | 65 | }
|
66 | 66 | void Backend::setHeight(int height_)
|
67 | 67 | {
|
68 |
| - this->height = height_; |
69 |
| - this->recreateSurface(); |
| 68 | + this->height = height_; |
| 69 | + this->recreateSurface(); |
| 70 | +} |
| 71 | + |
| 72 | +bool Backend::isSurfaceValid(){ |
| 73 | + bool hadSurface = surface != NULL; |
| 74 | + bool isValid = true; |
| 75 | + |
| 76 | + cairo_status_t status = cairo_surface_status(getSurface()); |
| 77 | + |
| 78 | + if (status != CAIRO_STATUS_SUCCESS) { |
| 79 | + error = cairo_status_to_string(status); |
| 80 | + isValid = false; |
| 81 | + } |
| 82 | + |
| 83 | + if (!hadSurface) |
| 84 | + destroySurface(); |
| 85 | + |
| 86 | + return isValid; |
70 | 87 | }
|
71 | 88 |
|
72 | 89 |
|
73 | 90 | BackendOperationNotAvailable::BackendOperationNotAvailable(Backend* backend,
|
74 |
| - string operation_name) |
75 |
| - : backend(backend) |
76 |
| - , operation_name(operation_name) |
| 91 | + string operation_name) |
| 92 | + : backend(backend) |
| 93 | + , operation_name(operation_name) |
77 | 94 | {};
|
78 | 95 |
|
79 | 96 | BackendOperationNotAvailable::~BackendOperationNotAvailable() throw() {};
|
80 | 97 |
|
81 | 98 | const char* BackendOperationNotAvailable::what() const throw()
|
82 | 99 | {
|
83 |
| - std::ostringstream o; |
| 100 | + std::ostringstream o; |
84 | 101 |
|
85 |
| - o << "operation " << this->operation_name; |
86 |
| - o << " not supported by backend " + backend->getName(); |
| 102 | + o << "operation " << this->operation_name; |
| 103 | + o << " not supported by backend " + backend->getName(); |
87 | 104 |
|
88 |
| - return o.str().c_str(); |
| 105 | + return o.str().c_str(); |
89 | 106 | };
|
0 commit comments