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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 ResourceProvider::Child::~Child() {} | 152 ResourceProvider::Child::~Child() {} |
153 | 153 |
154 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 154 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
155 OutputSurface* output_surface, | 155 OutputSurface* output_surface, |
156 int highp_threshold_min) { | 156 int highp_threshold_min) { |
157 scoped_ptr<ResourceProvider> resource_provider( | 157 scoped_ptr<ResourceProvider> resource_provider( |
158 new ResourceProvider(output_surface, highp_threshold_min)); | 158 new ResourceProvider(output_surface, highp_threshold_min)); |
159 | 159 |
160 bool success = false; | 160 bool success = false; |
161 if (output_surface->context3d()) { | 161 if (resource_provider->Context3d()) { |
162 success = resource_provider->InitializeGL(); | 162 success = resource_provider->InitializeGL(); |
163 } else { | 163 } else { |
164 resource_provider->InitializeSoftware(); | 164 resource_provider->InitializeSoftware(); |
165 success = true; | 165 success = true; |
166 } | 166 } |
167 | 167 |
168 if (!success) | 168 if (!success) |
169 return scoped_ptr<ResourceProvider>(); | 169 return scoped_ptr<ResourceProvider>(); |
170 | 170 |
171 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); | 171 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); |
172 return resource_provider.Pass(); | 172 return resource_provider.Pass(); |
173 } | 173 } |
174 | 174 |
175 ResourceProvider::~ResourceProvider() { | 175 ResourceProvider::~ResourceProvider() { |
176 while (!resources_.empty()) | 176 while (!resources_.empty()) |
177 DeleteResourceInternal(resources_.begin(), ForShutdown); | 177 DeleteResourceInternal(resources_.begin(), ForShutdown); |
178 | 178 |
179 CleanUpGLIfNeeded(); | 179 CleanUpGLIfNeeded(); |
180 } | 180 } |
181 | 181 |
182 WebGraphicsContext3D* ResourceProvider::GraphicsContext3D() { | |
183 DCHECK(thread_checker_.CalledOnValidThread()); | |
184 return output_surface_->context3d(); | |
185 } | |
186 | |
187 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 182 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
188 DCHECK(thread_checker_.CalledOnValidThread()); | 183 DCHECK(thread_checker_.CalledOnValidThread()); |
189 ResourceMap::iterator it = resources_.find(id); | 184 ResourceMap::iterator it = resources_.find(id); |
190 CHECK(it != resources_.end()); | 185 CHECK(it != resources_.end()); |
191 Resource* resource = &it->second; | 186 Resource* resource = &it->second; |
192 return !!resource->lock_for_read_count || resource->exported; | 187 return !!resource->lock_for_read_count || resource->exported; |
193 } | 188 } |
194 | 189 |
195 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 190 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
196 gfx::Size size, GLenum format, TextureUsageHint hint) { | 191 gfx::Size size, GLenum format, TextureUsageHint hint) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 resources_[id] = resource; | 247 resources_[id] = resource; |
253 return id; | 248 return id; |
254 } | 249 } |
255 | 250 |
256 ResourceProvider::ResourceId | 251 ResourceProvider::ResourceId |
257 ResourceProvider::CreateResourceFromExternalTexture( | 252 ResourceProvider::CreateResourceFromExternalTexture( |
258 unsigned texture_target, | 253 unsigned texture_target, |
259 unsigned texture_id) { | 254 unsigned texture_id) { |
260 DCHECK(thread_checker_.CalledOnValidThread()); | 255 DCHECK(thread_checker_.CalledOnValidThread()); |
261 | 256 |
262 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 257 WebGraphicsContext3D* context3d = Context3d(); |
263 DCHECK(context3d); | 258 DCHECK(context3d); |
264 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); | 259 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); |
265 GLC(context3d, context3d->texParameteri( | 260 GLC(context3d, context3d->texParameteri( |
266 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 261 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
267 GLC(context3d, context3d->texParameteri( | 262 GLC(context3d, context3d->texParameteri( |
268 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 263 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
269 GLC(context3d, context3d->texParameteri( | 264 GLC(context3d, context3d->texParameteri( |
270 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 265 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
271 GLC(context3d, context3d->texParameteri( | 266 GLC(context3d, context3d->texParameteri( |
272 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 267 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 317 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
323 DeleteStyle style) { | 318 DeleteStyle style) { |
324 Resource* resource = &it->second; | 319 Resource* resource = &it->second; |
325 bool lost_resource = lost_output_surface_; | 320 bool lost_resource = lost_output_surface_; |
326 | 321 |
327 DCHECK(!resource->exported || style != Normal); | 322 DCHECK(!resource->exported || style != Normal); |
328 if (style == ForShutdown && resource->exported) | 323 if (style == ForShutdown && resource->exported) |
329 lost_resource = true; | 324 lost_resource = true; |
330 | 325 |
331 if (resource->image_id) { | 326 if (resource->image_id) { |
332 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 327 WebGraphicsContext3D* context3d = Context3d(); |
333 DCHECK(context3d); | 328 DCHECK(context3d); |
334 GLC(context3d, context3d->destroyImageCHROMIUM(resource->image_id)); | 329 GLC(context3d, context3d->destroyImageCHROMIUM(resource->image_id)); |
335 } | 330 } |
336 | 331 |
337 if (resource->gl_id && !resource->external) { | 332 if (resource->gl_id && !resource->external) { |
338 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 333 WebGraphicsContext3D* context3d = Context3d(); |
339 DCHECK(context3d); | 334 DCHECK(context3d); |
340 GLC(context3d, context3d->deleteTexture(resource->gl_id)); | 335 GLC(context3d, context3d->deleteTexture(resource->gl_id)); |
341 } | 336 } |
342 if (resource->gl_upload_query_id) { | 337 if (resource->gl_upload_query_id) { |
343 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 338 WebGraphicsContext3D* context3d = Context3d(); |
344 DCHECK(context3d); | 339 DCHECK(context3d); |
345 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); | 340 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); |
346 } | 341 } |
347 if (resource->gl_pixel_buffer_id) { | 342 if (resource->gl_pixel_buffer_id) { |
348 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 343 WebGraphicsContext3D* context3d = Context3d(); |
349 DCHECK(context3d); | 344 DCHECK(context3d); |
350 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); | 345 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); |
351 } | 346 } |
352 if (resource->mailbox.IsValid() && resource->external) { | 347 if (resource->mailbox.IsValid() && resource->external) { |
353 unsigned sync_point = resource->mailbox.sync_point(); | 348 unsigned sync_point = resource->mailbox.sync_point(); |
354 if (resource->mailbox.IsTexture()) { | 349 if (resource->mailbox.IsTexture()) { |
355 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 350 WebGraphicsContext3D* context3d = Context3d(); |
356 DCHECK(context3d); | 351 DCHECK(context3d); |
357 if (resource->gl_id) | 352 if (resource->gl_id) |
358 GLC(context3d, context3d->deleteTexture(resource->gl_id)); | 353 GLC(context3d, context3d->deleteTexture(resource->gl_id)); |
359 if (!lost_resource && resource->gl_id) | 354 if (!lost_resource && resource->gl_id) |
360 sync_point = context3d->insertSyncPoint(); | 355 sync_point = context3d->insertSyncPoint(); |
361 } else { | 356 } else { |
362 DCHECK(resource->mailbox.IsSharedMemory()); | 357 DCHECK(resource->mailbox.IsSharedMemory()); |
363 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); | 358 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); |
364 if (resource->pixels && shared_memory) { | 359 if (resource->pixels && shared_memory) { |
365 DCHECK(shared_memory->memory() == resource->pixels); | 360 DCHECK(shared_memory->memory() == resource->pixels); |
(...skipping 29 matching lines...) Expand all Loading... |
395 Resource* resource = &it->second; | 390 Resource* resource = &it->second; |
396 DCHECK(!resource->locked_for_write); | 391 DCHECK(!resource->locked_for_write); |
397 DCHECK(!resource->lock_for_read_count); | 392 DCHECK(!resource->lock_for_read_count); |
398 DCHECK(!resource->external); | 393 DCHECK(!resource->external); |
399 DCHECK(!resource->exported); | 394 DCHECK(!resource->exported); |
400 DCHECK(ReadLockFenceHasPassed(resource)); | 395 DCHECK(ReadLockFenceHasPassed(resource)); |
401 LazyAllocate(resource); | 396 LazyAllocate(resource); |
402 | 397 |
403 if (resource->gl_id) { | 398 if (resource->gl_id) { |
404 DCHECK(!resource->pending_set_pixels); | 399 DCHECK(!resource->pending_set_pixels); |
405 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 400 WebGraphicsContext3D* context3d = Context3d(); |
406 DCHECK(context3d); | 401 DCHECK(context3d); |
407 DCHECK(texture_uploader_.get()); | 402 DCHECK(texture_uploader_.get()); |
408 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 403 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
409 texture_uploader_->Upload(image, | 404 texture_uploader_->Upload(image, |
410 image_rect, | 405 image_rect, |
411 source_rect, | 406 source_rect, |
412 dest_offset, | 407 dest_offset, |
413 resource->format, | 408 resource->format, |
414 resource->size); | 409 resource->size); |
415 } | 410 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 460 |
466 void ResourceProvider::ReleaseCachedData() { | 461 void ResourceProvider::ReleaseCachedData() { |
467 if (!texture_uploader_) | 462 if (!texture_uploader_) |
468 return; | 463 return; |
469 | 464 |
470 texture_uploader_->ReleaseCachedQueries(); | 465 texture_uploader_->ReleaseCachedQueries(); |
471 } | 466 } |
472 | 467 |
473 void ResourceProvider::Flush() { | 468 void ResourceProvider::Flush() { |
474 DCHECK(thread_checker_.CalledOnValidThread()); | 469 DCHECK(thread_checker_.CalledOnValidThread()); |
475 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 470 WebGraphicsContext3D* context3d = Context3d(); |
476 if (context3d) | 471 if (context3d) |
477 context3d->flush(); | 472 context3d->flush(); |
478 } | 473 } |
479 | 474 |
480 void ResourceProvider::Finish() { | 475 void ResourceProvider::Finish() { |
481 DCHECK(thread_checker_.CalledOnValidThread()); | 476 DCHECK(thread_checker_.CalledOnValidThread()); |
482 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 477 WebGraphicsContext3D* context3d = Context3d(); |
483 if (context3d) | 478 if (context3d) |
484 context3d->finish(); | 479 context3d->finish(); |
485 } | 480 } |
486 | 481 |
487 bool ResourceProvider::ShallowFlushIfSupported() { | 482 bool ResourceProvider::ShallowFlushIfSupported() { |
488 DCHECK(thread_checker_.CalledOnValidThread()); | 483 DCHECK(thread_checker_.CalledOnValidThread()); |
489 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 484 WebGraphicsContext3D* context3d = Context3d(); |
490 if (!context3d || !use_shallow_flush_) | 485 if (!context3d || !use_shallow_flush_) |
491 return false; | 486 return false; |
492 | 487 |
493 context3d->shallowFlushCHROMIUM(); | 488 context3d->shallowFlushCHROMIUM(); |
494 return true; | 489 return true; |
495 } | 490 } |
496 | 491 |
497 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { | 492 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { |
498 DCHECK(thread_checker_.CalledOnValidThread()); | 493 DCHECK(thread_checker_.CalledOnValidThread()); |
499 ResourceMap::iterator it = resources_.find(id); | 494 ResourceMap::iterator it = resources_.find(id); |
500 CHECK(it != resources_.end()); | 495 CHECK(it != resources_.end()); |
501 Resource* resource = &it->second; | 496 Resource* resource = &it->second; |
502 DCHECK(!resource->locked_for_write || | 497 DCHECK(!resource->locked_for_write || |
503 resource->set_pixels_completion_forced) << | 498 resource->set_pixels_completion_forced) << |
504 "locked for write: " << resource->locked_for_write << | 499 "locked for write: " << resource->locked_for_write << |
505 " pixels completion forced: " << resource->set_pixels_completion_forced; | 500 " pixels completion forced: " << resource->set_pixels_completion_forced; |
506 DCHECK(!resource->exported); | 501 DCHECK(!resource->exported); |
507 // Uninitialized! Call SetPixels or LockForWrite first. | 502 // Uninitialized! Call SetPixels or LockForWrite first. |
508 DCHECK(resource->allocated); | 503 DCHECK(resource->allocated); |
509 | 504 |
510 LazyCreate(resource); | 505 LazyCreate(resource); |
511 | 506 |
512 if (resource->external) { | 507 if (resource->external) { |
513 if (!resource->gl_id && resource->mailbox.IsTexture()) { | 508 if (!resource->gl_id && resource->mailbox.IsTexture()) { |
514 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 509 WebGraphicsContext3D* context3d = Context3d(); |
515 DCHECK(context3d); | 510 DCHECK(context3d); |
516 if (resource->mailbox.sync_point()) { | 511 if (resource->mailbox.sync_point()) { |
517 GLC(context3d, | 512 GLC(context3d, |
518 context3d->waitSyncPoint(resource->mailbox.sync_point())); | 513 context3d->waitSyncPoint(resource->mailbox.sync_point())); |
519 resource->mailbox.ResetSyncPoint(); | 514 resource->mailbox.ResetSyncPoint(); |
520 } | 515 } |
521 resource->gl_id = context3d->createTexture(); | 516 resource->gl_id = context3d->createTexture(); |
522 GLC(context3d, context3d->bindTexture( | 517 GLC(context3d, context3d->bindTexture( |
523 resource->mailbox.target(), resource->gl_id)); | 518 resource->mailbox.target(), resource->gl_id)); |
524 GLC(context3d, context3d->consumeTextureCHROMIUM( | 519 GLC(context3d, context3d->consumeTextureCHROMIUM( |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 : output_surface_(output_surface), | 673 : output_surface_(output_surface), |
679 lost_output_surface_(false), | 674 lost_output_surface_(false), |
680 highp_threshold_min_(highp_threshold_min), | 675 highp_threshold_min_(highp_threshold_min), |
681 next_id_(1), | 676 next_id_(1), |
682 next_child_(1), | 677 next_child_(1), |
683 default_resource_type_(InvalidType), | 678 default_resource_type_(InvalidType), |
684 use_texture_storage_ext_(false), | 679 use_texture_storage_ext_(false), |
685 use_texture_usage_hint_(false), | 680 use_texture_usage_hint_(false), |
686 use_shallow_flush_(false), | 681 use_shallow_flush_(false), |
687 max_texture_size_(0), | 682 max_texture_size_(0), |
688 best_texture_format_(0) {} | 683 best_texture_format_(0) { |
| 684 DCHECK(output_surface_->HasClient()); |
| 685 } |
689 | 686 |
690 void ResourceProvider::InitializeSoftware() { | 687 void ResourceProvider::InitializeSoftware() { |
691 DCHECK(thread_checker_.CalledOnValidThread()); | 688 DCHECK(thread_checker_.CalledOnValidThread()); |
692 DCHECK_NE(Bitmap, default_resource_type_); | 689 DCHECK_NE(Bitmap, default_resource_type_); |
693 | 690 |
694 CleanUpGLIfNeeded(); | 691 CleanUpGLIfNeeded(); |
695 | 692 |
696 default_resource_type_ = Bitmap; | 693 default_resource_type_ = Bitmap; |
697 max_texture_size_ = INT_MAX / 2; | 694 max_texture_size_ = INT_MAX / 2; |
698 best_texture_format_ = GL_RGBA; | 695 best_texture_format_ = GL_RGBA; |
699 } | 696 } |
700 | 697 |
701 bool ResourceProvider::InitializeGL() { | 698 bool ResourceProvider::InitializeGL() { |
702 DCHECK(thread_checker_.CalledOnValidThread()); | 699 DCHECK(thread_checker_.CalledOnValidThread()); |
703 DCHECK(!texture_uploader_); | 700 DCHECK(!texture_uploader_); |
704 DCHECK_NE(GLTexture, default_resource_type_); | 701 DCHECK_NE(GLTexture, default_resource_type_); |
705 | 702 |
706 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 703 WebGraphicsContext3D* context3d = Context3d(); |
707 DCHECK(context3d); | 704 DCHECK(context3d); |
708 | 705 |
709 if (!context3d->makeContextCurrent()) | 706 if (!context3d->makeContextCurrent()) |
710 return false; | 707 return false; |
711 | 708 |
712 default_resource_type_ = GLTexture; | 709 default_resource_type_ = GLTexture; |
713 | 710 |
714 std::string extensions_string = | 711 std::string extensions_string = |
715 UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); | 712 UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); |
716 std::vector<std::string> extensions; | 713 std::vector<std::string> extensions; |
(...skipping 16 matching lines...) Expand all Loading... |
733 texture_uploader_ = | 730 texture_uploader_ = |
734 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); | 731 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); |
735 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, | 732 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, |
736 &max_texture_size_)); | 733 &max_texture_size_)); |
737 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 734 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
738 | 735 |
739 return true; | 736 return true; |
740 } | 737 } |
741 | 738 |
742 void ResourceProvider::CleanUpGLIfNeeded() { | 739 void ResourceProvider::CleanUpGLIfNeeded() { |
743 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 740 WebGraphicsContext3D* context3d = Context3d(); |
744 if (default_resource_type_ != GLTexture) { | 741 if (default_resource_type_ != GLTexture) { |
745 // We are not in GL mode, but double check before returning. | 742 // We are not in GL mode, but double check before returning. |
746 DCHECK(!context3d); | 743 DCHECK(!context3d); |
747 DCHECK(!texture_uploader_); | 744 DCHECK(!texture_uploader_); |
748 return; | 745 return; |
749 } | 746 } |
750 | 747 |
751 DCHECK(context3d); | 748 DCHECK(context3d); |
752 context3d->makeContextCurrent(); | 749 context3d->makeContextCurrent(); |
753 texture_uploader_.reset(); | 750 texture_uploader_.reset(); |
(...skipping 24 matching lines...) Expand all Loading... |
778 int child) const { | 775 int child) const { |
779 DCHECK(thread_checker_.CalledOnValidThread()); | 776 DCHECK(thread_checker_.CalledOnValidThread()); |
780 ChildMap::const_iterator it = children_.find(child); | 777 ChildMap::const_iterator it = children_.find(child); |
781 DCHECK(it != children_.end()); | 778 DCHECK(it != children_.end()); |
782 return it->second.child_to_parent_map; | 779 return it->second.child_to_parent_map; |
783 } | 780 } |
784 | 781 |
785 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, | 782 void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, |
786 TransferableResourceArray* list) { | 783 TransferableResourceArray* list) { |
787 DCHECK(thread_checker_.CalledOnValidThread()); | 784 DCHECK(thread_checker_.CalledOnValidThread()); |
788 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 785 WebGraphicsContext3D* context3d = Context3d(); |
789 if (!context3d || !context3d->makeContextCurrent()) { | 786 if (!context3d || !context3d->makeContextCurrent()) { |
790 // TODO(skaslev): Implement this path for software compositing. | 787 // TODO(skaslev): Implement this path for software compositing. |
791 return; | 788 return; |
792 } | 789 } |
793 bool need_sync_point = false; | 790 bool need_sync_point = false; |
794 for (ResourceIdArray::const_iterator it = resources.begin(); | 791 for (ResourceIdArray::const_iterator it = resources.begin(); |
795 it != resources.end(); | 792 it != resources.end(); |
796 ++it) { | 793 ++it) { |
797 TransferableResource resource; | 794 TransferableResource resource; |
798 if (TransferResource(context3d, *it, &resource)) { | 795 if (TransferResource(context3d, *it, &resource)) { |
(...skipping 11 matching lines...) Expand all Loading... |
810 if (!it->sync_point) | 807 if (!it->sync_point) |
811 it->sync_point = sync_point; | 808 it->sync_point = sync_point; |
812 } | 809 } |
813 } | 810 } |
814 } | 811 } |
815 | 812 |
816 void ResourceProvider::PrepareSendToChild(int child, | 813 void ResourceProvider::PrepareSendToChild(int child, |
817 const ResourceIdArray& resources, | 814 const ResourceIdArray& resources, |
818 TransferableResourceArray* list) { | 815 TransferableResourceArray* list) { |
819 DCHECK(thread_checker_.CalledOnValidThread()); | 816 DCHECK(thread_checker_.CalledOnValidThread()); |
820 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 817 WebGraphicsContext3D* context3d = Context3d(); |
821 if (!context3d || !context3d->makeContextCurrent()) { | 818 if (!context3d || !context3d->makeContextCurrent()) { |
822 // TODO(skaslev): Implement this path for software compositing. | 819 // TODO(skaslev): Implement this path for software compositing. |
823 return; | 820 return; |
824 } | 821 } |
825 Child& child_info = children_.find(child)->second; | 822 Child& child_info = children_.find(child)->second; |
826 bool need_sync_point = false; | 823 bool need_sync_point = false; |
827 for (ResourceIdArray::const_iterator it = resources.begin(); | 824 for (ResourceIdArray::const_iterator it = resources.begin(); |
828 it != resources.end(); | 825 it != resources.end(); |
829 ++it) { | 826 ++it) { |
830 TransferableResource resource; | 827 TransferableResource resource; |
(...skipping 16 matching lines...) Expand all Loading... |
847 ++it) { | 844 ++it) { |
848 if (!it->sync_point) | 845 if (!it->sync_point) |
849 it->sync_point = sync_point; | 846 it->sync_point = sync_point; |
850 } | 847 } |
851 } | 848 } |
852 } | 849 } |
853 | 850 |
854 void ResourceProvider::ReceiveFromChild( | 851 void ResourceProvider::ReceiveFromChild( |
855 int child, const TransferableResourceArray& resources) { | 852 int child, const TransferableResourceArray& resources) { |
856 DCHECK(thread_checker_.CalledOnValidThread()); | 853 DCHECK(thread_checker_.CalledOnValidThread()); |
857 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 854 WebGraphicsContext3D* context3d = Context3d(); |
858 if (!context3d || !context3d->makeContextCurrent()) { | 855 if (!context3d || !context3d->makeContextCurrent()) { |
859 // TODO(skaslev): Implement this path for software compositing. | 856 // TODO(skaslev): Implement this path for software compositing. |
860 return; | 857 return; |
861 } | 858 } |
862 Child& child_info = children_.find(child)->second; | 859 Child& child_info = children_.find(child)->second; |
863 for (TransferableResourceArray::const_iterator it = resources.begin(); | 860 for (TransferableResourceArray::const_iterator it = resources.begin(); |
864 it != resources.end(); | 861 it != resources.end(); |
865 ++it) { | 862 ++it) { |
866 unsigned texture_id; | 863 unsigned texture_id; |
867 // NOTE: If the parent is a browser and the child a renderer, the parent | 864 // NOTE: If the parent is a browser and the child a renderer, the parent |
(...skipping 16 matching lines...) Expand all Loading... |
884 resource.allocated = true; | 881 resource.allocated = true; |
885 resources_[id] = resource; | 882 resources_[id] = resource; |
886 child_info.parent_to_child_map[id] = it->id; | 883 child_info.parent_to_child_map[id] = it->id; |
887 child_info.child_to_parent_map[it->id] = id; | 884 child_info.child_to_parent_map[it->id] = id; |
888 } | 885 } |
889 } | 886 } |
890 | 887 |
891 void ResourceProvider::ReceiveFromParent( | 888 void ResourceProvider::ReceiveFromParent( |
892 const TransferableResourceArray& resources) { | 889 const TransferableResourceArray& resources) { |
893 DCHECK(thread_checker_.CalledOnValidThread()); | 890 DCHECK(thread_checker_.CalledOnValidThread()); |
894 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 891 WebGraphicsContext3D* context3d = Context3d(); |
895 if (!context3d || !context3d->makeContextCurrent()) { | 892 if (!context3d || !context3d->makeContextCurrent()) { |
896 // TODO(skaslev): Implement this path for software compositing. | 893 // TODO(skaslev): Implement this path for software compositing. |
897 return; | 894 return; |
898 } | 895 } |
899 for (TransferableResourceArray::const_iterator it = resources.begin(); | 896 for (TransferableResourceArray::const_iterator it = resources.begin(); |
900 it != resources.end(); | 897 it != resources.end(); |
901 ++it) { | 898 ++it) { |
902 ResourceMap::iterator map_iterator = resources_.find(it->id); | 899 ResourceMap::iterator map_iterator = resources_.find(it->id); |
903 DCHECK(map_iterator != resources_.end()); | 900 DCHECK(map_iterator != resources_.end()); |
904 Resource* resource = &map_iterator->second; | 901 Resource* resource = &map_iterator->second; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | 960 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
964 DCHECK(thread_checker_.CalledOnValidThread()); | 961 DCHECK(thread_checker_.CalledOnValidThread()); |
965 ResourceMap::iterator it = resources_.find(id); | 962 ResourceMap::iterator it = resources_.find(id); |
966 CHECK(it != resources_.end()); | 963 CHECK(it != resources_.end()); |
967 Resource* resource = &it->second; | 964 Resource* resource = &it->second; |
968 DCHECK(!resource->external); | 965 DCHECK(!resource->external); |
969 DCHECK(!resource->exported); | 966 DCHECK(!resource->exported); |
970 DCHECK(!resource->image_id); | 967 DCHECK(!resource->image_id); |
971 | 968 |
972 if (resource->type == GLTexture) { | 969 if (resource->type == GLTexture) { |
973 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 970 WebGraphicsContext3D* context3d = Context3d(); |
974 DCHECK(context3d); | 971 DCHECK(context3d); |
975 if (!resource->gl_pixel_buffer_id) | 972 if (!resource->gl_pixel_buffer_id) |
976 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 973 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
977 context3d->bindBuffer( | 974 context3d->bindBuffer( |
978 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 975 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
979 resource->gl_pixel_buffer_id); | 976 resource->gl_pixel_buffer_id); |
980 context3d->bufferData( | 977 context3d->bufferData( |
981 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 978 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
982 4 * resource->size.GetArea(), | 979 4 * resource->size.GetArea(), |
983 NULL, | 980 NULL, |
(...skipping 26 matching lines...) Expand all Loading... |
1010 // as each new query has a unique submit count. | 1007 // as each new query has a unique submit count. |
1011 if (resource->pending_set_pixels) { | 1008 if (resource->pending_set_pixels) { |
1012 DCHECK(resource->set_pixels_completion_forced); | 1009 DCHECK(resource->set_pixels_completion_forced); |
1013 resource->pending_set_pixels = false; | 1010 resource->pending_set_pixels = false; |
1014 UnlockForWrite(id); | 1011 UnlockForWrite(id); |
1015 } | 1012 } |
1016 | 1013 |
1017 if (resource->type == GLTexture) { | 1014 if (resource->type == GLTexture) { |
1018 if (!resource->gl_pixel_buffer_id) | 1015 if (!resource->gl_pixel_buffer_id) |
1019 return; | 1016 return; |
1020 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1017 WebGraphicsContext3D* context3d = Context3d(); |
1021 DCHECK(context3d); | 1018 DCHECK(context3d); |
1022 context3d->bindBuffer( | 1019 context3d->bindBuffer( |
1023 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1020 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1024 resource->gl_pixel_buffer_id); | 1021 resource->gl_pixel_buffer_id); |
1025 context3d->bufferData( | 1022 context3d->bufferData( |
1026 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1023 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1027 0, | 1024 0, |
1028 NULL, | 1025 NULL, |
1029 GL_DYNAMIC_DRAW); | 1026 GL_DYNAMIC_DRAW); |
1030 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1027 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
1041 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { | 1038 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
1042 DCHECK(thread_checker_.CalledOnValidThread()); | 1039 DCHECK(thread_checker_.CalledOnValidThread()); |
1043 ResourceMap::iterator it = resources_.find(id); | 1040 ResourceMap::iterator it = resources_.find(id); |
1044 CHECK(it != resources_.end()); | 1041 CHECK(it != resources_.end()); |
1045 Resource* resource = &it->second; | 1042 Resource* resource = &it->second; |
1046 DCHECK(!resource->external); | 1043 DCHECK(!resource->external); |
1047 DCHECK(!resource->exported); | 1044 DCHECK(!resource->exported); |
1048 DCHECK(!resource->image_id); | 1045 DCHECK(!resource->image_id); |
1049 | 1046 |
1050 if (resource->type == GLTexture) { | 1047 if (resource->type == GLTexture) { |
1051 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1048 WebGraphicsContext3D* context3d = Context3d(); |
1052 DCHECK(context3d); | 1049 DCHECK(context3d); |
1053 DCHECK(resource->gl_pixel_buffer_id); | 1050 DCHECK(resource->gl_pixel_buffer_id); |
1054 context3d->bindBuffer( | 1051 context3d->bindBuffer( |
1055 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1052 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1056 resource->gl_pixel_buffer_id); | 1053 resource->gl_pixel_buffer_id); |
1057 uint8_t* image = static_cast<uint8_t*>( | 1054 uint8_t* image = static_cast<uint8_t*>( |
1058 context3d->mapBufferCHROMIUM( | 1055 context3d->mapBufferCHROMIUM( |
1059 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 1056 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
1060 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1057 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1061 // Buffer is required to be 4-byte aligned. | 1058 // Buffer is required to be 4-byte aligned. |
(...skipping 10 matching lines...) Expand all Loading... |
1072 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | 1069 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
1073 DCHECK(thread_checker_.CalledOnValidThread()); | 1070 DCHECK(thread_checker_.CalledOnValidThread()); |
1074 ResourceMap::iterator it = resources_.find(id); | 1071 ResourceMap::iterator it = resources_.find(id); |
1075 CHECK(it != resources_.end()); | 1072 CHECK(it != resources_.end()); |
1076 Resource* resource = &it->second; | 1073 Resource* resource = &it->second; |
1077 DCHECK(!resource->external); | 1074 DCHECK(!resource->external); |
1078 DCHECK(!resource->exported); | 1075 DCHECK(!resource->exported); |
1079 DCHECK(!resource->image_id); | 1076 DCHECK(!resource->image_id); |
1080 | 1077 |
1081 if (resource->type == GLTexture) { | 1078 if (resource->type == GLTexture) { |
1082 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1079 WebGraphicsContext3D* context3d = Context3d(); |
1083 DCHECK(context3d); | 1080 DCHECK(context3d); |
1084 DCHECK(resource->gl_pixel_buffer_id); | 1081 DCHECK(resource->gl_pixel_buffer_id); |
1085 context3d->bindBuffer( | 1082 context3d->bindBuffer( |
1086 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1083 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1087 resource->gl_pixel_buffer_id); | 1084 resource->gl_pixel_buffer_id); |
1088 context3d->unmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | 1085 context3d->unmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
1089 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1086 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1090 } | 1087 } |
1091 } | 1088 } |
1092 | 1089 |
1093 void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id, | 1090 void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id, |
1094 GLenum target, | 1091 GLenum target, |
1095 GLenum unit, | 1092 GLenum unit, |
1096 GLenum filter) { | 1093 GLenum filter) { |
1097 DCHECK(thread_checker_.CalledOnValidThread()); | 1094 DCHECK(thread_checker_.CalledOnValidThread()); |
1098 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1095 WebGraphicsContext3D* context3d = Context3d(); |
1099 ResourceMap::iterator it = resources_.find(resource_id); | 1096 ResourceMap::iterator it = resources_.find(resource_id); |
1100 DCHECK(it != resources_.end()); | 1097 DCHECK(it != resources_.end()); |
1101 Resource* resource = &it->second; | 1098 Resource* resource = &it->second; |
1102 DCHECK(resource->lock_for_read_count); | 1099 DCHECK(resource->lock_for_read_count); |
1103 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); | 1100 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); |
1104 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); | 1101 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); |
1105 | 1102 |
1106 if (unit != GL_TEXTURE0) | 1103 if (unit != GL_TEXTURE0) |
1107 GLC(context3d, context3d->activeTexture(unit)); | 1104 GLC(context3d, context3d->activeTexture(unit)); |
1108 GLC(context3d, context3d->bindTexture(target, resource->gl_id)); | 1105 GLC(context3d, context3d->bindTexture(target, resource->gl_id)); |
(...skipping 18 matching lines...) Expand all Loading... |
1127 void ResourceProvider::UnbindForSampling( | 1124 void ResourceProvider::UnbindForSampling( |
1128 ResourceProvider::ResourceId resource_id, GLenum target, GLenum unit) { | 1125 ResourceProvider::ResourceId resource_id, GLenum target, GLenum unit) { |
1129 DCHECK(thread_checker_.CalledOnValidThread()); | 1126 DCHECK(thread_checker_.CalledOnValidThread()); |
1130 ResourceMap::iterator it = resources_.find(resource_id); | 1127 ResourceMap::iterator it = resources_.find(resource_id); |
1131 DCHECK(it != resources_.end()); | 1128 DCHECK(it != resources_.end()); |
1132 Resource* resource = &it->second; | 1129 Resource* resource = &it->second; |
1133 | 1130 |
1134 if (!resource->image_id) | 1131 if (!resource->image_id) |
1135 return; | 1132 return; |
1136 | 1133 |
1137 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1134 WebGraphicsContext3D* context3d = Context3d(); |
1138 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); | 1135 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d)); |
1139 if (unit != GL_TEXTURE0) | 1136 if (unit != GL_TEXTURE0) |
1140 GLC(context3d, context3d->activeTexture(unit)); | 1137 GLC(context3d, context3d->activeTexture(unit)); |
1141 context3d->releaseTexImage2DCHROMIUM(target, resource->image_id); | 1138 context3d->releaseTexImage2DCHROMIUM(target, resource->image_id); |
1142 // Active unit being GL_TEXTURE0 is effectively the ground state. | 1139 // Active unit being GL_TEXTURE0 is effectively the ground state. |
1143 if (unit != GL_TEXTURE0) | 1140 if (unit != GL_TEXTURE0) |
1144 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); | 1141 GLC(context3d, context3d->activeTexture(GL_TEXTURE0)); |
1145 } | 1142 } |
1146 | 1143 |
1147 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1144 void ResourceProvider::BeginSetPixels(ResourceId id) { |
1148 DCHECK(thread_checker_.CalledOnValidThread()); | 1145 DCHECK(thread_checker_.CalledOnValidThread()); |
1149 ResourceMap::iterator it = resources_.find(id); | 1146 ResourceMap::iterator it = resources_.find(id); |
1150 CHECK(it != resources_.end()); | 1147 CHECK(it != resources_.end()); |
1151 Resource* resource = &it->second; | 1148 Resource* resource = &it->second; |
1152 DCHECK(!resource->pending_set_pixels); | 1149 DCHECK(!resource->pending_set_pixels); |
1153 | 1150 |
1154 LazyCreate(resource); | 1151 LazyCreate(resource); |
1155 DCHECK(resource->gl_id || resource->allocated); | 1152 DCHECK(resource->gl_id || resource->allocated); |
1156 DCHECK(ReadLockFenceHasPassed(resource)); | 1153 DCHECK(ReadLockFenceHasPassed(resource)); |
1157 DCHECK(!resource->image_id); | 1154 DCHECK(!resource->image_id); |
1158 | 1155 |
1159 bool allocate = !resource->allocated; | 1156 bool allocate = !resource->allocated; |
1160 resource->allocated = true; | 1157 resource->allocated = true; |
1161 LockForWrite(id); | 1158 LockForWrite(id); |
1162 | 1159 |
1163 if (resource->gl_id) { | 1160 if (resource->gl_id) { |
1164 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1161 WebGraphicsContext3D* context3d = Context3d(); |
1165 DCHECK(context3d); | 1162 DCHECK(context3d); |
1166 DCHECK(resource->gl_pixel_buffer_id); | 1163 DCHECK(resource->gl_pixel_buffer_id); |
1167 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1164 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1168 context3d->bindBuffer( | 1165 context3d->bindBuffer( |
1169 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1166 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1170 resource->gl_pixel_buffer_id); | 1167 resource->gl_pixel_buffer_id); |
1171 if (!resource->gl_upload_query_id) | 1168 if (!resource->gl_upload_query_id) |
1172 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1169 resource->gl_upload_query_id = context3d->createQueryEXT(); |
1173 context3d->beginQueryEXT( | 1170 context3d->beginQueryEXT( |
1174 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, | 1171 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { | 1212 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
1216 DCHECK(thread_checker_.CalledOnValidThread()); | 1213 DCHECK(thread_checker_.CalledOnValidThread()); |
1217 ResourceMap::iterator it = resources_.find(id); | 1214 ResourceMap::iterator it = resources_.find(id); |
1218 CHECK(it != resources_.end()); | 1215 CHECK(it != resources_.end()); |
1219 Resource* resource = &it->second; | 1216 Resource* resource = &it->second; |
1220 DCHECK(resource->locked_for_write); | 1217 DCHECK(resource->locked_for_write); |
1221 DCHECK(resource->pending_set_pixels); | 1218 DCHECK(resource->pending_set_pixels); |
1222 DCHECK(!resource->set_pixels_completion_forced); | 1219 DCHECK(!resource->set_pixels_completion_forced); |
1223 | 1220 |
1224 if (resource->gl_id) { | 1221 if (resource->gl_id) { |
1225 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1222 WebGraphicsContext3D* context3d = Context3d(); |
1226 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1223 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1227 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); | 1224 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); |
1228 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0)); | 1225 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0)); |
1229 } | 1226 } |
1230 | 1227 |
1231 resource->set_pixels_completion_forced = true; | 1228 resource->set_pixels_completion_forced = true; |
1232 } | 1229 } |
1233 | 1230 |
1234 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { | 1231 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { |
1235 DCHECK(thread_checker_.CalledOnValidThread()); | 1232 DCHECK(thread_checker_.CalledOnValidThread()); |
1236 ResourceMap::iterator it = resources_.find(id); | 1233 ResourceMap::iterator it = resources_.find(id); |
1237 CHECK(it != resources_.end()); | 1234 CHECK(it != resources_.end()); |
1238 Resource* resource = &it->second; | 1235 Resource* resource = &it->second; |
1239 DCHECK(resource->locked_for_write); | 1236 DCHECK(resource->locked_for_write); |
1240 DCHECK(resource->pending_set_pixels); | 1237 DCHECK(resource->pending_set_pixels); |
1241 | 1238 |
1242 if (resource->gl_id) { | 1239 if (resource->gl_id) { |
1243 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1240 WebGraphicsContext3D* context3d = Context3d(); |
1244 DCHECK(context3d); | 1241 DCHECK(context3d); |
1245 DCHECK(resource->gl_upload_query_id); | 1242 DCHECK(resource->gl_upload_query_id); |
1246 unsigned complete = 1; | 1243 unsigned complete = 1; |
1247 context3d->getQueryObjectuivEXT( | 1244 context3d->getQueryObjectuivEXT( |
1248 resource->gl_upload_query_id, | 1245 resource->gl_upload_query_id, |
1249 GL_QUERY_RESULT_AVAILABLE_EXT, | 1246 GL_QUERY_RESULT_AVAILABLE_EXT, |
1250 &complete); | 1247 &complete); |
1251 if (!complete) | 1248 if (!complete) |
1252 return false; | 1249 return false; |
1253 } | 1250 } |
(...skipping 12 matching lines...) Expand all Loading... |
1266 } | 1263 } |
1267 | 1264 |
1268 void ResourceProvider::LazyCreate(Resource* resource) { | 1265 void ResourceProvider::LazyCreate(Resource* resource) { |
1269 if (resource->type != GLTexture || resource->gl_id != 0) | 1266 if (resource->type != GLTexture || resource->gl_id != 0) |
1270 return; | 1267 return; |
1271 | 1268 |
1272 // Early out for resources that don't require texture creation. | 1269 // Early out for resources that don't require texture creation. |
1273 if (resource->texture_pool == 0) | 1270 if (resource->texture_pool == 0) |
1274 return; | 1271 return; |
1275 | 1272 |
1276 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1273 WebGraphicsContext3D* context3d = Context3d(); |
1277 DCHECK(context3d); | 1274 DCHECK(context3d); |
1278 // Create and set texture properties. Allocation is delayed until needed. | 1275 // Create and set texture properties. Allocation is delayed until needed. |
1279 resource->gl_id = CreateTextureId(context3d); | 1276 resource->gl_id = CreateTextureId(context3d); |
1280 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, | 1277 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, |
1281 GL_TEXTURE_POOL_CHROMIUM, | 1278 GL_TEXTURE_POOL_CHROMIUM, |
1282 resource->texture_pool)); | 1279 resource->texture_pool)); |
1283 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { | 1280 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { |
1284 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, | 1281 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, |
1285 GL_TEXTURE_USAGE_ANGLE, | 1282 GL_TEXTURE_USAGE_ANGLE, |
1286 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 1283 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
1287 } | 1284 } |
1288 } | 1285 } |
1289 | 1286 |
1290 void ResourceProvider::AllocateForTesting(ResourceId id) { | 1287 void ResourceProvider::AllocateForTesting(ResourceId id) { |
1291 ResourceMap::iterator it = resources_.find(id); | 1288 ResourceMap::iterator it = resources_.find(id); |
1292 CHECK(it != resources_.end()); | 1289 CHECK(it != resources_.end()); |
1293 Resource* resource = &it->second; | 1290 Resource* resource = &it->second; |
1294 LazyAllocate(resource); | 1291 LazyAllocate(resource); |
1295 } | 1292 } |
1296 | 1293 |
1297 void ResourceProvider::LazyAllocate(Resource* resource) { | 1294 void ResourceProvider::LazyAllocate(Resource* resource) { |
1298 DCHECK(resource); | 1295 DCHECK(resource); |
1299 LazyCreate(resource); | 1296 LazyCreate(resource); |
1300 | 1297 |
1301 DCHECK(resource->gl_id || resource->allocated); | 1298 DCHECK(resource->gl_id || resource->allocated); |
1302 if (resource->allocated || !resource->gl_id) | 1299 if (resource->allocated || !resource->gl_id) |
1303 return; | 1300 return; |
1304 resource->allocated = true; | 1301 resource->allocated = true; |
1305 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1302 WebGraphicsContext3D* context3d = Context3d(); |
1306 gfx::Size& size = resource->size; | 1303 gfx::Size& size = resource->size; |
1307 GLenum format = resource->format; | 1304 GLenum format = resource->format; |
1308 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1305 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1309 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1306 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { |
1310 GLenum storage_format = TextureToStorageFormat(format); | 1307 GLenum storage_format = TextureToStorageFormat(format); |
1311 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1308 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
1312 1, | 1309 1, |
1313 storage_format, | 1310 storage_format, |
1314 size.width(), | 1311 size.width(), |
1315 size.height())); | 1312 size.height())); |
(...skipping 28 matching lines...) Expand all Loading... |
1344 DCHECK(!resource->external); | 1341 DCHECK(!resource->external); |
1345 DCHECK(!resource->exported); | 1342 DCHECK(!resource->exported); |
1346 | 1343 |
1347 if (resource->type != GLTexture) | 1344 if (resource->type != GLTexture) |
1348 return; | 1345 return; |
1349 | 1346 |
1350 if (resource->image_id) | 1347 if (resource->image_id) |
1351 return; | 1348 return; |
1352 | 1349 |
1353 resource->allocated = true; | 1350 resource->allocated = true; |
1354 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1351 WebGraphicsContext3D* context3d = Context3d(); |
1355 DCHECK(context3d); | 1352 DCHECK(context3d); |
1356 resource->image_id = context3d->createImageCHROMIUM( | 1353 resource->image_id = context3d->createImageCHROMIUM( |
1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | 1354 resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
1358 DCHECK(resource->image_id); | 1355 DCHECK(resource->image_id); |
1359 } | 1356 } |
1360 | 1357 |
1361 void ResourceProvider::ReleaseImage(ResourceId id) { | 1358 void ResourceProvider::ReleaseImage(ResourceId id) { |
1362 DCHECK(thread_checker_.CalledOnValidThread()); | 1359 DCHECK(thread_checker_.CalledOnValidThread()); |
1363 ResourceMap::iterator it = resources_.find(id); | 1360 ResourceMap::iterator it = resources_.find(id); |
1364 CHECK(it != resources_.end()); | 1361 CHECK(it != resources_.end()); |
1365 Resource* resource = &it->second; | 1362 Resource* resource = &it->second; |
1366 | 1363 |
1367 DCHECK(!resource->external); | 1364 DCHECK(!resource->external); |
1368 DCHECK(!resource->exported); | 1365 DCHECK(!resource->exported); |
1369 | 1366 |
1370 if (!resource->image_id) | 1367 if (!resource->image_id) |
1371 return; | 1368 return; |
1372 | 1369 |
1373 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1370 WebGraphicsContext3D* context3d = Context3d(); |
1374 DCHECK(context3d); | 1371 DCHECK(context3d); |
1375 context3d->destroyImageCHROMIUM(resource->image_id); | 1372 context3d->destroyImageCHROMIUM(resource->image_id); |
1376 resource->image_id = 0; | 1373 resource->image_id = 0; |
1377 resource->allocated = false; | 1374 resource->allocated = false; |
1378 } | 1375 } |
1379 | 1376 |
1380 uint8_t* ResourceProvider::MapImage(ResourceId id) { | 1377 uint8_t* ResourceProvider::MapImage(ResourceId id) { |
1381 DCHECK(thread_checker_.CalledOnValidThread()); | 1378 DCHECK(thread_checker_.CalledOnValidThread()); |
1382 ResourceMap::iterator it = resources_.find(id); | 1379 ResourceMap::iterator it = resources_.find(id); |
1383 CHECK(it != resources_.end()); | 1380 CHECK(it != resources_.end()); |
1384 Resource* resource = &it->second; | 1381 Resource* resource = &it->second; |
1385 | 1382 |
1386 DCHECK(ReadLockFenceHasPassed(resource)); | 1383 DCHECK(ReadLockFenceHasPassed(resource)); |
1387 DCHECK(!resource->external); | 1384 DCHECK(!resource->external); |
1388 DCHECK(!resource->exported); | 1385 DCHECK(!resource->exported); |
1389 | 1386 |
1390 if (resource->image_id) { | 1387 if (resource->image_id) { |
1391 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1388 WebGraphicsContext3D* context3d = Context3d(); |
1392 DCHECK(context3d); | 1389 DCHECK(context3d); |
1393 return static_cast<uint8_t*>( | 1390 return static_cast<uint8_t*>( |
1394 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); | 1391 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); |
1395 } | 1392 } |
1396 | 1393 |
1397 if (resource->pixels) | 1394 if (resource->pixels) |
1398 return resource->pixels; | 1395 return resource->pixels; |
1399 | 1396 |
1400 return NULL; | 1397 return NULL; |
1401 } | 1398 } |
1402 | 1399 |
1403 void ResourceProvider::UnmapImage(ResourceId id) { | 1400 void ResourceProvider::UnmapImage(ResourceId id) { |
1404 DCHECK(thread_checker_.CalledOnValidThread()); | 1401 DCHECK(thread_checker_.CalledOnValidThread()); |
1405 ResourceMap::iterator it = resources_.find(id); | 1402 ResourceMap::iterator it = resources_.find(id); |
1406 CHECK(it != resources_.end()); | 1403 CHECK(it != resources_.end()); |
1407 Resource* resource = &it->second; | 1404 Resource* resource = &it->second; |
1408 | 1405 |
1409 DCHECK(!resource->external); | 1406 DCHECK(!resource->external); |
1410 DCHECK(!resource->exported); | 1407 DCHECK(!resource->exported); |
1411 | 1408 |
1412 if (resource->image_id) { | 1409 if (resource->image_id) { |
1413 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1410 WebGraphicsContext3D* context3d = Context3d(); |
1414 DCHECK(context3d); | 1411 DCHECK(context3d); |
1415 context3d->unmapImageCHROMIUM(resource->image_id); | 1412 context3d->unmapImageCHROMIUM(resource->image_id); |
1416 } | 1413 } |
1417 } | 1414 } |
1418 | 1415 |
1419 int ResourceProvider::GetImageStride(ResourceId id) { | 1416 int ResourceProvider::GetImageStride(ResourceId id) { |
1420 DCHECK(thread_checker_.CalledOnValidThread()); | 1417 DCHECK(thread_checker_.CalledOnValidThread()); |
1421 ResourceMap::iterator it = resources_.find(id); | 1418 ResourceMap::iterator it = resources_.find(id); |
1422 CHECK(it != resources_.end()); | 1419 CHECK(it != resources_.end()); |
1423 Resource* resource = &it->second; | 1420 Resource* resource = &it->second; |
1424 | 1421 |
1425 DCHECK(!resource->external); | 1422 DCHECK(!resource->external); |
1426 DCHECK(!resource->exported); | 1423 DCHECK(!resource->exported); |
1427 | 1424 |
1428 int stride = 0; | 1425 int stride = 0; |
1429 | 1426 |
1430 if (resource->image_id) { | 1427 if (resource->image_id) { |
1431 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1428 WebGraphicsContext3D* context3d = Context3d(); |
1432 DCHECK(context3d); | 1429 DCHECK(context3d); |
1433 context3d->getImageParameterivCHROMIUM( | 1430 context3d->getImageParameterivCHROMIUM( |
1434 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); | 1431 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); |
1435 } | 1432 } |
1436 | 1433 |
1437 return stride; | 1434 return stride; |
1438 } | 1435 } |
1439 | 1436 |
1440 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) { | 1437 GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) { |
1441 GLint active_unit = 0; | 1438 GLint active_unit = 0; |
1442 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1439 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1443 return active_unit; | 1440 return active_unit; |
1444 } | 1441 } |
1445 | 1442 |
| 1443 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1444 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1445 return context_provider ? context_provider->Context3d() : NULL; |
| 1446 } |
| 1447 |
1446 } // namespace cc | 1448 } // namespace cc |
OLD | NEW |