OLD | NEW |
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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 switch (format) { | 68 switch (format) { |
69 case RGBA_8888: | 69 case RGBA_8888: |
70 break; | 70 break; |
71 case BGRA_8888: | 71 case BGRA_8888: |
72 storage_format = GL_BGRA8_EXT; | 72 storage_format = GL_BGRA8_EXT; |
73 break; | 73 break; |
74 case RGBA_4444: | 74 case RGBA_4444: |
75 case ALPHA_8: | 75 case ALPHA_8: |
76 case LUMINANCE_8: | 76 case LUMINANCE_8: |
77 case RGB_565: | 77 case RGB_565: |
| 78 case ATC: |
| 79 case ATC_IA: |
| 80 case DXT1: |
| 81 case DXT5: |
78 case ETC1: | 82 case ETC1: |
79 case RED_8: | 83 case RED_8: |
80 NOTREACHED(); | 84 NOTREACHED(); |
81 break; | 85 break; |
82 } | 86 } |
83 | 87 |
84 return storage_format; | 88 return storage_format; |
85 } | 89 } |
86 | 90 |
87 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { | 91 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { |
88 switch (format) { | 92 switch (format) { |
89 case RGBA_8888: | 93 case RGBA_8888: |
90 return true; | 94 return true; |
91 case BGRA_8888: | 95 case BGRA_8888: |
92 return use_bgra; | 96 return use_bgra; |
93 case RGBA_4444: | 97 case RGBA_4444: |
94 case ALPHA_8: | 98 case ALPHA_8: |
95 case LUMINANCE_8: | 99 case LUMINANCE_8: |
96 case RGB_565: | 100 case RGB_565: |
| 101 case ATC: |
| 102 case ATC_IA: |
| 103 case DXT1: |
| 104 case DXT5: |
97 case ETC1: | 105 case ETC1: |
98 case RED_8: | 106 case RED_8: |
99 return false; | 107 return false; |
100 } | 108 } |
101 return false; | 109 return false; |
102 } | 110 } |
103 | 111 |
104 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { | 112 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { |
105 switch (format) { | 113 switch (format) { |
106 case RGBA_8888: | 114 case RGBA_8888: |
107 return kRGBA_8888_GrPixelConfig; | 115 return kRGBA_8888_GrPixelConfig; |
108 case BGRA_8888: | 116 case BGRA_8888: |
109 return kBGRA_8888_GrPixelConfig; | 117 return kBGRA_8888_GrPixelConfig; |
110 case RGBA_4444: | 118 case RGBA_4444: |
111 return kRGBA_4444_GrPixelConfig; | 119 return kRGBA_4444_GrPixelConfig; |
112 default: | 120 default: |
113 break; | 121 break; |
114 } | 122 } |
115 DCHECK(false) << "Unsupported resource format."; | 123 DCHECK(false) << "Unsupported resource format."; |
116 return kSkia8888_GrPixelConfig; | 124 return kSkia8888_GrPixelConfig; |
117 } | 125 } |
118 | 126 |
119 gfx::GpuMemoryBuffer::Format ToGpuMemoryBufferFormat(ResourceFormat format) { | 127 gfx::GpuMemoryBuffer::Format ToGpuMemoryBufferFormat(ResourceFormat format) { |
120 switch (format) { | 128 switch (format) { |
121 case RGBA_8888: | 129 case RGBA_8888: |
122 return gfx::GpuMemoryBuffer::Format::RGBA_8888; | 130 return gfx::GpuMemoryBuffer::Format::RGBA_8888; |
123 case BGRA_8888: | 131 case BGRA_8888: |
124 return gfx::GpuMemoryBuffer::Format::BGRA_8888; | 132 return gfx::GpuMemoryBuffer::Format::BGRA_8888; |
| 133 case ATC: |
| 134 return gfx::GpuMemoryBuffer::Format::ATC; |
| 135 case ATC_IA: |
| 136 return gfx::GpuMemoryBuffer::Format::ATCIA; |
| 137 case DXT1: |
| 138 return gfx::GpuMemoryBuffer::Format::DXT1; |
| 139 case DXT5: |
| 140 return gfx::GpuMemoryBuffer::Format::DXT5; |
| 141 case ETC1: |
| 142 return gfx::GpuMemoryBuffer::Format::ETC1; |
| 143 case RED_8: |
125 case RGBA_4444: | 144 case RGBA_4444: |
126 case ALPHA_8: | 145 case ALPHA_8: |
127 case LUMINANCE_8: | 146 case LUMINANCE_8: |
128 case RGB_565: | 147 case RGB_565: |
129 case ETC1: | |
130 case RED_8: | |
131 break; | 148 break; |
132 } | 149 } |
133 NOTREACHED(); | 150 NOTREACHED(); |
134 return gfx::GpuMemoryBuffer::Format::RGBA_8888; | 151 return gfx::GpuMemoryBuffer::Format::RGBA_8888; |
135 } | 152 } |
136 | 153 |
137 class ScopedSetActiveTexture { | 154 class ScopedSetActiveTexture { |
138 public: | 155 public: |
139 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) | 156 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) |
140 : gl_(gl), unit_(unit) { | 157 : gl_(gl), unit_(unit) { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 wrap_mode(wrap_mode), | 429 wrap_mode(wrap_mode), |
413 hint(TextureHintImmutable), | 430 hint(TextureHintImmutable), |
414 type(Bitmap), | 431 type(Bitmap), |
415 format(RGBA_8888), | 432 format(RGBA_8888), |
416 shared_bitmap_id(bitmap_id), | 433 shared_bitmap_id(bitmap_id), |
417 shared_bitmap(NULL), | 434 shared_bitmap(NULL), |
418 gpu_memory_buffer(NULL) { | 435 gpu_memory_buffer(NULL) { |
419 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 436 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
420 } | 437 } |
421 | 438 |
| 439 bool ResourceProvider::Resource::IsCompressed() const { |
| 440 return IsFormatCompressed(format); |
| 441 } |
| 442 |
| 443 size_t ResourceProvider::Resource::CompressedSize() const { |
| 444 switch (format) { |
| 445 case ATC: |
| 446 case DXT1: |
| 447 case ETC1: |
| 448 return size.width() * size.height() / 2; |
| 449 case ATC_IA: |
| 450 case DXT5: |
| 451 return size.width() * size.height(); |
| 452 default: |
| 453 NOTREACHED(); |
| 454 return 0; |
| 455 } |
| 456 } |
| 457 |
422 ResourceProvider::Child::Child() : marked_for_deletion(false) {} | 458 ResourceProvider::Child::Child() : marked_for_deletion(false) {} |
423 | 459 |
424 ResourceProvider::Child::~Child() {} | 460 ResourceProvider::Child::~Child() {} |
425 | 461 |
426 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 462 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
427 OutputSurface* output_surface, | 463 OutputSurface* output_surface, |
428 SharedBitmapManager* shared_bitmap_manager, | 464 SharedBitmapManager* shared_bitmap_manager, |
429 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 465 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
430 BlockingTaskRunner* blocking_main_thread_task_runner, | 466 BlockingTaskRunner* blocking_main_thread_task_runner, |
431 int highp_threshold_min, | 467 int highp_threshold_min, |
432 bool use_rgba_4444_texture_format, | 468 bool use_rgba_4444_texture_format, |
| 469 bool use_texture_compression, |
433 size_t id_allocation_chunk_size) { | 470 size_t id_allocation_chunk_size) { |
434 scoped_ptr<ResourceProvider> resource_provider( | 471 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( |
435 new ResourceProvider(output_surface, | 472 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, |
436 shared_bitmap_manager, | 473 blocking_main_thread_task_runner, highp_threshold_min, |
437 gpu_memory_buffer_manager, | 474 use_rgba_4444_texture_format, use_texture_compression, |
438 blocking_main_thread_task_runner, | 475 id_allocation_chunk_size)); |
439 highp_threshold_min, | |
440 use_rgba_4444_texture_format, | |
441 id_allocation_chunk_size)); | |
442 | 476 |
443 if (resource_provider->ContextGL()) | 477 if (resource_provider->ContextGL()) |
444 resource_provider->InitializeGL(); | 478 resource_provider->InitializeGL(); |
445 else | 479 else |
446 resource_provider->InitializeSoftware(); | 480 resource_provider->InitializeSoftware(); |
447 | 481 |
448 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); | 482 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); |
449 return resource_provider.Pass(); | 483 return resource_provider.Pass(); |
450 } | 484 } |
451 | 485 |
452 ResourceProvider::~ResourceProvider() { | 486 ResourceProvider::~ResourceProvider() { |
453 while (!children_.empty()) | 487 while (!children_.empty()) |
454 DestroyChildInternal(children_.begin(), ForShutdown); | 488 DestroyChildInternal(children_.begin(), ForShutdown); |
455 while (!resources_.empty()) | 489 while (!resources_.empty()) |
456 DeleteResourceInternal(resources_.begin(), ForShutdown); | 490 DeleteResourceInternal(resources_.begin(), ForShutdown); |
457 | 491 |
458 CleanUpGLIfNeeded(); | 492 CleanUpGLIfNeeded(); |
459 } | 493 } |
460 | 494 |
| 495 ResourceFormat ResourceProvider::memory_efficient_texture_format( |
| 496 ResourceFormatUsage usage) const { |
| 497 if (use_texture_compression_ && usage != FORMAT_USAGE_NATIVE) { |
| 498 // Try to select the prefered compression method. |
| 499 switch (preferred_tile_compression_method_) { |
| 500 case TILE_COMPRESSION_METHOD_ATC: |
| 501 if (use_compressed_texture_atc_) { |
| 502 return usage == FORMAT_USAGE_OPAQUE ? ATC : ATC_IA; |
| 503 } |
| 504 break; |
| 505 case TILE_COMPRESSION_METHOD_DXT: |
| 506 if (use_compressed_texture_dxt_) { |
| 507 return usage == FORMAT_USAGE_OPAQUE ? DXT1 : DXT5; |
| 508 } |
| 509 break; |
| 510 case TILE_COMPRESSION_METHOD_ETC: |
| 511 if (use_compressed_texture_etc1_ && usage == FORMAT_USAGE_OPAQUE) { |
| 512 return ETC1; |
| 513 } |
| 514 break; |
| 515 default: |
| 516 break; |
| 517 } |
| 518 |
| 519 // Check the formats in preferred order, based on encoding speed and |
| 520 // compression ratio. |
| 521 if (use_compressed_texture_atc_) { |
| 522 return usage == FORMAT_USAGE_OPAQUE ? ATC : ATC_IA; |
| 523 } |
| 524 if (use_compressed_texture_dxt_) { |
| 525 return usage == FORMAT_USAGE_OPAQUE ? DXT1 : DXT5; |
| 526 } |
| 527 } |
| 528 |
| 529 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; |
| 530 } |
| 531 |
461 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 532 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
462 Resource* resource = GetResource(id); | 533 Resource* resource = GetResource(id); |
463 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 534 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
464 resource->lost; | 535 resource->lost; |
465 } | 536 } |
466 | 537 |
467 bool ResourceProvider::IsLost(ResourceId id) { | 538 bool ResourceProvider::IsLost(ResourceId id) { |
468 Resource* resource = GetResource(id); | 539 Resource* resource = GetResource(id); |
469 return resource->lost; | 540 return resource->lost; |
470 } | 541 } |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 gl_->Finish(); | 1269 gl_->Finish(); |
1199 } | 1270 } |
1200 | 1271 |
1201 ResourceProvider::ResourceProvider( | 1272 ResourceProvider::ResourceProvider( |
1202 OutputSurface* output_surface, | 1273 OutputSurface* output_surface, |
1203 SharedBitmapManager* shared_bitmap_manager, | 1274 SharedBitmapManager* shared_bitmap_manager, |
1204 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 1275 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
1205 BlockingTaskRunner* blocking_main_thread_task_runner, | 1276 BlockingTaskRunner* blocking_main_thread_task_runner, |
1206 int highp_threshold_min, | 1277 int highp_threshold_min, |
1207 bool use_rgba_4444_texture_format, | 1278 bool use_rgba_4444_texture_format, |
| 1279 bool use_texture_compression, |
1208 size_t id_allocation_chunk_size) | 1280 size_t id_allocation_chunk_size) |
1209 : output_surface_(output_surface), | 1281 : output_surface_(output_surface), |
1210 shared_bitmap_manager_(shared_bitmap_manager), | 1282 shared_bitmap_manager_(shared_bitmap_manager), |
1211 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 1283 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
1212 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), | 1284 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), |
1213 lost_output_surface_(false), | 1285 lost_output_surface_(false), |
1214 highp_threshold_min_(highp_threshold_min), | 1286 highp_threshold_min_(highp_threshold_min), |
1215 next_id_(1), | 1287 next_id_(1), |
1216 next_child_(1), | 1288 next_child_(1), |
1217 default_resource_type_(InvalidType), | 1289 default_resource_type_(InvalidType), |
1218 use_texture_storage_ext_(false), | 1290 use_texture_storage_ext_(false), |
1219 use_texture_format_bgra_(false), | 1291 use_texture_format_bgra_(false), |
1220 use_texture_usage_hint_(false), | 1292 use_texture_usage_hint_(false), |
| 1293 use_compressed_texture_atc_(false), |
| 1294 use_compressed_texture_dxt_(false), |
1221 use_compressed_texture_etc1_(false), | 1295 use_compressed_texture_etc1_(false), |
1222 yuv_resource_format_(LUMINANCE_8), | 1296 yuv_resource_format_(LUMINANCE_8), |
1223 max_texture_size_(0), | 1297 max_texture_size_(0), |
1224 best_texture_format_(RGBA_8888), | 1298 best_texture_format_(RGBA_8888), |
1225 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), | 1299 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), |
| 1300 use_texture_compression_(use_texture_compression), |
1226 id_allocation_chunk_size_(id_allocation_chunk_size), | 1301 id_allocation_chunk_size_(id_allocation_chunk_size), |
1227 use_sync_query_(false) { | 1302 use_sync_query_(false) { |
1228 DCHECK(output_surface_->HasClient()); | 1303 DCHECK(output_surface_->HasClient()); |
1229 DCHECK(id_allocation_chunk_size_); | 1304 DCHECK(id_allocation_chunk_size_); |
1230 } | 1305 } |
1231 | 1306 |
1232 void ResourceProvider::InitializeSoftware() { | 1307 void ResourceProvider::InitializeSoftware() { |
1233 DCHECK(thread_checker_.CalledOnValidThread()); | 1308 DCHECK(thread_checker_.CalledOnValidThread()); |
1234 DCHECK_NE(Bitmap, default_resource_type_); | 1309 DCHECK_NE(Bitmap, default_resource_type_); |
1235 | 1310 |
(...skipping 14 matching lines...) Expand all Loading... |
1250 | 1325 |
1251 default_resource_type_ = GLTexture; | 1326 default_resource_type_ = GLTexture; |
1252 | 1327 |
1253 const ContextProvider::Capabilities& caps = | 1328 const ContextProvider::Capabilities& caps = |
1254 output_surface_->context_provider()->ContextCapabilities(); | 1329 output_surface_->context_provider()->ContextCapabilities(); |
1255 | 1330 |
1256 bool use_bgra = caps.gpu.texture_format_bgra8888; | 1331 bool use_bgra = caps.gpu.texture_format_bgra8888; |
1257 use_texture_storage_ext_ = caps.gpu.texture_storage; | 1332 use_texture_storage_ext_ = caps.gpu.texture_storage; |
1258 use_texture_format_bgra_ = caps.gpu.texture_format_bgra8888; | 1333 use_texture_format_bgra_ = caps.gpu.texture_format_bgra8888; |
1259 use_texture_usage_hint_ = caps.gpu.texture_usage; | 1334 use_texture_usage_hint_ = caps.gpu.texture_usage; |
| 1335 use_compressed_texture_atc_ = caps.gpu.texture_format_atc; |
| 1336 use_compressed_texture_dxt_ = caps.gpu.texture_format_dxt; |
1260 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; | 1337 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; |
1261 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8; | 1338 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8; |
1262 use_sync_query_ = caps.gpu.sync_query; | 1339 use_sync_query_ = caps.gpu.sync_query; |
1263 | 1340 |
1264 GLES2Interface* gl = ContextGL(); | 1341 GLES2Interface* gl = ContextGL(); |
1265 DCHECK(gl); | 1342 DCHECK(gl); |
1266 | 1343 |
1267 texture_uploader_ = TextureUploader::Create(gl); | 1344 texture_uploader_ = TextureUploader::Create(gl); |
1268 max_texture_size_ = 0; // Context expects cleared value. | 1345 max_texture_size_ = 0; // Context expects cleared value. |
1269 GLC(gl, gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_)); | 1346 GLC(gl, gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_)); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 } | 1802 } |
1726 | 1803 |
1727 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | 1804 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
1728 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1805 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
1729 "ResourceProvider::AcquirePixelBuffer"); | 1806 "ResourceProvider::AcquirePixelBuffer"); |
1730 | 1807 |
1731 Resource* resource = GetResource(id); | 1808 Resource* resource = GetResource(id); |
1732 DCHECK(resource->origin == Resource::Internal); | 1809 DCHECK(resource->origin == Resource::Internal); |
1733 DCHECK_EQ(resource->exported_count, 0); | 1810 DCHECK_EQ(resource->exported_count, 0); |
1734 DCHECK(!resource->image_id); | 1811 DCHECK(!resource->image_id); |
1735 DCHECK_NE(ETC1, resource->format); | |
1736 | 1812 |
1737 DCHECK_EQ(GLTexture, resource->type); | 1813 DCHECK_EQ(GLTexture, resource->type); |
1738 GLES2Interface* gl = ContextGL(); | 1814 GLES2Interface* gl = ContextGL(); |
1739 DCHECK(gl); | 1815 DCHECK(gl); |
1740 if (!resource->gl_pixel_buffer_id) | 1816 if (!resource->gl_pixel_buffer_id) |
1741 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); | 1817 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
1742 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1818 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1743 resource->gl_pixel_buffer_id); | 1819 resource->gl_pixel_buffer_id); |
1744 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; | 1820 unsigned width_in_bytes = |
1745 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1821 BitsPerPixel(resource->format) * resource->size.width() / 8; |
1746 resource->size.height() * | 1822 unsigned image_size = resource->size.height() * RoundUp(width_in_bytes, 4u); |
1747 RoundUp(bytes_per_pixel * resource->size.width(), 4u), | 1823 DCHECK(image_size); |
1748 NULL, | 1824 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, image_size, NULL, |
1749 GL_DYNAMIC_DRAW); | 1825 GL_DYNAMIC_DRAW); |
1750 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1826 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1751 } | 1827 } |
1752 | 1828 |
1753 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 1829 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
1754 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1830 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
1755 "ResourceProvider::ReleasePixelBuffer"); | 1831 "ResourceProvider::ReleasePixelBuffer"); |
1756 | 1832 |
1757 Resource* resource = GetResource(id); | 1833 Resource* resource = GetResource(id); |
1758 DCHECK(resource->origin == Resource::Internal); | 1834 DCHECK(resource->origin == Resource::Internal); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 DCHECK(gl); | 1951 DCHECK(gl); |
1876 DCHECK(resource->gl_pixel_buffer_id); | 1952 DCHECK(resource->gl_pixel_buffer_id); |
1877 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 1953 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
1878 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 1954 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
1879 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1955 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1880 resource->gl_pixel_buffer_id); | 1956 resource->gl_pixel_buffer_id); |
1881 if (!resource->gl_upload_query_id) | 1957 if (!resource->gl_upload_query_id) |
1882 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); | 1958 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); |
1883 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1959 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
1884 resource->gl_upload_query_id); | 1960 resource->gl_upload_query_id); |
1885 if (allocate) { | 1961 if (resource->IsCompressed()) { |
1886 gl->AsyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1962 if (allocate) { |
1887 0, /* level */ | 1963 gl->AsyncCompressedTexImage2DCHROMIUM( |
1888 GLInternalFormat(resource->format), | 1964 GL_TEXTURE_2D, 0 /* level */, GLInternalFormat(resource->format), |
1889 resource->size.width(), | 1965 resource->size.width(), resource->size.height(), 0 /* border */, |
1890 resource->size.height(), | 1966 resource->CompressedSize(), NULL); |
1891 0, /* border */ | 1967 } else { |
1892 GLDataFormat(resource->format), | 1968 gl->AsyncCompressedTexSubImage2DCHROMIUM( |
1893 GLDataType(resource->format), | 1969 GL_TEXTURE_2D, 0 /* level */, 0 /* x */, 0 /* y */, |
1894 NULL); | 1970 resource->size.width(), resource->size.height(), |
| 1971 GLInternalFormat(resource->format), resource->CompressedSize(), NULL); |
| 1972 } |
1895 } else { | 1973 } else { |
1896 gl->AsyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1974 if (allocate) { |
1897 0, /* level */ | 1975 gl->AsyncTexImage2DCHROMIUM( |
1898 0, /* x */ | 1976 GL_TEXTURE_2D, 0, /* level */ |
1899 0, /* y */ | 1977 GLInternalFormat(resource->format), resource->size.width(), |
1900 resource->size.width(), | 1978 resource->size.height(), 0, /* border */ |
1901 resource->size.height(), | 1979 GLDataFormat(resource->format), GLDataType(resource->format), NULL); |
1902 GLDataFormat(resource->format), | 1980 } else { |
1903 GLDataType(resource->format), | 1981 gl->AsyncTexSubImage2DCHROMIUM( |
1904 NULL); | 1982 GL_TEXTURE_2D, 0, /* level */ |
| 1983 0, /* x */ |
| 1984 0, /* y */ |
| 1985 resource->size.width(), resource->size.height(), |
| 1986 GLDataFormat(resource->format), GLDataType(resource->format), NULL); |
| 1987 } |
1905 } | 1988 } |
1906 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1989 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
1907 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1990 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1908 | 1991 |
1909 resource->pending_set_pixels = true; | 1992 resource->pending_set_pixels = true; |
1910 resource->set_pixels_completion_forced = false; | 1993 resource->set_pixels_completion_forced = false; |
1911 } | 1994 } |
1912 | 1995 |
1913 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { | 1996 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
1914 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1997 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 ResourceFormat format = resource->format; | 2111 ResourceFormat format = resource->format; |
2029 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); | 2112 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); |
2030 if (use_texture_storage_ext_ && | 2113 if (use_texture_storage_ext_ && |
2031 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 2114 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
2032 (resource->hint & TextureHintImmutable)) { | 2115 (resource->hint & TextureHintImmutable)) { |
2033 GLenum storage_format = TextureToStorageFormat(format); | 2116 GLenum storage_format = TextureToStorageFormat(format); |
2034 GLC(gl, | 2117 GLC(gl, |
2035 gl->TexStorage2DEXT( | 2118 gl->TexStorage2DEXT( |
2036 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height())); | 2119 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height())); |
2037 } else { | 2120 } else { |
2038 // ETC1 does not support preallocation. | 2121 // Compressed formats does not support preallocation. |
2039 if (format != ETC1) { | 2122 if (!IsFormatCompressed(format)) { |
2040 GLC(gl, | 2123 GLC(gl, |
2041 gl->TexImage2D(GL_TEXTURE_2D, | 2124 gl->TexImage2D(GL_TEXTURE_2D, |
2042 0, | 2125 0, |
2043 GLInternalFormat(format), | 2126 GLInternalFormat(format), |
2044 size.width(), | 2127 size.width(), |
2045 size.height(), | 2128 size.height(), |
2046 0, | 2129 0, |
2047 GLDataFormat(format), | 2130 GLDataFormat(format), |
2048 GLDataType(format), | 2131 GLDataType(format), |
2049 NULL)); | 2132 NULL)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2094 BindImageForSampling(source_resource); | 2177 BindImageForSampling(source_resource); |
2095 } | 2178 } |
2096 if (use_sync_query_) { | 2179 if (use_sync_query_) { |
2097 if (!source_resource->gl_read_lock_query_id) | 2180 if (!source_resource->gl_read_lock_query_id) |
2098 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); | 2181 gl->GenQueriesEXT(1, &source_resource->gl_read_lock_query_id); |
2099 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 2182 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
2100 source_resource->gl_read_lock_query_id); | 2183 source_resource->gl_read_lock_query_id); |
2101 } | 2184 } |
2102 DCHECK(!dest_resource->image_id); | 2185 DCHECK(!dest_resource->image_id); |
2103 dest_resource->allocated = true; | 2186 dest_resource->allocated = true; |
2104 gl->CopyTextureCHROMIUM(dest_resource->target, | 2187 if (!source_resource->IsCompressed()) { |
2105 source_resource->gl_id, | 2188 gl->CopyTextureCHROMIUM(dest_resource->target, source_resource->gl_id, |
2106 dest_resource->gl_id, | 2189 dest_resource->gl_id, 0, |
2107 0, | 2190 GLInternalFormat(dest_resource->format), |
2108 GLInternalFormat(dest_resource->format), | 2191 GLDataType(dest_resource->format)); |
2109 GLDataType(dest_resource->format)); | 2192 } else { |
| 2193 gl->CopyCompressedTextureCHROMIUM( |
| 2194 dest_resource->target, source_resource->gl_id, dest_resource->gl_id, |
| 2195 GLInternalFormat(dest_resource->format), |
| 2196 GLDataType(dest_resource->format)); |
| 2197 } |
2110 if (source_resource->gl_read_lock_query_id) { | 2198 if (source_resource->gl_read_lock_query_id) { |
2111 // End query and create a read lock fence that will prevent access to | 2199 // End query and create a read lock fence that will prevent access to |
2112 // source resource until CopyTextureCHROMIUM command has completed. | 2200 // source resource until CopyTextureCHROMIUM command has completed. |
2113 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 2201 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
2114 source_resource->read_lock_fence = make_scoped_refptr( | 2202 source_resource->read_lock_fence = make_scoped_refptr( |
2115 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 2203 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); |
2116 } else { | 2204 } else { |
2117 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. | 2205 // Create a SynchronousFence when CHROMIUM_sync_query extension is missing. |
2118 // Try to use one synchronous fence for as many CopyResource operations as | 2206 // Try to use one synchronous fence for as many CopyResource operations as |
2119 // possible as that reduce the number of times we have to synchronize with | 2207 // possible as that reduce the number of times we have to synchronize with |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2159 ContextProvider* context_provider = output_surface_->context_provider(); | 2247 ContextProvider* context_provider = output_surface_->context_provider(); |
2160 return context_provider ? context_provider->ContextGL() : NULL; | 2248 return context_provider ? context_provider->ContextGL() : NULL; |
2161 } | 2249 } |
2162 | 2250 |
2163 class GrContext* ResourceProvider::GrContext() const { | 2251 class GrContext* ResourceProvider::GrContext() const { |
2164 ContextProvider* context_provider = output_surface_->context_provider(); | 2252 ContextProvider* context_provider = output_surface_->context_provider(); |
2165 return context_provider ? context_provider->GrContext() : NULL; | 2253 return context_provider ? context_provider->GrContext() : NULL; |
2166 } | 2254 } |
2167 | 2255 |
2168 } // namespace cc | 2256 } // namespace cc |
OLD | NEW |