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

Side by Side Diff: cc/resource_provider.cc

Issue 11638028: Mailbox support for texture layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 7 years, 11 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
« no previous file with comments | « cc/resource_provider.h ('k') | cc/texture_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/resource_provider.h" 5 #include "cc/resource_provider.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include "base/debug/alias.h" 9 #include "base/debug/alias.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 , exported(false) 59 , exported(false)
60 , markedForDeletion(false) 60 , markedForDeletion(false)
61 , pendingSetPixels(false) 61 , pendingSetPixels(false)
62 , size() 62 , size()
63 , format(0) 63 , format(0)
64 , filter(0) 64 , filter(0)
65 , type(static_cast<ResourceType>(0)) 65 , type(static_cast<ResourceType>(0))
66 { 66 {
67 } 67 }
68 68
69 ResourceProvider::Resource::~Resource()
70 {
71 }
72
69 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenum filter) 73 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenum filter)
70 : glId(textureId) 74 : glId(textureId)
71 , glPixelBufferId(0) 75 , glPixelBufferId(0)
72 , glUploadQueryId(0) 76 , glUploadQueryId(0)
73 , pixels(0) 77 , pixels(0)
74 , pixelBuffer(0) 78 , pixelBuffer(0)
75 , lockForReadCount(0) 79 , lockForReadCount(0)
76 , lockedForWrite(false) 80 , lockedForWrite(false)
77 , external(false) 81 , external(false)
78 , exported(false) 82 , exported(false)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 231 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
228 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 232 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
229 233
230 ResourceId id = m_nextId++; 234 ResourceId id = m_nextId++;
231 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); 235 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
232 resource.external = true; 236 resource.external = true;
233 m_resources[id] = resource; 237 m_resources[id] = resource;
234 return id; 238 return id;
235 } 239 }
236 240
241 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const std::string& mailbox, const base::Callback<void(unsigned)>& releaseCallbac k)
242 {
243 DCHECK(m_threadChecker.CalledOnValidThread());
244
245 // FIXME: As an optimization, delay consuming the mailbox
246 // and creating the texture ID until lockForRead.
247 const int8* name = reinterpret_cast<const int8*>(mailbox.data());
248 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
249 DCHECK(context3d);
250 unsigned textureId = context3d->createTexture();
251 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
252 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, name));
253
254 ResourceId id = m_nextId++;
255 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
256 resource.external = true;
257 resource.mailbox.setName(name);
258 resource.mailboxReleaseCallback = releaseCallback;
259 m_resources[id] = resource;
260 return id;
261 }
262
237 void ResourceProvider::deleteResource(ResourceId id) 263 void ResourceProvider::deleteResource(ResourceId id)
238 { 264 {
239 DCHECK(m_threadChecker.CalledOnValidThread()); 265 DCHECK(m_threadChecker.CalledOnValidThread());
240 ResourceMap::iterator it = m_resources.find(id); 266 ResourceMap::iterator it = m_resources.find(id);
241 CHECK(it != m_resources.end()); 267 CHECK(it != m_resources.end());
242 Resource* resource = &it->second; 268 Resource* resource = &it->second;
243 DCHECK(!resource->lockedForWrite); 269 DCHECK(!resource->lockedForWrite);
244 DCHECK(!resource->lockForReadCount); 270 DCHECK(!resource->lockForReadCount);
245 DCHECK(!resource->markedForDeletion); 271 DCHECK(!resource->markedForDeletion);
246 272
(...skipping 15 matching lines...) Expand all
262 if (resource->glUploadQueryId) { 288 if (resource->glUploadQueryId) {
263 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 289 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
264 DCHECK(context3d); 290 DCHECK(context3d);
265 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); 291 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId));
266 } 292 }
267 if (resource->glPixelBufferId) { 293 if (resource->glPixelBufferId) {
268 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 294 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
269 DCHECK(context3d); 295 DCHECK(context3d);
270 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); 296 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId));
271 } 297 }
298 if (!resource->mailbox.isZero() && resource->external) {
299 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
300 DCHECK(context3d);
301 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
302 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, resource ->mailbox.name));
303 GLC(context3d, context3d->deleteTexture(resource->glId));
304 if (!resource->mailboxReleaseCallback.is_null()) {
305 unsigned syncPoint = context3d->insertSyncPoint();
306 resource->mailboxReleaseCallback.Run(syncPoint);
307 }
308 }
272 if (resource->pixels) 309 if (resource->pixels)
273 delete[] resource->pixels; 310 delete[] resource->pixels;
274 if (resource->pixelBuffer) 311 if (resource->pixelBuffer)
275 delete[] resource->pixelBuffer; 312 delete[] resource->pixelBuffer;
276 313
277 m_resources.erase(it); 314 m_resources.erase(it);
278 } 315 }
279 316
280 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) 317 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id)
281 { 318 {
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 714
678 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) 715 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource)
679 { 716 {
680 DCHECK(m_threadChecker.CalledOnValidThread()); 717 DCHECK(m_threadChecker.CalledOnValidThread());
681 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 718 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
682 ResourceMap::iterator it = m_resources.find(id); 719 ResourceMap::iterator it = m_resources.find(id);
683 CHECK(it != m_resources.end()); 720 CHECK(it != m_resources.end());
684 Resource* source = &it->second; 721 Resource* source = &it->second;
685 DCHECK(!source->lockedForWrite); 722 DCHECK(!source->lockedForWrite);
686 DCHECK(!source->lockForReadCount); 723 DCHECK(!source->lockForReadCount);
687 DCHECK(!source->external); 724 DCHECK(!source->external || (source->external && !source->mailbox.isZero())) ;
688 if (source->exported) 725 if (source->exported)
689 return false; 726 return false;
690 resource->id = id; 727 resource->id = id;
691 resource->format = source->format; 728 resource->format = source->format;
692 resource->filter = source->filter; 729 resource->filter = source->filter;
693 resource->size = source->size; 730 resource->size = source->size;
694 731
695 if (source->mailbox.isZero()) { 732 if (source->mailbox.isZero()) {
696 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; 733 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM];
697 GLC(context3d, context3d->genMailboxCHROMIUM(name)); 734 GLC(context3d, context3d->genMailboxCHROMIUM(name));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 return false; 986 return false;
950 } 987 }
951 988
952 resource->pendingSetPixels = false; 989 resource->pendingSetPixels = false;
953 unlockForWrite(id); 990 unlockForWrite(id);
954 991
955 return true; 992 return true;
956 } 993 }
957 994
958 } // namespace cc 995 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resource_provider.h ('k') | cc/texture_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698