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/transferable_resource.h" | 21 #include "cc/resources/transferable_resource.h" |
18 #include "cc/scheduler/texture_uploader.h" | 22 #include "cc/scheduler/texture_uploader.h" |
19 #include "gpu/GLES2/gl2extchromium.h" | 23 #include "gpu/GLES2/gl2extchromium.h" |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 : output_surface_(output_surface), | 682 : output_surface_(output_surface), |
679 lost_output_surface_(false), | 683 lost_output_surface_(false), |
680 highp_threshold_min_(highp_threshold_min), | 684 highp_threshold_min_(highp_threshold_min), |
681 next_id_(1), | 685 next_id_(1), |
682 next_child_(1), | 686 next_child_(1), |
683 default_resource_type_(InvalidType), | 687 default_resource_type_(InvalidType), |
684 use_texture_storage_ext_(false), | 688 use_texture_storage_ext_(false), |
685 use_texture_usage_hint_(false), | 689 use_texture_usage_hint_(false), |
686 use_shallow_flush_(false), | 690 use_shallow_flush_(false), |
687 max_texture_size_(0), | 691 max_texture_size_(0), |
688 best_texture_format_(0) {} | 692 best_texture_format_(0), |
| 693 use_16bit_textures_(false) { |
| 694 #if defined(OS_ANDROID) |
| 695 if (base::android::SysUtils::IsLowEndDevice()) |
| 696 use_16bit_textures_ = true; |
| 697 #endif |
| 698 } |
689 | 699 |
690 void ResourceProvider::InitializeSoftware() { | 700 void ResourceProvider::InitializeSoftware() { |
691 DCHECK(thread_checker_.CalledOnValidThread()); | 701 DCHECK(thread_checker_.CalledOnValidThread()); |
692 DCHECK_NE(Bitmap, default_resource_type_); | 702 DCHECK_NE(Bitmap, default_resource_type_); |
693 | 703 |
694 CleanUpGLIfNeeded(); | 704 CleanUpGLIfNeeded(); |
695 | 705 |
696 default_resource_type_ = Bitmap; | 706 default_resource_type_ = Bitmap; |
697 max_texture_size_ = INT_MAX / 2; | 707 max_texture_size_ = INT_MAX / 2; |
698 best_texture_format_ = GL_RGBA; | 708 best_texture_format_ = GL_RGBA; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1042 |
1033 if (resource->pixels) { | 1043 if (resource->pixels) { |
1034 if (!resource->pixel_buffer) | 1044 if (!resource->pixel_buffer) |
1035 return; | 1045 return; |
1036 delete[] resource->pixel_buffer; | 1046 delete[] resource->pixel_buffer; |
1037 resource->pixel_buffer = NULL; | 1047 resource->pixel_buffer = NULL; |
1038 } | 1048 } |
1039 } | 1049 } |
1040 | 1050 |
1041 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { | 1051 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
| 1052 LOG(ERROR) << "KAANB: MapPixelBuffer!!!!!!!!!!!!!!!!!!!!!!!!"; |
1042 DCHECK(thread_checker_.CalledOnValidThread()); | 1053 DCHECK(thread_checker_.CalledOnValidThread()); |
1043 ResourceMap::iterator it = resources_.find(id); | 1054 ResourceMap::iterator it = resources_.find(id); |
1044 CHECK(it != resources_.end()); | 1055 CHECK(it != resources_.end()); |
1045 Resource* resource = &it->second; | 1056 Resource* resource = &it->second; |
1046 DCHECK(!resource->external); | 1057 DCHECK(!resource->external); |
1047 DCHECK(!resource->exported); | 1058 DCHECK(!resource->exported); |
1048 DCHECK(!resource->image_id); | 1059 DCHECK(!resource->image_id); |
1049 | 1060 |
1050 if (resource->type == GLTexture) { | 1061 if (resource->type == GLTexture) { |
1051 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1062 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 DCHECK(resource->gl_pixel_buffer_id); | 1177 DCHECK(resource->gl_pixel_buffer_id); |
1167 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1178 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1168 context3d->bindBuffer( | 1179 context3d->bindBuffer( |
1169 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1180 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1170 resource->gl_pixel_buffer_id); | 1181 resource->gl_pixel_buffer_id); |
1171 if (!resource->gl_upload_query_id) | 1182 if (!resource->gl_upload_query_id) |
1172 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1183 resource->gl_upload_query_id = context3d->createQueryEXT(); |
1173 context3d->beginQueryEXT( | 1184 context3d->beginQueryEXT( |
1174 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, | 1185 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
1175 resource->gl_upload_query_id); | 1186 resource->gl_upload_query_id); |
| 1187 GLenum texture_data_type = use_16bit_textures_ |
| 1188 ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_BYTE; |
1176 if (allocate) { | 1189 if (allocate) { |
1177 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1190 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, |
1178 0, /* level */ | 1191 0, /* level */ |
1179 resource->format, | 1192 resource->format, |
1180 resource->size.width(), | 1193 resource->size.width(), |
1181 resource->size.height(), | 1194 resource->size.height(), |
1182 0, /* border */ | 1195 0, /* border */ |
1183 resource->format, | 1196 resource->format, |
1184 GL_UNSIGNED_BYTE, | 1197 texture_data_type, |
1185 NULL); | 1198 NULL); |
1186 } else { | 1199 } else { |
1187 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1200 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
1188 0, /* level */ | 1201 0, /* level */ |
1189 0, /* x */ | 1202 0, /* x */ |
1190 0, /* y */ | 1203 0, /* y */ |
1191 resource->size.width(), | 1204 resource->size.width(), |
1192 resource->size.height(), | 1205 resource->size.height(), |
1193 resource->format, | 1206 resource->format, |
1194 GL_UNSIGNED_BYTE, | 1207 texture_data_type, |
1195 NULL); | 1208 NULL); |
1196 } | 1209 } |
1197 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); | 1210 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); |
1198 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1211 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1199 } | 1212 } |
1200 | 1213 |
1201 if (resource->pixels) { | 1214 if (resource->pixels) { |
1202 DCHECK(!resource->mailbox.IsValid()); | 1215 DCHECK(!resource->mailbox.IsValid()); |
1203 DCHECK(resource->pixel_buffer); | 1216 DCHECK(resource->pixel_buffer); |
1204 DCHECK(resource->format == GL_RGBA); | 1217 DCHECK(resource->format == GL_RGBA); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 GLenum format = resource->format; | 1320 GLenum format = resource->format; |
1308 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1321 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1309 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1322 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { |
1310 GLenum storage_format = TextureToStorageFormat(format); | 1323 GLenum storage_format = TextureToStorageFormat(format); |
1311 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1324 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
1312 1, | 1325 1, |
1313 storage_format, | 1326 storage_format, |
1314 size.width(), | 1327 size.width(), |
1315 size.height())); | 1328 size.height())); |
1316 } else { | 1329 } else { |
| 1330 GLenum texture_data_type = use_16bit_textures_ |
| 1331 ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_BYTE; |
1317 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1332 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
1318 0, | 1333 0, |
1319 format, | 1334 format, |
1320 size.width(), | 1335 size.width(), |
1321 size.height(), | 1336 size.height(), |
1322 0, | 1337 0, |
1323 format, | 1338 format, |
1324 GL_UNSIGNED_BYTE, | 1339 texture_data_type, |
1325 NULL)); | 1340 NULL)); |
1326 } | 1341 } |
1327 } | 1342 } |
1328 | 1343 |
1329 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1344 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1330 bool enable) { | 1345 bool enable) { |
1331 DCHECK(thread_checker_.CalledOnValidThread()); | 1346 DCHECK(thread_checker_.CalledOnValidThread()); |
1332 ResourceMap::iterator it = resources_.find(id); | 1347 ResourceMap::iterator it = resources_.find(id); |
1333 CHECK(it != resources_.end()); | 1348 CHECK(it != resources_.end()); |
1334 Resource* resource = &it->second; | 1349 Resource* resource = &it->second; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 return stride; | 1452 return stride; |
1438 } | 1453 } |
1439 | 1454 |
1440 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) { | 1455 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) { |
1441 GLint active_unit = 0; | 1456 GLint active_unit = 0; |
1442 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1457 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1443 return active_unit; | 1458 return active_unit; |
1444 } | 1459 } |
1445 | 1460 |
1446 } // namespace cc | 1461 } // namespace cc |
OLD | NEW |