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

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: Created 8 years, 2 months 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 = Texture::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 = source_rect.width() * source_rect.height() * bytes_ per_pixel;
219 if (m_subImageSize < needed_size) { 222 if (m_subImageSize < needed_size) {
220 m_subImage.reset(new uint8_t[needed_size]); 223 m_subImage.reset(new uint8_t[needed_size]);
221 m_subImageSize = needed_size; 224 m_subImageSize = needed_size;
222 } 225 }
223 // Strides not equal, so do a row-by-row memcpy from the 226 // Strides not equal, so do a row-by-row memcpy from the
224 // paint results into a temp buffer for uploading. 227 // paint results into a temp buffer for uploading.
225 for (int row = 0; row < source_rect.height(); ++row) 228 for (int row = 0; row < source_rect.height(); ++row)
226 memcpy(&m_subImage[source_rect.width() * 4 * row], 229 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row],
227 &image[4 * (offset.x() + 230 &image[bytes_per_pixel * (offset.x() +
228 (offset.y() + row) * image_rect.width())], 231 (offset.y() + row) * image_rect.width())],
229 source_rect.width() * 4); 232 source_rect.width() * bytes_per_pixel);
230 233
231 pixel_source = &m_subImage[0]; 234 pixel_source = &m_subImage[0];
232 } 235 }
233 236
234 m_context->texSubImage2D(GL_TEXTURE_2D, 237 m_context->texSubImage2D(GL_TEXTURE_2D,
235 0, 238 0,
236 dest_offset.width(), 239 dest_offset.width(),
237 dest_offset.height(), 240 dest_offset.height(),
238 source_rect.width(), 241 source_rect.width(),
239 source_rect.height(), 242 source_rect.height(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 format, 291 format,
289 GL_UNSIGNED_BYTE, 292 GL_UNSIGNED_BYTE,
290 GL_WRITE_ONLY)); 293 GL_WRITE_ONLY));
291 294
292 if (!pixel_dest) { 295 if (!pixel_dest) {
293 uploadWithTexSubImage( 296 uploadWithTexSubImage(
294 image, image_rect, source_rect, dest_offset, format); 297 image, image_rect, source_rect, dest_offset, format);
295 return; 298 return;
296 } 299 }
297 300
298 unsigned int components_per_pixel = 0; 301 unsigned int bytes_per_pixel = Texture::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 302
313 if (image_rect.width() == source_rect.width() && !offset.x()) { 303 if (image_rect.width() == source_rect.width() && !offset.x()) {
314 memcpy(pixel_dest, 304 memcpy(pixel_dest,
315 &image[offset.y() * image_rect.width() * bytes_per_pixel], 305 &image[offset.y() * image_rect.width() * bytes_per_pixel],
316 image_rect.width() * source_rect.height() * bytes_per_pixel); 306 image_rect.width() * source_rect.height() * bytes_per_pixel);
317 } else { 307 } else {
318 // Strides not equal, so do a row-by-row memcpy from the 308 // Strides not equal, so do a row-by-row memcpy from the
319 // paint results into the pixelDest 309 // paint results into the pixelDest
320 for (int row = 0; row < source_rect.height(); ++row) 310 for (int row = 0; row < source_rect.height(); ++row)
321 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel], 311 memcpy(&pixel_dest[source_rect.width() * row * bytes_per_pixel],
322 &image[4 * (offset.x() + 312 &image[bytes_per_pixel * (offset.x() +
323 (offset.y() + row) * image_rect.width())], 313 (offset.y() + row) * image_rect.width())],
324 source_rect.width() * bytes_per_pixel); 314 source_rect.width() * bytes_per_pixel);
325 } 315 }
326 316
327 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest); 317 m_context->unmapTexSubImage2DCHROMIUM(pixel_dest);
328 } 318 }
329 319
330 void TextureUploader::processQueries() 320 void TextureUploader::processQueries()
331 { 321 {
332 while (!m_pendingQueries.isEmpty()) { 322 while (!m_pendingQueries.isEmpty()) {
333 if (m_pendingQueries.first()->isPending()) 323 if (m_pendingQueries.first()->isPending())
334 break; 324 break;
335 325
336 unsigned usElapsed = m_pendingQueries.first()->value(); 326 unsigned usElapsed = m_pendingQueries.first()->value();
337 HISTOGRAM_CUSTOM_COUNTS("Renderer4.TextureGpuUploadTimeUS", usElapsed, 0 , 100000, 50); 327 HISTOGRAM_CUSTOM_COUNTS("Renderer4.TextureGpuUploadTimeUS", usElapsed, 0 , 100000, 50);
338 328
339 if (!m_pendingQueries.first()->isNonBlocking()) 329 if (!m_pendingQueries.first()->isNonBlocking())
340 m_numBlockingTextureUploads--; 330 m_numBlockingTextureUploads--;
341 331
342 // Remove the oldest values from our history and insert the new one 332 // Remove the oldest values from our history and insert the new one
343 double texturesPerSecond = 1.0 / (usElapsed * 1e-6); 333 double texturesPerSecond = 1.0 / (usElapsed * 1e-6);
344 m_texturesPerSecondHistory.pop_back(); 334 m_texturesPerSecondHistory.pop_back();
345 m_texturesPerSecondHistory.push_front(texturesPerSecond); 335 m_texturesPerSecondHistory.push_front(texturesPerSecond);
346 336
347 m_availableQueries.append(m_pendingQueries.takeFirst()); 337 m_availableQueries.append(m_pendingQueries.takeFirst());
348 } 338 }
349 } 339 }
350 340
351 } 341 }
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