OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/scheduler/texture_uploader.h" | 5 #include "cc/scheduler/texture_uploader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 unsigned TextureUploader::Query::Value() { | 70 unsigned TextureUploader::Query::Value() { |
71 if (!has_value_) { | 71 if (!has_value_) { |
72 context_->getQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &value_); | 72 context_->getQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &value_); |
73 has_value_ = true; | 73 has_value_ = true; |
74 } | 74 } |
75 return value_; | 75 return value_; |
76 } | 76 } |
77 | 77 |
78 TextureUploader::TextureUploader(WebKit::WebGraphicsContext3D* context, | 78 TextureUploader::TextureUploader(WebKit::WebGraphicsContext3D* context, |
79 bool use_map_tex_sub_image, | 79 bool use_map_tex_sub_image, |
80 bool useShallowFlush) | 80 bool use_shallow_flush) |
81 : context_(context), | 81 : context_(context), |
82 num_blocking_texture_uploads_(0), | 82 num_blocking_texture_uploads_(0), |
83 use_map_tex_sub_image_(use_map_tex_sub_image), | 83 use_map_tex_sub_image_(use_map_tex_sub_image), |
84 sub_image_size_(0), | 84 sub_image_size_(0), |
85 use_shallow_flush_(useShallowFlush), | 85 use_shallow_flush_(use_shallow_flush), |
86 num_texture_uploads_since_last_flush_(0) { | 86 num_texture_uploads_since_last_flush_(0) { |
87 for (size_t i = kUploadHistorySizeInitial; i > 0; i--) | 87 for (size_t i = kUploadHistorySizeInitial; i > 0; i--) |
88 textures_per_second_history_.insert(kDefaultEstimatedTexturesPerSecond); | 88 textures_per_second_history_.insert(kDefaultEstimatedTexturesPerSecond); |
89 } | 89 } |
90 | 90 |
91 TextureUploader::~TextureUploader() {} | 91 TextureUploader::~TextureUploader() {} |
92 | 92 |
93 size_t TextureUploader::NumBlockingUploads() { | 93 size_t TextureUploader::NumBlockingUploads() { |
94 ProcessQueries(); | 94 ProcessQueries(); |
95 return num_blocking_texture_uploads_; | 95 return num_blocking_texture_uploads_; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 base::debug::Alias(&source_rect_x); | 195 base::debug::Alias(&source_rect_x); |
196 base::debug::Alias(&source_rect_y); | 196 base::debug::Alias(&source_rect_y); |
197 base::debug::Alias(&source_rect_width); | 197 base::debug::Alias(&source_rect_width); |
198 base::debug::Alias(&source_rect_height); | 198 base::debug::Alias(&source_rect_height); |
199 base::debug::Alias(&image_rect_x); | 199 base::debug::Alias(&image_rect_x); |
200 base::debug::Alias(&image_rect_y); | 200 base::debug::Alias(&image_rect_y); |
201 base::debug::Alias(&image_rect_width); | 201 base::debug::Alias(&image_rect_width); |
202 base::debug::Alias(&image_rect_height); | 202 base::debug::Alias(&image_rect_height); |
203 base::debug::Alias(&dest_offset_x); | 203 base::debug::Alias(&dest_offset_x); |
204 base::debug::Alias(&dest_offset_y); | 204 base::debug::Alias(&dest_offset_y); |
205 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); | 205 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); |
206 | 206 |
207 // Offset from image-rect to source-rect. | 207 // Offset from image-rect to source-rect. |
208 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 208 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
209 | 209 |
210 const uint8* pixel_source; | 210 const uint8* pixel_source; |
211 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 211 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); |
212 // Use 4-byte row alignment (OpenGL default) for upload performance. | 212 // Use 4-byte row alignment (OpenGL default) for upload performance. |
213 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 213 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
214 unsigned int upload_image_stride = | 214 unsigned int upload_image_stride = |
215 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 215 RoundUp(bytes_per_pixel * source_rect.width(), 4u); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 base::debug::Alias(&source_rect_y); | 266 base::debug::Alias(&source_rect_y); |
267 base::debug::Alias(&source_rect_width); | 267 base::debug::Alias(&source_rect_width); |
268 base::debug::Alias(&source_rect_height); | 268 base::debug::Alias(&source_rect_height); |
269 base::debug::Alias(&image_rect_x); | 269 base::debug::Alias(&image_rect_x); |
270 base::debug::Alias(&image_rect_y); | 270 base::debug::Alias(&image_rect_y); |
271 base::debug::Alias(&image_rect_width); | 271 base::debug::Alias(&image_rect_width); |
272 base::debug::Alias(&image_rect_height); | 272 base::debug::Alias(&image_rect_height); |
273 base::debug::Alias(&dest_offset_x); | 273 base::debug::Alias(&dest_offset_x); |
274 base::debug::Alias(&dest_offset_y); | 274 base::debug::Alias(&dest_offset_y); |
275 | 275 |
276 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); | 276 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); |
277 | 277 |
278 // Offset from image-rect to source-rect. | 278 // Offset from image-rect to source-rect. |
279 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 279 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
280 | 280 |
281 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 281 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); |
282 // Use 4-byte row alignment (OpenGL default) for upload performance. | 282 // Use 4-byte row alignment (OpenGL default) for upload performance. |
283 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 283 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
284 unsigned int upload_image_stride = | 284 unsigned int upload_image_stride = |
285 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 285 RoundUp(bytes_per_pixel * source_rect.width(), 4u); |
286 | 286 |
(...skipping 14 matching lines...) Expand all Loading... |
301 return; | 301 return; |
302 } | 302 } |
303 | 303 |
304 if (upload_image_stride == image_rect.width() * bytes_per_pixel && | 304 if (upload_image_stride == image_rect.width() * bytes_per_pixel && |
305 !offset.x()) { | 305 !offset.x()) { |
306 memcpy(pixel_dest, | 306 memcpy(pixel_dest, |
307 &image[image_rect.width() * bytes_per_pixel * offset.y()], | 307 &image[image_rect.width() * bytes_per_pixel * offset.y()], |
308 source_rect.height() * image_rect.width() * bytes_per_pixel); | 308 source_rect.height() * image_rect.width() * bytes_per_pixel); |
309 } else { | 309 } else { |
310 // Strides not equal, so do a row-by-row memcpy from the | 310 // Strides not equal, so do a row-by-row memcpy from the |
311 // paint results into the pixelDest | 311 // paint results into the pixel_dest. |
312 for (int row = 0; row < source_rect.height(); ++row) { | 312 for (int row = 0; row < source_rect.height(); ++row) { |
313 memcpy(&pixel_dest[upload_image_stride * row], | 313 memcpy(&pixel_dest[upload_image_stride * row], |
314 &image[bytes_per_pixel * | 314 &image[bytes_per_pixel * |
315 (offset.x() + (offset.y() + row) * image_rect.width())], | 315 (offset.x() + (offset.y() + row) * image_rect.width())], |
316 source_rect.width() * bytes_per_pixel); | 316 source_rect.width() * bytes_per_pixel); |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 context_->unmapTexSubImage2DCHROMIUM(pixel_dest); | 320 context_->unmapTexSubImage2DCHROMIUM(pixel_dest); |
321 } | 321 } |
(...skipping 20 matching lines...) Expand all Loading... |
342 textures_per_second_history_.erase(textures_per_second_history_.begin()); | 342 textures_per_second_history_.erase(textures_per_second_history_.begin()); |
343 textures_per_second_history_.erase(--textures_per_second_history_.end()); | 343 textures_per_second_history_.erase(--textures_per_second_history_.end()); |
344 } | 344 } |
345 textures_per_second_history_.insert(textures_per_second); | 345 textures_per_second_history_.insert(textures_per_second); |
346 | 346 |
347 available_queries_.push_back(pending_queries_.take_front()); | 347 available_queries_.push_back(pending_queries_.take_front()); |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 } // namespace cc | 351 } // namespace cc |
OLD | NEW |