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

Side by Side Diff: cc/resource_provider.cc

Issue 11358181: Use nearest neighbor filtering for non-translated quads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Associate resources with min/mag filters and use NEAREST for tile quads when feasible. Created 8 years, 1 month 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/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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 : glId(0) 51 : glId(0)
52 , pixels(0) 52 , pixels(0)
53 , pool(0) 53 , pool(0)
54 , lockForReadCount(0) 54 , lockForReadCount(0)
55 , lockedForWrite(false) 55 , lockedForWrite(false)
56 , external(false) 56 , external(false)
57 , exported(false) 57 , exported(false)
58 , markedForDeletion(false) 58 , markedForDeletion(false)
59 , size() 59 , size()
60 , format(0) 60 , format(0)
61 , minFilter(0)
62 , magFilter(0)
61 , type(static_cast<ResourceType>(0)) 63 , type(static_cast<ResourceType>(0))
62 { 64 {
63 } 65 }
64 66
65 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format) 67 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format, GLenum minFilter, GLenum magFilter)
66 : glId(textureId) 68 : glId(textureId)
67 , pixels(0) 69 , pixels(0)
68 , pool(pool) 70 , pool(pool)
69 , lockForReadCount(0) 71 , lockForReadCount(0)
70 , lockedForWrite(false) 72 , lockedForWrite(false)
71 , external(false) 73 , external(false)
72 , exported(false) 74 , exported(false)
73 , markedForDeletion(false) 75 , markedForDeletion(false)
74 , size(size) 76 , size(size)
75 , format(format) 77 , format(format)
78 , minFilter(minFilter)
79 , magFilter(magFilter)
76 , type(GLTexture) 80 , type(GLTexture)
77 { 81 {
78 } 82 }
79 83
80 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format) 84 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format, GLenum minFilter, GLenum magFilter)
81 : glId(0) 85 : glId(0)
82 , pixels(pixels) 86 , pixels(pixels)
83 , pool(pool) 87 , pool(pool)
84 , lockForReadCount(0) 88 , lockForReadCount(0)
85 , lockedForWrite(false) 89 , lockedForWrite(false)
86 , external(false) 90 , external(false)
87 , exported(false) 91 , exported(false)
88 , markedForDeletion(false) 92 , markedForDeletion(false)
89 , size(size) 93 , size(size)
90 , format(format) 94 , format(format)
95 , minFilter(minFilter)
96 , magFilter(magFilter)
91 , type(Bitmap) 97 , type(Bitmap)
92 { 98 {
93 } 99 }
94 100
95 ResourceProvider::Child::Child() 101 ResourceProvider::Child::Child()
96 { 102 {
97 } 103 }
98 104
99 ResourceProvider::Child::~Child() 105 ResourceProvider::Child::~Child()
100 { 106 {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 167
162 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 168 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
163 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
164 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { 170 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
165 GLenum storageFormat = textureToStorageFormat(format); 171 GLenum storageFormat = textureToStorageFormat(format);
166 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); 172 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
167 } else 173 } else
168 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); 174 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
169 175
170 ResourceId id = m_nextId++; 176 ResourceId id = m_nextId++;
171 Resource resource(textureId, pool, size, format); 177 Resource resource(textureId, pool, size, format, GL_LINEAR, GL_LINEAR);
172 m_resources[id] = resource; 178 m_resources[id] = resource;
173 return id; 179 return id;
174 } 180 }
175 181
176 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) 182 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size)
177 { 183 {
178 DCHECK(m_threadChecker.CalledOnValidThread()); 184 DCHECK(m_threadChecker.CalledOnValidThread());
179 185
180 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 186 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
181 187
182 ResourceId id = m_nextId++; 188 ResourceId id = m_nextId++;
183 Resource resource(pixels, pool, size, GL_RGBA); 189 Resource resource(pixels, pool, size, GL_RGBA, GL_LINEAR, GL_LINEAR);
184 m_resources[id] = resource; 190 m_resources[id] = resource;
185 return id; 191 return id;
186 } 192 }
187 193
188 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) 194 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId)
189 { 195 {
190 DCHECK(m_threadChecker.CalledOnValidThread()); 196 DCHECK(m_threadChecker.CalledOnValidThread());
191 197
192 WebGraphicsContext3D* context3d = m_context->context3D(); 198 WebGraphicsContext3D* context3d = m_context->context3D();
193 DCHECK(context3d); 199 DCHECK(context3d);
194 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 200 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
195 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 201 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
196 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 202 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
197 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 203 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
198 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 204 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
199 205
200 ResourceId id = m_nextId++; 206 ResourceId id = m_nextId++;
201 Resource resource(textureId, 0, gfx::Size(), 0); 207 Resource resource(textureId, 0, gfx::Size(), 0, GL_LINEAR, GL_LINEAR);
202 resource.external = true; 208 resource.external = true;
203 m_resources[id] = resource; 209 m_resources[id] = resource;
204 return id; 210 return id;
205 } 211 }
206 212
207 void ResourceProvider::deleteResource(ResourceId id) 213 void ResourceProvider::deleteResource(ResourceId id)
208 { 214 {
209 DCHECK(m_threadChecker.CalledOnValidThread()); 215 DCHECK(m_threadChecker.CalledOnValidThread());
210 ResourceMap::iterator it = m_resources.find(id); 216 ResourceMap::iterator it = m_resources.find(id);
211 CHECK(it != m_resources.end()); 217 CHECK(it != m_resources.end());
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) 407 , m_textureId(resourceProvider->lockForRead(resourceId)->glId)
402 { 408 {
403 DCHECK(m_textureId); 409 DCHECK(m_textureId);
404 } 410 }
405 411
406 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() 412 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL()
407 { 413 {
408 m_resourceProvider->unlockForRead(m_resourceId); 414 m_resourceProvider->unlockForRead(m_resourceId);
409 } 415 }
410 416
417 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL(ResourceProvider* resourcePro vider, ResourceProvider::ResourceId resourceId, GLenum target, GLenum minFilter, GLenum magFilter)
418 : ScopedReadLockGL(resourceProvider, resourceId)
419 {
420 resourceProvider->bindForSampling(resourceId, target, minFilter, magFilter);
421 }
422
411 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(ResourceProvider* resourc eProvider, ResourceProvider::ResourceId resourceId) 423 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(ResourceProvider* resourc eProvider, ResourceProvider::ResourceId resourceId)
412 : m_resourceProvider(resourceProvider) 424 : m_resourceProvider(resourceProvider)
413 , m_resourceId(resourceId) 425 , m_resourceId(resourceId)
414 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) 426 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId)
415 { 427 {
416 DCHECK(m_textureId); 428 DCHECK(m_textureId);
417 } 429 }
418 430
419 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() 431 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL()
420 { 432 {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // (and is simpler) to wait. 605 // (and is simpler) to wait.
594 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 606 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
595 } 607 }
596 Child& childInfo = m_children.find(child)->second; 608 Child& childInfo = m_children.find(child)->second;
597 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 609 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
598 unsigned textureId; 610 unsigned textureId;
599 GLC(context3d, textureId = context3d->createTexture()); 611 GLC(context3d, textureId = context3d->createTexture());
600 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 612 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
601 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 613 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
602 ResourceId id = m_nextId++; 614 ResourceId id = m_nextId++;
603 Resource resource(textureId, childInfo.pool, it->size, it->format); 615 Resource resource(textureId, childInfo.pool, it->size, it->format, it->m inFilter, it->magFilter);
604 resource.mailbox.setName(it->mailbox.name); 616 resource.mailbox.setName(it->mailbox.name);
605 m_resources[id] = resource; 617 m_resources[id] = resource;
606 childInfo.parentToChildMap[id] = it->id; 618 childInfo.parentToChildMap[id] = it->id;
607 childInfo.childToParentMap[it->id] = id; 619 childInfo.childToParentMap[it->id] = id;
608 } 620 }
609 } 621 }
610 622
611 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 623 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
612 { 624 {
613 DCHECK(m_threadChecker.CalledOnValidThread()); 625 DCHECK(m_threadChecker.CalledOnValidThread());
(...skipping 25 matching lines...) Expand all
639 ResourceMap::iterator it = m_resources.find(id); 651 ResourceMap::iterator it = m_resources.find(id);
640 CHECK(it != m_resources.end()); 652 CHECK(it != m_resources.end());
641 Resource* source = &it->second; 653 Resource* source = &it->second;
642 DCHECK(!source->lockedForWrite); 654 DCHECK(!source->lockedForWrite);
643 DCHECK(!source->lockForReadCount); 655 DCHECK(!source->lockForReadCount);
644 DCHECK(!source->external); 656 DCHECK(!source->external);
645 if (source->exported) 657 if (source->exported)
646 return false; 658 return false;
647 resource->id = id; 659 resource->id = id;
648 resource->format = source->format; 660 resource->format = source->format;
661 resource->minFilter = source->minFilter;
662 resource->magFilter = source->magFilter;
649 resource->size = source->size; 663 resource->size = source->size;
650 664
651 if (source->mailbox.isZero()) { 665 if (source->mailbox.isZero()) {
652 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; 666 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM];
653 GLC(context3d, context3d->genMailboxCHROMIUM(name)); 667 GLC(context3d, context3d->genMailboxCHROMIUM(name));
654 source->mailbox.setName(name); 668 source->mailbox.setName(name);
655 } 669 }
656 670
657 resource->mailbox = source->mailbox; 671 resource->mailbox = source->mailbox;
658 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); 672 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId));
659 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo x.name)); 673 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbo x.name));
660 return true; 674 return true;
661 } 675 }
662 676
677 void ResourceProvider::bindForSampling(ResourceProvider::ResourceId resourceId, GLenum target, GLenum minFilter, GLenum magFilter)
678 {
679 DCHECK(m_threadChecker.CalledOnValidThread());
680 WebGraphicsContext3D* context3d = m_context->context3D();
681 ResourceMap::iterator it = m_resources.find(resourceId);
682 CHECK(it != m_resources.end());
683 Resource* resource = &it->second;
684 DCHECK(resource->lockForReadCount);
685 DCHECK(!resource->lockedForWrite);
686
687 GLC(context3d, context3d->bindTexture(target, resource->glId));
688 if (minFilter != resource->minFilter) {
689 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, m inFilter));
690 resource->minFilter = minFilter;
691 }
692 if (magFilter != resource->magFilter) {
693 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, m agFilter));
694 resource->magFilter = magFilter;
695 }
696 }
697
663 } // namespace cc 698 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698