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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/texture_uploader.h" | 7 #include "cc/texture_uploader.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "cc/texture.h" | |
16 #include "cc/prioritized_resource.h" | 15 #include "cc/prioritized_resource.h" |
| 16 #include "cc/resource.h" |
17 #include "third_party/khronos/GLES2/gl2.h" | 17 #include "third_party/khronos/GLES2/gl2.h" |
18 #include "third_party/khronos/GLES2/gl2ext.h" | 18 #include "third_party/khronos/GLES2/gl2ext.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 #include "ui/gfx/vector2d.h" | 20 #include "ui/gfx/vector2d.h" |
21 #include <public/WebGraphicsContext3D.h> | 21 #include <public/WebGraphicsContext3D.h> |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // How many previous uploads to use when predicting future throughput. | 25 // How many previous uploads to use when predicting future throughput. |
26 static const size_t uploadHistorySizeMax = 1000; | 26 static const size_t uploadHistorySizeMax = 1000; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 base::debug::Alias(&image_rect_width); | 223 base::debug::Alias(&image_rect_width); |
224 base::debug::Alias(&image_rect_height); | 224 base::debug::Alias(&image_rect_height); |
225 base::debug::Alias(&dest_offset_x); | 225 base::debug::Alias(&dest_offset_x); |
226 base::debug::Alias(&dest_offset_y); | 226 base::debug::Alias(&dest_offset_y); |
227 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); | 227 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); |
228 | 228 |
229 // Offset from image-rect to source-rect. | 229 // Offset from image-rect to source-rect. |
230 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 230 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
231 | 231 |
232 const uint8* pixel_source; | 232 const uint8* pixel_source; |
233 unsigned int bytes_per_pixel = Texture::bytesPerPixel(format); | 233 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format); |
234 | 234 |
235 if (image_rect.width() == source_rect.width() && !offset.x()) { | 235 if (image_rect.width() == source_rect.width() && !offset.x()) { |
236 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()]
; | 236 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()]
; |
237 } else { | 237 } else { |
238 size_t needed_size = source_rect.width() * source_rect.height() * bytes_
per_pixel; | 238 size_t needed_size = source_rect.width() * source_rect.height() * bytes_
per_pixel; |
239 if (m_subImageSize < needed_size) { | 239 if (m_subImageSize < needed_size) { |
240 m_subImage.reset(new uint8[needed_size]); | 240 m_subImage.reset(new uint8[needed_size]); |
241 m_subImageSize = needed_size; | 241 m_subImageSize = needed_size; |
242 } | 242 } |
243 // Strides not equal, so do a row-by-row memcpy from the | 243 // Strides not equal, so do a row-by-row memcpy from the |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 format, | 307 format, |
308 GL_UNSIGNED_BYTE, | 308 GL_UNSIGNED_BYTE, |
309 GL_WRITE_ONLY)); | 309 GL_WRITE_ONLY)); |
310 | 310 |
311 if (!pixel_dest) { | 311 if (!pixel_dest) { |
312 uploadWithTexSubImage( | 312 uploadWithTexSubImage( |
313 image, image_rect, source_rect, dest_offset, format); | 313 image, image_rect, source_rect, dest_offset, format); |
314 return; | 314 return; |
315 } | 315 } |
316 | 316 |
317 unsigned int bytes_per_pixel = Texture::bytesPerPixel(format); | 317 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format); |
318 | 318 |
319 if (image_rect.width() == source_rect.width() && !offset.x()) { | 319 if (image_rect.width() == source_rect.width() && !offset.x()) { |
320 memcpy(pixel_dest, | 320 memcpy(pixel_dest, |
321 &image[offset.y() * image_rect.width() * bytes_per_pixel], | 321 &image[offset.y() * image_rect.width() * bytes_per_pixel], |
322 image_rect.width() * source_rect.height() * bytes_per_pixel); | 322 image_rect.width() * source_rect.height() * bytes_per_pixel); |
323 } else { | 323 } else { |
324 // Strides not equal, so do a row-by-row memcpy from the | 324 // Strides not equal, so do a row-by-row memcpy from the |
325 // paint results into the pixelDest | 325 // paint results into the pixelDest |
326 for (int row = 0; row < source_rect.height(); ++row) | 326 for (int row = 0; row < source_rect.height(); ++row) |
327 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], | 327 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], |
(...skipping 23 matching lines...) Expand all Loading... |
351 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin())
; | 351 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin())
; |
352 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end())
; | 352 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end())
; |
353 } | 353 } |
354 m_texturesPerSecondHistory.insert(texturesPerSecond); | 354 m_texturesPerSecondHistory.insert(texturesPerSecond); |
355 | 355 |
356 m_availableQueries.append(m_pendingQueries.takeFirst()); | 356 m_availableQueries.append(m_pendingQueries.takeFirst()); |
357 } | 357 } |
358 } | 358 } |
359 | 359 |
360 } // namespace cc | 360 } // namespace cc |
OLD | NEW |