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

Side by Side Diff: cc/resource_provider.cc

Issue 11348371: cc: Move WebCompositorOutputSurface and related classes into cc/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forlanding6 Created 8 years 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/proxy.h ('k') | cc/resource_provider_unittest.cc » ('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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 scoped_ptr<ResourceProvider> ResourceProvider::create(OutputSurface* context) 118 scoped_ptr<ResourceProvider> ResourceProvider::create(OutputSurface* context)
119 { 119 {
120 scoped_ptr<ResourceProvider> resourceProvider(new ResourceProvider(context)) ; 120 scoped_ptr<ResourceProvider> resourceProvider(new ResourceProvider(context)) ;
121 if (!resourceProvider->initialize()) 121 if (!resourceProvider->initialize())
122 return scoped_ptr<ResourceProvider>(); 122 return scoped_ptr<ResourceProvider>();
123 return resourceProvider.Pass(); 123 return resourceProvider.Pass();
124 } 124 }
125 125
126 ResourceProvider::~ResourceProvider() 126 ResourceProvider::~ResourceProvider()
127 { 127 {
128 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 128 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
129 if (!context3d || !context3d->makeContextCurrent()) 129 if (!context3d || !context3d->makeContextCurrent())
130 return; 130 return;
131 m_textureUploader.reset(); 131 m_textureUploader.reset();
132 m_textureCopier.reset(); 132 m_textureCopier.reset();
133 } 133 }
134 134
135 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() 135 WebGraphicsContext3D* ResourceProvider::graphicsContext3D()
136 { 136 {
137 DCHECK(m_threadChecker.CalledOnValidThread()); 137 DCHECK(m_threadChecker.CalledOnValidThread());
138 return m_outputSurface->context3D(); 138 return m_outputSurface->Context3D();
139 } 139 }
140 140
141 bool ResourceProvider::inUseByConsumer(ResourceId id) 141 bool ResourceProvider::inUseByConsumer(ResourceId id)
142 { 142 {
143 DCHECK(m_threadChecker.CalledOnValidThread()); 143 DCHECK(m_threadChecker.CalledOnValidThread());
144 ResourceMap::iterator it = m_resources.find(id); 144 ResourceMap::iterator it = m_resources.find(id);
145 CHECK(it != m_resources.end()); 145 CHECK(it != m_resources.end());
146 Resource* resource = &it->second; 146 Resource* resource = &it->second;
147 return !!resource->lockForReadCount || resource->exported; 147 return !!resource->lockForReadCount || resource->exported;
148 } 148 }
(...skipping 12 matching lines...) Expand all
161 return 0; 161 return 0;
162 } 162 }
163 163
164 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g fx::Size& size, GLenum format, TextureUsageHint hint) 164 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g fx::Size& size, GLenum format, TextureUsageHint hint)
165 { 165 {
166 DCHECK_LE(size.width(), m_maxTextureSize); 166 DCHECK_LE(size.width(), m_maxTextureSize);
167 DCHECK_LE(size.height(), m_maxTextureSize); 167 DCHECK_LE(size.height(), m_maxTextureSize);
168 168
169 DCHECK(m_threadChecker.CalledOnValidThread()); 169 DCHECK(m_threadChecker.CalledOnValidThread());
170 unsigned textureId = 0; 170 unsigned textureId = 0;
171 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 171 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
172 DCHECK(context3d); 172 DCHECK(context3d);
173 GLC(context3d, textureId = context3d->createTexture()); 173 GLC(context3d, textureId = context3d->createTexture());
174 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 174 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
177 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 177 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
178 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 178 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
179 179
180 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 180 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
181 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 181 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
(...skipping 18 matching lines...) Expand all
200 ResourceId id = m_nextId++; 200 ResourceId id = m_nextId++;
201 Resource resource(pixels, pool, size, GL_RGBA, GL_LINEAR); 201 Resource resource(pixels, pool, size, GL_RGBA, GL_LINEAR);
202 m_resources[id] = resource; 202 m_resources[id] = resource;
203 return id; 203 return id;
204 } 204 }
205 205
206 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) 206 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId)
207 { 207 {
208 DCHECK(m_threadChecker.CalledOnValidThread()); 208 DCHECK(m_threadChecker.CalledOnValidThread());
209 209
210 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 210 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
211 DCHECK(context3d); 211 DCHECK(context3d);
212 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 212 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
213 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 213 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
214 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 214 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
215 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 215 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
216 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 216 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
217 217
218 ResourceId id = m_nextId++; 218 ResourceId id = m_nextId++;
219 Resource resource(textureId, 0, gfx::Size(), 0, GL_LINEAR); 219 Resource resource(textureId, 0, gfx::Size(), 0, GL_LINEAR);
220 resource.external = true; 220 resource.external = true;
(...skipping 15 matching lines...) Expand all
236 resource->markedForDeletion = true; 236 resource->markedForDeletion = true;
237 return; 237 return;
238 } else 238 } else
239 deleteResourceInternal(it); 239 deleteResourceInternal(it);
240 } 240 }
241 241
242 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) 242 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it)
243 { 243 {
244 Resource* resource = &it->second; 244 Resource* resource = &it->second;
245 if (resource->glId && !resource->external) { 245 if (resource->glId && !resource->external) {
246 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 246 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
247 DCHECK(context3d); 247 DCHECK(context3d);
248 GLC(context3d, context3d->deleteTexture(resource->glId)); 248 GLC(context3d, context3d->deleteTexture(resource->glId));
249 } 249 }
250 if (resource->glUploadQueryId) { 250 if (resource->glUploadQueryId) {
251 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 251 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
252 DCHECK(context3d); 252 DCHECK(context3d);
253 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); 253 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId));
254 } 254 }
255 if (resource->glPixelBufferId) { 255 if (resource->glPixelBufferId) {
256 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 256 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
257 DCHECK(context3d); 257 DCHECK(context3d);
258 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); 258 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId));
259 } 259 }
260 if (resource->pixels) 260 if (resource->pixels)
261 delete[] resource->pixels; 261 delete[] resource->pixels;
262 if (resource->pixelBuffer) 262 if (resource->pixelBuffer)
263 delete[] resource->pixelBuffer; 263 delete[] resource->pixelBuffer;
264 264
265 m_resources.erase(it); 265 m_resources.erase(it);
266 } 266 }
(...skipping 23 matching lines...) Expand all
290 DCHECK(m_threadChecker.CalledOnValidThread()); 290 DCHECK(m_threadChecker.CalledOnValidThread());
291 ResourceMap::iterator it = m_resources.find(id); 291 ResourceMap::iterator it = m_resources.find(id);
292 CHECK(it != m_resources.end()); 292 CHECK(it != m_resources.end());
293 Resource* resource = &it->second; 293 Resource* resource = &it->second;
294 DCHECK(!resource->lockedForWrite); 294 DCHECK(!resource->lockedForWrite);
295 DCHECK(!resource->lockForReadCount); 295 DCHECK(!resource->lockForReadCount);
296 DCHECK(!resource->external); 296 DCHECK(!resource->external);
297 DCHECK(!resource->exported); 297 DCHECK(!resource->exported);
298 298
299 if (resource->glId) { 299 if (resource->glId) {
300 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 300 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
301 DCHECK(context3d); 301 DCHECK(context3d);
302 DCHECK(m_textureUploader.get()); 302 DCHECK(m_textureUploader.get());
303 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 303 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
304 m_textureUploader->upload(image, 304 m_textureUploader->upload(image,
305 imageRect, 305 imageRect,
306 sourceRect, 306 sourceRect,
307 destOffset, 307 destOffset,
308 resource->format, 308 resource->format,
309 resource->size); 309 resource->size);
310 } 310 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 { 353 {
354 if (!m_textureUploader) 354 if (!m_textureUploader)
355 return; 355 return;
356 356
357 m_textureUploader->flush(); 357 m_textureUploader->flush();
358 } 358 }
359 359
360 void ResourceProvider::flush() 360 void ResourceProvider::flush()
361 { 361 {
362 DCHECK(m_threadChecker.CalledOnValidThread()); 362 DCHECK(m_threadChecker.CalledOnValidThread());
363 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 363 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
364 if (context3d) 364 if (context3d)
365 context3d->flush(); 365 context3d->flush();
366 } 366 }
367 367
368 bool ResourceProvider::shallowFlushIfSupported() 368 bool ResourceProvider::shallowFlushIfSupported()
369 { 369 {
370 DCHECK(m_threadChecker.CalledOnValidThread()); 370 DCHECK(m_threadChecker.CalledOnValidThread());
371 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 371 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
372 if (!context3d || !m_useShallowFlush) 372 if (!context3d || !m_useShallowFlush)
373 return false; 373 return false;
374 374
375 context3d->shallowFlushCHROMIUM(); 375 context3d->shallowFlushCHROMIUM();
376 return true; 376 return true;
377 } 377 }
378 378
379 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) 379 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id)
380 { 380 {
381 DCHECK(m_threadChecker.CalledOnValidThread()); 381 DCHECK(m_threadChecker.CalledOnValidThread());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 , m_useTextureStorageExt(false) 498 , m_useTextureStorageExt(false)
499 , m_useTextureUsageHint(false) 499 , m_useTextureUsageHint(false)
500 , m_useShallowFlush(false) 500 , m_useShallowFlush(false)
501 , m_maxTextureSize(0) 501 , m_maxTextureSize(0)
502 { 502 {
503 } 503 }
504 504
505 bool ResourceProvider::initialize() 505 bool ResourceProvider::initialize()
506 { 506 {
507 DCHECK(m_threadChecker.CalledOnValidThread()); 507 DCHECK(m_threadChecker.CalledOnValidThread());
508 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 508 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
509 if (!context3d) { 509 if (!context3d) {
510 m_maxTextureSize = INT_MAX / 2; 510 m_maxTextureSize = INT_MAX / 2;
511 return true; 511 return true;
512 } 512 }
513 if (!context3d->makeContextCurrent()) 513 if (!context3d->makeContextCurrent())
514 return false; 514 return false;
515 515
516 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO NS)); 516 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO NS));
517 std::vector<std::string> extensions; 517 std::vector<std::string> extensions;
518 base::SplitString(extensionsString, ' ', &extensions); 518 base::SplitString(extensionsString, ' ', &extensions);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 ChildMap::const_iterator it = m_children.find(child); 563 ChildMap::const_iterator it = m_children.find(child);
564 DCHECK(it != m_children.end()); 564 DCHECK(it != m_children.end());
565 return it->second.childToParentMap; 565 return it->second.childToParentMap;
566 } 566 }
567 567
568 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra nsferableResourceList* list) 568 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra nsferableResourceList* list)
569 { 569 {
570 DCHECK(m_threadChecker.CalledOnValidThread()); 570 DCHECK(m_threadChecker.CalledOnValidThread());
571 list->sync_point = 0; 571 list->sync_point = 0;
572 list->resources.clear(); 572 list->resources.clear();
573 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 573 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
574 if (!context3d || !context3d->makeContextCurrent()) { 574 if (!context3d || !context3d->makeContextCurrent()) {
575 // FIXME: Implement this path for software compositing. 575 // FIXME: Implement this path for software compositing.
576 return; 576 return;
577 } 577 }
578 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 578 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
579 TransferableResource resource; 579 TransferableResource resource;
580 if (transferResource(context3d, *it, &resource)) { 580 if (transferResource(context3d, *it, &resource)) {
581 m_resources.find(*it)->second.exported = true; 581 m_resources.find(*it)->second.exported = true;
582 list->resources.push_back(resource); 582 list->resources.push_back(resource);
583 } 583 }
584 } 584 }
585 if (list->resources.size()) 585 if (list->resources.size())
586 list->sync_point = context3d->insertSyncPoint(); 586 list->sync_point = context3d->insertSyncPoint();
587 } 587 }
588 588
589 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso urces, TransferableResourceList* list) 589 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso urces, TransferableResourceList* list)
590 { 590 {
591 DCHECK(m_threadChecker.CalledOnValidThread()); 591 DCHECK(m_threadChecker.CalledOnValidThread());
592 list->sync_point = 0; 592 list->sync_point = 0;
593 list->resources.clear(); 593 list->resources.clear();
594 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 594 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
595 if (!context3d || !context3d->makeContextCurrent()) { 595 if (!context3d || !context3d->makeContextCurrent()) {
596 // FIXME: Implement this path for software compositing. 596 // FIXME: Implement this path for software compositing.
597 return; 597 return;
598 } 598 }
599 Child& childInfo = m_children.find(child)->second; 599 Child& childInfo = m_children.find(child)->second;
600 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 600 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
601 TransferableResource resource; 601 TransferableResource resource;
602 if (!transferResource(context3d, *it, &resource)) 602 if (!transferResource(context3d, *it, &resource))
603 NOTREACHED(); 603 NOTREACHED();
604 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa p.end()); 604 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa p.end());
605 resource.id = childInfo.parentToChildMap[*it]; 605 resource.id = childInfo.parentToChildMap[*it];
606 childInfo.parentToChildMap.erase(*it); 606 childInfo.parentToChildMap.erase(*it);
607 childInfo.childToParentMap.erase(resource.id); 607 childInfo.childToParentMap.erase(resource.id);
608 list->resources.push_back(resource); 608 list->resources.push_back(resource);
609 deleteResource(*it); 609 deleteResource(*it);
610 } 610 }
611 if (list->resources.size()) 611 if (list->resources.size())
612 list->sync_point = context3d->insertSyncPoint(); 612 list->sync_point = context3d->insertSyncPoint();
613 } 613 }
614 614
615 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis t& resources) 615 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis t& resources)
616 { 616 {
617 DCHECK(m_threadChecker.CalledOnValidThread()); 617 DCHECK(m_threadChecker.CalledOnValidThread());
618 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 618 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
619 if (!context3d || !context3d->makeContextCurrent()) { 619 if (!context3d || !context3d->makeContextCurrent()) {
620 // FIXME: Implement this path for software compositing. 620 // FIXME: Implement this path for software compositing.
621 return; 621 return;
622 } 622 }
623 if (resources.sync_point) { 623 if (resources.sync_point) {
624 // NOTE: If the parent is a browser and the child a renderer, the parent 624 // NOTE: If the parent is a browser and the child a renderer, the parent
625 // is not supposed to have its context wait, because that could induce 625 // is not supposed to have its context wait, because that could induce
626 // deadlocks and/or security issues. The caller is responsible for 626 // deadlocks and/or security issues. The caller is responsible for
627 // waiting asynchronously, and resetting sync_point before calling this. 627 // waiting asynchronously, and resetting sync_point before calling this.
628 // However if the parent is a renderer (e.g. browser tag), it may be ok 628 // However if the parent is a renderer (e.g. browser tag), it may be ok
(...skipping 11 matching lines...) Expand all
640 resource.mailbox.setName(it->mailbox.name); 640 resource.mailbox.setName(it->mailbox.name);
641 m_resources[id] = resource; 641 m_resources[id] = resource;
642 childInfo.parentToChildMap[id] = it->id; 642 childInfo.parentToChildMap[id] = it->id;
643 childInfo.childToParentMap[it->id] = id; 643 childInfo.childToParentMap[it->id] = id;
644 } 644 }
645 } 645 }
646 646
647 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 647 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
648 { 648 {
649 DCHECK(m_threadChecker.CalledOnValidThread()); 649 DCHECK(m_threadChecker.CalledOnValidThread());
650 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 650 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
651 if (!context3d || !context3d->makeContextCurrent()) { 651 if (!context3d || !context3d->makeContextCurrent()) {
652 // FIXME: Implement this path for software compositing. 652 // FIXME: Implement this path for software compositing.
653 return; 653 return;
654 } 654 }
655 if (resources.sync_point) 655 if (resources.sync_point)
656 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 656 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
657 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 657 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
658 ResourceMap::iterator mapIterator = m_resources.find(it->id); 658 ResourceMap::iterator mapIterator = m_resources.find(it->id);
659 DCHECK(mapIterator != m_resources.end()); 659 DCHECK(mapIterator != m_resources.end());
660 Resource* resource = &mapIterator->second; 660 Resource* resource = &mapIterator->second;
661 DCHECK(resource->exported); 661 DCHECK(resource->exported);
662 resource->exported = false; 662 resource->exported = false;
663 resource->mailbox.setName(it->mailbox.name); 663 resource->mailbox.setName(it->mailbox.name);
664 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); 664 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
665 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 665 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
666 if (resource->markedForDeletion) 666 if (resource->markedForDeletion)
667 deleteResourceInternal(mapIterator); 667 deleteResourceInternal(mapIterator);
668 } 668 }
669 } 669 }
670 670
671 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) 671 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource)
672 { 672 {
673 DCHECK(m_threadChecker.CalledOnValidThread()); 673 DCHECK(m_threadChecker.CalledOnValidThread());
674 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 674 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
675 ResourceMap::iterator it = m_resources.find(id); 675 ResourceMap::iterator it = m_resources.find(id);
676 CHECK(it != m_resources.end()); 676 CHECK(it != m_resources.end());
677 Resource* source = &it->second; 677 Resource* source = &it->second;
678 DCHECK(!source->lockedForWrite); 678 DCHECK(!source->lockedForWrite);
679 DCHECK(!source->lockForReadCount); 679 DCHECK(!source->lockForReadCount);
680 DCHECK(!source->external); 680 DCHECK(!source->external);
681 if (source->exported) 681 if (source->exported)
682 return false; 682 return false;
683 resource->id = id; 683 resource->id = id;
684 resource->format = source->format; 684 resource->format = source->format;
(...skipping 15 matching lines...) Expand all
700 void ResourceProvider::acquirePixelBuffer(ResourceId id) 700 void ResourceProvider::acquirePixelBuffer(ResourceId id)
701 { 701 {
702 DCHECK(m_threadChecker.CalledOnValidThread()); 702 DCHECK(m_threadChecker.CalledOnValidThread());
703 ResourceMap::iterator it = m_resources.find(id); 703 ResourceMap::iterator it = m_resources.find(id);
704 CHECK(it != m_resources.end()); 704 CHECK(it != m_resources.end());
705 Resource* resource = &it->second; 705 Resource* resource = &it->second;
706 DCHECK(!resource->external); 706 DCHECK(!resource->external);
707 DCHECK(!resource->exported); 707 DCHECK(!resource->exported);
708 708
709 if (resource->glId) { 709 if (resource->glId) {
710 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 710 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
711 DCHECK(context3d); 711 DCHECK(context3d);
712 if (!resource->glPixelBufferId) 712 if (!resource->glPixelBufferId)
713 resource->glPixelBufferId = context3d->createBuffer(); 713 resource->glPixelBufferId = context3d->createBuffer();
714 context3d->bindBuffer( 714 context3d->bindBuffer(
715 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 715 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
716 resource->glPixelBufferId); 716 resource->glPixelBufferId);
717 context3d->bufferData( 717 context3d->bufferData(
718 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 718 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
719 resource->size.width() * resource->size.height() * 4, 719 resource->size.width() * resource->size.height() * 4,
720 NULL, 720 NULL,
(...skipping 14 matching lines...) Expand all
735 { 735 {
736 DCHECK(m_threadChecker.CalledOnValidThread()); 736 DCHECK(m_threadChecker.CalledOnValidThread());
737 ResourceMap::iterator it = m_resources.find(id); 737 ResourceMap::iterator it = m_resources.find(id);
738 CHECK(it != m_resources.end()); 738 CHECK(it != m_resources.end());
739 Resource* resource = &it->second; 739 Resource* resource = &it->second;
740 DCHECK(!resource->external); 740 DCHECK(!resource->external);
741 DCHECK(!resource->exported); 741 DCHECK(!resource->exported);
742 742
743 if (resource->glId) { 743 if (resource->glId) {
744 DCHECK(resource->glPixelBufferId); 744 DCHECK(resource->glPixelBufferId);
745 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 745 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
746 DCHECK(context3d); 746 DCHECK(context3d);
747 context3d->bindBuffer( 747 context3d->bindBuffer(
748 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 748 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
749 resource->glPixelBufferId); 749 resource->glPixelBufferId);
750 context3d->bufferData( 750 context3d->bufferData(
751 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 751 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
752 0, 752 0,
753 NULL, 753 NULL,
754 GL_DYNAMIC_DRAW); 754 GL_DYNAMIC_DRAW);
755 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 755 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
(...skipping 10 matching lines...) Expand all
766 uint8_t* ResourceProvider::mapPixelBuffer(ResourceId id) 766 uint8_t* ResourceProvider::mapPixelBuffer(ResourceId id)
767 { 767 {
768 DCHECK(m_threadChecker.CalledOnValidThread()); 768 DCHECK(m_threadChecker.CalledOnValidThread());
769 ResourceMap::iterator it = m_resources.find(id); 769 ResourceMap::iterator it = m_resources.find(id);
770 CHECK(it != m_resources.end()); 770 CHECK(it != m_resources.end());
771 Resource* resource = &it->second; 771 Resource* resource = &it->second;
772 DCHECK(!resource->external); 772 DCHECK(!resource->external);
773 DCHECK(!resource->exported); 773 DCHECK(!resource->exported);
774 774
775 if (resource->glId) { 775 if (resource->glId) {
776 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 776 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
777 DCHECK(context3d); 777 DCHECK(context3d);
778 DCHECK(resource->glPixelBufferId); 778 DCHECK(resource->glPixelBufferId);
779 context3d->bindBuffer( 779 context3d->bindBuffer(
780 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 780 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
781 resource->glPixelBufferId); 781 resource->glPixelBufferId);
782 uint8_t* image = static_cast<uint8_t*>( 782 uint8_t* image = static_cast<uint8_t*>(
783 context3d->mapBufferCHROMIUM( 783 context3d->mapBufferCHROMIUM(
784 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); 784 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY));
785 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 785 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
786 DCHECK(image); 786 DCHECK(image);
787 return image; 787 return image;
788 } 788 }
789 789
790 if (resource->pixels) 790 if (resource->pixels)
791 return resource->pixelBuffer; 791 return resource->pixelBuffer;
792 792
793 return NULL; 793 return NULL;
794 } 794 }
795 795
796 void ResourceProvider::unmapPixelBuffer(ResourceId id) 796 void ResourceProvider::unmapPixelBuffer(ResourceId id)
797 { 797 {
798 DCHECK(m_threadChecker.CalledOnValidThread()); 798 DCHECK(m_threadChecker.CalledOnValidThread());
799 ResourceMap::iterator it = m_resources.find(id); 799 ResourceMap::iterator it = m_resources.find(id);
800 CHECK(it != m_resources.end()); 800 CHECK(it != m_resources.end());
801 Resource* resource = &it->second; 801 Resource* resource = &it->second;
802 DCHECK(!resource->external); 802 DCHECK(!resource->external);
803 DCHECK(!resource->exported); 803 DCHECK(!resource->exported);
804 804
805 if (resource->glId) { 805 if (resource->glId) {
806 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 806 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
807 DCHECK(context3d); 807 DCHECK(context3d);
808 DCHECK(resource->glPixelBufferId); 808 DCHECK(resource->glPixelBufferId);
809 context3d->bindBuffer( 809 context3d->bindBuffer(
810 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 810 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
811 resource->glPixelBufferId); 811 resource->glPixelBufferId);
812 context3d->unmapBufferCHROMIUM( 812 context3d->unmapBufferCHROMIUM(
813 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); 813 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM);
814 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 814 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
815 } 815 }
816 } 816 }
817 817
818 void ResourceProvider::setPixelsFromBuffer(ResourceId id) 818 void ResourceProvider::setPixelsFromBuffer(ResourceId id)
819 { 819 {
820 DCHECK(m_threadChecker.CalledOnValidThread()); 820 DCHECK(m_threadChecker.CalledOnValidThread());
821 ResourceMap::iterator it = m_resources.find(id); 821 ResourceMap::iterator it = m_resources.find(id);
822 CHECK(it != m_resources.end()); 822 CHECK(it != m_resources.end());
823 Resource* resource = &it->second; 823 Resource* resource = &it->second;
824 DCHECK(!resource->lockedForWrite); 824 DCHECK(!resource->lockedForWrite);
825 DCHECK(!resource->lockForReadCount); 825 DCHECK(!resource->lockForReadCount);
826 DCHECK(!resource->external); 826 DCHECK(!resource->external);
827 DCHECK(!resource->exported); 827 DCHECK(!resource->exported);
828 828
829 if (resource->glId) { 829 if (resource->glId) {
830 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 830 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
831 DCHECK(context3d); 831 DCHECK(context3d);
832 DCHECK(resource->glPixelBufferId); 832 DCHECK(resource->glPixelBufferId);
833 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 833 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
834 context3d->bindBuffer( 834 context3d->bindBuffer(
835 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 835 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
836 resource->glPixelBufferId); 836 resource->glPixelBufferId);
837 context3d->texSubImage2D(GL_TEXTURE_2D, 837 context3d->texSubImage2D(GL_TEXTURE_2D,
838 0, /* level */ 838 0, /* level */
839 0, /* x */ 839 0, /* x */
840 0, /* y */ 840 0, /* y */
(...skipping 16 matching lines...) Expand all
857 857
858 ScopedWriteLockSoftware lock(this, id); 858 ScopedWriteLockSoftware lock(this, id);
859 SkCanvas* dest = lock.skCanvas(); 859 SkCanvas* dest = lock.skCanvas();
860 dest->writePixels(src, 0, 0); 860 dest->writePixels(src, 0, 0);
861 } 861 }
862 } 862 }
863 863
864 void ResourceProvider::bindForSampling(ResourceProvider::ResourceId resourceId, GLenum target, GLenum filter) 864 void ResourceProvider::bindForSampling(ResourceProvider::ResourceId resourceId, GLenum target, GLenum filter)
865 { 865 {
866 DCHECK(m_threadChecker.CalledOnValidThread()); 866 DCHECK(m_threadChecker.CalledOnValidThread());
867 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 867 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
868 ResourceMap::iterator it = m_resources.find(resourceId); 868 ResourceMap::iterator it = m_resources.find(resourceId);
869 DCHECK(it != m_resources.end()); 869 DCHECK(it != m_resources.end());
870 Resource* resource = &it->second; 870 Resource* resource = &it->second;
871 DCHECK(resource->lockForReadCount); 871 DCHECK(resource->lockForReadCount);
872 DCHECK(!resource->lockedForWrite); 872 DCHECK(!resource->lockedForWrite);
873 873
874 GLC(context3d, context3d->bindTexture(target, resource->glId)); 874 GLC(context3d, context3d->bindTexture(target, resource->glId));
875 if (filter != resource->filter) { 875 if (filter != resource->filter) {
876 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, f ilter)); 876 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, f ilter));
877 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, f ilter)); 877 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, f ilter));
878 resource->filter = filter; 878 resource->filter = filter;
879 } 879 }
880 } 880 }
881 881
882 void ResourceProvider::beginSetPixels(ResourceId id) 882 void ResourceProvider::beginSetPixels(ResourceId id)
883 { 883 {
884 DCHECK(m_threadChecker.CalledOnValidThread()); 884 DCHECK(m_threadChecker.CalledOnValidThread());
885 ResourceMap::iterator it = m_resources.find(id); 885 ResourceMap::iterator it = m_resources.find(id);
886 CHECK(it != m_resources.end()); 886 CHECK(it != m_resources.end());
887 Resource* resource = &it->second; 887 Resource* resource = &it->second;
888 DCHECK(!resource->pendingSetPixels); 888 DCHECK(!resource->pendingSetPixels);
889 889
890 lockForWrite(id); 890 lockForWrite(id);
891 891
892 if (resource->glId) { 892 if (resource->glId) {
893 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 893 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
894 DCHECK(context3d); 894 DCHECK(context3d);
895 DCHECK(resource->glPixelBufferId); 895 DCHECK(resource->glPixelBufferId);
896 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 896 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
897 context3d->bindBuffer( 897 context3d->bindBuffer(
898 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 898 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
899 resource->glPixelBufferId); 899 resource->glPixelBufferId);
900 if (!resource->glUploadQueryId) 900 if (!resource->glUploadQueryId)
901 resource->glUploadQueryId = context3d->createQueryEXT(); 901 resource->glUploadQueryId = context3d->createQueryEXT();
902 context3d->beginQueryEXT( 902 context3d->beginQueryEXT(
903 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, 903 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM,
(...skipping 19 matching lines...) Expand all
923 923
924 bool ResourceProvider::didSetPixelsComplete(ResourceId id) { 924 bool ResourceProvider::didSetPixelsComplete(ResourceId id) {
925 DCHECK(m_threadChecker.CalledOnValidThread()); 925 DCHECK(m_threadChecker.CalledOnValidThread());
926 ResourceMap::iterator it = m_resources.find(id); 926 ResourceMap::iterator it = m_resources.find(id);
927 CHECK(it != m_resources.end()); 927 CHECK(it != m_resources.end());
928 Resource* resource = &it->second; 928 Resource* resource = &it->second;
929 DCHECK(resource->lockedForWrite); 929 DCHECK(resource->lockedForWrite);
930 DCHECK(resource->pendingSetPixels); 930 DCHECK(resource->pendingSetPixels);
931 931
932 if (resource->glId) { 932 if (resource->glId) {
933 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); 933 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
934 DCHECK(context3d); 934 DCHECK(context3d);
935 DCHECK(resource->glUploadQueryId); 935 DCHECK(resource->glUploadQueryId);
936 unsigned complete = 1; 936 unsigned complete = 1;
937 context3d->getQueryObjectuivEXT( 937 context3d->getQueryObjectuivEXT(
938 resource->glUploadQueryId, 938 resource->glUploadQueryId,
939 GL_QUERY_RESULT_AVAILABLE_EXT, 939 GL_QUERY_RESULT_AVAILABLE_EXT,
940 &complete); 940 &complete);
941 if (!complete) 941 if (!complete)
942 return false; 942 return false;
943 } 943 }
944 944
945 resource->pendingSetPixels = false; 945 resource->pendingSetPixels = false;
946 unlockForWrite(id); 946 unlockForWrite(id);
947 947
948 return true; 948 return true;
949 } 949 }
950 950
951 } // namespace cc 951 } // namespace cc
OLDNEW
« no previous file with comments | « cc/proxy.h ('k') | cc/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698