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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 base::debug::Alias(&image_rect_height); | 222 base::debug::Alias(&image_rect_height); |
223 base::debug::Alias(&dest_offset_x); | 223 base::debug::Alias(&dest_offset_x); |
224 base::debug::Alias(&dest_offset_y); | 224 base::debug::Alias(&dest_offset_y); |
225 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); | 225 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); |
226 | 226 |
227 // Offset from image-rect to source-rect. | 227 // Offset from image-rect to source-rect. |
228 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 228 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
229 | 229 |
230 const uint8* pixel_source; | 230 const uint8* pixel_source; |
231 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format); | 231 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format); |
232 // Use 4-byte row alignment (OpenGL default) for upload performance. | |
233 unsigned int upload_image_stride = | |
234 (bytes_per_pixel * source_rect.width() + 3) & ~0x3; | |
danakj
2012/11/19 22:57:00
Oh, I see. This is ((image_stride + 3) / 4) * 4. C
danakj
2012/11/19 22:58:11
Or, make a nice descriptively named static functio
| |
235 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 4); | |
232 | 236 |
233 if (image_rect.width() == source_rect.width() && !offset.x()) { | 237 if (upload_image_stride == image_rect.width() * bytes_per_pixel && !offset.x ()) { |
234 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()] ; | 238 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()] ; |
235 } else { | 239 } else { |
236 size_t needed_size = source_rect.width() * source_rect.height() * bytes_ per_pixel; | 240 size_t needed_size = upload_image_stride * source_rect.height(); |
237 if (m_subImageSize < needed_size) { | 241 if (m_subImageSize < needed_size) { |
238 m_subImage.reset(new uint8[needed_size]); | 242 m_subImage.reset(new uint8[needed_size]); |
239 m_subImageSize = needed_size; | 243 m_subImageSize = needed_size; |
240 } | 244 } |
241 // Strides not equal, so do a row-by-row memcpy from the | 245 // Strides not equal, so do a row-by-row memcpy from the |
242 // paint results into a temp buffer for uploading. | 246 // paint results into a temp buffer for uploading. |
243 for (int row = 0; row < source_rect.height(); ++row) | 247 for (int row = 0; row < source_rect.height(); ++row) |
244 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row], | 248 memcpy(&m_subImage[upload_image_stride * row], |
245 &image[bytes_per_pixel * (offset.x() + | 249 &image[bytes_per_pixel * (offset.x() + |
246 (offset.y() + row) * image_rect.width())], | 250 (offset.y() + row) * image_rect.width())], |
247 source_rect.width() * bytes_per_pixel); | 251 source_rect.width() * bytes_per_pixel); |
248 | 252 |
249 pixel_source = &m_subImage[0]; | 253 pixel_source = &m_subImage[0]; |
250 } | 254 } |
251 | 255 |
252 m_context->texSubImage2D(GL_TEXTURE_2D, | 256 m_context->texSubImage2D(GL_TEXTURE_2D, |
253 0, | 257 0, |
254 dest_offset.x(), | 258 dest_offset.x(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 base::debug::Alias(&image_rect_width); | 291 base::debug::Alias(&image_rect_width); |
288 base::debug::Alias(&image_rect_height); | 292 base::debug::Alias(&image_rect_height); |
289 base::debug::Alias(&dest_offset_x); | 293 base::debug::Alias(&dest_offset_x); |
290 base::debug::Alias(&dest_offset_y); | 294 base::debug::Alias(&dest_offset_y); |
291 | 295 |
292 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); | 296 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); |
293 | 297 |
294 // Offset from image-rect to source-rect. | 298 // Offset from image-rect to source-rect. |
295 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); | 299 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); |
296 | 300 |
301 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format); | |
302 // Use 4-byte row alignment (OpenGL default) for upload performance. | |
303 unsigned int upload_image_stride = | |
304 (bytes_per_pixel * source_rect.width() + 3) & ~0x3; | |
305 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 4); | |
306 | |
297 // Upload tile data via a mapped transfer buffer | 307 // Upload tile data via a mapped transfer buffer |
298 uint8* pixel_dest = static_cast<uint8*>( | 308 uint8* pixel_dest = static_cast<uint8*>( |
299 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 309 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
300 0, | 310 0, |
301 dest_offset.x(), | 311 dest_offset.x(), |
302 dest_offset.y(), | 312 dest_offset.y(), |
303 source_rect.width(), | 313 source_rect.width(), |
304 source_rect.height(), | 314 source_rect.height(), |
305 format, | 315 format, |
306 GL_UNSIGNED_BYTE, | 316 GL_UNSIGNED_BYTE, |
307 GL_WRITE_ONLY)); | 317 GL_WRITE_ONLY)); |
308 | 318 |
309 if (!pixel_dest) { | 319 if (!pixel_dest) { |
310 uploadWithTexSubImage( | 320 uploadWithTexSubImage( |
311 image, image_rect, source_rect, dest_offset, format); | 321 image, image_rect, source_rect, dest_offset, format); |
312 return; | 322 return; |
313 } | 323 } |
314 | 324 |
315 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format); | 325 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, | 326 memcpy(pixel_dest, |
319 &image[offset.y() * image_rect.width() * bytes_per_pixel], | 327 &image[image_rect.width() * bytes_per_pixel * offset.y()], |
320 image_rect.width() * source_rect.height() * bytes_per_pixel); | 328 source_rect.height() * image_rect.width() * bytes_per_pixel); |
321 } else { | 329 } else { |
322 // Strides not equal, so do a row-by-row memcpy from the | 330 // Strides not equal, so do a row-by-row memcpy from the |
323 // paint results into the pixelDest | 331 // paint results into the pixelDest |
324 for (int row = 0; row < source_rect.height(); ++row) | 332 for (int row = 0; row < source_rect.height(); ++row) |
325 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], | 333 memcpy(&pixel_dest[upload_image_stride * row], |
326 &image[bytes_per_pixel * (offset.x() + | 334 &image[bytes_per_pixel * (offset.x() + |
327 (offset.y() + row) * image_rect.width())], | 335 (offset.y() + row) * image_rect.width())], |
328 source_rect.width() * bytes_per_pixel); | 336 source_rect.width() * bytes_per_pixel); |
329 } | 337 } |
330 | 338 |
331 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); | 339 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); |
332 } | 340 } |
333 | 341 |
334 void TextureUploader::processQueries() | 342 void TextureUploader::processQueries() |
335 { | 343 { |
(...skipping 13 matching lines...) Expand all Loading... | |
349 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ; | 357 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ; |
350 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ; | 358 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ; |
351 } | 359 } |
352 m_texturesPerSecondHistory.insert(texturesPerSecond); | 360 m_texturesPerSecondHistory.insert(texturesPerSecond); |
353 | 361 |
354 m_availableQueries.append(m_pendingQueries.takeFirst()); | 362 m_availableQueries.append(m_pendingQueries.takeFirst()); |
355 } | 363 } |
356 } | 364 } |
357 | 365 |
358 } // namespace cc | 366 } // namespace cc |
OLD | NEW |