OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 if (main_surface_ != NULL) { | 67 if (main_surface_ != NULL) { |
68 cairo_surface_destroy(main_surface_); | 68 cairo_surface_destroy(main_surface_); |
69 main_surface_= NULL; | 69 main_surface_= NULL; |
70 } | 70 } |
71 | 71 |
72 display_ = NULL; | 72 display_ = NULL; |
73 } | 73 } |
74 | 74 |
75 void RendererCairo::Paint() { | 75 void RendererCairo::Paint() { |
76 DLOG(INFO) << "To paint"; | |
77 cairo_t* current_drawing = cairo_create(main_surface_); | 76 cairo_t* current_drawing = cairo_create(main_surface_); |
78 | 77 |
79 // Paint the background. | 78 // Paint the background. |
80 PaintBackground(current_drawing); | 79 PaintBackground(current_drawing); |
81 | 80 |
82 // Core process of painting. | 81 // Core process of painting. |
83 for (LayerRefList::iterator i = layer_list_.begin(); | 82 for (LayerRefList::iterator i = layer_list_.begin(); |
84 i != layer_list_.end(); i++) { | 83 i != layer_list_.end(); i++) { |
85 // Put the state with no mask to the stack. | 84 // Put the state with no mask to the stack. |
86 cairo_save(current_drawing); | 85 cairo_save(current_drawing); |
87 | 86 |
88 // Preparing and updating the Layer. | 87 // Preparing and updating the Layer. |
89 Layer* cur = *i; | 88 Layer* cur = *i; |
90 TextureCairo* cur_texture = cur->GetTexture(); | 89 Pattern* pattern = cur->pattern(); |
91 | 90 if (!pattern) { |
92 if (!cur_texture) { | 91 // Skip layers with no pattern assigned. |
93 // Skip layers with no texture assigned. | |
94 continue; | 92 continue; |
95 } | 93 } |
96 | 94 |
97 // Masking areas for other scene. | 95 // Masking areas for other scene. |
98 LayerRefList::iterator start_mask_it = i; | 96 LayerRefList::iterator start_mask_it = i; |
99 start_mask_it++; | 97 start_mask_it++; |
100 MaskArea(current_drawing, start_mask_it); | 98 MaskArea(current_drawing, start_mask_it); |
101 | 99 |
102 // Preparing the image to render. | 100 cairo_translate(current_drawing, cur->x(), cur->y()); |
103 cairo_surface_t* image = cur_texture->image_surface(); | |
104 | 101 |
105 // Scale the image. | 102 cairo_scale(current_drawing, cur->scale_x(), cur->scale_y()); |
106 double width_scaling = | |
107 (static_cast<double>(cur->GetScaleX())) / cur_texture->width(); | |
108 double height_scaling = | |
109 (static_cast<double>(cur->GetScaleY())) / cur_texture->height(); | |
110 | |
111 cairo_scale(current_drawing, width_scaling, height_scaling); | |
112 | 103 |
113 // Painting the image to the surface. | 104 // Painting the image to the surface. |
114 cairo_set_source_surface(current_drawing, image, | 105 cairo_set_source(current_drawing, pattern->pattern()); |
115 cur->GetTranslateX() / width_scaling, | |
116 cur->GetTranslateY() / height_scaling); | |
117 | 106 |
118 cairo_paint_with_alpha(current_drawing, cur->GetAlpha()); | 107 cairo_paint_with_alpha(current_drawing, cur->alpha()); |
119 | 108 |
120 // Restore to the state with no mask. | 109 // Restore to the state with no mask. |
121 cairo_restore(current_drawing); | 110 cairo_restore(current_drawing); |
122 } | 111 } |
123 cairo_destroy(current_drawing); | 112 cairo_destroy(current_drawing); |
124 } | 113 } |
125 | 114 |
126 void RendererCairo::PaintBackground(cairo_t* cr) { | 115 void RendererCairo::PaintBackground(cairo_t* cr) { |
127 cairo_save(cr); | 116 cairo_save(cr); |
128 MaskArea(cr, layer_list_.begin()); | 117 MaskArea(cr, layer_list_.begin()); |
129 | 118 |
130 cairo_rectangle(cr, 0, 0, display_width(), display_height()); | 119 cairo_rectangle(cr, 0, 0, display_width(), display_height()); |
131 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); | 120 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
132 cairo_fill(cr); | 121 cairo_fill(cr); |
133 cairo_restore(cr); | 122 cairo_restore(cr); |
134 } | 123 } |
135 | 124 |
136 void RendererCairo::MaskArea(cairo_t* cr, LayerRefList::iterator it) { | 125 void RendererCairo::MaskArea(cairo_t* cr, LayerRefList::iterator it) { |
137 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); | 126 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); |
138 | 127 |
139 for (LayerRefList::iterator i = it; i != layer_list_.end(); i++) { | 128 for (LayerRefList::iterator i = it; i != layer_list_.end(); i++) { |
140 // Preparing and updating the Layer. | 129 // Preparing and updating the Layer. |
141 Layer* cur_mask = *i; | 130 Layer* cur_mask = *i; |
142 | 131 |
143 cairo_rectangle(cr, 0, 0, display_width(), display_height()); | 132 cairo_rectangle(cr, 0, 0, display_width(), display_height()); |
144 cairo_rectangle(cr, | 133 cairo_rectangle(cr, |
145 cur_mask->GetTranslateX(), | 134 cur_mask->x(), |
146 cur_mask->GetTranslateY(), | 135 cur_mask->y(), |
147 static_cast<double>(cur_mask->GetScaleX()), | 136 cur_mask->width(), |
148 static_cast<double>(cur_mask->GetScaleY())); | 137 cur_mask->height()); |
149 cairo_clip(cr); | 138 cairo_clip(cr); |
150 } | 139 } |
151 } | 140 } |
152 | 141 |
153 void RendererCairo::AddLayer(Layer* image) { | 142 void RendererCairo::AddLayer(Layer* image) { |
154 layer_list_.push_front(Layer::Ref(image)); | 143 layer_list_.push_front(Layer::Ref(image)); |
155 } | 144 } |
156 | 145 |
157 void RendererCairo::InitCommon() { | 146 void RendererCairo::InitCommon() { |
158 main_surface_ = cairo_xlib_surface_create(display_, window_, | 147 main_surface_ = cairo_xlib_surface_create(display_, window_, |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 NOTIMPLEMENTED(); | 412 NOTIMPLEMENTED(); |
424 } | 413 } |
425 | 414 |
426 void RendererCairo::PopRenderStates() { | 415 void RendererCairo::PopRenderStates() { |
427 NOTIMPLEMENTED(); | 416 NOTIMPLEMENTED(); |
428 } | 417 } |
429 | 418 |
430 } // namespace o2d | 419 } // namespace o2d |
431 | 420 |
432 } // namespace o3d | 421 } // namespace o3d |
OLD | NEW |