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

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: Created 7 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
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 // ETC1 textures take a separate path
kaanb 2013/10/18 16:54:49 I don't think you need this comment, the code is s
powei 2013/10/23 05:36:15 Done.
190 if (format == ETC1) {
191 UploadWithTexSubImageETC1(
192 image, image_rect, source_rect, dest_offset, format);
193 return;
194 }
195
189 // Offset from image-rect to source-rect. 196 // Offset from image-rect to source-rect.
190 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); 197 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
191 198
192 const uint8* pixel_source; 199 const uint8* pixel_source;
193 unsigned bytes_per_pixel = BytesPerPixel(format); 200 unsigned bytes_per_pixel = BytesPerPixel(format);
194 // Use 4-byte row alignment (OpenGL default) for upload performance. 201 // Use 4-byte row alignment (OpenGL default) for upload performance.
195 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. 202 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
196 unsigned upload_image_stride = 203 unsigned upload_image_stride =
197 RoundUp(bytes_per_pixel * source_rect.width(), 4u); 204 RoundUp(bytes_per_pixel * source_rect.width(), 4u);
198 205
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 gfx::Rect source_rect, 239 gfx::Rect source_rect,
233 gfx::Vector2d dest_offset, 240 gfx::Vector2d dest_offset,
234 ResourceFormat format) { 241 ResourceFormat format) {
235 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage"); 242 TRACE_EVENT0("cc", "TextureUploader::UploadWithMapTexSubImage");
236 243
237 // Early-out if this is a no-op, and assert that |image| be valid if this is 244 // Early-out if this is a no-op, and assert that |image| be valid if this is
238 // not a no-op. 245 // not a no-op.
239 if (source_rect.IsEmpty()) 246 if (source_rect.IsEmpty())
240 return; 247 return;
241 DCHECK(image); 248 DCHECK(image);
249 // Compressed textures have no implementation of mapTexSubImage.
250 DCHECK_NE(format, ETC1);
kaanb 2013/10/18 16:54:49 nit: DCHECK_NE(ETC1, format);
powei 2013/10/23 05:36:15 Done.
242 251
243 // Offset from image-rect to source-rect. 252 // Offset from image-rect to source-rect.
244 gfx::Vector2d offset(source_rect.origin() - image_rect.origin()); 253 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
245 254
246 unsigned bytes_per_pixel = BytesPerPixel(format); 255 unsigned bytes_per_pixel = BytesPerPixel(format);
247 // Use 4-byte row alignment (OpenGL default) for upload performance. 256 // Use 4-byte row alignment (OpenGL default) for upload performance.
248 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default. 257 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
249 unsigned upload_image_stride = 258 unsigned upload_image_stride =
250 RoundUp(bytes_per_pixel * source_rect.width(), 4u); 259 RoundUp(bytes_per_pixel * source_rect.width(), 4u);
251 260
(...skipping 26 matching lines...) Expand all
278 memcpy(&pixel_dest[upload_image_stride * row], 287 memcpy(&pixel_dest[upload_image_stride * row],
279 &image[bytes_per_pixel * 288 &image[bytes_per_pixel *
280 (offset.x() + (offset.y() + row) * image_rect.width())], 289 (offset.x() + (offset.y() + row) * image_rect.width())],
281 source_rect.width() * bytes_per_pixel); 290 source_rect.width() * bytes_per_pixel);
282 } 291 }
283 } 292 }
284 293
285 context_->unmapTexSubImage2DCHROMIUM(pixel_dest); 294 context_->unmapTexSubImage2DCHROMIUM(pixel_dest);
286 } 295 }
287 296
297 void TextureUploader::UploadWithTexSubImageETC1(const uint8* image,
298 gfx::Rect image_rect,
299 gfx::Rect source_rect,
300 gfx::Vector2d dest_offset,
301 ResourceFormat format) {
302 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexSubImageETC1");
303
304 // ETC1 does not support subimage uploads yet.
305 DCHECK(image_rect == source_rect);
306 DCHECK_EQ(dest_offset.x(), 0);
kaanb 2013/10/18 16:54:49 nit: the first parameter to DCHECK is the expected
powei 2013/10/23 05:36:15 Done.
307 DCHECK_EQ(dest_offset.y(), 0);
308
309 context_->compressedTexSubImage2D(
310 GL_TEXTURE_2D,
311 0, /* level */
312 0, /* x */
313 0, /* y */
314 source_rect.width(),
315 source_rect.height(),
316 GLDataFormat(format),
317 Resource::ETC1SizeInBytes(source_rect.size()),
318 image);
319 }
320
288 void TextureUploader::ProcessQueries() { 321 void TextureUploader::ProcessQueries() {
289 while (!pending_queries_.empty()) { 322 while (!pending_queries_.empty()) {
290 if (pending_queries_.front()->IsPending()) 323 if (pending_queries_.front()->IsPending())
291 break; 324 break;
292 325
293 unsigned us_elapsed = pending_queries_.front()->Value(); 326 unsigned us_elapsed = pending_queries_.front()->Value();
294 UMA_HISTOGRAM_CUSTOM_COUNTS( 327 UMA_HISTOGRAM_CUSTOM_COUNTS(
295 "Renderer4.TextureGpuUploadTimeUS", us_elapsed, 0, 100000, 50); 328 "Renderer4.TextureGpuUploadTimeUS", us_elapsed, 0, 100000, 50);
296 329
297 // Clamp the queries to saner values in case the queries fail. 330 // Clamp the queries to saner values in case the queries fail.
298 us_elapsed = std::max(1u, us_elapsed); 331 us_elapsed = std::max(1u, us_elapsed);
299 us_elapsed = std::min(15000u, us_elapsed); 332 us_elapsed = std::min(15000u, us_elapsed);
300 333
301 if (!pending_queries_.front()->is_non_blocking()) 334 if (!pending_queries_.front()->is_non_blocking())
302 num_blocking_texture_uploads_--; 335 num_blocking_texture_uploads_--;
303 336
304 // Remove the min and max value from our history and insert the new one. 337 // 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); 338 double textures_per_second = 1.0 / (us_elapsed * 1e-6);
306 if (textures_per_second_history_.size() >= kUploadHistorySizeMax) { 339 if (textures_per_second_history_.size() >= kUploadHistorySizeMax) {
307 textures_per_second_history_.erase(textures_per_second_history_.begin()); 340 textures_per_second_history_.erase(textures_per_second_history_.begin());
308 textures_per_second_history_.erase(--textures_per_second_history_.end()); 341 textures_per_second_history_.erase(--textures_per_second_history_.end());
309 } 342 }
310 textures_per_second_history_.insert(textures_per_second); 343 textures_per_second_history_.insert(textures_per_second);
311 344
312 available_queries_.push_back(pending_queries_.take_front()); 345 available_queries_.push_back(pending_queries_.take_front());
313 } 346 }
314 } 347 }
315 348
316 } // namespace cc 349 } // namespace cc
OLDNEW
« cc/resources/ui_resource_bitmap.h ('K') | « cc/scheduler/texture_uploader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698