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