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

Side by Side Diff: cc/texture_uploader.cc

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