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

Side by Side Diff: cc/texture_uploader.cc

Issue 11229040: Fix glTexSubImage2D for non-32bpp formats. (Closed) Base URL: https://git.chromium.org/git/chromium/src@git-svn
Patch Set: Removed formatting changes, added CCTexture 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
« no previous file with comments | « cc/texture.cc ('k') | no next file » | 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 "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"
15 #include "cc/prioritized_texture.h" 16 #include "cc/prioritized_texture.h"
16 #include "third_party/khronos/GLES2/gl2.h" 17 #include "third_party/khronos/GLES2/gl2.h"
17 #include "third_party/khronos/GLES2/gl2ext.h" 18 #include "third_party/khronos/GLES2/gl2ext.h"
18 #include <public/WebGraphicsContext3D.h> 19 #include <public/WebGraphicsContext3D.h>
19 20
20 namespace { 21 namespace {
21 22
22 // How many previous uploads to use when predicting future throughput. 23 // How many previous uploads to use when predicting future throughput.
23 static const size_t uploadHistorySize = 100; 24 static const size_t uploadHistorySize = 100;
24 25
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 base::debug::Alias(&image_rect_height); 206 base::debug::Alias(&image_rect_height);
206 base::debug::Alias(&dest_offset_width); 207 base::debug::Alias(&dest_offset_width);
207 base::debug::Alias(&dest_offset_height); 208 base::debug::Alias(&dest_offset_height);
208 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); 209 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage");
209 210
210 // Offset from image-rect to source-rect. 211 // Offset from image-rect to source-rect.
211 IntPoint offset(source_rect.x() - image_rect.x(), 212 IntPoint offset(source_rect.x() - image_rect.x(),
212 source_rect.y() - image_rect.y()); 213 source_rect.y() - image_rect.y());
213 214
214 const uint8_t* pixel_source; 215 const uint8_t* pixel_source;
216 unsigned int bytes_per_pixel = CCTexture::bytesPerPixel(format);
217
215 if (image_rect.width() == source_rect.width() && !offset.x()) { 218 if (image_rect.width() == source_rect.width() && !offset.x()) {
216 pixel_source = &image[4 * offset.y() * image_rect.width()]; 219 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()] ;
217 } else { 220 } else {
218 size_t needed_size = source_rect.width() * source_rect.height() * 4; 221 size_t needed_size =
222 source_rect.width() * source_rect.height() * bytes_per_pixel;
jamesr 2012/10/22 21:47:59 don't line wrap this, just let it go long. we'll r
sheu 2012/10/22 21:56:47 Done.
219 if (m_subImageSize < needed_size) { 223 if (m_subImageSize < needed_size) {
220 m_subImage.reset(new uint8_t[needed_size]); 224 m_subImage.reset(new uint8_t[needed_size]);
221 m_subImageSize = needed_size; 225 m_subImageSize = needed_size;
222 } 226 }
223 // Strides not equal, so do a row-by-row memcpy from the 227 // Strides not equal, so do a row-by-row memcpy from the
224 // paint results into a temp buffer for uploading. 228 // paint results into a temp buffer for uploading.
225 for (int row = 0; row < source_rect.height(); ++row) 229 for (int row = 0; row < source_rect.height(); ++row)
226 memcpy(&m_subImage[source_rect.width() * 4 * row], 230 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row],
227 &image[4 * (offset.x() + 231 &image[bytes_per_pixel * (offset.x() +
228 (offset.y() + row) * image_rect.width())], 232 (offset.y() + row) * image_rect.width())],
229 source_rect.width() * 4); 233 source_rect.width() * bytes_per_pixel);
230 234
231 pixel_source = &m_subImage[0]; 235 pixel_source = &m_subImage[0];
232 } 236 }
233 237
234 m_context->texSubImage2D(GL_TEXTURE_2D, 238 m_context->texSubImage2D(GL_TEXTURE_2D,
235 0, 239 0,
236 dest_offset.width(), 240 dest_offset.width(),
237 dest_offset.height(), 241 dest_offset.height(),
238 source_rect.width(), 242 source_rect.width(),
239 source_rect.height(), 243 source_rect.height(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 format, 292 format,
289 GL_UNSIGNED_BYTE, 293 GL_UNSIGNED_BYTE,
290 GL_WRITE_ONLY)); 294 GL_WRITE_ONLY));
291 295
292 if (!pixel_dest) { 296 if (!pixel_dest) {
293 uploadWithTexSubImage( 297 uploadWithTexSubImage(
294 image, image_rect, source_rect, dest_offset, format); 298 image, image_rect, source_rect, dest_offset, format);
295 return; 299 return;
296 } 300 }
297 301
298 unsigned int components_per_pixel = 0; 302 unsigned int bytes_per_pixel = CCTexture::bytesPerPixel(format);
299 switch (format) {
300 case GL_RGBA:
301 case GL_BGRA_EXT:
302 components_per_pixel = 4;
303 break;
304 case GL_LUMINANCE:
305 components_per_pixel = 1;
306 break;
307 default:
308 NOTREACHED();
309 }
310 unsigned int bytes_per_component = 1;
311 unsigned int bytes_per_pixel = components_per_pixel * bytes_per_component;
312 303
313 if (image_rect.width() == source_rect.width() && !offset.x()) { 304 if (image_rect.width() == source_rect.width() && !offset.x()) {
314 memcpy(pixel_dest, 305 memcpy(pixel_dest,
315 &image[offset.y() * image_rect.width() * bytes_per_pixel], 306 &image[offset.y() * image_rect.width() * bytes_per_pixel],
316 image_rect.width() * source_rect.height() * bytes_per_pixel); 307 image_rect.width() * source_rect.height() * bytes_per_pixel);
317 } else { 308 } else {
318 // Strides not equal, so do a row-by-row memcpy from the 309 // Strides not equal, so do a row-by-row memcpy from the
319 // paint results into the pixelDest 310 // paint results into the pixelDest
320 for (int row = 0; row < source_rect.height(); ++row) 311 for (int row = 0; row < source_rect.height(); ++row)
321 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], 312 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel],
322 &image[4 * (offset.x() + 313 &image[bytes_per_pixel * (offset.x() +
323 (offset.y() + row) * image_rect.width())], 314 (offset.y() + row) * image_rect.width())],
324 source_rect.width() * bytes_per_pixel); 315 source_rect.width() * bytes_per_pixel);
325 } 316 }
326 317
327 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); 318 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest);
328 } 319 }
329 320
330 void TextureUploader::processQueries() 321 void TextureUploader::processQueries()
331 { 322 {
332 while (!m_pendingQueries.isEmpty()) { 323 while (!m_pendingQueries.isEmpty()) {
333 if (m_pendingQueries.first()->isPending()) 324 if (m_pendingQueries.first()->isPending())
334 break; 325 break;
335 326
336 unsigned usElapsed = m_pendingQueries.first()->value(); 327 unsigned usElapsed = m_pendingQueries.first()->value();
337 HISTOGRAM_CUSTOM_COUNTS("Renderer4.TextureGpuUploadTimeUS", usElapsed, 0 , 100000, 50); 328 HISTOGRAM_CUSTOM_COUNTS("Renderer4.TextureGpuUploadTimeUS", usElapsed, 0 , 100000, 50);
338 329
339 if (!m_pendingQueries.first()->isNonBlocking()) 330 if (!m_pendingQueries.first()->isNonBlocking())
340 m_numBlockingTextureUploads--; 331 m_numBlockingTextureUploads--;
341 332
342 // Remove the oldest values from our history and insert the new one 333 // Remove the oldest values from our history and insert the new one
343 double texturesPerSecond = 1.0 / (usElapsed * 1e-6); 334 double texturesPerSecond = 1.0 / (usElapsed * 1e-6);
344 m_texturesPerSecondHistory.pop_back(); 335 m_texturesPerSecondHistory.pop_back();
345 m_texturesPerSecondHistory.push_front(texturesPerSecond); 336 m_texturesPerSecondHistory.push_front(texturesPerSecond);
346 337
347 m_availableQueries.append(m_pendingQueries.takeFirst()); 338 m_availableQueries.append(m_pendingQueries.takeFirst());
348 } 339 }
349 } 340 }
350 341
351 } 342 }
OLDNEW
« no previous file with comments | « cc/texture.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698