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

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

Issue 23648014: cc: Move TextureMailbox::ReleaseCallback to SingleReleaseCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: releasecallback: dchecks 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 | Annotate | Revision Log
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 scoped_ptr<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 =
331 base::Bind(&ScopedReleaseCallback::Run,
332 base::Owned(release_callback.release()));
329 return id; 333 return id;
330 } 334 }
331 335
332 void ResourceProvider::DeleteResource(ResourceId id) { 336 void ResourceProvider::DeleteResource(ResourceId id) {
333 DCHECK(thread_checker_.CalledOnValidThread()); 337 DCHECK(thread_checker_.CalledOnValidThread());
334 ResourceMap::iterator it = resources_.find(id); 338 ResourceMap::iterator it = resources_.find(id);
335 CHECK(it != resources_.end()); 339 CHECK(it != resources_.end());
336 Resource* resource = &it->second; 340 Resource* resource = &it->second;
337 DCHECK(!resource->lock_for_read_count); 341 DCHECK(!resource->lock_for_read_count);
338 DCHECK(!resource->marked_for_deletion); 342 DCHECK(!resource->marked_for_deletion);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 if (!lost_resource && resource->gl_id) 391 if (!lost_resource && resource->gl_id)
388 sync_point = context3d->insertSyncPoint(); 392 sync_point = context3d->insertSyncPoint();
389 } else { 393 } else {
390 DCHECK(resource->mailbox.IsSharedMemory()); 394 DCHECK(resource->mailbox.IsSharedMemory());
391 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); 395 base::SharedMemory* shared_memory = resource->mailbox.shared_memory();
392 if (resource->pixels && shared_memory) { 396 if (resource->pixels && shared_memory) {
393 DCHECK(shared_memory->memory() == resource->pixels); 397 DCHECK(shared_memory->memory() == resource->pixels);
394 resource->pixels = NULL; 398 resource->pixels = NULL;
395 } 399 }
396 } 400 }
397 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); 401 resource->release_callback.Run(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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698