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