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 #if defined(OS_ANDROID) | |
11 #include "base/android/sys_utils.h" | |
12 #endif | |
13 | |
10 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
11 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
12 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
13 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
15 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 19 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
16 #include "cc/resources/platform_color.h" | 20 #include "cc/resources/platform_color.h" |
17 #include "cc/resources/returned_resource.h" | 21 #include "cc/resources/returned_resource.h" |
18 #include "cc/resources/transferable_resource.h" | 22 #include "cc/resources/transferable_resource.h" |
19 #include "cc/scheduler/texture_uploader.h" | 23 #include "cc/scheduler/texture_uploader.h" |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 : output_surface_(output_surface), | 678 : output_surface_(output_surface), |
675 lost_output_surface_(false), | 679 lost_output_surface_(false), |
676 highp_threshold_min_(highp_threshold_min), | 680 highp_threshold_min_(highp_threshold_min), |
677 next_id_(1), | 681 next_id_(1), |
678 next_child_(1), | 682 next_child_(1), |
679 default_resource_type_(InvalidType), | 683 default_resource_type_(InvalidType), |
680 use_texture_storage_ext_(false), | 684 use_texture_storage_ext_(false), |
681 use_texture_usage_hint_(false), | 685 use_texture_usage_hint_(false), |
682 use_shallow_flush_(false), | 686 use_shallow_flush_(false), |
683 max_texture_size_(0), | 687 max_texture_size_(0), |
684 best_texture_format_(0) { | 688 best_texture_format_(0), |
epennerAtGoogle
2013/09/05 01:54:15
Could we have best_texture_type in addition to bes
kaanb
2013/09/06 02:05:54
Done.
| |
689 use_16_bit_textures_(false) { | |
685 DCHECK(output_surface_->HasClient()); | 690 DCHECK(output_surface_->HasClient()); |
691 #if defined(OS_ANDROID) | |
692 if (base::android::SysUtils::IsLowEndDevice()) | |
693 use_16_bit_textures_ = true; | |
enne (OOO)
2013/09/05 02:01:19
Please make this a LayerTreeSetting and keep the #
kaanb
2013/09/06 02:05:54
Done.
| |
694 #endif | |
686 } | 695 } |
687 | 696 |
688 void ResourceProvider::InitializeSoftware() { | 697 void ResourceProvider::InitializeSoftware() { |
689 DCHECK(thread_checker_.CalledOnValidThread()); | 698 DCHECK(thread_checker_.CalledOnValidThread()); |
690 DCHECK_NE(Bitmap, default_resource_type_); | 699 DCHECK_NE(Bitmap, default_resource_type_); |
691 | 700 |
692 CleanUpGLIfNeeded(); | 701 CleanUpGLIfNeeded(); |
693 | 702 |
694 default_resource_type_ = Bitmap; | 703 default_resource_type_ = Bitmap; |
695 max_texture_size_ = INT_MAX / 2; | 704 max_texture_size_ = INT_MAX / 2; |
(...skipping 16 matching lines...) Expand all Loading... | |
712 const ContextProvider::Capabilities& caps = | 721 const ContextProvider::Capabilities& caps = |
713 output_surface_->context_provider()->ContextCapabilities(); | 722 output_surface_->context_provider()->ContextCapabilities(); |
714 | 723 |
715 bool use_map_sub = caps.map_sub; | 724 bool use_map_sub = caps.map_sub; |
716 bool use_bgra = caps.texture_format_bgra8888; | 725 bool use_bgra = caps.texture_format_bgra8888; |
717 use_texture_storage_ext_ = caps.texture_storage; | 726 use_texture_storage_ext_ = caps.texture_storage; |
718 use_shallow_flush_ = caps.shallow_flush; | 727 use_shallow_flush_ = caps.shallow_flush; |
719 use_texture_usage_hint_ = caps.texture_usage; | 728 use_texture_usage_hint_ = caps.texture_usage; |
720 | 729 |
721 texture_uploader_ = | 730 texture_uploader_ = |
722 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); | 731 TextureUploader::Create(context3d, |
732 use_map_sub, | |
733 use_shallow_flush_, | |
734 use_16_bit_textures_); | |
723 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, | 735 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, |
724 &max_texture_size_)); | 736 &max_texture_size_)); |
725 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 737 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
726 | 738 |
727 return true; | 739 return true; |
728 } | 740 } |
729 | 741 |
730 void ResourceProvider::CleanUpGLIfNeeded() { | 742 void ResourceProvider::CleanUpGLIfNeeded() { |
731 WebGraphicsContext3D* context3d = Context3d(); | 743 WebGraphicsContext3D* context3d = Context3d(); |
732 if (default_resource_type_ != GLTexture) { | 744 if (default_resource_type_ != GLTexture) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
968 DCHECK(!resource->image_id); | 980 DCHECK(!resource->image_id); |
969 | 981 |
970 if (resource->type == GLTexture) { | 982 if (resource->type == GLTexture) { |
971 WebGraphicsContext3D* context3d = Context3d(); | 983 WebGraphicsContext3D* context3d = Context3d(); |
972 DCHECK(context3d); | 984 DCHECK(context3d); |
973 if (!resource->gl_pixel_buffer_id) | 985 if (!resource->gl_pixel_buffer_id) |
974 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 986 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
975 context3d->bindBuffer( | 987 context3d->bindBuffer( |
976 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 988 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
977 resource->gl_pixel_buffer_id); | 989 resource->gl_pixel_buffer_id); |
990 size_t bytes_per_pixel = use_16_bit_textures_ ? 2 : 4; | |
978 context3d->bufferData( | 991 context3d->bufferData( |
979 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 992 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
980 4 * resource->size.GetArea(), | 993 bytes_per_pixel * resource->size.GetArea(), |
981 NULL, | 994 NULL, |
982 GL_DYNAMIC_DRAW); | 995 GL_DYNAMIC_DRAW); |
983 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 996 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
984 } | 997 } |
985 | 998 |
986 if (resource->pixels) { | 999 if (resource->pixels) { |
987 if (resource->pixel_buffer) | 1000 if (resource->pixel_buffer) |
988 return; | 1001 return; |
989 | 1002 |
990 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1003 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 DCHECK(resource->gl_pixel_buffer_id); | 1165 DCHECK(resource->gl_pixel_buffer_id); |
1153 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1166 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1154 context3d->bindBuffer( | 1167 context3d->bindBuffer( |
1155 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1168 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1156 resource->gl_pixel_buffer_id); | 1169 resource->gl_pixel_buffer_id); |
1157 if (!resource->gl_upload_query_id) | 1170 if (!resource->gl_upload_query_id) |
1158 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1171 resource->gl_upload_query_id = context3d->createQueryEXT(); |
1159 context3d->beginQueryEXT( | 1172 context3d->beginQueryEXT( |
1160 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1173 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
1161 resource->gl_upload_query_id); | 1174 resource->gl_upload_query_id); |
1175 GLenum texture_data_type = use_16_bit_textures_ | |
enne (OOO)
2013/09/05 02:01:19
Rather than having to pass around booleans and set
kaanb
2013/09/06 02:05:54
Great point, I didn't have time for it today. I'll
| |
1176 ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_BYTE; | |
1162 if (allocate) { | 1177 if (allocate) { |
1163 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1178 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, |
1164 0, /* level */ | 1179 0, /* level */ |
1165 resource->format, | 1180 resource->format, |
1166 resource->size.width(), | 1181 resource->size.width(), |
1167 resource->size.height(), | 1182 resource->size.height(), |
1168 0, /* border */ | 1183 0, /* border */ |
1169 resource->format, | 1184 resource->format, |
1170 GL_UNSIGNED_BYTE, | 1185 texture_data_type, |
1171 NULL); | 1186 NULL); |
1172 } else { | 1187 } else { |
1173 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1188 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
1174 0, /* level */ | 1189 0, /* level */ |
1175 0, /* x */ | 1190 0, /* x */ |
1176 0, /* y */ | 1191 0, /* y */ |
1177 resource->size.width(), | 1192 resource->size.width(), |
1178 resource->size.height(), | 1193 resource->size.height(), |
1179 resource->format, | 1194 resource->format, |
1180 GL_UNSIGNED_BYTE, | 1195 texture_data_type, |
1181 NULL); | 1196 NULL); |
1182 } | 1197 } |
1183 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1198 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
1184 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1199 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1185 } | 1200 } |
1186 | 1201 |
1187 if (resource->pixels) { | 1202 if (resource->pixels) { |
1188 DCHECK(!resource->mailbox.IsValid()); | 1203 DCHECK(!resource->mailbox.IsValid()); |
1189 DCHECK(resource->pixel_buffer); | 1204 DCHECK(resource->pixel_buffer); |
1190 DCHECK(resource->format == GL_RGBA); | 1205 DCHECK(resource->format == GL_RGBA); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 GLenum format = resource->format; | 1296 GLenum format = resource->format; |
1282 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1297 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1283 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1298 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { |
1284 GLenum storage_format = TextureToStorageFormat(format); | 1299 GLenum storage_format = TextureToStorageFormat(format); |
1285 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1300 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
1286 1, | 1301 1, |
1287 storage_format, | 1302 storage_format, |
1288 size.width(), | 1303 size.width(), |
1289 size.height())); | 1304 size.height())); |
1290 } else { | 1305 } else { |
1306 GLenum texture_data_type = use_16_bit_textures_ | |
1307 ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_BYTE; | |
1291 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1308 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
1292 0, | 1309 0, |
1293 format, | 1310 format, |
1294 size.width(), | 1311 size.width(), |
1295 size.height(), | 1312 size.height(), |
1296 0, | 1313 0, |
1297 format, | 1314 format, |
1298 GL_UNSIGNED_BYTE, | 1315 texture_data_type, |
1299 NULL)); | 1316 NULL)); |
1300 } | 1317 } |
1301 } | 1318 } |
1302 | 1319 |
1303 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1320 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1304 bool enable) { | 1321 bool enable) { |
1305 Resource* resource = GetResource(id); | 1322 Resource* resource = GetResource(id); |
1306 resource->enable_read_lock_fences = enable; | 1323 resource->enable_read_lock_fences = enable; |
1307 } | 1324 } |
1308 | 1325 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1394 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1411 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1395 return active_unit; | 1412 return active_unit; |
1396 } | 1413 } |
1397 | 1414 |
1398 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1415 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
1399 ContextProvider* context_provider = output_surface_->context_provider(); | 1416 ContextProvider* context_provider = output_surface_->context_provider(); |
1400 return context_provider ? context_provider->Context3d() : NULL; | 1417 return context_provider ? context_provider->Context3d() : NULL; |
1401 } | 1418 } |
1402 | 1419 |
1403 } // namespace cc | 1420 } // namespace cc |
OLD | NEW |