Chromium Code Reviews| 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 use_shallow_flush) | 80 bool use_shallow_flush, |
| 81 bool use_16_bit_textures) | |
| 81 : context_(context), | 82 : context_(context), |
| 82 num_blocking_texture_uploads_(0), | 83 num_blocking_texture_uploads_(0), |
| 83 use_map_tex_sub_image_(use_map_tex_sub_image), | 84 use_map_tex_sub_image_(use_map_tex_sub_image), |
| 84 sub_image_size_(0), | 85 sub_image_size_(0), |
| 85 use_shallow_flush_(use_shallow_flush), | 86 use_shallow_flush_(use_shallow_flush), |
| 86 num_texture_uploads_since_last_flush_(0) { | 87 num_texture_uploads_since_last_flush_(0), |
| 88 use_16_bit_textures_(use_16_bit_textures) { | |
| 87 for (size_t i = kUploadHistorySizeInitial; i > 0; i--) | 89 for (size_t i = kUploadHistorySizeInitial; i > 0; i--) |
| 88 textures_per_second_history_.insert(kDefaultEstimatedTexturesPerSecond); | 90 textures_per_second_history_.insert(kDefaultEstimatedTexturesPerSecond); |
| 89 } | 91 } |
| 90 | 92 |
| 91 TextureUploader::~TextureUploader() {} | 93 TextureUploader::~TextureUploader() {} |
| 92 | 94 |
| 93 size_t TextureUploader::NumBlockingUploads() { | 95 size_t TextureUploader::NumBlockingUploads() { |
| 94 ProcessQueries(); | 96 ProcessQueries(); |
| 95 return num_blocking_texture_uploads_; | 97 return num_blocking_texture_uploads_; |
| 96 } | 98 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 base::debug::Alias(&image_rect_width); | 202 base::debug::Alias(&image_rect_width); |
| 201 base::debug::Alias(&image_rect_height); | 203 base::debug::Alias(&image_rect_height); |
| 202 base::debug::Alias(&dest_offset_x); | 204 base::debug::Alias(&dest_offset_x); |
| 203 base::debug::Alias(&dest_offset_y); | 205 base::debug::Alias(&dest_offset_y); |
| 204 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); | 206 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); |
| 205 | 207 |
| 206 // Offset from image-rect to source-rect. | 208 // Offset from image-rect to source-rect. |
| 207 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 209 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
| 208 | 210 |
| 209 const uint8* pixel_source; | 211 const uint8* pixel_source; |
| 210 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 212 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format, |
| 213 use_16_bit_textures_); | |
| 214 // TODO(kaanb): anything to do to GL_UNPACK_ALIGNMENT for 16_bit? | |
|
Sami
2013/09/05 14:13:26
Yes, it needs to be set to 2 bytes. Otherwise odd-
kaanb
2013/09/06 02:05:54
Silly question, how and where should it be set?
| |
| 211 // Use 4-byte row alignment (OpenGL default) for upload performance. | 215 // Use 4-byte row alignment (OpenGL default) for upload performance. |
| 212 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 216 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
| 213 unsigned int upload_image_stride = | 217 unsigned int upload_image_stride = |
| 214 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 218 RoundUp(bytes_per_pixel * source_rect.width(), bytes_per_pixel); |
| 215 | 219 |
| 216 if (upload_image_stride == image_rect.width() * bytes_per_pixel && | 220 if (upload_image_stride == image_rect.width() * bytes_per_pixel && |
| 217 !offset.x()) { | 221 !offset.x()) { |
| 218 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]; | 222 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]; |
| 219 } else { | 223 } else { |
| 220 size_t needed_size = upload_image_stride * source_rect.height(); | 224 size_t needed_size = upload_image_stride * source_rect.height(); |
| 221 if (sub_image_size_ < needed_size) { | 225 if (sub_image_size_ < needed_size) { |
| 222 sub_image_.reset(new uint8[needed_size]); | 226 sub_image_.reset(new uint8[needed_size]); |
| 223 sub_image_size_ = needed_size; | 227 sub_image_size_ = needed_size; |
| 224 } | 228 } |
| 225 // Strides not equal, so do a row-by-row memcpy from the | 229 // Strides not equal, so do a row-by-row memcpy from the |
| 226 // paint results into a temp buffer for uploading. | 230 // paint results into a temp buffer for uploading. |
| 227 for (int row = 0; row < source_rect.height(); ++row) | 231 for (int row = 0; row < source_rect.height(); ++row) |
| 228 memcpy(&sub_image_[upload_image_stride * row], | 232 memcpy(&sub_image_[upload_image_stride * row], |
| 229 &image[bytes_per_pixel * | 233 &image[bytes_per_pixel * |
| 230 (offset.x() + (offset.y() + row) * image_rect.width())], | 234 (offset.x() + (offset.y() + row) * image_rect.width())], |
| 231 source_rect.width() * bytes_per_pixel); | 235 source_rect.width() * bytes_per_pixel); |
| 232 | 236 |
| 233 pixel_source = &sub_image_[0]; | 237 pixel_source = &sub_image_[0]; |
| 234 } | 238 } |
| 235 | 239 |
| 240 GLenum texture_data_type = use_16_bit_textures_ | |
| 241 ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_BYTE; | |
| 236 context_->texSubImage2D(GL_TEXTURE_2D, | 242 context_->texSubImage2D(GL_TEXTURE_2D, |
| 237 0, | 243 0, |
| 238 dest_offset.x(), | 244 dest_offset.x(), |
| 239 dest_offset.y(), | 245 dest_offset.y(), |
| 240 source_rect.width(), | 246 source_rect.width(), |
| 241 source_rect.height(), | 247 source_rect.height(), |
| 242 format, | 248 format, |
| 243 GL_UNSIGNED_BYTE, | 249 texture_data_type, |
| 244 pixel_source); | 250 pixel_source); |
| 245 } | 251 } |
| 246 | 252 |
| 247 void TextureUploader::UploadWithMapTexSubImage(const uint8* image, | 253 void TextureUploader::UploadWithMapTexSubImage(const uint8* image, |
| 248 gfx::Rect image_rect, | 254 gfx::Rect image_rect, |
| 249 gfx::Rect source_rect, | 255 gfx::Rect source_rect, |
| 250 gfx::Vector2d dest_offset, | 256 gfx::Vector2d dest_offset, |
| 251 GLenum format) { | 257 GLenum format) { |
| 252 // Instrumentation to debug issue 156107 | 258 // Instrumentation to debug issue 156107 |
| 253 int source_rect_x = source_rect.x(); | 259 int source_rect_x = source_rect.x(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 270 base::debug::Alias(&image_rect_width); | 276 base::debug::Alias(&image_rect_width); |
| 271 base::debug::Alias(&image_rect_height); | 277 base::debug::Alias(&image_rect_height); |
| 272 base::debug::Alias(&dest_offset_x); | 278 base::debug::Alias(&dest_offset_x); |
| 273 base::debug::Alias(&dest_offset_y); | 279 base::debug::Alias(&dest_offset_y); |
| 274 | 280 |
| 275 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); | 281 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); |
| 276 | 282 |
| 277 // Offset from image-rect to source-rect. | 283 // Offset from image-rect to source-rect. |
| 278 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 284 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
| 279 | 285 |
| 280 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 286 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format, |
| 287 use_16_bit_textures_); | |
| 288 // TODO(kaanb): anything to do to GL_UNPACK_ALIGNMENT for 16 bit? | |
| 281 // Use 4-byte row alignment (OpenGL default) for upload performance. | 289 // Use 4-byte row alignment (OpenGL default) for upload performance. |
| 282 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 290 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
| 283 unsigned int upload_image_stride = | 291 unsigned int upload_image_stride = |
| 284 RoundUp(bytes_per_pixel * source_rect.width(), 4u); | 292 RoundUp(bytes_per_pixel * source_rect.width(), bytes_per_pixel); |
| 285 | 293 |
| 294 GLenum texture_data_type = use_16_bit_textures_ | |
| 295 ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_BYTE; | |
| 286 // Upload tile data via a mapped transfer buffer | 296 // Upload tile data via a mapped transfer buffer |
| 287 uint8* pixel_dest = static_cast<uint8*>( | 297 uint8* pixel_dest = static_cast<uint8*>( |
| 288 context_->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 298 context_->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
| 289 0, | 299 0, |
| 290 dest_offset.x(), | 300 dest_offset.x(), |
| 291 dest_offset.y(), | 301 dest_offset.y(), |
| 292 source_rect.width(), | 302 source_rect.width(), |
| 293 source_rect.height(), | 303 source_rect.height(), |
| 294 format, | 304 format, |
| 295 GL_UNSIGNED_BYTE, | 305 texture_data_type, |
| 296 GL_WRITE_ONLY)); | 306 GL_WRITE_ONLY)); |
| 297 | 307 |
| 298 if (!pixel_dest) { | 308 if (!pixel_dest) { |
| 299 UploadWithTexSubImage(image, image_rect, source_rect, dest_offset, format); | 309 UploadWithTexSubImage(image, image_rect, source_rect, dest_offset, format); |
| 300 return; | 310 return; |
| 301 } | 311 } |
| 302 | 312 |
| 303 if (upload_image_stride == image_rect.width() * bytes_per_pixel && | 313 if (upload_image_stride == image_rect.width() * bytes_per_pixel && |
| 304 !offset.x()) { | 314 !offset.x()) { |
| 305 memcpy(pixel_dest, | 315 memcpy(pixel_dest, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 textures_per_second_history_.erase(textures_per_second_history_.begin()); | 351 textures_per_second_history_.erase(textures_per_second_history_.begin()); |
| 342 textures_per_second_history_.erase(--textures_per_second_history_.end()); | 352 textures_per_second_history_.erase(--textures_per_second_history_.end()); |
| 343 } | 353 } |
| 344 textures_per_second_history_.insert(textures_per_second); | 354 textures_per_second_history_.insert(textures_per_second); |
| 345 | 355 |
| 346 available_queries_.push_back(pending_queries_.take_front()); | 356 available_queries_.push_back(pending_queries_.take_front()); |
| 347 } | 357 } |
| 348 } | 358 } |
| 349 | 359 |
| 350 } // namespace cc | 360 } // namespace cc |
| OLD | NEW |