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

Side by Side Diff: cc/resources/resource_provider.cc

Issue 21159007: cc: Adding support for RGBA_4444 tile textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments Created 7 years, 3 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
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/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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 texture_pool(0), 154 texture_pool(0),
155 hint(TextureUsageAny), 155 hint(TextureUsageAny),
156 type(Bitmap) {} 156 type(Bitmap) {}
157 157
158 ResourceProvider::Child::Child() {} 158 ResourceProvider::Child::Child() {}
159 159
160 ResourceProvider::Child::~Child() {} 160 ResourceProvider::Child::~Child() {}
161 161
162 scoped_ptr<ResourceProvider> ResourceProvider::Create( 162 scoped_ptr<ResourceProvider> ResourceProvider::Create(
163 OutputSurface* output_surface, 163 OutputSurface* output_surface,
164 int highp_threshold_min) { 164 int highp_threshold_min,
165 bool use_rgba_4444_textures) {
165 scoped_ptr<ResourceProvider> resource_provider( 166 scoped_ptr<ResourceProvider> resource_provider(
166 new ResourceProvider(output_surface, highp_threshold_min)); 167 new ResourceProvider(output_surface,
168 highp_threshold_min,
169 use_rgba_4444_textures));
167 170
168 bool success = false; 171 bool success = false;
169 if (resource_provider->Context3d()) { 172 if (resource_provider->Context3d()) {
170 success = resource_provider->InitializeGL(); 173 success = resource_provider->InitializeGL();
171 } else { 174 } else {
172 resource_provider->InitializeSoftware(); 175 resource_provider->InitializeSoftware();
173 success = true; 176 success = true;
174 } 177 }
175 178
176 if (!success) 179 if (!success)
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 ResourceProvider::PopulateSkBitmapWithResource( 666 ResourceProvider::PopulateSkBitmapWithResource(
664 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); 667 &sk_bitmap_, resource_provider->LockForWrite(resource_id));
665 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); 668 sk_canvas_.reset(new SkCanvas(sk_bitmap_));
666 } 669 }
667 670
668 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { 671 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
669 resource_provider_->UnlockForWrite(resource_id_); 672 resource_provider_->UnlockForWrite(resource_id_);
670 } 673 }
671 674
672 ResourceProvider::ResourceProvider(OutputSurface* output_surface, 675 ResourceProvider::ResourceProvider(OutputSurface* output_surface,
673 int highp_threshold_min) 676 int highp_threshold_min,
677 bool use_rgba_4444_textures)
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),
689 best_texture_type_(use_rgba_4444_textures ? RGBA_4444 : RGBA_8888) {
685 DCHECK(output_surface_->HasClient()); 690 DCHECK(output_surface_->HasClient());
686 } 691 }
687 692
688 void ResourceProvider::InitializeSoftware() { 693 void ResourceProvider::InitializeSoftware() {
689 DCHECK(thread_checker_.CalledOnValidThread()); 694 DCHECK(thread_checker_.CalledOnValidThread());
690 DCHECK_NE(Bitmap, default_resource_type_); 695 DCHECK_NE(Bitmap, default_resource_type_);
691 696
692 CleanUpGLIfNeeded(); 697 CleanUpGLIfNeeded();
693 698
694 default_resource_type_ = Bitmap; 699 default_resource_type_ = Bitmap;
(...skipping 17 matching lines...) Expand all
712 const ContextProvider::Capabilities& caps = 717 const ContextProvider::Capabilities& caps =
713 output_surface_->context_provider()->ContextCapabilities(); 718 output_surface_->context_provider()->ContextCapabilities();
714 719
715 bool use_map_sub = caps.map_sub; 720 bool use_map_sub = caps.map_sub;
716 bool use_bgra = caps.texture_format_bgra8888; 721 bool use_bgra = caps.texture_format_bgra8888;
717 use_texture_storage_ext_ = caps.texture_storage; 722 use_texture_storage_ext_ = caps.texture_storage;
718 use_shallow_flush_ = caps.shallow_flush; 723 use_shallow_flush_ = caps.shallow_flush;
719 use_texture_usage_hint_ = caps.texture_usage; 724 use_texture_usage_hint_ = caps.texture_usage;
720 725
721 texture_uploader_ = 726 texture_uploader_ =
722 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); 727 TextureUploader::Create(context3d,
728 use_map_sub,
729 use_shallow_flush_,
730 best_texture_type_ == RGBA_4444);
723 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, 731 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE,
724 &max_texture_size_)); 732 &max_texture_size_));
725 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); 733 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra);
726 734
727 return true; 735 return true;
728 } 736 }
729 737
730 void ResourceProvider::CleanUpGLIfNeeded() { 738 void ResourceProvider::CleanUpGLIfNeeded() {
731 WebGraphicsContext3D* context3d = Context3d(); 739 WebGraphicsContext3D* context3d = Context3d();
732 if (default_resource_type_ != GLTexture) { 740 if (default_resource_type_ != GLTexture) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 DCHECK(!resource->image_id); 976 DCHECK(!resource->image_id);
969 977
970 if (resource->type == GLTexture) { 978 if (resource->type == GLTexture) {
971 WebGraphicsContext3D* context3d = Context3d(); 979 WebGraphicsContext3D* context3d = Context3d();
972 DCHECK(context3d); 980 DCHECK(context3d);
973 if (!resource->gl_pixel_buffer_id) 981 if (!resource->gl_pixel_buffer_id)
974 resource->gl_pixel_buffer_id = context3d->createBuffer(); 982 resource->gl_pixel_buffer_id = context3d->createBuffer();
975 context3d->bindBuffer( 983 context3d->bindBuffer(
976 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 984 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
977 resource->gl_pixel_buffer_id); 985 resource->gl_pixel_buffer_id);
986 size_t bytes_per_pixel = (best_texture_type_ == RGBA_4444) ? 2 : 4;
978 context3d->bufferData( 987 context3d->bufferData(
979 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 988 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
980 4 * resource->size.GetArea(), 989 bytes_per_pixel * resource->size.GetArea(),
981 NULL, 990 NULL,
982 GL_DYNAMIC_DRAW); 991 GL_DYNAMIC_DRAW);
983 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 992 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
984 } 993 }
985 994
986 if (resource->pixels) { 995 if (resource->pixels) {
987 if (resource->pixel_buffer) 996 if (resource->pixel_buffer)
988 return; 997 return;
989 998
990 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 999 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()];
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 DCHECK(resource->gl_pixel_buffer_id); 1161 DCHECK(resource->gl_pixel_buffer_id);
1153 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1162 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1154 context3d->bindBuffer( 1163 context3d->bindBuffer(
1155 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1164 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1156 resource->gl_pixel_buffer_id); 1165 resource->gl_pixel_buffer_id);
1157 if (!resource->gl_upload_query_id) 1166 if (!resource->gl_upload_query_id)
1158 resource->gl_upload_query_id = context3d->createQueryEXT(); 1167 resource->gl_upload_query_id = context3d->createQueryEXT();
1159 context3d->beginQueryEXT( 1168 context3d->beginQueryEXT(
1160 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1169 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
1161 resource->gl_upload_query_id); 1170 resource->gl_upload_query_id);
1171 GLenum texture_data_type = GL_UNSIGNED_BYTE;
1172 switch (best_texture_type_) {
1173 case RGBA_4444:
1174 texture_data_type = GL_UNSIGNED_SHORT_4_4_4_4;
1175 break;
1176 case RGBA_8888:
1177 texture_data_type = GL_UNSIGNED_BYTE;
1178 break;
1179 default:
1180 NOTREACHED();
1181 break;
1182 }
1183
1162 if (allocate) { 1184 if (allocate) {
1163 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, 1185 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
1164 0, /* level */ 1186 0, /* level */
1165 resource->format, 1187 resource->format,
1166 resource->size.width(), 1188 resource->size.width(),
1167 resource->size.height(), 1189 resource->size.height(),
1168 0, /* border */ 1190 0, /* border */
1169 resource->format, 1191 resource->format,
1170 GL_UNSIGNED_BYTE, 1192 texture_data_type,
1171 NULL); 1193 NULL);
1172 } else { 1194 } else {
1173 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 1195 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
1174 0, /* level */ 1196 0, /* level */
1175 0, /* x */ 1197 0, /* x */
1176 0, /* y */ 1198 0, /* y */
1177 resource->size.width(), 1199 resource->size.width(),
1178 resource->size.height(), 1200 resource->size.height(),
1179 resource->format, 1201 resource->format,
1180 GL_UNSIGNED_BYTE, 1202 texture_data_type,
1181 NULL); 1203 NULL);
1182 } 1204 }
1183 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1205 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1184 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1206 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1185 } 1207 }
1186 1208
1187 if (resource->pixels) { 1209 if (resource->pixels) {
1188 DCHECK(!resource->mailbox.IsValid()); 1210 DCHECK(!resource->mailbox.IsValid());
1189 DCHECK(resource->pixel_buffer); 1211 DCHECK(resource->pixel_buffer);
1190 DCHECK(resource->format == GL_RGBA); 1212 DCHECK(resource->format == GL_RGBA);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 GLenum format = resource->format; 1303 GLenum format = resource->format;
1282 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 1304 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
1283 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { 1305 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) {
1284 GLenum storage_format = TextureToStorageFormat(format); 1306 GLenum storage_format = TextureToStorageFormat(format);
1285 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1307 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D,
1286 1, 1308 1,
1287 storage_format, 1309 storage_format,
1288 size.width(), 1310 size.width(),
1289 size.height())); 1311 size.height()));
1290 } else { 1312 } else {
1313 GLenum texture_data_type = GL_UNSIGNED_BYTE;
1314 switch (best_texture_type_) {
1315 case RGBA_4444:
1316 texture_data_type = GL_UNSIGNED_SHORT_4_4_4_4;
1317 break;
1318 case RGBA_8888:
1319 texture_data_type = GL_UNSIGNED_BYTE;
1320 break;
1321 default:
1322 NOTREACHED();
1323 break;
1324 }
1291 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 1325 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D,
1292 0, 1326 0,
1293 format, 1327 format,
1294 size.width(), 1328 size.width(),
1295 size.height(), 1329 size.height(),
1296 0, 1330 0,
1297 format, 1331 format,
1298 GL_UNSIGNED_BYTE, 1332 texture_data_type,
1299 NULL)); 1333 NULL));
1300 } 1334 }
1301 } 1335 }
1302 1336
1303 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1337 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1304 bool enable) { 1338 bool enable) {
1305 Resource* resource = GetResource(id); 1339 Resource* resource = GetResource(id);
1306 resource->enable_read_lock_fences = enable; 1340 resource->enable_read_lock_fences = enable;
1307 } 1341 }
1308 1342
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1428 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1395 return active_unit; 1429 return active_unit;
1396 } 1430 }
1397 1431
1398 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1432 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1399 ContextProvider* context_provider = output_surface_->context_provider(); 1433 ContextProvider* context_provider = output_surface_->context_provider();
1400 return context_provider ? context_provider->Context3d() : NULL; 1434 return context_provider ? context_provider->Context3d() : NULL;
1401 } 1435 }
1402 1436
1403 } // namespace cc 1437 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698