Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1248)

Side by Side Diff: core/cross/cairo/renderer_cairo.cc

Issue 2825074: Initial version rendering 2D path for O3D. This will eventually allow O3D app... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/o3d/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « core/cross/cairo/renderer_cairo.h ('k') | core/cross/cairo/texture_cairo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 */ 30 */
31 31
32 // Renderer that is using 2D Library Cairo. 32 // Renderer that is using 2D Library Cairo.
33 33
34 #include "core/cross/cairo/renderer_cairo.h" 34 #include "core/cross/cairo/renderer_cairo.h"
35 #include <cairo-xlib.h> 35 #include <cairo-xlib.h>
36 #include <stdio.h> 36 #include <stdio.h>
37 #include <stdlib.h> 37 #include <stdlib.h>
38 #include <string.h> 38 #include <string.h>
39 #include "core/cross/cairo/texture_cairo.h" 39 #include "core/cross/cairo/texture_cairo.h"
40 #include "core/cross/cairo/image_2d.h"
40 41
41 namespace o3d { 42 namespace o3d {
42 43
43 Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) { 44 Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) {
44 return RendererCairo::CreateDefault(service_locator); 45 return RendererCairo::CreateDefault(service_locator);
45 } 46 }
46 47
47 RendererCairo::RendererCairo(ServiceLocator* service_locator) 48 RendererCairo::RendererCairo(ServiceLocator* service_locator)
48 : Renderer(service_locator), display_(NULL), window_(0), 49 : Renderer(service_locator), display_(NULL), main_surface_(NULL) {
49 main_surface_(NULL), frame_src_data_(NULL), frame_src_width_(0),
50 frame_src_height_(0), frame_src_pitch_(0) {
51 // Don't need to do anything. 50 // Don't need to do anything.
52 } 51 }
53 52
54 RendererCairo::~RendererCairo() { 53 RendererCairo::~RendererCairo() {
55 Destroy(); 54 Destroy();
56 } 55 }
57 56
58 RendererCairo* RendererCairo::CreateDefault(ServiceLocator* service_locator) { 57 RendererCairo* RendererCairo::CreateDefault(ServiceLocator* service_locator) {
59 return new RendererCairo(service_locator); 58 return new RendererCairo(service_locator);
60 } 59 }
61 60
62 // Released all hardware resources. 61 // Released all hardware resources.
63 void RendererCairo::Destroy() { 62 void RendererCairo::Destroy() {
64 DLOG(INFO) << "To Destroy"; 63 DLOG(INFO) << "To Destroy";
65 64
66 if (main_surface_ != NULL) { 65 if (main_surface_ != NULL) {
67 cairo_surface_destroy(main_surface_); 66 cairo_surface_destroy(main_surface_);
68 main_surface_= NULL; 67 main_surface_= NULL;
69 } 68 }
70 69
71 display_ = NULL; 70 display_ = NULL;
72 frame_src_data_ = NULL;
73 }
74
75 void RendererCairo::SetNewFrame(const void* src_data, unsigned src_width,
76 unsigned src_height, int src_pitch) {
77 DLOG(INFO) << "To Set New Frame";
78 if (src_data == NULL)
79 return;
80
81 frame_src_data_ = src_data;
82 frame_src_width_ = src_width;
83 frame_src_height_ = src_height;
84 frame_src_pitch_ = src_pitch;
85 } 71 }
86 72
87 // TODO(fransiskusx): Need to check if the shared memory data has been 73 // TODO(fransiskusx): Need to check if the shared memory data has been
88 // unregistered. It will prevent errors when accessing unregistered 74 // unregistered. It will prevent errors when accessing unregistered
89 // shared memory data to render the frame. 75 // shared memory data to render the frame.
90 void RendererCairo::Paint() { 76 void RendererCairo::Paint() {
91 DLOG(INFO) << "To paint"; 77 DLOG(INFO) << "To paint";
92 78
93 if (frame_src_data_ != NULL) { 79 cairo_t* current_drawing = cairo_create(main_surface_);
94 DLOG(INFO) << "To paint new drawing"; 80 cairo_save(current_drawing);
95 81
96 // Preparing the image to render 82 int arr_size = static_cast<int>(image_2d_array_.size());
83
84 // Update resource.
85 for (int i = arr_size-1; i >= 0; i--) {
86 Image2D* cur = image_2d_array_.at(i);
87 cur->updateTextureResource();
88 }
89
90 // Paint the background.
91 PaintBackGround(current_drawing);
92
93 // Core process of painting
94 for (int i = arr_size-1; i >= 0 ; i--) {
95 // Preparing and updating the image2d.
96 Image2D* cur = image_2d_array_.at(i);
97
98 // Check if the pointer to data is null.
99 if (cur->src_data_ == NULL) {
100 continue;
101 }
102
103 DLOG(INFO) << "INDEX = "<< i;
104
105 DLOG(INFO) << cur->src_width_ << ", " <<
106 cur->src_height_<< ", " << cur->src_pitch_ << ", " << cur->scale_x_ <<
107 ", " << cur->scale_y_ << ", " << cur->translate_x_<< ", " <<
108 cur->translate_y_<< ", " << cur->dest_x_<< ", " <<
109 cur->dest_y_<< ", " << cur->alpha_ << "v3.5.7";
110
111 MaskArea(current_drawing, i);
112
113 // Preparing the image to render.
97 cairo_surface_t* image = cairo_image_surface_create_for_data( 114 cairo_surface_t* image = cairo_image_surface_create_for_data(
98 const_cast<unsigned char*>( 115 const_cast<unsigned char*>(
99 static_cast<const unsigned char*>(frame_src_data_)), 116 static_cast<const unsigned char*>(cur->src_data_)),
100 CAIRO_FORMAT_ARGB32, frame_src_width_, 117 CAIRO_FORMAT_ARGB32, cur->src_width_,
101 frame_src_height_, frame_src_pitch_); 118 cur->src_height_, cur->src_pitch_);
102 cairo_t* current_drawing = cairo_create(main_surface_);
103 119
104 // Scaling the image 120 // Scale the image.
105 double width_scaling = 121 double width_scaling =
106 (static_cast<double>(display_width())) / frame_src_width_; 122 (static_cast<double>(cur->scale_x_)) / cur->src_width_;
107 double height_scaling = 123 double height_scaling =
108 (static_cast<double>(display_height())) / frame_src_height_; 124 (static_cast<double>(cur->scale_y_)) / cur->src_height_;
125
109 cairo_scale(current_drawing, width_scaling, height_scaling); 126 cairo_scale(current_drawing, width_scaling, height_scaling);
110 127
111 // Painting the image to the surface 128 // Painting the image to the surface.
112 cairo_set_source_surface(current_drawing, image, 0, 0); 129 cairo_set_source_surface(current_drawing, image,
113 cairo_paint(current_drawing); 130 (cur->dest_x_+cur->translate_x_)/width_scaling,
131 (cur->dest_y_+cur->translate_y_)/height_scaling);
114 132
115 // Cleaning up the memory 133 cairo_paint_with_alpha(current_drawing, cur->alpha_);
116 cairo_destroy(current_drawing); 134
135 // Cleaning up the memory.
117 cairo_surface_destroy(image); 136 cairo_surface_destroy(image);
137
138 // Restore to the state with no mask and put the state
139 // back in the save stack.
140 cairo_restore(current_drawing);
141 cairo_save(current_drawing);
118 } 142 }
143 cairo_destroy(current_drawing);
144 }
145
146 void RendererCairo::PaintBackGround(cairo_t* cr) {
147 cairo_save(cr);
148 MaskArea(cr, static_cast<int>(image_2d_array_.size()));
149
150 cairo_rectangle(cr, 0, 0, display_width(), display_height());
151 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
152 cairo_fill(cr);
153 cairo_restore(cr);
154 }
155
156 void RendererCairo::MaskArea(cairo_t* cr, int index) {
157 // Check if the given index is out of bound(too big) for the image2d array.
158 if (index > static_cast<int>(image_2d_array_.size())) {
159 return;
160 }
161
162 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
163
164 for (int j = index-1; j >= 0; j--) {
165 // Preparing and updating the image2d.
166 Image2D* curMask = image_2d_array_.at(j);
167
168 DLOG(INFO) << curMask->dest_x_+curMask->translate_x_ << ", " <<
169 curMask->dest_y_+curMask->translate_y_<< ", " <<
170 static_cast<double>(curMask->scale_x_) << ", " <<
171 static_cast<double>(curMask->scale_y_) << "index = " << j;
172
173 cairo_rectangle(cr, 0, 0, display_width(), display_height());
174 cairo_rectangle(cr,
175 curMask->dest_x_+curMask->translate_x_,
176 curMask->dest_y_+curMask->translate_y_,
177 static_cast<double>(curMask->scale_x_),
178 static_cast<double>(curMask->scale_y_));
179 cairo_clip(cr);
180 }
181 }
182
183 void RendererCairo::AddImage2D(Image2D* image) {
184 image_2d_array_.push_back(image);
119 } 185 }
120 186
121 void RendererCairo::InitCommon() { 187 void RendererCairo::InitCommon() {
122 main_surface_ = cairo_xlib_surface_create(display_, window_, 188 main_surface_ = cairo_xlib_surface_create(display_, window_,
123 XDefaultVisual(display_, 0), 189 XDefaultVisual(display_, 0),
124 display_width(), display_height()); 190 display_width(), display_height());
125 } 191 }
126 192
127 void RendererCairo::UninitCommon() { 193 void RendererCairo::UninitCommon() {
128 // Don't need to do anything. 194 // Don't need to do anything.
129 } 195 }
130 196
131 Renderer::InitStatus RendererCairo::InitPlatformSpecific( 197 Renderer::InitStatus RendererCairo::InitPlatformSpecific(
132 const DisplayWindow& display_window, 198 const DisplayWindow& display_window,
133 bool off_screen) { 199 bool off_screen) {
134 const DisplayWindowLinux &display_platform = 200 const DisplayWindowLinux &display_platform =
135 static_cast<const DisplayWindowLinux&>(display_window); 201 static_cast<const DisplayWindowLinux&>(display_window);
136 display_ = display_platform.display(); 202 display_ = display_platform.display();
137 window_ = display_platform.window(); 203 window_ = display_platform.window();
138 204
139 return SUCCESS; 205 return SUCCESS;
140 } 206 }
141 207
142 // Handles the plugin resize event. 208 // Handles the plugin resize event.
143 void RendererCairo::Resize(int width, int height) { 209 void RendererCairo::Resize(int width, int height) {
144 DLOG(INFO) << "To Resize " << width << " x " << height; 210 DLOG(INFO) << "To Resize " << width << " x " << height;
145 SetClientSize(width, height); 211 SetClientSize(width, height);
146 212
147 // Resize the mainSurface 213 // Resize the mainSurface and buffer
148 cairo_xlib_surface_set_size(main_surface_, width, height); 214 cairo_xlib_surface_set_size(main_surface_, width, height);
149 } 215 }
150 216
151 // The platform specific part of BeginDraw. 217 // The platform specific part of BeginDraw.
152 bool RendererCairo::PlatformSpecificBeginDraw() { 218 bool RendererCairo::PlatformSpecificBeginDraw() {
153 return true; 219 return true;
154 } 220 }
155 221
156 // Platform specific version of CreateTexture2D 222 // Platform specific version of CreateTexture2D
157 Texture2D::Ref RendererCairo::CreatePlatformSpecificTexture2D( 223 Texture2D::Ref RendererCairo::CreatePlatformSpecificTexture2D(
(...skipping 24 matching lines...) Expand all
182 void RendererCairo::PlatformSpecificFinishRendering() { 248 void RendererCairo::PlatformSpecificFinishRendering() {
183 Paint(); 249 Paint();
184 } 250 }
185 251
186 // The platform specific part of Present. 252 // The platform specific part of Present.
187 void RendererCairo::PlatformSpecificPresent() { 253 void RendererCairo::PlatformSpecificPresent() {
188 // Don't need to do anything. 254 // Don't need to do anything.
189 } 255 }
190 256
191 // TODO(fransiskusx): DO need to implement before shipped. 257 // TODO(fransiskusx): DO need to implement before shipped.
258 // Removes the Image2D from the array.
259 void RendererCairo::RemoveImage2D(Image2D* image) {
260 NOTIMPLEMENTED();
261 }
262
263 // TODO(fransiskusx): DO need to implement before shipped.
192 // Get a single fullscreen display mode by id. 264 // Get a single fullscreen display mode by id.
193 // Returns true on success, false on error. 265 // Returns true on success, false on error.
194 bool RendererCairo::GetDisplayMode(int id, DisplayMode* mode) { 266 bool RendererCairo::GetDisplayMode(int id, DisplayMode* mode) {
195 NOTIMPLEMENTED(); 267 NOTIMPLEMENTED();
196 return true; 268 return true;
197 } 269 }
198 270
199 // TODO(fransiskusx): DO need to implement before shipped. 271 // TODO(fransiskusx): DO need to implement before shipped.
200 // Get a vector of the available fullscreen display modes. 272 // Get a vector of the available fullscreen display modes.
201 // Clears *modes on error. 273 // Clears *modes on error.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 NOTIMPLEMENTED(); 446 NOTIMPLEMENTED();
375 return RenderDepthStencilSurface::Ref(); 447 return RenderDepthStencilSurface::Ref();
376 } 448 }
377 449
378 // TODO(fransiskusx): This function is not applicable to 2D rendering. 450 // TODO(fransiskusx): This function is not applicable to 2D rendering.
379 void RendererCairo::SetState(Renderer* renderer, Param* param) { 451 void RendererCairo::SetState(Renderer* renderer, Param* param) {
380 // Don't need to do anything. 452 // Don't need to do anything.
381 NOTIMPLEMENTED(); 453 NOTIMPLEMENTED();
382 } 454 }
383 455
456 void RendererCairo::PopRenderStates() {
457 NOTIMPLEMENTED();
458 }
459
384 } // namespace o3d 460 } // namespace o3d
385 461
OLDNEW
« no previous file with comments | « core/cross/cairo/renderer_cairo.h ('k') | core/cross/cairo/texture_cairo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698