| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 ResourceId id = next_id_++; | 299 ResourceId id = next_id_++; |
| 300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, |
| 301 TextureUsageAny); | 301 TextureUsageAny); |
| 302 resource.external = true; | 302 resource.external = true; |
| 303 resource.allocated = true; | 303 resource.allocated = true; |
| 304 resources_[id] = resource; | 304 resources_[id] = resource; |
| 305 return id; | 305 return id; |
| 306 } | 306 } |
| 307 | 307 |
| 308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 309 const TextureMailbox& mailbox) { | 309 const TextureMailbox& mailbox, |
| 310 ScopedReleaseCallback release_callback) { |
| 310 DCHECK(thread_checker_.CalledOnValidThread()); | 311 DCHECK(thread_checker_.CalledOnValidThread()); |
| 311 // Just store the information. Mailbox will be consumed in LockForRead(). | 312 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 312 ResourceId id = next_id_++; | 313 ResourceId id = next_id_++; |
| 313 DCHECK(mailbox.IsValid()); | 314 DCHECK(mailbox.IsValid()); |
| 314 Resource& resource = resources_[id]; | 315 Resource& resource = resources_[id]; |
| 315 if (mailbox.IsTexture()) { | 316 if (mailbox.IsTexture()) { |
| 316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 317 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, |
| 317 TextureUsageAny); | 318 TextureUsageAny); |
| 318 } else { | 319 } else { |
| 319 DCHECK(mailbox.IsSharedMemory()); | 320 DCHECK(mailbox.IsSharedMemory()); |
| 320 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 321 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
| 321 DCHECK(shared_memory->memory()); | 322 DCHECK(shared_memory->memory()); |
| 322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 323 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
| 323 resource = Resource(pixels, mailbox.shared_memory_size(), | 324 resource = Resource(pixels, mailbox.shared_memory_size(), |
| 324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 325 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 325 } | 326 } |
| 326 resource.external = true; | 327 resource.external = true; |
| 327 resource.allocated = true; | 328 resource.allocated = true; |
| 328 resource.mailbox = mailbox; | 329 resource.mailbox = mailbox; |
| 330 resource.release_callback = release_callback.Leak(); |
| 329 return id; | 331 return id; |
| 330 } | 332 } |
| 331 | 333 |
| 332 void ResourceProvider::DeleteResource(ResourceId id) { | 334 void ResourceProvider::DeleteResource(ResourceId id) { |
| 333 DCHECK(thread_checker_.CalledOnValidThread()); | 335 DCHECK(thread_checker_.CalledOnValidThread()); |
| 334 ResourceMap::iterator it = resources_.find(id); | 336 ResourceMap::iterator it = resources_.find(id); |
| 335 CHECK(it != resources_.end()); | 337 CHECK(it != resources_.end()); |
| 336 Resource* resource = &it->second; | 338 Resource* resource = &it->second; |
| 337 DCHECK(!resource->lock_for_read_count); | 339 DCHECK(!resource->lock_for_read_count); |
| 338 DCHECK(!resource->marked_for_deletion); | 340 DCHECK(!resource->marked_for_deletion); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 if (!lost_resource && resource->gl_id) | 389 if (!lost_resource && resource->gl_id) |
| 388 sync_point = context3d->insertSyncPoint(); | 390 sync_point = context3d->insertSyncPoint(); |
| 389 } else { | 391 } else { |
| 390 DCHECK(resource->mailbox.IsSharedMemory()); | 392 DCHECK(resource->mailbox.IsSharedMemory()); |
| 391 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); | 393 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); |
| 392 if (resource->pixels && shared_memory) { | 394 if (resource->pixels && shared_memory) { |
| 393 DCHECK(shared_memory->memory() == resource->pixels); | 395 DCHECK(shared_memory->memory() == resource->pixels); |
| 394 resource->pixels = NULL; | 396 resource->pixels = NULL; |
| 395 } | 397 } |
| 396 } | 398 } |
| 397 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); | 399 resource->release_callback.Run(sync_point, lost_resource); |
| 398 } | 400 } |
| 399 if (resource->pixels) | 401 if (resource->pixels) |
| 400 delete[] resource->pixels; | 402 delete[] resource->pixels; |
| 401 if (resource->pixel_buffer) | 403 if (resource->pixel_buffer) |
| 402 delete[] resource->pixel_buffer; | 404 delete[] resource->pixel_buffer; |
| 403 | 405 |
| 404 resources_.erase(it); | 406 resources_.erase(it); |
| 405 } | 407 } |
| 406 | 408 |
| 407 ResourceProvider::ResourceType ResourceProvider::GetResourceType( | 409 ResourceProvider::ResourceType ResourceProvider::GetResourceType( |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 Resource* resource = &map_iterator->second; | 941 Resource* resource = &map_iterator->second; |
| 940 CHECK_GE(resource->exported_count, it->count); | 942 CHECK_GE(resource->exported_count, it->count); |
| 941 resource->exported_count -= it->count; | 943 resource->exported_count -= it->count; |
| 942 if (resource->exported_count) | 944 if (resource->exported_count) |
| 943 continue; | 945 continue; |
| 944 resource->filter = it->filter; | 946 resource->filter = it->filter; |
| 945 if (resource->gl_id) { | 947 if (resource->gl_id) { |
| 946 if (it->sync_point) | 948 if (it->sync_point) |
| 947 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 949 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
| 948 } else { | 950 } else { |
| 949 resource->mailbox = TextureMailbox(resource->mailbox.name(), | 951 resource->mailbox = |
| 950 resource->mailbox.callback(), | 952 TextureMailbox(resource->mailbox.name(), it->sync_point); |
| 951 it->sync_point); | |
| 952 } | 953 } |
| 953 if (resource->marked_for_deletion) | 954 if (resource->marked_for_deletion) |
| 954 DeleteResourceInternal(map_iterator, Normal); | 955 DeleteResourceInternal(map_iterator, Normal); |
| 955 } | 956 } |
| 956 } | 957 } |
| 957 | 958 |
| 958 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, | 959 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
| 959 ResourceId id, | 960 ResourceId id, |
| 960 TransferableResource* resource) { | 961 TransferableResource* resource) { |
| 961 Resource* source = GetResource(id); | 962 Resource* source = GetResource(id); |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1427 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1427 return active_unit; | 1428 return active_unit; |
| 1428 } | 1429 } |
| 1429 | 1430 |
| 1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1431 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1431 ContextProvider* context_provider = output_surface_->context_provider(); | 1432 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1432 return context_provider ? context_provider->Context3d() : NULL; | 1433 return context_provider ? context_provider->Context3d() : NULL; |
| 1433 } | 1434 } |
| 1434 | 1435 |
| 1435 } // namespace cc | 1436 } // namespace cc |
| OLD | NEW |