OLD | NEW |
---|---|
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 30 matching lines...) Expand all Loading... | |
41 } | 41 } |
42 | 42 |
43 return storageFormat; | 43 return storageFormat; |
44 } | 44 } |
45 | 45 |
46 static bool isTextureFormatSupportedForStorage(GLenum format) | 46 static bool isTextureFormatSupportedForStorage(GLenum format) |
47 { | 47 { |
48 return (format == GL_RGBA || format == GL_BGRA_EXT); | 48 return (format == GL_RGBA || format == GL_BGRA_EXT); |
49 } | 49 } |
50 | 50 |
51 static unsigned createTextureId(WebGraphicsContext3D* context3d) | |
52 { | |
53 unsigned textureId = 0; | |
54 GLC(context3d, textureId = context3d->createTexture()); | |
55 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | |
56 | |
57 // Set texture properties. | |
piman
2013/02/11 19:32:49
nit: no need for this comment.
reveman
2013/02/11 20:29:57
Done.
| |
58 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | |
59 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | |
60 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_C LAMP_TO_EDGE)); | |
61 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_C LAMP_TO_EDGE)); | |
62 | |
63 return textureId; | |
64 } | |
65 | |
51 ResourceProvider::Resource::Resource() | 66 ResourceProvider::Resource::Resource() |
52 : glId(0) | 67 : glId(0) |
53 , glPixelBufferId(0) | 68 , glPixelBufferId(0) |
54 , glUploadQueryId(0) | 69 , glUploadQueryId(0) |
55 , pixels(0) | 70 , pixels(0) |
56 , pixelBuffer(0) | 71 , pixelBuffer(0) |
57 , lockForReadCount(0) | 72 , lockForReadCount(0) |
58 , lockedForWrite(false) | 73 , lockedForWrite(false) |
59 , external(false) | 74 , external(false) |
60 , exported(false) | 75 , exported(false) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 LOG(FATAL) << "Invalid default resource type."; | 200 LOG(FATAL) << "Invalid default resource type."; |
186 return 0; | 201 return 0; |
187 } | 202 } |
188 | 203 |
189 ResourceProvider::ResourceId ResourceProvider::createGLTexture(const gfx::Size& size, GLenum format, GLenum texturePool, TextureUsageHint hint) | 204 ResourceProvider::ResourceId ResourceProvider::createGLTexture(const gfx::Size& size, GLenum format, GLenum texturePool, TextureUsageHint hint) |
190 { | 205 { |
191 DCHECK_LE(size.width(), m_maxTextureSize); | 206 DCHECK_LE(size.width(), m_maxTextureSize); |
192 DCHECK_LE(size.height(), m_maxTextureSize); | 207 DCHECK_LE(size.height(), m_maxTextureSize); |
193 | 208 |
194 DCHECK(m_threadChecker.CalledOnValidThread()); | 209 DCHECK(m_threadChecker.CalledOnValidThread()); |
195 unsigned textureId = 0; | |
196 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 210 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
197 DCHECK(context3d); | 211 DCHECK(context3d); |
198 GLC(context3d, textureId = context3d->createTexture()); | |
199 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | |
200 | 212 |
201 // Set texture properties. Allocation is delayed until needed. | 213 // Create and set texture properties. Allocation is delayed until needed. |
202 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); | 214 unsigned textureId = createTextureId(context3d); |
203 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); | |
204 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); | |
205 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); | |
206 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM IUM, texturePool)); | 215 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM IUM, texturePool)); |
207 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 216 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
208 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 217 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
209 | 218 |
210 ResourceId id = m_nextId++; | 219 ResourceId id = m_nextId++; |
211 Resource resource(textureId, size, format, GL_LINEAR); | 220 Resource resource(textureId, size, format, GL_LINEAR); |
212 resource.allocated = false; | 221 resource.allocated = false; |
213 m_resources[id] = resource; | 222 m_resources[id] = resource; |
214 return id; | 223 return id; |
215 } | 224 } |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 if (!complete) | 1053 if (!complete) |
1045 return false; | 1054 return false; |
1046 } | 1055 } |
1047 | 1056 |
1048 resource->pendingSetPixels = false; | 1057 resource->pendingSetPixels = false; |
1049 unlockForWrite(id); | 1058 unlockForWrite(id); |
1050 | 1059 |
1051 return true; | 1060 return true; |
1052 } | 1061 } |
1053 | 1062 |
1063 void ResourceProvider::abortSetPixels(ResourceId id) { | |
1064 DCHECK(m_threadChecker.CalledOnValidThread()); | |
1065 ResourceMap::iterator it = m_resources.find(id); | |
1066 CHECK(it != m_resources.end()); | |
1067 Resource* resource = &it->second; | |
1068 DCHECK(resource->lockedForWrite); | |
1069 DCHECK(resource->pendingSetPixels); | |
1070 | |
1071 if (resource->glId) { | |
1072 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | |
1073 DCHECK(context3d); | |
1074 DCHECK(resource->glUploadQueryId); | |
1075 // CHROMIUM_async_pixel_transfers currently doesn't have a way to | |
1076 // abort an upload. The best we can do is delete the query and | |
1077 // the texture. | |
1078 context3d->deleteQueryEXT(resource->glUploadQueryId); | |
1079 resource->glUploadQueryId = 0; | |
1080 context3d->deleteTexture(resource->glId); | |
1081 resource->glId = createTextureId(context3d); | |
1082 resource->allocated = false; | |
1083 } | |
1084 | |
1085 resource->pendingSetPixels = false; | |
1086 unlockForWrite(id); | |
1087 } | |
1088 | |
1054 void ResourceProvider::allocateForTesting(ResourceId id) { | 1089 void ResourceProvider::allocateForTesting(ResourceId id) { |
1055 ResourceMap::iterator it = m_resources.find(id); | 1090 ResourceMap::iterator it = m_resources.find(id); |
1056 CHECK(it != m_resources.end()); | 1091 CHECK(it != m_resources.end()); |
1057 Resource* resource = &it->second; | 1092 Resource* resource = &it->second; |
1058 lazyAllocate(resource); | 1093 lazyAllocate(resource); |
1059 } | 1094 } |
1060 | 1095 |
1061 void ResourceProvider::lazyAllocate(Resource* resource) { | 1096 void ResourceProvider::lazyAllocate(Resource* resource) { |
1062 DCHECK(resource); | 1097 DCHECK(resource); |
1063 DCHECK(resource->glId || resource->allocated); | 1098 DCHECK(resource->glId || resource->allocated); |
(...skipping 14 matching lines...) Expand all Loading... | |
1078 | 1113 |
1079 void ResourceProvider::enableReadLockFences(ResourceProvider::ResourceId id, boo l enable) { | 1114 void ResourceProvider::enableReadLockFences(ResourceProvider::ResourceId id, boo l enable) { |
1080 DCHECK(m_threadChecker.CalledOnValidThread()); | 1115 DCHECK(m_threadChecker.CalledOnValidThread()); |
1081 ResourceMap::iterator it = m_resources.find(id); | 1116 ResourceMap::iterator it = m_resources.find(id); |
1082 CHECK(it != m_resources.end()); | 1117 CHECK(it != m_resources.end()); |
1083 Resource* resource = &it->second; | 1118 Resource* resource = &it->second; |
1084 resource->enableReadLockFences = enable; | 1119 resource->enableReadLockFences = enable; |
1085 } | 1120 } |
1086 | 1121 |
1087 } // namespace cc | 1122 } // namespace cc |
OLD | NEW |