| 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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 break; | 47 break; |
| 48 } | 48 } |
| 49 | 49 |
| 50 return storage_format; | 50 return storage_format; |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool IsTextureFormatSupportedForStorage(GLenum format) { | 53 bool IsTextureFormatSupportedForStorage(GLenum format) { |
| 54 return (format == GL_RGBA || format == GL_BGRA_EXT); | 54 return (format == GL_RGBA || format == GL_BGRA_EXT); |
| 55 } | 55 } |
| 56 | 56 |
| 57 unsigned CreateTextureId(WebGraphicsContext3D* context3d) { | |
| 58 unsigned texture_id = 0; | |
| 59 GLC(context3d, texture_id = context3d->createTexture()); | |
| 60 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); | |
| 61 GLC(context3d, context3d->texParameteri( | |
| 62 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | |
| 63 GLC(context3d, context3d->texParameteri( | |
| 64 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | |
| 65 GLC(context3d, context3d->texParameteri( | |
| 66 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | |
| 67 GLC(context3d, context3d->texParameteri( | |
| 68 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | |
| 69 return texture_id; | |
| 70 } | |
| 71 | |
| 72 } // namespace | 57 } // namespace |
| 73 | 58 |
| 74 ResourceProvider::Resource::Resource() | 59 ResourceProvider::Resource::Resource() |
| 75 : gl_id(0), | 60 : gl_id(0), |
| 76 gl_pixel_buffer_id(0), | 61 gl_pixel_buffer_id(0), |
| 77 gl_upload_query_id(0), | 62 gl_upload_query_id(0), |
| 78 pixels(NULL), | 63 pixels(NULL), |
| 79 pixel_buffer(NULL), | 64 pixel_buffer(NULL), |
| 80 lock_for_read_count(0), | 65 lock_for_read_count(0), |
| 81 imported_count(0), | 66 imported_count(0), |
| 82 exported_count(0), | 67 exported_count(0), |
| 83 locked_for_write(false), | 68 locked_for_write(false), |
| 84 external(false), | 69 external(false), |
| 85 marked_for_deletion(false), | 70 marked_for_deletion(false), |
| 86 pending_set_pixels(false), | 71 pending_set_pixels(false), |
| 87 set_pixels_completion_forced(false), | 72 set_pixels_completion_forced(false), |
| 88 allocated(false), | 73 allocated(false), |
| 89 enable_read_lock_fences(false), | 74 enable_read_lock_fences(false), |
| 90 read_lock_fence(NULL), | 75 read_lock_fence(NULL), |
| 91 size(), | 76 size(), |
| 92 format(0), | 77 format(0), |
| 93 filter(0), | 78 filter(0), |
| 94 image_id(0), | 79 image_id(0), |
| 95 texture_pool(0), | 80 texture_pool(0), |
| 81 wrap_mode(0), |
| 96 hint(TextureUsageAny), | 82 hint(TextureUsageAny), |
| 97 type(static_cast<ResourceType>(0)) {} | 83 type(static_cast<ResourceType>(0)) {} |
| 98 | 84 |
| 99 ResourceProvider::Resource::~Resource() {} | 85 ResourceProvider::Resource::~Resource() {} |
| 100 | 86 |
| 101 ResourceProvider::Resource::Resource( | 87 ResourceProvider::Resource::Resource( |
| 102 unsigned texture_id, | 88 unsigned texture_id, |
| 103 gfx::Size size, | 89 gfx::Size size, |
| 104 GLenum format, | 90 GLenum format, |
| 105 GLenum filter, | 91 GLenum filter, |
| 106 GLenum texture_pool, | 92 GLenum texture_pool, |
| 93 GLint wrap_mode, |
| 107 TextureUsageHint hint) | 94 TextureUsageHint hint) |
| 108 : gl_id(texture_id), | 95 : gl_id(texture_id), |
| 109 gl_pixel_buffer_id(0), | 96 gl_pixel_buffer_id(0), |
| 110 gl_upload_query_id(0), | 97 gl_upload_query_id(0), |
| 111 pixels(NULL), | 98 pixels(NULL), |
| 112 pixel_buffer(NULL), | 99 pixel_buffer(NULL), |
| 113 lock_for_read_count(0), | 100 lock_for_read_count(0), |
| 114 imported_count(0), | 101 imported_count(0), |
| 115 exported_count(0), | 102 exported_count(0), |
| 116 locked_for_write(false), | 103 locked_for_write(false), |
| 117 external(false), | 104 external(false), |
| 118 marked_for_deletion(false), | 105 marked_for_deletion(false), |
| 119 pending_set_pixels(false), | 106 pending_set_pixels(false), |
| 120 set_pixels_completion_forced(false), | 107 set_pixels_completion_forced(false), |
| 121 allocated(false), | 108 allocated(false), |
| 122 enable_read_lock_fences(false), | 109 enable_read_lock_fences(false), |
| 123 read_lock_fence(NULL), | 110 read_lock_fence(NULL), |
| 124 size(size), | 111 size(size), |
| 125 format(format), | 112 format(format), |
| 126 filter(filter), | 113 filter(filter), |
| 127 image_id(0), | 114 image_id(0), |
| 128 texture_pool(texture_pool), | 115 texture_pool(texture_pool), |
| 116 wrap_mode(wrap_mode), |
| 129 hint(hint), | 117 hint(hint), |
| 130 type(GLTexture) {} | 118 type(GLTexture) { |
| 119 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 120 } |
| 131 | 121 |
| 132 ResourceProvider::Resource::Resource( | 122 ResourceProvider::Resource::Resource( |
| 133 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) | 123 uint8_t* pixels, |
| 124 gfx::Size size, |
| 125 GLenum format, |
| 126 GLenum filter, |
| 127 GLint wrap_mode) |
| 134 : gl_id(0), | 128 : gl_id(0), |
| 135 gl_pixel_buffer_id(0), | 129 gl_pixel_buffer_id(0), |
| 136 gl_upload_query_id(0), | 130 gl_upload_query_id(0), |
| 137 pixels(pixels), | 131 pixels(pixels), |
| 138 pixel_buffer(NULL), | 132 pixel_buffer(NULL), |
| 139 lock_for_read_count(0), | 133 lock_for_read_count(0), |
| 140 imported_count(0), | 134 imported_count(0), |
| 141 exported_count(0), | 135 exported_count(0), |
| 142 locked_for_write(false), | 136 locked_for_write(false), |
| 143 external(false), | 137 external(false), |
| 144 marked_for_deletion(false), | 138 marked_for_deletion(false), |
| 145 pending_set_pixels(false), | 139 pending_set_pixels(false), |
| 146 set_pixels_completion_forced(false), | 140 set_pixels_completion_forced(false), |
| 147 allocated(false), | 141 allocated(false), |
| 148 enable_read_lock_fences(false), | 142 enable_read_lock_fences(false), |
| 149 read_lock_fence(NULL), | 143 read_lock_fence(NULL), |
| 150 size(size), | 144 size(size), |
| 151 format(format), | 145 format(format), |
| 152 filter(filter), | 146 filter(filter), |
| 153 image_id(0), | 147 image_id(0), |
| 154 texture_pool(0), | 148 texture_pool(0), |
| 149 wrap_mode(wrap_mode), |
| 155 hint(TextureUsageAny), | 150 hint(TextureUsageAny), |
| 156 type(Bitmap) {} | 151 type(Bitmap) { |
| 152 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 153 } |
| 157 | 154 |
| 158 ResourceProvider::Child::Child() {} | 155 ResourceProvider::Child::Child() {} |
| 159 | 156 |
| 160 ResourceProvider::Child::~Child() {} | 157 ResourceProvider::Child::~Child() {} |
| 161 | 158 |
| 162 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 159 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| 163 OutputSurface* output_surface, | 160 OutputSurface* output_surface, |
| 164 int highp_threshold_min) { | 161 int highp_threshold_min) { |
| 165 scoped_ptr<ResourceProvider> resource_provider( | 162 scoped_ptr<ResourceProvider> resource_provider( |
| 166 new ResourceProvider(output_surface, highp_threshold_min)); | 163 new ResourceProvider(output_surface, highp_threshold_min)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 186 | 183 |
| 187 CleanUpGLIfNeeded(); | 184 CleanUpGLIfNeeded(); |
| 188 } | 185 } |
| 189 | 186 |
| 190 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 187 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
| 191 Resource* resource = GetResource(id); | 188 Resource* resource = GetResource(id); |
| 192 return resource->lock_for_read_count > 0 || resource->exported_count > 0; | 189 return resource->lock_for_read_count > 0 || resource->exported_count > 0; |
| 193 } | 190 } |
| 194 | 191 |
| 195 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 192 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
| 196 gfx::Size size, GLenum format, TextureUsageHint hint) { | 193 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { |
| 197 DCHECK(!size.IsEmpty()); | 194 DCHECK(!size.IsEmpty()); |
| 198 switch (default_resource_type_) { | 195 switch (default_resource_type_) { |
| 199 case GLTexture: | 196 case GLTexture: |
| 200 return CreateGLTexture( | 197 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 201 size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, hint); | 198 wrap_mode, hint); |
| 202 case Bitmap: | 199 case Bitmap: |
| 200 // The only wrap_mode currently implemented in software mode is |
| 201 // GL_CLAMP_TO_EDGE. |
| 202 // http://crbug.com/284796 |
| 203 DCHECK(format == GL_RGBA); | 203 DCHECK(format == GL_RGBA); |
| 204 return CreateBitmap(size); | 204 return CreateBitmap(size); |
| 205 case InvalidType: | 205 case InvalidType: |
| 206 break; | 206 break; |
| 207 } | 207 } |
| 208 | 208 |
| 209 LOG(FATAL) << "Invalid default resource type."; | 209 LOG(FATAL) << "Invalid default resource type."; |
| 210 return 0; | 210 return 0; |
| 211 } | 211 } |
| 212 | 212 |
| 213 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 213 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
| 214 gfx::Size size, GLenum format, TextureUsageHint hint) { | 214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { |
| 215 DCHECK(!size.IsEmpty()); | 215 DCHECK(!size.IsEmpty()); |
| 216 switch (default_resource_type_) { | 216 switch (default_resource_type_) { |
| 217 case GLTexture: | 217 case GLTexture: |
| 218 return CreateGLTexture( | 218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
| 219 size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, hint); | 219 wrap_mode, hint); |
| 220 case Bitmap: | 220 case Bitmap: |
| 221 DCHECK(format == GL_RGBA); | 221 DCHECK(format == GL_RGBA); |
| 222 return CreateBitmap(size); | 222 return CreateBitmap(size); |
| 223 case InvalidType: | 223 case InvalidType: |
| 224 break; | 224 break; |
| 225 } | 225 } |
| 226 | 226 |
| 227 LOG(FATAL) << "Invalid default resource type."; | 227 LOG(FATAL) << "Invalid default resource type."; |
| 228 return 0; | 228 return 0; |
| 229 } | 229 } |
| 230 | 230 |
| 231 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 231 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
| 232 gfx::Size size, GLenum format, GLenum texture_pool, TextureUsageHint hint) { | 232 gfx::Size size, |
| 233 GLenum format, |
| 234 GLenum texture_pool, |
| 235 GLint wrap_mode, |
| 236 TextureUsageHint hint) { |
| 233 DCHECK_LE(size.width(), max_texture_size_); | 237 DCHECK_LE(size.width(), max_texture_size_); |
| 234 DCHECK_LE(size.height(), max_texture_size_); | 238 DCHECK_LE(size.height(), max_texture_size_); |
| 235 DCHECK(thread_checker_.CalledOnValidThread()); | 239 DCHECK(thread_checker_.CalledOnValidThread()); |
| 236 | 240 |
| 237 ResourceId id = next_id_++; | 241 ResourceId id = next_id_++; |
| 238 Resource resource(0, size, format, GL_LINEAR, texture_pool, hint); | 242 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); |
| 239 resource.allocated = false; | 243 resource.allocated = false; |
| 240 resources_[id] = resource; | 244 resources_[id] = resource; |
| 241 return id; | 245 return id; |
| 242 } | 246 } |
| 243 | 247 |
| 244 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { | 248 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { |
| 245 DCHECK(thread_checker_.CalledOnValidThread()); | 249 DCHECK(thread_checker_.CalledOnValidThread()); |
| 246 | 250 |
| 247 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; | 251 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; |
| 248 | 252 |
| 249 ResourceId id = next_id_++; | 253 ResourceId id = next_id_++; |
| 250 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); | 254 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 251 resource.allocated = true; | 255 resource.allocated = true; |
| 252 resources_[id] = resource; | 256 resources_[id] = resource; |
| 253 return id; | 257 return id; |
| 254 } | 258 } |
| 255 | 259 |
| 256 ResourceProvider::ResourceId | 260 ResourceProvider::ResourceId |
| 257 ResourceProvider::CreateResourceFromExternalTexture( | 261 ResourceProvider::CreateResourceFromExternalTexture( |
| 258 unsigned texture_target, | 262 unsigned texture_target, |
| 259 unsigned texture_id) { | 263 unsigned texture_id) { |
| 260 DCHECK(thread_checker_.CalledOnValidThread()); | 264 DCHECK(thread_checker_.CalledOnValidThread()); |
| 261 | 265 |
| 262 WebGraphicsContext3D* context3d = Context3d(); | 266 WebGraphicsContext3D* context3d = Context3d(); |
| 263 DCHECK(context3d); | 267 DCHECK(context3d); |
| 264 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); | 268 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); |
| 265 GLC(context3d, context3d->texParameteri( | 269 GLC(context3d, context3d->texParameteri( |
| 266 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 270 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 267 GLC(context3d, context3d->texParameteri( | 271 GLC(context3d, context3d->texParameteri( |
| 268 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 272 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 269 GLC(context3d, context3d->texParameteri( | 273 GLC(context3d, context3d->texParameteri( |
| 270 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 274 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 271 GLC(context3d, context3d->texParameteri( | 275 GLC(context3d, context3d->texParameteri( |
| 272 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 276 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 273 | 277 |
| 274 ResourceId id = next_id_++; | 278 ResourceId id = next_id_++; |
| 275 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, TextureUsageAny); | 279 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, |
| 280 TextureUsageAny); |
| 276 resource.external = true; | 281 resource.external = true; |
| 277 resource.allocated = true; | 282 resource.allocated = true; |
| 278 resources_[id] = resource; | 283 resources_[id] = resource; |
| 279 return id; | 284 return id; |
| 280 } | 285 } |
| 281 | 286 |
| 282 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 287 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 283 const TextureMailbox& mailbox) { | 288 const TextureMailbox& mailbox) { |
| 284 DCHECK(thread_checker_.CalledOnValidThread()); | 289 DCHECK(thread_checker_.CalledOnValidThread()); |
| 285 // Just store the information. Mailbox will be consumed in LockForRead(). | 290 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 286 ResourceId id = next_id_++; | 291 ResourceId id = next_id_++; |
| 287 DCHECK(mailbox.IsValid()); | 292 DCHECK(mailbox.IsValid()); |
| 288 Resource& resource = resources_[id]; | 293 Resource& resource = resources_[id]; |
| 289 if (mailbox.IsTexture()) { | 294 if (mailbox.IsTexture()) { |
| 290 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, TextureUsageAny); | 295 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, |
| 296 TextureUsageAny); |
| 291 } else { | 297 } else { |
| 292 DCHECK(mailbox.IsSharedMemory()); | 298 DCHECK(mailbox.IsSharedMemory()); |
| 293 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 299 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
| 294 DCHECK(shared_memory->memory()); | 300 DCHECK(shared_memory->memory()); |
| 295 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 301 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
| 296 resource = Resource(pixels, mailbox.shared_memory_size(), | 302 resource = Resource(pixels, mailbox.shared_memory_size(), |
| 297 GL_RGBA, GL_LINEAR); | 303 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 298 } | 304 } |
| 299 resource.external = true; | 305 resource.external = true; |
| 300 resource.allocated = true; | 306 resource.allocated = true; |
| 301 resource.mailbox = mailbox; | 307 resource.mailbox = mailbox; |
| 302 return id; | 308 return id; |
| 303 } | 309 } |
| 304 | 310 |
| 305 void ResourceProvider::DeleteResource(ResourceId id) { | 311 void ResourceProvider::DeleteResource(ResourceId id) { |
| 306 DCHECK(thread_checker_.CalledOnValidThread()); | 312 DCHECK(thread_checker_.CalledOnValidThread()); |
| 307 ResourceMap::iterator it = resources_.find(id); | 313 ResourceMap::iterator it = resources_.find(id); |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 // However if the parent is a renderer (e.g. browser tag), it may be ok | 883 // However if the parent is a renderer (e.g. browser tag), it may be ok |
| 878 // (and is simpler) to wait. | 884 // (and is simpler) to wait. |
| 879 if (it->sync_point) | 885 if (it->sync_point) |
| 880 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 886 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
| 881 GLC(context3d, texture_id = context3d->createTexture()); | 887 GLC(context3d, texture_id = context3d->createTexture()); |
| 882 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); | 888 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 883 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, | 889 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, |
| 884 it->mailbox.name)); | 890 it->mailbox.name)); |
| 885 ResourceId id = next_id_++; | 891 ResourceId id = next_id_++; |
| 886 Resource resource( | 892 Resource resource( |
| 887 texture_id, it->size, it->format, it->filter, 0, TextureUsageAny); | 893 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, |
| 894 TextureUsageAny); |
| 888 resource.mailbox.SetName(it->mailbox); | 895 resource.mailbox.SetName(it->mailbox); |
| 889 // Don't allocate a texture for a child. | 896 // Don't allocate a texture for a child. |
| 890 resource.allocated = true; | 897 resource.allocated = true; |
| 891 resource.imported_count = 1; | 898 resource.imported_count = 1; |
| 892 resources_[id] = resource; | 899 resources_[id] = resource; |
| 893 child_info.parent_to_child_map[id] = it->id; | 900 child_info.parent_to_child_map[id] = it->id; |
| 894 child_info.child_to_parent_map[it->id] = id; | 901 child_info.child_to_parent_map[it->id] = id; |
| 895 } | 902 } |
| 896 } | 903 } |
| 897 | 904 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 resource->pending_set_pixels = false; | 1242 resource->pending_set_pixels = false; |
| 1236 UnlockForWrite(id); | 1243 UnlockForWrite(id); |
| 1237 | 1244 |
| 1238 return true; | 1245 return true; |
| 1239 } | 1246 } |
| 1240 | 1247 |
| 1241 void ResourceProvider::CreateForTesting(ResourceId id) { | 1248 void ResourceProvider::CreateForTesting(ResourceId id) { |
| 1242 LazyCreate(GetResource(id)); | 1249 LazyCreate(GetResource(id)); |
| 1243 } | 1250 } |
| 1244 | 1251 |
| 1252 GLint ResourceProvider::WrapModeForTesting(ResourceId id) { |
| 1253 Resource* resource = GetResource(id); |
| 1254 return resource->wrap_mode; |
| 1255 } |
| 1256 |
| 1245 void ResourceProvider::LazyCreate(Resource* resource) { | 1257 void ResourceProvider::LazyCreate(Resource* resource) { |
| 1246 if (resource->type != GLTexture || resource->gl_id != 0) | 1258 if (resource->type != GLTexture || resource->gl_id != 0) |
| 1247 return; | 1259 return; |
| 1248 | 1260 |
| 1249 // Early out for resources that don't require texture creation. | 1261 // Early out for resources that don't require texture creation. |
| 1250 if (resource->texture_pool == 0) | 1262 if (resource->texture_pool == 0) |
| 1251 return; | 1263 return; |
| 1252 | 1264 |
| 1253 WebGraphicsContext3D* context3d = Context3d(); | 1265 WebGraphicsContext3D* context3d = Context3d(); |
| 1254 DCHECK(context3d); | 1266 DCHECK(context3d); |
| 1267 |
| 1255 // Create and set texture properties. Allocation is delayed until needed. | 1268 // Create and set texture properties. Allocation is delayed until needed. |
| 1256 resource->gl_id = CreateTextureId(context3d); | 1269 GLC(context3d, resource->gl_id = context3d->createTexture()); |
| 1270 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 1271 GLC(context3d, context3d->texParameteri( |
| 1272 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 1273 GLC(context3d, context3d->texParameteri( |
| 1274 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 1275 GLC(context3d, context3d->texParameteri( |
| 1276 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, resource->wrap_mode)); |
| 1277 GLC(context3d, context3d->texParameteri( |
| 1278 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, resource->wrap_mode)); |
| 1257 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, | 1279 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, |
| 1258 GL_TEXTURE_POOL_CHROMIUM, | 1280 GL_TEXTURE_POOL_CHROMIUM, |
| 1259 resource->texture_pool)); | 1281 resource->texture_pool)); |
| 1260 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { | 1282 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { |
| 1261 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, | 1283 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, |
| 1262 GL_TEXTURE_USAGE_ANGLE, | 1284 GL_TEXTURE_USAGE_ANGLE, |
| 1263 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 1285 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
| 1264 } | 1286 } |
| 1265 } | 1287 } |
| 1266 | 1288 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1416 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1395 return active_unit; | 1417 return active_unit; |
| 1396 } | 1418 } |
| 1397 | 1419 |
| 1398 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1420 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1399 ContextProvider* context_provider = output_surface_->context_provider(); | 1421 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1400 return context_provider ? context_provider->Context3d() : NULL; | 1422 return context_provider ? context_provider->Context3d() : NULL; |
| 1401 } | 1423 } |
| 1402 | 1424 |
| 1403 } // namespace cc | 1425 } // namespace cc |
| OLD | NEW |