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

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: Unittest segfault fix.wq 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
« no previous file with comments | « no previous file | cc/video_layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 unsigned int upload_image_stride =
jamesr 2012/11/19 04:14:46 why is this change necessary?
233 (bytes_per_pixel * source_rect.width() + 3) & ~0x3;
danakj 2012/11/17 19:25:14 I'm certain this can be written in a way that make
234 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 4);
232 235
233 if (image_rect.width() == source_rect.width() && !offset.x()) { 236 if (upload_image_stride == image_rect.width() * bytes_per_pixel && !offset.x ()) {
234 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()] ; 237 pixel_source = &image[image_rect.width() * bytes_per_pixel * offset.y()] ;
235 } else { 238 } else {
236 size_t needed_size = source_rect.width() * source_rect.height() * bytes_ per_pixel; 239 size_t needed_size = upload_image_stride * source_rect.height();
237 if (m_subImageSize < needed_size) { 240 if (m_subImageSize < needed_size) {
238 m_subImage.reset(new uint8[needed_size]); 241 m_subImage.reset(new uint8[needed_size]);
239 m_subImageSize = needed_size; 242 m_subImageSize = needed_size;
240 } 243 }
241 // Strides not equal, so do a row-by-row memcpy from the 244 // Strides not equal, so do a row-by-row memcpy from the
242 // paint results into a temp buffer for uploading. 245 // paint results into a temp buffer for uploading.
243 for (int row = 0; row < source_rect.height(); ++row) 246 for (int row = 0; row < source_rect.height(); ++row)
244 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row], 247 memcpy(&m_subImage[upload_image_stride * row],
245 &image[bytes_per_pixel * (offset.x() + 248 &image[bytes_per_pixel * (offset.x() +
246 (offset.y() + row) * image_rect.width())], 249 (offset.y() + row) * image_rect.width())],
247 source_rect.width() * bytes_per_pixel); 250 source_rect.width() * bytes_per_pixel);
248 251
249 pixel_source = &m_subImage[0]; 252 pixel_source = &m_subImage[0];
250 } 253 }
251 254
252 m_context->texSubImage2D(GL_TEXTURE_2D, 255 m_context->texSubImage2D(GL_TEXTURE_2D,
253 0, 256 0,
254 dest_offset.x(), 257 dest_offset.x(),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 base::debug::Alias(&image_rect_width); 290 base::debug::Alias(&image_rect_width);
288 base::debug::Alias(&image_rect_height); 291 base::debug::Alias(&image_rect_height);
289 base::debug::Alias(&dest_offset_x); 292 base::debug::Alias(&dest_offset_x);
290 base::debug::Alias(&dest_offset_y); 293 base::debug::Alias(&dest_offset_y);
291 294
292 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); 295 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage");
293 296
294 // Offset from image-rect to source-rect. 297 // Offset from image-rect to source-rect.
295 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); 298 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
296 299
300 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format);
301 unsigned int upload_image_stride =
302 (bytes_per_pixel * source_rect.width() + 3) & ~0x3;
danakj 2012/11/17 19:25:14 same. helper method?
303 m_context->pixelStorei(GL_UNPACK_ALIGNMENT, 4);
304
297 // Upload tile data via a mapped transfer buffer 305 // Upload tile data via a mapped transfer buffer
298 uint8* pixel_dest = static_cast<uint8*>( 306 uint8* pixel_dest = static_cast<uint8*>(
299 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 307 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
300 0, 308 0,
301 dest_offset.x(), 309 dest_offset.x(),
302 dest_offset.y(), 310 dest_offset.y(),
303 source_rect.width(), 311 source_rect.width(),
304 source_rect.height(), 312 source_rect.height(),
305 format, 313 format,
306 GL_UNSIGNED_BYTE, 314 GL_UNSIGNED_BYTE,
307 GL_WRITE_ONLY)); 315 GL_WRITE_ONLY));
308 316
309 if (!pixel_dest) { 317 if (!pixel_dest) {
310 uploadWithTexSubImage( 318 uploadWithTexSubImage(
311 image, image_rect, source_rect, dest_offset, format); 319 image, image_rect, source_rect, dest_offset, format);
312 return; 320 return;
313 } 321 }
314 322
315 unsigned int bytes_per_pixel = Resource::bytesPerPixel(format); 323 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, 324 memcpy(pixel_dest,
319 &image[offset.y() * image_rect.width() * bytes_per_pixel], 325 &image[image_rect.width() * bytes_per_pixel * offset.y()],
320 image_rect.width() * source_rect.height() * bytes_per_pixel); 326 source_rect.height() * image_rect.width() * bytes_per_pixel);
321 } else { 327 } else {
322 // Strides not equal, so do a row-by-row memcpy from the 328 // Strides not equal, so do a row-by-row memcpy from the
323 // paint results into the pixelDest 329 // paint results into the pixelDest
324 for (int row = 0; row < source_rect.height(); ++row) 330 for (int row = 0; row < source_rect.height(); ++row)
325 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], 331 memcpy(&pixel_dest[upload_image_stride * row],
326 &image[bytes_per_pixel * (offset.x() + 332 &image[bytes_per_pixel * (offset.x() +
327 (offset.y() + row) * image_rect.width())], 333 (offset.y() + row) * image_rect.width())],
328 source_rect.width() * bytes_per_pixel); 334 source_rect.width() * bytes_per_pixel);
329 } 335 }
330 336
331 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); 337 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest);
332 } 338 }
333 339
334 void TextureUploader::processQueries() 340 void TextureUploader::processQueries()
335 { 341 {
(...skipping 13 matching lines...) Expand all
349 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ; 355 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ;
350 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ; 356 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ;
351 } 357 }
352 m_texturesPerSecondHistory.insert(texturesPerSecond); 358 m_texturesPerSecondHistory.insert(texturesPerSecond);
353 359
354 m_availableQueries.append(m_pendingQueries.takeFirst()); 360 m_availableQueries.append(m_pendingQueries.takeFirst());
355 } 361 }
356 } 362 }
357 363
358 } // namespace cc 364 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/video_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698