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

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: Change CHECK() into DCHECK(). 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/resource_provider.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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 , pixels(0) 53 , pixels(0)
54 , pixelBuffer(0) 54 , pixelBuffer(0)
55 , pool(0) 55 , pool(0)
56 , lockForReadCount(0) 56 , lockForReadCount(0)
57 , lockedForWrite(false) 57 , lockedForWrite(false)
58 , external(false) 58 , external(false)
59 , exported(false) 59 , exported(false)
60 , markedForDeletion(false) 60 , markedForDeletion(false)
61 , size() 61 , size()
62 , format(0) 62 , format(0)
63 , filter(0)
63 , type(static_cast<ResourceType>(0)) 64 , type(static_cast<ResourceType>(0))
64 { 65 {
65 } 66 }
66 67
67 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format) 68 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format, GLenum filter)
68 : glId(textureId) 69 : glId(textureId)
69 , glPixelBufferId(0) 70 , glPixelBufferId(0)
70 , pixels(0) 71 , pixels(0)
71 , pixelBuffer(0) 72 , pixelBuffer(0)
72 , pool(pool) 73 , pool(pool)
73 , lockForReadCount(0) 74 , lockForReadCount(0)
74 , lockedForWrite(false) 75 , lockedForWrite(false)
75 , external(false) 76 , external(false)
76 , exported(false) 77 , exported(false)
77 , markedForDeletion(false) 78 , markedForDeletion(false)
78 , size(size) 79 , size(size)
79 , format(format) 80 , format(format)
81 , filter(filter)
80 , type(GLTexture) 82 , type(GLTexture)
81 { 83 {
82 } 84 }
83 85
84 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format) 86 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format, GLenum filter)
85 : glId(0) 87 : glId(0)
86 , glPixelBufferId(0) 88 , glPixelBufferId(0)
87 , pixels(pixels) 89 , pixels(pixels)
88 , pixelBuffer(0) 90 , pixelBuffer(0)
89 , pool(pool) 91 , pool(pool)
90 , lockForReadCount(0) 92 , lockForReadCount(0)
91 , lockedForWrite(false) 93 , lockedForWrite(false)
92 , external(false) 94 , external(false)
93 , exported(false) 95 , exported(false)
94 , markedForDeletion(false) 96 , markedForDeletion(false)
95 , size(size) 97 , size(size)
96 , format(format) 98 , format(format)
99 , filter(filter)
97 , type(Bitmap) 100 , type(Bitmap)
98 { 101 {
99 } 102 }
100 103
101 ResourceProvider::Child::Child() 104 ResourceProvider::Child::Child()
102 { 105 {
103 } 106 }
104 107
105 ResourceProvider::Child::~Child() 108 ResourceProvider::Child::~Child()
106 { 109 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 173
171 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
173 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { 176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
174 GLenum storageFormat = textureToStorageFormat(format); 177 GLenum storageFormat = textureToStorageFormat(format);
175 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); 178 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
176 } else 179 } else
177 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); 180 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
178 181
179 ResourceId id = m_nextId++; 182 ResourceId id = m_nextId++;
180 Resource resource(textureId, pool, size, format); 183 Resource resource(textureId, pool, size, format, GL_LINEAR);
181 m_resources[id] = resource; 184 m_resources[id] = resource;
182 return id; 185 return id;
183 } 186 }
184 187
185 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) 188 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size)
186 { 189 {
187 DCHECK(m_threadChecker.CalledOnValidThread()); 190 DCHECK(m_threadChecker.CalledOnValidThread());
188 191
189 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 192 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
190 193
191 ResourceId id = m_nextId++; 194 ResourceId id = m_nextId++;
192 Resource resource(pixels, pool, size, GL_RGBA); 195 Resource resource(pixels, pool, size, GL_RGBA, GL_LINEAR);
193 m_resources[id] = resource; 196 m_resources[id] = resource;
194 return id; 197 return id;
195 } 198 }
196 199
197 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) 200 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId)
198 { 201 {
199 DCHECK(m_threadChecker.CalledOnValidThread()); 202 DCHECK(m_threadChecker.CalledOnValidThread());
200 203
201 WebGraphicsContext3D* context3d = m_context->context3D(); 204 WebGraphicsContext3D* context3d = m_context->context3D();
202 DCHECK(context3d); 205 DCHECK(context3d);
203 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 206 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
204 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 207 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
205 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 208 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
206 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 209 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
207 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 210 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
208 211
209 ResourceId id = m_nextId++; 212 ResourceId id = m_nextId++;
210 Resource resource(textureId, 0, gfx::Size(), 0); 213 Resource resource(textureId, 0, gfx::Size(), 0, GL_LINEAR);
211 resource.external = true; 214 resource.external = true;
212 m_resources[id] = resource; 215 m_resources[id] = resource;
213 return id; 216 return id;
214 } 217 }
215 218
216 void ResourceProvider::deleteResource(ResourceId id) 219 void ResourceProvider::deleteResource(ResourceId id)
217 { 220 {
218 DCHECK(m_threadChecker.CalledOnValidThread()); 221 DCHECK(m_threadChecker.CalledOnValidThread());
219 ResourceMap::iterator it = m_resources.find(id); 222 ResourceMap::iterator it = m_resources.find(id);
220 CHECK(it != m_resources.end()); 223 CHECK(it != m_resources.end());
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) 420 , m_textureId(resourceProvider->lockForRead(resourceId)->glId)
418 { 421 {
419 DCHECK(m_textureId); 422 DCHECK(m_textureId);
420 } 423 }
421 424
422 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() 425 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL()
423 { 426 {
424 m_resourceProvider->unlockForRead(m_resourceId); 427 m_resourceProvider->unlockForRead(m_resourceId);
425 } 428 }
426 429
430 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL(ResourceProvider* resourcePro vider, ResourceProvider::ResourceId resourceId, GLenum target, GLenum filter)
431 : ScopedReadLockGL(resourceProvider, resourceId)
432 {
433 resourceProvider->bindForSampling(resourceId, target, filter);
434 }
435
427 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(ResourceProvider* resourc eProvider, ResourceProvider::ResourceId resourceId) 436 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(ResourceProvider* resourc eProvider, ResourceProvider::ResourceId resourceId)
428 : m_resourceProvider(resourceProvider) 437 : m_resourceProvider(resourceProvider)
429 , m_resourceId(resourceId) 438 , m_resourceId(resourceId)
430 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) 439 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId)
431 { 440 {
432 DCHECK(m_textureId); 441 DCHECK(m_textureId);
433 } 442 }
434 443
435 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() 444 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL()
436 { 445 {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // (and is simpler) to wait. 618 // (and is simpler) to wait.
610 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 619 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
611 } 620 }
612 Child& childInfo = m_children.find(child)->second; 621 Child& childInfo = m_children.find(child)->second;
613 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 622 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
614 unsigned textureId; 623 unsigned textureId;
615 GLC(context3d, textureId = context3d->createTexture()); 624 GLC(context3d, textureId = context3d->createTexture());
616 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 625 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
617 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 626 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
618 ResourceId id = m_nextId++; 627 ResourceId id = m_nextId++;
619 Resource resource(textureId, childInfo.pool, it->size, it->format); 628 Resource resource(textureId, childInfo.pool, it->size, it->format, it->f ilter);
620 resource.mailbox.setName(it->mailbox.name); 629 resource.mailbox.setName(it->mailbox.name);
621 m_resources[id] = resource; 630 m_resources[id] = resource;
622 childInfo.parentToChildMap[id] = it->id; 631 childInfo.parentToChildMap[id] = it->id;
623 childInfo.childToParentMap[it->id] = id; 632 childInfo.childToParentMap[it->id] = id;
624 } 633 }
625 } 634 }
626 635
627 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 636 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
628 { 637 {
629 DCHECK(m_threadChecker.CalledOnValidThread()); 638 DCHECK(m_threadChecker.CalledOnValidThread());
(...skipping 25 matching lines...) Expand all
655 ResourceMap::iterator it = m_resources.find(id); 664 ResourceMap::iterator it = m_resources.find(id);
656 CHECK(it != m_resources.end()); 665 CHECK(it != m_resources.end());
657 Resource* source = &it->second; 666 Resource* source = &it->second;
658 DCHECK(!source->lockedForWrite); 667 DCHECK(!source->lockedForWrite);
659 DCHECK(!source->lockForReadCount); 668 DCHECK(!source->lockForReadCount);
660 DCHECK(!source->external); 669 DCHECK(!source->external);
661 if (source->exported) 670 if (source->exported)
662 return false; 671 return false;
663 resource->id = id; 672 resource->id = id;
664 resource->format = source->format; 673 resource->format = source->format;
674 resource->filter = source->filter;
665 resource->size = source->size; 675 resource->size = source->size;
666 676
667 if (source->mailbox.isZero()) { 677 if (source->mailbox.isZero()) {
668 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; 678 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM];
669 GLC(context3d, context3d->genMailboxCHROMIUM(name)); 679 GLC(context3d, context3d->genMailboxCHROMIUM(name));
670 source->mailbox.setName(name); 680 source->mailbox.setName(name);
671 } 681 }
672 682
673 resource->mailbox = source->mailbox; 683 resource->mailbox = source->mailbox;
674 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId)); 684 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->glId));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 resource->size.width(), 838 resource->size.width(),
829 resource->size.height()); 839 resource->size.height());
830 src.setPixels(resource->pixelBuffer); 840 src.setPixels(resource->pixelBuffer);
831 841
832 ScopedWriteLockSoftware lock(this, id); 842 ScopedWriteLockSoftware lock(this, id);
833 SkCanvas* dest = lock.skCanvas(); 843 SkCanvas* dest = lock.skCanvas();
834 dest->writePixels(src, 0, 0); 844 dest->writePixels(src, 0, 0);
835 } 845 }
836 } 846 }
837 847
848 void ResourceProvider::bindForSampling(ResourceProvider::ResourceId resourceId, GLenum target, GLenum filter)
849 {
850 DCHECK(m_threadChecker.CalledOnValidThread());
851 WebGraphicsContext3D* context3d = m_context->context3D();
852 ResourceMap::iterator it = m_resources.find(resourceId);
853 DCHECK(it != m_resources.end());
854 Resource* resource = &it->second;
855 DCHECK(resource->lockForReadCount);
856 DCHECK(!resource->lockedForWrite);
857
858 GLC(context3d, context3d->bindTexture(target, resource->glId));
859 if (filter != resource->filter) {
860 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, f ilter));
861 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, f ilter));
862 resource->filter = filter;
863 }
864 }
865
838 } // namespace cc 866 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resource_provider.h ('k') | cc/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698