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" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "cc/prioritized_resource.h" | 13 #include "cc/prioritized_resource.h" |
14 #include "cc/resource.h" | 14 #include "cc/resource.h" |
| 15 #include "cc/util.h" |
15 #include "third_party/khronos/GLES2/gl2.h" | 16 #include "third_party/khronos/GLES2/gl2.h" |
16 #include "third_party/khronos/GLES2/gl2ext.h" | 17 #include "third_party/khronos/GLES2/gl2ext.h" |
17 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
18 #include "ui/gfx/vector2d.h" | 19 #include "ui/gfx/vector2d.h" |
19 #include <public/WebGraphicsContext3D.h> | 20 #include <public/WebGraphicsContext3D.h> |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // How many previous uploads to use when predicting future throughput. | 24 // How many previous uploads to use when predicting future throughput. |
24 static const size_t uploadHistorySizeMax = 1000; | 25 static const size_t uploadHistorySizeMax = 1000; |
25 static const size_t uploadHistorySizeInitial = 100; | 26 static const size_t uploadHistorySizeInitial = 100; |
26 | 27 |
27 // Global estimated number of textures per second to maintain estimates across | 28 // Global estimated number of textures per second to maintain estimates across |
28 // subsequent instances of TextureUploader. | 29 // subsequent instances of TextureUploader. |
29 // More than one thread will not access this variable, so we do not need to sync
hronize access. | 30 // 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; | 31 static const double defaultEstimatedTexturesPerSecond = 48.0 * 60.0; |
31 | 32 |
32 // Flush interval when performing texture uploads. | 33 // Flush interval when performing texture uploads. |
33 const int textureUploadFlushPeriod = 4; | 34 const int textureUploadFlushPeriod = 4; |
34 | 35 |
35 unsigned int RoundUp(unsigned int n, unsigned int mul) | |
36 { | |
37 return (((n - 1) / mul) * mul) + mul; | |
38 } | |
39 | |
40 } // anonymous namespace | 36 } // anonymous namespace |
41 | 37 |
42 namespace cc { | 38 namespace cc { |
43 | 39 |
44 TextureUploader::Query::Query(WebKit::WebGraphicsContext3D* context) | 40 TextureUploader::Query::Query(WebKit::WebGraphicsContext3D* context) |
45 : m_context(context) | 41 : m_context(context) |
46 , m_queryId(0) | 42 , m_queryId(0) |
47 , m_value(0) | 43 , m_value(0) |
48 , m_hasValue(false) | 44 , m_hasValue(false) |
49 , m_isNonBlocking(false) | 45 , m_isNonBlocking(false) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); | 226 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); |
231 | 227 |
232 // Offset from image-rect to source-rect. | 228 // Offset from image-rect to source-rect. |
233 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 229 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
234 | 230 |
235 const uint8* pixel_source; | 231 const uint8* pixel_source; |
236 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 232 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); |
237 // Use 4-byte row alignment (OpenGL default) for upload performance. | 233 // Use 4-byte row alignment (OpenGL default) for upload performance. |
238 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 234 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
239 unsigned int upload_image_stride = | 235 unsigned int upload_image_stride = |
240 RoundUp(bytes_per_pixel * source_rect.width(), 4); | 236 RoundUp(bytes_per_pixel * source_rect.width(), 4u); |
241 | 237 |
242 if (upload_image_stride == image_rect.width() * bytes_per_pixel && !offset.x
()) { | 238 if (upload_image_stride == image_rect.width() * bytes_per_pixel && !offset.x
()) { |
243 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]
; | 239 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()]
; |
244 } else { | 240 } else { |
245 size_t needed_size = upload_image_stride * source_rect.height(); | 241 size_t needed_size = upload_image_stride * source_rect.height(); |
246 if (m_subImageSize < needed_size) { | 242 if (m_subImageSize < needed_size) { |
247 m_subImage.reset(new uint8[needed_size]); | 243 m_subImage.reset(new uint8[needed_size]); |
248 m_subImageSize = needed_size; | 244 m_subImageSize = needed_size; |
249 } | 245 } |
250 // Strides not equal, so do a row-by-row memcpy from the | 246 // Strides not equal, so do a row-by-row memcpy from the |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 296 |
301 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); | 297 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); |
302 | 298 |
303 // Offset from image-rect to source-rect. | 299 // Offset from image-rect to source-rect. |
304 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 300 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
305 | 301 |
306 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); | 302 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); |
307 // Use 4-byte row alignment (OpenGL default) for upload performance. | 303 // Use 4-byte row alignment (OpenGL default) for upload performance. |
308 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. | 304 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. |
309 unsigned int upload_image_stride = | 305 unsigned int upload_image_stride = |
310 RoundUp(bytes_per_pixel * source_rect.width(), 4); | 306 RoundUp(bytes_per_pixel * source_rect.width(), 4u); |
311 | 307 |
312 // Upload tile data via a mapped transfer buffer | 308 // Upload tile data via a mapped transfer buffer |
313 uint8* pixel_dest = static_cast<uint8*>( | 309 uint8* pixel_dest = static_cast<uint8*>( |
314 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 310 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
315 0, | 311 0, |
316 dest_offset.x(), | 312 dest_offset.x(), |
317 dest_offset.y(), | 313 dest_offset.y(), |
318 source_rect.width(), | 314 source_rect.width(), |
319 source_rect.height(), | 315 source_rect.height(), |
320 format, | 316 format, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin())
; | 358 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin())
; |
363 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end())
; | 359 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end())
; |
364 } | 360 } |
365 m_texturesPerSecondHistory.insert(texturesPerSecond); | 361 m_texturesPerSecondHistory.insert(texturesPerSecond); |
366 | 362 |
367 m_availableQueries.append(m_pendingQueries.takeFirst()); | 363 m_availableQueries.append(m_pendingQueries.takeFirst()); |
368 } | 364 } |
369 } | 365 } |
370 | 366 |
371 } // namespace cc | 367 } // namespace cc |
OLD | NEW |