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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 ResourceId id = next_id_++; | 305 ResourceId id = next_id_++; |
306 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 306 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, |
307 TextureUsageAny); | 307 TextureUsageAny); |
308 resource.external = true; | 308 resource.external = true; |
309 resource.allocated = true; | 309 resource.allocated = true; |
310 resources_[id] = resource; | 310 resources_[id] = resource; |
311 return id; | 311 return id; |
312 } | 312 } |
313 | 313 |
314 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 314 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
315 const TextureMailbox& mailbox) { | 315 const TextureMailbox& mailbox, |
| 316 scoped_ptr<SingleReleaseCallback> release_callback) { |
316 DCHECK(thread_checker_.CalledOnValidThread()); | 317 DCHECK(thread_checker_.CalledOnValidThread()); |
317 // Just store the information. Mailbox will be consumed in LockForRead(). | 318 // Just store the information. Mailbox will be consumed in LockForRead(). |
318 ResourceId id = next_id_++; | 319 ResourceId id = next_id_++; |
319 DCHECK(mailbox.IsValid()); | 320 DCHECK(mailbox.IsValid()); |
320 Resource& resource = resources_[id]; | 321 Resource& resource = resources_[id]; |
321 if (mailbox.IsTexture()) { | 322 if (mailbox.IsTexture()) { |
322 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 323 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, |
323 TextureUsageAny); | 324 TextureUsageAny); |
324 } else { | 325 } else { |
325 DCHECK(mailbox.IsSharedMemory()); | 326 DCHECK(mailbox.IsSharedMemory()); |
326 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 327 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
327 DCHECK(shared_memory->memory()); | 328 DCHECK(shared_memory->memory()); |
328 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 329 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
329 resource = Resource(pixels, mailbox.shared_memory_size(), | 330 resource = Resource(pixels, mailbox.shared_memory_size(), |
330 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 331 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); |
331 } | 332 } |
332 resource.external = true; | 333 resource.external = true; |
333 resource.allocated = true; | 334 resource.allocated = true; |
334 resource.mailbox = mailbox; | 335 resource.mailbox = mailbox; |
| 336 resource.release_callback = |
| 337 base::Bind(&SingleReleaseCallback::Run, |
| 338 base::Owned(release_callback.release())); |
335 return id; | 339 return id; |
336 } | 340 } |
337 | 341 |
338 void ResourceProvider::DeleteResource(ResourceId id) { | 342 void ResourceProvider::DeleteResource(ResourceId id) { |
339 DCHECK(thread_checker_.CalledOnValidThread()); | 343 DCHECK(thread_checker_.CalledOnValidThread()); |
340 ResourceMap::iterator it = resources_.find(id); | 344 ResourceMap::iterator it = resources_.find(id); |
341 CHECK(it != resources_.end()); | 345 CHECK(it != resources_.end()); |
342 Resource* resource = &it->second; | 346 Resource* resource = &it->second; |
343 DCHECK(!resource->lock_for_read_count); | 347 DCHECK(!resource->lock_for_read_count); |
344 DCHECK(!resource->marked_for_deletion); | 348 DCHECK(!resource->marked_for_deletion); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 if (!lost_resource && resource->gl_id) | 397 if (!lost_resource && resource->gl_id) |
394 sync_point = context3d->insertSyncPoint(); | 398 sync_point = context3d->insertSyncPoint(); |
395 } else { | 399 } else { |
396 DCHECK(resource->mailbox.IsSharedMemory()); | 400 DCHECK(resource->mailbox.IsSharedMemory()); |
397 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); | 401 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); |
398 if (resource->pixels && shared_memory) { | 402 if (resource->pixels && shared_memory) { |
399 DCHECK(shared_memory->memory() == resource->pixels); | 403 DCHECK(shared_memory->memory() == resource->pixels); |
400 resource->pixels = NULL; | 404 resource->pixels = NULL; |
401 } | 405 } |
402 } | 406 } |
403 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); | 407 resource->release_callback.Run(sync_point, lost_resource); |
404 } | 408 } |
405 if (resource->pixels) | 409 if (resource->pixels) |
406 delete[] resource->pixels; | 410 delete[] resource->pixels; |
407 if (resource->pixel_buffer) | 411 if (resource->pixel_buffer) |
408 delete[] resource->pixel_buffer; | 412 delete[] resource->pixel_buffer; |
409 | 413 |
410 resources_.erase(it); | 414 resources_.erase(it); |
411 } | 415 } |
412 | 416 |
413 ResourceProvider::ResourceType ResourceProvider::GetResourceType( | 417 ResourceProvider::ResourceType ResourceProvider::GetResourceType( |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 DCHECK(map_iterator != resources_.end()); | 960 DCHECK(map_iterator != resources_.end()); |
957 Resource* resource = &map_iterator->second; | 961 Resource* resource = &map_iterator->second; |
958 CHECK_GE(resource->exported_count, it->count); | 962 CHECK_GE(resource->exported_count, it->count); |
959 resource->exported_count -= it->count; | 963 resource->exported_count -= it->count; |
960 if (resource->exported_count) | 964 if (resource->exported_count) |
961 continue; | 965 continue; |
962 if (resource->gl_id) { | 966 if (resource->gl_id) { |
963 if (it->sync_point) | 967 if (it->sync_point) |
964 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 968 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
965 } else { | 969 } else { |
966 resource->mailbox = TextureMailbox(resource->mailbox.name(), | 970 resource->mailbox = |
967 resource->mailbox.callback(), | 971 TextureMailbox(resource->mailbox.name(), it->sync_point); |
968 it->sync_point); | |
969 } | 972 } |
970 if (resource->marked_for_deletion) | 973 if (resource->marked_for_deletion) |
971 DeleteResourceInternal(map_iterator, Normal); | 974 DeleteResourceInternal(map_iterator, Normal); |
972 } | 975 } |
973 } | 976 } |
974 | 977 |
975 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, | 978 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
976 ResourceId id, | 979 ResourceId id, |
977 TransferableResource* resource) { | 980 TransferableResource* resource) { |
978 Resource* source = GetResource(id); | 981 Resource* source = GetResource(id); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1450 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1448 return active_unit; | 1451 return active_unit; |
1449 } | 1452 } |
1450 | 1453 |
1451 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1454 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
1452 ContextProvider* context_provider = output_surface_->context_provider(); | 1455 ContextProvider* context_provider = output_surface_->context_provider(); |
1453 return context_provider ? context_provider->Context3d() : NULL; | 1456 return context_provider ? context_provider->Context3d() : NULL; |
1454 } | 1457 } |
1455 | 1458 |
1456 } // namespace cc | 1459 } // namespace cc |
OLD | NEW |