| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/resources/texture_uploader.h" | 5 #include "cc/resources/texture_uploader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 gfx::Vector2d dest_offset, | 139 gfx::Vector2d dest_offset, |
| 140 ResourceFormat format, | 140 ResourceFormat format, |
| 141 const gfx::Size& size) { | 141 const gfx::Size& size) { |
| 142 CHECK(image_rect.Contains(source_rect)); | 142 CHECK(image_rect.Contains(source_rect)); |
| 143 | 143 |
| 144 bool is_full_upload = dest_offset.IsZero() && source_rect.size() == size; | 144 bool is_full_upload = dest_offset.IsZero() && source_rect.size() == size; |
| 145 | 145 |
| 146 if (is_full_upload) | 146 if (is_full_upload) |
| 147 BeginQuery(); | 147 BeginQuery(); |
| 148 | 148 |
| 149 if (format == ETC1) { | 149 UploadWithMapTexSubImage(image, image_rect, source_rect, dest_offset, format); |
| 150 // ETC1 does not support subimage uploads. | |
| 151 DCHECK(is_full_upload); | |
| 152 UploadWithTexImageETC1(image, size); | |
| 153 } else { | |
| 154 UploadWithMapTexSubImage( | |
| 155 image, image_rect, source_rect, dest_offset, format); | |
| 156 } | |
| 157 | 150 |
| 158 if (is_full_upload) | 151 if (is_full_upload) |
| 159 EndQuery(); | 152 EndQuery(); |
| 160 | 153 |
| 161 num_texture_uploads_since_last_flush_++; | 154 num_texture_uploads_since_last_flush_++; |
| 162 if (num_texture_uploads_since_last_flush_ >= kTextureUploadFlushPeriod) | 155 if (num_texture_uploads_since_last_flush_ >= kTextureUploadFlushPeriod) |
| 163 Flush(); | 156 Flush(); |
| 164 } | 157 } |
| 165 | 158 |
| 166 void TextureUploader::Flush() { | 159 void TextureUploader::Flush() { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 memcpy(&pixel_dest[upload_image_stride * row], | 277 memcpy(&pixel_dest[upload_image_stride * row], |
| 285 &image[bytes_per_pixel * | 278 &image[bytes_per_pixel * |
| 286 (offset.x() + (offset.y() + row) * image_rect.width())], | 279 (offset.x() + (offset.y() + row) * image_rect.width())], |
| 287 source_rect.width() * bytes_per_pixel); | 280 source_rect.width() * bytes_per_pixel); |
| 288 } | 281 } |
| 289 } | 282 } |
| 290 | 283 |
| 291 gl_->UnmapTexSubImage2DCHROMIUM(pixel_dest); | 284 gl_->UnmapTexSubImage2DCHROMIUM(pixel_dest); |
| 292 } | 285 } |
| 293 | 286 |
| 294 void TextureUploader::UploadWithTexImageETC1(const uint8* image, | |
| 295 const gfx::Size& size) { | |
| 296 TRACE_EVENT0("cc", "TextureUploader::UploadWithTexImageETC1"); | |
| 297 DCHECK_EQ(0, size.width() % 4); | |
| 298 DCHECK_EQ(0, size.height() % 4); | |
| 299 | |
| 300 gl_->CompressedTexImage2D(GL_TEXTURE_2D, | |
| 301 0, | |
| 302 GLInternalFormat(ETC1), | |
| 303 size.width(), | |
| 304 size.height(), | |
| 305 0, | |
| 306 Resource::MemorySizeBytes(size, ETC1), | |
| 307 image); | |
| 308 } | |
| 309 | |
| 310 void TextureUploader::ProcessQueries() { | 287 void TextureUploader::ProcessQueries() { |
| 311 while (!pending_queries_.empty()) { | 288 while (!pending_queries_.empty()) { |
| 312 if (pending_queries_.front()->IsPending()) | 289 if (pending_queries_.front()->IsPending()) |
| 313 break; | 290 break; |
| 314 | 291 |
| 315 unsigned us_elapsed = pending_queries_.front()->Value(); | 292 unsigned us_elapsed = pending_queries_.front()->Value(); |
| 316 UMA_HISTOGRAM_CUSTOM_COUNTS( | 293 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 317 "Renderer4.TextureGpuUploadTimeUS", us_elapsed, 0, 100000, 50); | 294 "Renderer4.TextureGpuUploadTimeUS", us_elapsed, 0, 100000, 50); |
| 318 | 295 |
| 319 // Clamp the queries to saner values in case the queries fail. | 296 // Clamp the queries to saner values in case the queries fail. |
| 320 us_elapsed = std::max(1u, us_elapsed); | 297 us_elapsed = std::max(1u, us_elapsed); |
| 321 us_elapsed = std::min(15000u, us_elapsed); | 298 us_elapsed = std::min(15000u, us_elapsed); |
| 322 | 299 |
| 323 if (!pending_queries_.front()->is_non_blocking()) | 300 if (!pending_queries_.front()->is_non_blocking()) |
| 324 num_blocking_texture_uploads_--; | 301 num_blocking_texture_uploads_--; |
| 325 | 302 |
| 326 // Remove the min and max value from our history and insert the new one. | 303 // Remove the min and max value from our history and insert the new one. |
| 327 double textures_per_second = 1.0 / (us_elapsed * 1e-6); | 304 double textures_per_second = 1.0 / (us_elapsed * 1e-6); |
| 328 if (textures_per_second_history_.size() >= kUploadHistorySizeMax) { | 305 if (textures_per_second_history_.size() >= kUploadHistorySizeMax) { |
| 329 textures_per_second_history_.erase(textures_per_second_history_.begin()); | 306 textures_per_second_history_.erase(textures_per_second_history_.begin()); |
| 330 textures_per_second_history_.erase(--textures_per_second_history_.end()); | 307 textures_per_second_history_.erase(--textures_per_second_history_.end()); |
| 331 } | 308 } |
| 332 textures_per_second_history_.insert(textures_per_second); | 309 textures_per_second_history_.insert(textures_per_second); |
| 333 | 310 |
| 334 available_queries_.push_back(pending_queries_.take_front()); | 311 available_queries_.push_back(pending_queries_.take_front()); |
| 335 } | 312 } |
| 336 } | 313 } |
| 337 | 314 |
| 338 } // namespace cc | 315 } // namespace cc |
| OLD | NEW |