Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: cc/texture_uploader.cc

Issue 11413005: YUV software decode path stride fixes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cc LGTM'ed. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bits.h"
10 #include "base/debug/alias.h" 11 #include "base/debug/alias.h"
11 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
12 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
13 #include "cc/prioritized_resource.h" 14 #include "cc/prioritized_resource.h"
14 #include "cc/resource.h" 15 #include "cc/resource.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>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 base::debug::Alias(&image_rect_height); 223 base::debug::Alias(&image_rect_height);
223 base::debug::Alias(&dest_offset_x); 224 base::debug::Alias(&dest_offset_x);
224 base::debug::Alias(&dest_offset_y); 225 base::debug::Alias(&dest_offset_y);
225 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); 226 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage");
226 227
227 // Offset from image-rect to source-rect. 228 // Offset from image-rect to source-rect.
228 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); 229 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
229 230
230 const uint8* pixel_source; 231 const uint8* pixel_source;
231 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); 232 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format);
233 // Use 4-byte row alignment (OpenGL default) for upload performance.
234 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
235 unsigned int upload_image_stride =
236 base::bits::RoundUp(bytes_per_pixel * source_rect.width(), 4);
232 237
233 if (image_rect.width() == source_rect.width() && !offset.x()) { 238 if (upload_image_stride == image_rect.width() * bytes_per_pixel && !offset.x ()) {
234 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()] ; 239 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()] ;
235 } else { 240 } else {
236 size_t needed_size = source_rect.width() * source_rect.height() * bytes_ per_pixel; 241 size_t needed_size = upload_image_stride * source_rect.height();
237 if (m_subImageSize < needed_size) { 242 if (m_subImageSize < needed_size) {
238 m_subImage.reset(new uint8[needed_size]); 243 m_subImage.reset(new uint8[needed_size]);
239 m_subImageSize = needed_size; 244 m_subImageSize = needed_size;
240 } 245 }
241 // 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
242 // paint results into a temp buffer for uploading. 247 // paint results into a temp buffer for uploading.
243 for (int row = 0; row < source_rect.height(); ++row) 248 for (int row = 0; row < source_rect.height(); ++row)
244 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row], 249 memcpy(&m_subImage[upload_image_stride * row],
245 &image[bytes_per_pixel * (offset.x() + 250 &image[bytes_per_pixel * (offset.x() +
246 (offset.y() + row) * image_rect.width())], 251 (offset.y() + row) * image_rect.width())],
247 source_rect.width() * bytes_per_pixel); 252 source_rect.width() * bytes_per_pixel);
248 253
249 pixel_source = &m_subImage[0]; 254 pixel_source = &m_subImage[0];
250 } 255 }
251 256
252 m_context->texSubImage2D(GL_TEXTURE_2D, 257 m_context->texSubImage2D(GL_TEXTURE_2D,
253 0, 258 0,
254 dest_offset.x(), 259 dest_offset.x(),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 base::debug::Alias(&image_rect_width); 292 base::debug::Alias(&image_rect_width);
288 base::debug::Alias(&image_rect_height); 293 base::debug::Alias(&image_rect_height);
289 base::debug::Alias(&dest_offset_x); 294 base::debug::Alias(&dest_offset_x);
290 base::debug::Alias(&dest_offset_y); 295 base::debug::Alias(&dest_offset_y);
291 296
292 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); 297 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage");
293 298
294 // Offset from image-rect to source-rect. 299 // Offset from image-rect to source-rect.
295 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); 300 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
296 301
302 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format);
303 // Use 4-byte row alignment (OpenGL default) for upload performance.
304 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
305 unsigned int upload_image_stride =
306 base::bits::RoundUp(bytes_per_pixel * source_rect.width(), 4);
307
297 // Upload tile data via a mapped transfer buffer 308 // Upload tile data via a mapped transfer buffer
298 uint8* pixel_dest = static_cast<uint8*>( 309 uint8* pixel_dest = static_cast<uint8*>(
299 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 310 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
300 0, 311 0,
301 dest_offset.x(), 312 dest_offset.x(),
302 dest_offset.y(), 313 dest_offset.y(),
303 source_rect.width(), 314 source_rect.width(),
304 source_rect.height(), 315 source_rect.height(),
305 format, 316 format,
306 GL_UNSIGNED_BYTE, 317 GL_UNSIGNED_BYTE,
307 GL_WRITE_ONLY)); 318 GL_WRITE_ONLY));
308 319
309 if (!pixel_dest) { 320 if (!pixel_dest) {
310 uploadWithTexSubImage( 321 uploadWithTexSubImage(
311 image, image_rect, source_rect, dest_offset, format); 322 image, image_rect, source_rect, dest_offset, format);
312 return; 323 return;
313 } 324 }
314 325
315 unsigned int bytes_per_pixel = Resource::BytesPerPixel(format); 326 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, 327 memcpy(pixel_dest,
319 &image[offset.y() * image_rect.width() * bytes_per_pixel], 328 &image[image_rect.width() * bytes_per_pixel * offset.y()],
320 image_rect.width() * source_rect.height() * bytes_per_pixel); 329 source_rect.height() * image_rect.width() * bytes_per_pixel);
321 } else { 330 } else {
322 // Strides not equal, so do a row-by-row memcpy from the 331 // Strides not equal, so do a row-by-row memcpy from the
323 // paint results into the pixelDest 332 // paint results into the pixelDest
324 for (int row = 0; row < source_rect.height(); ++row) 333 for (int row = 0; row < source_rect.height(); ++row)
325 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], 334 memcpy(&pixel_dest[upload_image_stride * row],
326 &image[bytes_per_pixel * (offset.x() + 335 &image[bytes_per_pixel * (offset.x() +
327 (offset.y() + row) * image_rect.width())], 336 (offset.y() + row) * image_rect.width())],
328 source_rect.width() * bytes_per_pixel); 337 source_rect.width() * bytes_per_pixel);
329 } 338 }
330 339
331 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); 340 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest);
332 } 341 }
333 342
334 void TextureUploader::processQueries() 343 void TextureUploader::processQueries()
335 { 344 {
(...skipping 13 matching lines...) Expand all
349 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ; 358 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ;
350 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ; 359 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ;
351 } 360 }
352 m_texturesPerSecondHistory.insert(texturesPerSecond); 361 m_texturesPerSecondHistory.insert(texturesPerSecond);
353 362
354 m_availableQueries.append(m_pendingQueries.takeFirst()); 363 m_availableQueries.append(m_pendingQueries.takeFirst());
355 } 364 }
356 } 365 }
357 366
358 } // namespace cc 367 } // namespace cc
OLDNEW
« base/bits.h ('K') | « base/bits.h ('k') | cc/texture_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698