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/texture_uploader.h" | 5 #include "cc/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 14 matching lines...) Expand all Loading... | |
25 static const size_t uploadHistorySizeInitial = 100; | 25 static const size_t uploadHistorySizeInitial = 100; |
26 | 26 |
27 // Global estimated number of textures per second to maintain estimates across | 27 // Global estimated number of textures per second to maintain estimates across |
28 // subsequent instances of TextureUploader. | 28 // subsequent instances of TextureUploader. |
29 // More than one thread will not access this variable, so we do not need to sync hronize access. | 29 // More than one thread will not access this variable, so we do not need to sync hronize access. |
30 static const double defaultEstimatedTexturesPerSecond = 48.0 * 60.0; | 30 static const double defaultEstimatedTexturesPerSecond = 48.0 * 60.0; |
31 | 31 |
32 // Flush interval when performing texture uploads. | 32 // Flush interval when performing texture uploads. |
33 const int textureUploadFlushPeriod = 4; | 33 const int textureUploadFlushPeriod = 4; |
34 | 34 |
35 static uint32 RoundUp(uint32 n, uint32 mul) | |
danakj
2012/11/21 01:24:27
don't use static here. it's already in anonymous n
| |
36 { | |
37 return (((n - 1) / mul) * mul) + mul; | |
38 } | |
39 | |
35 } // anonymous namespace | 40 } // anonymous namespace |
36 | 41 |
37 namespace cc { | 42 namespace cc { |
38 | 43 |
39 TextureUploader::Query::Query(WebKit::WebGraphicsContext3D* context) | 44 TextureUploader::Query::Query(WebKit::WebGraphicsContext3D* context) |
40 : m_context(context) | 45 : m_context(context) |
41 , m_queryId(0) | 46 , m_queryId(0) |
42 , m_value(0) | 47 , m_value(0) |
43 , m_hasValue(false) | 48 , m_hasValue(false) |
44 , m_isNonBlocking(false) | 49 , m_isNonBlocking(false) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 base::debug::Alias(&image_rect_height); | 227 base::debug::Alias(&image_rect_height); |
223 base::debug::Alias(&dest_offset_x); | 228 base::debug::Alias(&dest_offset_x); |
224 base::debug::Alias(&dest_offset_y); | 229 base::debug::Alias(&dest_offset_y); |
225 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); | 230 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); |
226 | 231 |
227 // Offset from image-rect to source-rect. | 232 // Offset from image-rect to source-rect. |
228 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 233 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
229 | 234 |
230 const uint8* pixel_source; | 235 const uint8* pixel_source; |
231 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 236 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); |
237 // Use 4-byte row alignment (OpenGL default) for upload performance. | |
238 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | |
239 unsigned int upload_image_stride = | |
240 RoundUp(bytes_per_pixel * source_rect.width(), 4); | |
232 | 241 |
233 if (image_rect.width() == source_rect.width() && !offset.x()) { | 242 if (upload_image_stride == image_rect.width() * bytes_per_pixel && !offset.x ()) { |
234 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()] ; | 243 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()] ; |
235 } else { | 244 } else { |
236 size_t needed_size = source_rect.width() * source_rect.height() * bytes_ per_pixel; | 245 size_t needed_size = upload_image_stride * source_rect.height(); |
237 if (m_subImageSize < needed_size) { | 246 if (m_subImageSize < needed_size) { |
238 m_subImage.reset(new uint8[needed_size]); | 247 m_subImage.reset(new uint8[needed_size]); |
239 m_subImageSize = needed_size; | 248 m_subImageSize = needed_size; |
240 } | 249 } |
241 // Strides not equal, so do a row-by-row memcpy from the | 250 // Strides not equal, so do a row-by-row memcpy from the |
242 // paint results into a temp buffer for uploading. | 251 // paint results into a temp buffer for uploading. |
243 for (int row = 0; row < source_rect.height(); ++row) | 252 for (int row = 0; row < source_rect.height(); ++row) |
244 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row], | 253 memcpy(&m_subImage[upload_image_stride * row], |
245 &image[bytes_per_pixel * (offset.x() + | 254 &image[bytes_per_pixel * (offset.x() + |
246 (offset.y() + row) * image_rect.width())], | 255 (offset.y() + row) * image_rect.width())], |
247 source_rect.width() * bytes_per_pixel); | 256 source_rect.width() * bytes_per_pixel); |
248 | 257 |
249 pixel_source = &m_subImage[0]; | 258 pixel_source = &m_subImage[0]; |
250 } | 259 } |
251 | 260 |
252 m_context->texSubImage2D(GL_TEXTURE_2D, | 261 m_context->texSubImage2D(GL_TEXTURE_2D, |
253 0, | 262 0, |
254 dest_offset.x(), | 263 dest_offset.x(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 base::debug::Alias(&image_rect_width); | 296 base::debug::Alias(&image_rect_width); |
288 base::debug::Alias(&image_rect_height); | 297 base::debug::Alias(&image_rect_height); |
289 base::debug::Alias(&dest_offset_x); | 298 base::debug::Alias(&dest_offset_x); |
290 base::debug::Alias(&dest_offset_y); | 299 base::debug::Alias(&dest_offset_y); |
291 | 300 |
292 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); | 301 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); |
293 | 302 |
294 // Offset from image-rect to source-rect. | 303 // Offset from image-rect to source-rect. |
295 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 304 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
296 | 305 |
306 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | |
307 // Use 4-byte row alignment (OpenGL default) for upload performance. | |
308 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | |
309 unsigned int upload_image_stride = | |
310 RoundUp(bytes_per_pixel * source_rect.width(), 4); | |
311 | |
297 // Upload tile data via a mapped transfer buffer | 312 // Upload tile data via a mapped transfer buffer |
298 uint8* pixel_dest = static_cast<uint8*>( | 313 uint8* pixel_dest = static_cast<uint8*>( |
299 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 314 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
300 0, | 315 0, |
301 dest_offset.x(), | 316 dest_offset.x(), |
302 dest_offset.y(), | 317 dest_offset.y(), |
303 source_rect.width(), | 318 source_rect.width(), |
304 source_rect.height(), | 319 source_rect.height(), |
305 format, | 320 format, |
306 GL_UNSIGNED_BYTE, | 321 GL_UNSIGNED_BYTE, |
307 GL_WRITE_ONLY)); | 322 GL_WRITE_ONLY)); |
308 | 323 |
309 if (!pixel_dest) { | 324 if (!pixel_dest) { |
310 uploadWithTexSubImage( | 325 uploadWithTexSubImage( |
311 image, image_rect, source_rect, dest_offset, format); | 326 image, image_rect, source_rect, dest_offset, format); |
312 return; | 327 return; |
313 } | 328 } |
314 | 329 |
315 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 330 if (upload_image_stride == image_rect.width() * bytes_per_pixel && !offset.x ()) { |
316 | |
317 if (image_rect.width() == source_rect.width() && !offset.x()) { | |
318 memcpy(pixel_dest, | 331 memcpy(pixel_dest, |
319 &image[offset.y() * image_rect.width() * bytes_per_pixel], | 332 &image[image_rect.width() * bytes_per_pixel * offset.y()], |
320 image_rect.width() * source_rect.height() * bytes_per_pixel); | 333 source_rect.height() * image_rect.width() * bytes_per_pixel); |
321 } else { | 334 } else { |
322 // Strides not equal, so do a row-by-row memcpy from the | 335 // Strides not equal, so do a row-by-row memcpy from the |
323 // paint results into the pixelDest | 336 // paint results into the pixelDest |
324 for (int row = 0; row < source_rect.height(); ++row) | 337 for (int row = 0; row < source_rect.height(); ++row) |
325 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], | 338 memcpy(&pixel_dest[upload_image_stride * row], |
326 &image[bytes_per_pixel * (offset.x() + | 339 &image[bytes_per_pixel * (offset.x() + |
327 (offset.y() + row) * image_rect.width())], | 340 (offset.y() + row) * image_rect.width())], |
328 source_rect.width() * bytes_per_pixel); | 341 source_rect.width() * bytes_per_pixel); |
329 } | 342 } |
330 | 343 |
331 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); | 344 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); |
332 } | 345 } |
333 | 346 |
334 void TextureUploader::processQueries() | 347 void TextureUploader::processQueries() |
335 { | 348 { |
(...skipping 13 matching lines...) Expand all Loading... | |
349 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ; | 362 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ; |
350 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ; | 363 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ; |
351 } | 364 } |
352 m_texturesPerSecondHistory.insert(texturesPerSecond); | 365 m_texturesPerSecondHistory.insert(texturesPerSecond); |
353 | 366 |
354 m_availableQueries.append(m_pendingQueries.takeFirst()); | 367 m_availableQueries.append(m_pendingQueries.takeFirst()); |
355 } | 368 } |
356 } | 369 } |
357 | 370 |
358 } // namespace cc | 371 } // namespace cc |
OLD | NEW |