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

Side by Side Diff: cc/scheduler/texture_uploader.cc

Issue 27973002: cc: Adding ETC1 support to UIResourceBitmap and ResourceProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed latest comments, rebased Created 7 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/scheduler/texture_uploader.h" 5 #include "cc/scheduler/texture_uploader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 gfx::Vector2d dest_offset, 179 gfx::Vector2d dest_offset,
180 ResourceFormat format) { 180 ResourceFormat format) {
181 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage"); 181 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImage");
182 182
183 // Early-out if this is a no-op, and assert that |image| be valid if this is 183 // Early-out if this is a no-op, and assert that |image| be valid if this is
184 // not a no-op. 184 // not a no-op.
185 if (source_rect.IsEmpty()) 185 if (source_rect.IsEmpty())
186 return; 186 return;
187 DCHECK(image); 187 DCHECK(image);
188 188
189 if (format == ETC1) {
190 UploadWithTexSubImageETC1(
191 image, image_rect, source_rect, dest_offset, format);
192 return;
193 }
194
189 // Offset from image-rect to source-rect. 195 // Offset from image-rect to source-rect.
190 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); 196 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
191 197
192 const uint8* pixel_source; 198 const uint8* pixel_source;
193 unsigned bytes_per_pixel = BytesPerPixel(format); 199 unsigned bytes_per_pixel = BytesPerPixel(format);
194 // Use 4-byte row alignment (OpenGL default) for upload performance. 200 // Use 4-byte row alignment (OpenGL default) for upload performance.
195 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. 201 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
196 unsigned upload_image_stride = 202 unsigned upload_image_stride =
197 RoundUp(bytes_per_pixel * source_rect.width(), 4u); 203 RoundUp(bytes_per_pixel * source_rect.width(), 4u);
198 204
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 gfx::Rect source_rect, 238 gfx::Rect source_rect,
233 gfx::Vector2d dest_offset, 239 gfx::Vector2d dest_offset,
234 ResourceFormat format) { 240 ResourceFormat format) {
235 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); 241 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage");
236 242
237 // Early-out if this is a no-op, and assert that |image| be valid if this is 243 // Early-out if this is a no-op, and assert that |image| be valid if this is
238 // not a no-op. 244 // not a no-op.
239 if (source_rect.IsEmpty()) 245 if (source_rect.IsEmpty())
240 return; 246 return;
241 DCHECK(image); 247 DCHECK(image);
248 // Compressed textures have no implementation of mapTexSubImage.
249 DCHECK_NE(ETC1, format);
242 250
243 // Offset from image-rect to source-rect. 251 // Offset from image-rect to source-rect.
244 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); 252 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
245 253
246 unsigned bytes_per_pixel = BytesPerPixel(format); 254 unsigned bytes_per_pixel = BytesPerPixel(format);
247 // Use 4-byte row alignment (OpenGL default) for upload performance. 255 // Use 4-byte row alignment (OpenGL default) for upload performance.
248 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. 256 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
249 unsigned upload_image_stride = 257 unsigned upload_image_stride =
250 RoundUp(bytes_per_pixel * source_rect.width(), 4u); 258 RoundUp(bytes_per_pixel * source_rect.width(), 4u);
251 259
(...skipping 26 matching lines...) Expand all
278 memcpy(&pixel_dest[upload_image_stride * row], 286 memcpy(&pixel_dest[upload_image_stride * row],
279 &image[bytes_per_pixel * 287 &image[bytes_per_pixel *
280 (offset.x() + (offset.y() + row) * image_rect.width())], 288 (offset.x() + (offset.y() + row) * image_rect.width())],
281 source_rect.width() * bytes_per_pixel); 289 source_rect.width() * bytes_per_pixel);
282 } 290 }
283 } 291 }
284 292
285 context_->unmapTexSubImage2DCHROMIUM(pixel_dest); 293 context_->unmapTexSubImage2DCHROMIUM(pixel_dest);
286 } 294 }
287 295
296 void TextureUploader::UploadWithTexSubImageETC1(const uint8* image,
no sievers 2013/10/23 22:49:59 nit: UploadWithTexImageETC1 I also suggest callin
powei 2013/10/23 23:25:58 Done.
297 gfx::Rect image_rect,
298 gfx::Rect source_rect,
299 gfx::Vector2d dest_offset,
300 ResourceFormat format) {
301 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImageETC1");
302 // ETC1 does not support subimage uploads yet.
no sievers 2013/10/23 22:49:59 nit: remove the 'yet'.
powei 2013/10/23 23:25:58 Done.
303 DCHECK(image_rect == source_rect);
304 DCHECK_EQ(0, dest_offset.x());
305 DCHECK_EQ(0, dest_offset.y());
306
307 gfx::Size size = source_rect.size();
308 DCHECK_EQ(0, size.width() % 4);
309 DCHECK_EQ(0, size.height() % 4);
310
311 context_->compressedTexImage2D(
312 GL_TEXTURE_2D,
313 0,
314 GLInternalFormat(format),
315 size.width(),
316 size.height(),
317 0,
318 Resource::MemorySizeBytes(size, format),
319 image);
320 }
321
288 void TextureUploader::ProcessQueries() { 322 void TextureUploader::ProcessQueries() {
289 while (!pending_queries_.empty()) { 323 while (!pending_queries_.empty()) {
290 if (pending_queries_.front()->IsPending()) 324 if (pending_queries_.front()->IsPending())
291 break; 325 break;
292 326
293 unsigned us_elapsed = pending_queries_.front()->Value(); 327 unsigned us_elapsed = pending_queries_.front()->Value();
294 UMA_HISTOGRAM_CUSTOM_COUNTS( 328 UMA_HISTOGRAM_CUSTOM_COUNTS(
295 "Renderer4.TextureGpuUploadTimeUS", us_elapsed, 0, 100000, 50); 329 "Renderer4.TextureGpuUploadTimeUS", us_elapsed, 0, 100000, 50);
296 330
297 // Clamp the queries to saner values in case the queries fail. 331 // Clamp the queries to saner values in case the queries fail.
298 us_elapsed = std::max(1u, us_elapsed); 332 us_elapsed = std::max(1u, us_elapsed);
299 us_elapsed = std::min(15000u, us_elapsed); 333 us_elapsed = std::min(15000u, us_elapsed);
300 334
301 if (!pending_queries_.front()->is_non_blocking()) 335 if (!pending_queries_.front()->is_non_blocking())
302 num_blocking_texture_uploads_--; 336 num_blocking_texture_uploads_--;
303 337
304 // Remove the min and max value from our history and insert the new one. 338 // Remove the min and max value from our history and insert the new one.
305 double textures_per_second = 1.0 / (us_elapsed * 1e-6); 339 double textures_per_second = 1.0 / (us_elapsed * 1e-6);
306 if (textures_per_second_history_.size() >= kUploadHistorySizeMax) { 340 if (textures_per_second_history_.size() >= kUploadHistorySizeMax) {
307 textures_per_second_history_.erase(textures_per_second_history_.begin()); 341 textures_per_second_history_.erase(textures_per_second_history_.begin());
308 textures_per_second_history_.erase(--textures_per_second_history_.end()); 342 textures_per_second_history_.erase(--textures_per_second_history_.end());
309 } 343 }
310 textures_per_second_history_.insert(textures_per_second); 344 textures_per_second_history_.insert(textures_per_second);
311 345
312 available_queries_.push_back(pending_queries_.take_front()); 346 available_queries_.push_back(pending_queries_.take_front());
313 } 347 }
314 } 348 }
315 349
316 } // namespace cc 350 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698