Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 using WebKit::WebGraphicsContext3D; | 27 using WebKit::WebGraphicsContext3D; |
| 28 | 28 |
| 29 namespace cc { | 29 namespace cc { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Measured in seconds. | 33 // Measured in seconds. |
| 34 const double kSoftwareUploadTickRate = 0.000250; | 34 const double kSoftwareUploadTickRate = 0.000250; |
| 35 const double kTextureUploadTickRate = 0.004; | 35 const double kTextureUploadTickRate = 0.004; |
| 36 | 36 |
| 37 GLenum TextureToStorageFormat(GLenum texture_format) { | 37 GLenum TextureToStorageFormat(cc::ResourceProvider::TextureFormat format) { |
| 38 GLenum storage_format = GL_RGBA8_OES; | 38 GLenum storage_format = GL_RGBA8_OES; |
| 39 switch (texture_format) { | 39 switch (format) { |
| 40 case GL_RGBA: | 40 case cc::ResourceProvider::RGBA_8888: |
| 41 break; | 41 break; |
| 42 case GL_BGRA_EXT: | 42 case cc::ResourceProvider::BGRA_8888: |
| 43 storage_format = GL_BGRA8_EXT; | 43 storage_format = GL_BGRA8_EXT; |
| 44 break; | 44 break; |
| 45 default: | 45 default: |
|
reveman
2013/09/12 15:57:40
Remove "default:" after removing INVALID_FORMAT en
kaanb
2013/09/13 00:11:08
Done.
| |
| 46 NOTREACHED(); | 46 NOTREACHED(); |
| 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( |
| 54 return (format == GL_RGBA || format == GL_BGRA_EXT); | 54 cc::ResourceProvider::TextureFormat format) { |
| 55 return (format == cc::ResourceProvider::RGBA_8888 || | |
| 56 format == cc::ResourceProvider::BGRA_8888); | |
|
reveman
2013/09/12 15:57:40
please change this to a switch statement now that
kaanb
2013/09/13 00:11:08
Done.
| |
| 55 } | 57 } |
| 56 | 58 |
| 57 class ScopedSetActiveTexture { | 59 class ScopedSetActiveTexture { |
| 58 public: | 60 public: |
| 59 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) | 61 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) |
| 60 : context3d_(context3d), unit_(unit) { | 62 : context3d_(context3d), unit_(unit) { |
| 61 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); | 63 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); |
| 62 | 64 |
| 63 if (unit_ != GL_TEXTURE0) | 65 if (unit_ != GL_TEXTURE0) |
| 64 GLC(context3d_, context3d_->activeTexture(unit_)); | 66 GLC(context3d_, context3d_->activeTexture(unit_)); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 88 exported_count(0), | 90 exported_count(0), |
| 89 locked_for_write(false), | 91 locked_for_write(false), |
| 90 external(false), | 92 external(false), |
| 91 marked_for_deletion(false), | 93 marked_for_deletion(false), |
| 92 pending_set_pixels(false), | 94 pending_set_pixels(false), |
| 93 set_pixels_completion_forced(false), | 95 set_pixels_completion_forced(false), |
| 94 allocated(false), | 96 allocated(false), |
| 95 enable_read_lock_fences(false), | 97 enable_read_lock_fences(false), |
| 96 read_lock_fence(NULL), | 98 read_lock_fence(NULL), |
| 97 size(), | 99 size(), |
| 98 format(0), | |
| 99 filter(0), | 100 filter(0), |
| 100 image_id(0), | 101 image_id(0), |
| 101 texture_pool(0), | 102 texture_pool(0), |
| 102 wrap_mode(0), | 103 wrap_mode(0), |
| 103 hint(TextureUsageAny), | 104 hint(TextureUsageAny), |
| 104 type(static_cast<ResourceType>(0)) {} | 105 type(static_cast<ResourceType>(0)), |
| 106 texture_format(INVALID_FORMAT) {} | |
| 105 | 107 |
| 106 ResourceProvider::Resource::~Resource() {} | 108 ResourceProvider::Resource::~Resource() {} |
| 107 | 109 |
| 108 ResourceProvider::Resource::Resource( | 110 ResourceProvider::Resource::Resource( |
| 109 unsigned texture_id, | 111 unsigned texture_id, |
| 110 gfx::Size size, | 112 gfx::Size size, |
| 111 GLenum format, | |
| 112 GLenum filter, | 113 GLenum filter, |
| 113 GLenum texture_pool, | 114 GLenum texture_pool, |
| 114 GLint wrap_mode, | 115 GLint wrap_mode, |
| 115 TextureUsageHint hint) | 116 TextureUsageHint hint, |
| 117 TextureFormat texture_format) | |
| 116 : gl_id(texture_id), | 118 : gl_id(texture_id), |
| 117 gl_pixel_buffer_id(0), | 119 gl_pixel_buffer_id(0), |
| 118 gl_upload_query_id(0), | 120 gl_upload_query_id(0), |
| 119 pixels(NULL), | 121 pixels(NULL), |
| 120 pixel_buffer(NULL), | 122 pixel_buffer(NULL), |
| 121 lock_for_read_count(0), | 123 lock_for_read_count(0), |
| 122 imported_count(0), | 124 imported_count(0), |
| 123 exported_count(0), | 125 exported_count(0), |
| 124 locked_for_write(false), | 126 locked_for_write(false), |
| 125 external(false), | 127 external(false), |
| 126 marked_for_deletion(false), | 128 marked_for_deletion(false), |
| 127 pending_set_pixels(false), | 129 pending_set_pixels(false), |
| 128 set_pixels_completion_forced(false), | 130 set_pixels_completion_forced(false), |
| 129 allocated(false), | 131 allocated(false), |
| 130 enable_read_lock_fences(false), | 132 enable_read_lock_fences(false), |
| 131 read_lock_fence(NULL), | 133 read_lock_fence(NULL), |
| 132 size(size), | 134 size(size), |
| 133 format(format), | |
| 134 filter(filter), | 135 filter(filter), |
| 135 image_id(0), | 136 image_id(0), |
| 136 texture_pool(texture_pool), | 137 texture_pool(texture_pool), |
| 137 wrap_mode(wrap_mode), | 138 wrap_mode(wrap_mode), |
| 138 hint(hint), | 139 hint(hint), |
| 139 type(GLTexture) { | 140 type(GLTexture), |
| 141 texture_format(texture_format) { | |
| 140 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 142 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 141 } | 143 } |
| 142 | 144 |
| 143 ResourceProvider::Resource::Resource( | 145 ResourceProvider::Resource::Resource( |
| 144 uint8_t* pixels, | 146 uint8_t* pixels, |
| 145 gfx::Size size, | 147 gfx::Size size, |
| 146 GLenum format, | |
| 147 GLenum filter, | 148 GLenum filter, |
| 148 GLint wrap_mode) | 149 GLint wrap_mode) |
| 149 : gl_id(0), | 150 : gl_id(0), |
| 150 gl_pixel_buffer_id(0), | 151 gl_pixel_buffer_id(0), |
| 151 gl_upload_query_id(0), | 152 gl_upload_query_id(0), |
| 152 pixels(pixels), | 153 pixels(pixels), |
| 153 pixel_buffer(NULL), | 154 pixel_buffer(NULL), |
| 154 lock_for_read_count(0), | 155 lock_for_read_count(0), |
| 155 imported_count(0), | 156 imported_count(0), |
| 156 exported_count(0), | 157 exported_count(0), |
| 157 locked_for_write(false), | 158 locked_for_write(false), |
| 158 external(false), | 159 external(false), |
| 159 marked_for_deletion(false), | 160 marked_for_deletion(false), |
| 160 pending_set_pixels(false), | 161 pending_set_pixels(false), |
| 161 set_pixels_completion_forced(false), | 162 set_pixels_completion_forced(false), |
| 162 allocated(false), | 163 allocated(false), |
| 163 enable_read_lock_fences(false), | 164 enable_read_lock_fences(false), |
| 164 read_lock_fence(NULL), | 165 read_lock_fence(NULL), |
| 165 size(size), | 166 size(size), |
| 166 format(format), | |
| 167 filter(filter), | 167 filter(filter), |
| 168 image_id(0), | 168 image_id(0), |
| 169 texture_pool(0), | 169 texture_pool(0), |
| 170 wrap_mode(wrap_mode), | 170 wrap_mode(wrap_mode), |
| 171 hint(TextureUsageAny), | 171 hint(TextureUsageAny), |
| 172 type(Bitmap) { | 172 type(Bitmap), |
| 173 texture_format(RGBA_8888) { | |
| 173 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 174 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 174 } | 175 } |
| 175 | 176 |
| 176 ResourceProvider::Child::Child() {} | 177 ResourceProvider::Child::Child() {} |
| 177 | 178 |
| 178 ResourceProvider::Child::~Child() {} | 179 ResourceProvider::Child::~Child() {} |
| 179 | 180 |
| 180 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 181 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| 181 OutputSurface* output_surface, | 182 OutputSurface* output_surface, |
| 182 int highp_threshold_min) { | 183 int highp_threshold_min) { |
| 183 scoped_ptr<ResourceProvider> resource_provider( | 184 scoped_ptr<ResourceProvider> resource_provider( |
| 184 new ResourceProvider(output_surface, highp_threshold_min)); | 185 new ResourceProvider(output_surface, |
| 186 highp_threshold_min)); | |
| 185 | 187 |
| 186 bool success = false; | 188 bool success = false; |
| 187 if (resource_provider->Context3d()) { | 189 if (resource_provider->Context3d()) { |
| 188 success = resource_provider->InitializeGL(); | 190 success = resource_provider->InitializeGL(); |
| 189 } else { | 191 } else { |
| 190 resource_provider->InitializeSoftware(); | 192 resource_provider->InitializeSoftware(); |
| 191 success = true; | 193 success = true; |
| 192 } | 194 } |
| 193 | 195 |
| 194 if (!success) | 196 if (!success) |
| 195 return scoped_ptr<ResourceProvider>(); | 197 return scoped_ptr<ResourceProvider>(); |
| 196 | 198 |
| 197 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); | 199 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); |
| 198 return resource_provider.Pass(); | 200 return resource_provider.Pass(); |
| 199 } | 201 } |
| 200 | 202 |
| 201 ResourceProvider::~ResourceProvider() { | 203 ResourceProvider::~ResourceProvider() { |
| 202 while (!resources_.empty()) | 204 while (!resources_.empty()) |
| 203 DeleteResourceInternal(resources_.begin(), ForShutdown); | 205 DeleteResourceInternal(resources_.begin(), ForShutdown); |
| 204 | 206 |
| 205 CleanUpGLIfNeeded(); | 207 CleanUpGLIfNeeded(); |
| 206 } | 208 } |
| 207 | 209 |
| 208 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 210 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
| 209 Resource* resource = GetResource(id); | 211 Resource* resource = GetResource(id); |
| 210 return resource->lock_for_read_count > 0 || resource->exported_count > 0; | 212 return resource->lock_for_read_count > 0 || resource->exported_count > 0; |
| 211 } | 213 } |
| 212 | 214 |
| 213 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 215 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
| 214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 216 gfx::Size size, |
| 217 GLint wrap_mode, | |
| 218 TextureUsageHint hint, | |
| 219 TextureFormat texture_format) { | |
| 215 DCHECK(!size.IsEmpty()); | 220 DCHECK(!size.IsEmpty()); |
| 216 switch (default_resource_type_) { | 221 switch (default_resource_type_) { |
| 217 case GLTexture: | 222 case GLTexture: |
| 218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 223 return CreateGLTexture(size, |
| 219 wrap_mode, hint); | 224 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 225 wrap_mode, | |
| 226 hint, | |
| 227 texture_format); | |
| 220 case Bitmap: | 228 case Bitmap: |
| 221 // The only wrap_mode currently implemented in software mode is | 229 DCHECK(texture_format == RGBA_8888); |
| 222 // GL_CLAMP_TO_EDGE. | |
| 223 // http://crbug.com/284796 | |
| 224 DCHECK(format == GL_RGBA); | |
| 225 return CreateBitmap(size); | 230 return CreateBitmap(size); |
| 226 case InvalidType: | 231 case InvalidType: |
| 227 break; | 232 break; |
| 228 } | 233 } |
| 229 | 234 |
| 230 LOG(FATAL) << "Invalid default resource type."; | 235 LOG(FATAL) << "Invalid default resource type."; |
| 231 return 0; | 236 return 0; |
| 232 } | 237 } |
| 233 | 238 |
| 234 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 239 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
| 235 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 240 gfx::Size size, |
| 241 GLint wrap_mode, | |
| 242 TextureUsageHint hint, | |
| 243 TextureFormat texture_format) { | |
| 236 DCHECK(!size.IsEmpty()); | 244 DCHECK(!size.IsEmpty()); |
| 237 switch (default_resource_type_) { | 245 switch (default_resource_type_) { |
| 238 case GLTexture: | 246 case GLTexture: |
| 239 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, | 247 return CreateGLTexture(size, |
| 240 wrap_mode, hint); | 248 GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
| 249 wrap_mode, | |
| 250 hint, | |
| 251 texture_format); | |
| 241 case Bitmap: | 252 case Bitmap: |
| 242 DCHECK(format == GL_RGBA); | 253 DCHECK(texture_format == RGBA_8888); |
| 243 return CreateBitmap(size); | 254 return CreateBitmap(size); |
| 244 case InvalidType: | 255 case InvalidType: |
| 245 break; | 256 break; |
| 246 } | 257 } |
| 247 | 258 |
| 248 LOG(FATAL) << "Invalid default resource type."; | 259 LOG(FATAL) << "Invalid default resource type."; |
| 249 return 0; | 260 return 0; |
| 250 } | 261 } |
| 251 | 262 |
| 252 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 263 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
| 253 gfx::Size size, | 264 gfx::Size size, |
| 254 GLenum format, | |
| 255 GLenum texture_pool, | 265 GLenum texture_pool, |
| 256 GLint wrap_mode, | 266 GLint wrap_mode, |
| 257 TextureUsageHint hint) { | 267 TextureUsageHint hint, |
| 268 TextureFormat texture_format) { | |
| 258 DCHECK_LE(size.width(), max_texture_size_); | 269 DCHECK_LE(size.width(), max_texture_size_); |
| 259 DCHECK_LE(size.height(), max_texture_size_); | 270 DCHECK_LE(size.height(), max_texture_size_); |
| 260 DCHECK(thread_checker_.CalledOnValidThread()); | 271 DCHECK(thread_checker_.CalledOnValidThread()); |
| 261 | 272 |
| 262 ResourceId id = next_id_++; | 273 ResourceId id = next_id_++; |
| 263 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); | 274 Resource resource( |
| 275 0, size, GL_LINEAR, texture_pool, wrap_mode, hint, texture_format); | |
| 264 resource.allocated = false; | 276 resource.allocated = false; |
| 265 resources_[id] = resource; | 277 resources_[id] = resource; |
| 266 return id; | 278 return id; |
| 267 } | 279 } |
| 268 | 280 |
| 269 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { | 281 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { |
| 270 DCHECK(thread_checker_.CalledOnValidThread()); | 282 DCHECK(thread_checker_.CalledOnValidThread()); |
| 271 | 283 |
| 272 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; | 284 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; |
| 273 | 285 |
| 274 ResourceId id = next_id_++; | 286 ResourceId id = next_id_++; |
| 275 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 287 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 276 resource.allocated = true; | 288 resource.allocated = true; |
| 277 resources_[id] = resource; | 289 resources_[id] = resource; |
| 278 return id; | 290 return id; |
| 279 } | 291 } |
| 280 | 292 |
| 281 ResourceProvider::ResourceId | 293 ResourceProvider::ResourceId |
| 282 ResourceProvider::CreateResourceFromExternalTexture( | 294 ResourceProvider::CreateResourceFromExternalTexture( |
| 283 unsigned texture_target, | 295 unsigned texture_target, |
| 284 unsigned texture_id) { | 296 unsigned texture_id) { |
| 285 DCHECK(thread_checker_.CalledOnValidThread()); | 297 DCHECK(thread_checker_.CalledOnValidThread()); |
| 286 | 298 |
| 287 WebGraphicsContext3D* context3d = Context3d(); | 299 WebGraphicsContext3D* context3d = Context3d(); |
| 288 DCHECK(context3d); | 300 DCHECK(context3d); |
| 289 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); | 301 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); |
| 290 GLC(context3d, context3d->texParameteri( | 302 GLC(context3d, context3d->texParameteri( |
| 291 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 303 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 292 GLC(context3d, context3d->texParameteri( | 304 GLC(context3d, context3d->texParameteri( |
| 293 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 305 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 294 GLC(context3d, context3d->texParameteri( | 306 GLC(context3d, context3d->texParameteri( |
| 295 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 307 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 296 GLC(context3d, context3d->texParameteri( | 308 GLC(context3d, context3d->texParameteri( |
| 297 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 309 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 298 | 310 |
| 299 ResourceId id = next_id_++; | 311 ResourceId id = next_id_++; |
| 300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 312 Resource resource(texture_id, |
| 301 TextureUsageAny); | 313 gfx::Size(), |
| 314 GL_LINEAR, | |
| 315 0, | |
| 316 GL_CLAMP_TO_EDGE, | |
| 317 TextureUsageAny, | |
| 318 INVALID_FORMAT); | |
| 302 resource.external = true; | 319 resource.external = true; |
| 303 resource.allocated = true; | 320 resource.allocated = true; |
| 304 resources_[id] = resource; | 321 resources_[id] = resource; |
| 305 return id; | 322 return id; |
| 306 } | 323 } |
| 307 | 324 |
| 308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 325 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 309 const TextureMailbox& mailbox) { | 326 const TextureMailbox& mailbox) { |
| 310 DCHECK(thread_checker_.CalledOnValidThread()); | 327 DCHECK(thread_checker_.CalledOnValidThread()); |
| 311 // Just store the information. Mailbox will be consumed in LockForRead(). | 328 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 312 ResourceId id = next_id_++; | 329 ResourceId id = next_id_++; |
| 313 DCHECK(mailbox.IsValid()); | 330 DCHECK(mailbox.IsValid()); |
| 314 Resource& resource = resources_[id]; | 331 Resource& resource = resources_[id]; |
| 315 if (mailbox.IsTexture()) { | 332 if (mailbox.IsTexture()) { |
| 316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 333 resource = Resource(0, |
| 317 TextureUsageAny); | 334 gfx::Size(), |
| 335 GL_LINEAR, | |
| 336 0, | |
| 337 GL_CLAMP_TO_EDGE, | |
| 338 TextureUsageAny, | |
| 339 INVALID_FORMAT); | |
| 318 } else { | 340 } else { |
| 319 DCHECK(mailbox.IsSharedMemory()); | 341 DCHECK(mailbox.IsSharedMemory()); |
| 320 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 342 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
| 321 DCHECK(shared_memory->memory()); | 343 DCHECK(shared_memory->memory()); |
| 322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 344 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
| 323 resource = Resource(pixels, mailbox.shared_memory_size(), | 345 resource = Resource( |
| 324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 346 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 325 } | 347 } |
| 326 resource.external = true; | 348 resource.external = true; |
| 327 resource.allocated = true; | 349 resource.allocated = true; |
| 328 resource.mailbox = mailbox; | 350 resource.mailbox = mailbox; |
| 329 return id; | 351 return id; |
| 330 } | 352 } |
| 331 | 353 |
| 332 void ResourceProvider::DeleteResource(ResourceId id) { | 354 void ResourceProvider::DeleteResource(ResourceId id) { |
| 333 DCHECK(thread_checker_.CalledOnValidThread()); | 355 DCHECK(thread_checker_.CalledOnValidThread()); |
| 334 ResourceMap::iterator it = resources_.find(id); | 356 ResourceMap::iterator it = resources_.find(id); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 if (resource->gl_id) { | 447 if (resource->gl_id) { |
| 426 DCHECK(!resource->pending_set_pixels); | 448 DCHECK(!resource->pending_set_pixels); |
| 427 WebGraphicsContext3D* context3d = Context3d(); | 449 WebGraphicsContext3D* context3d = Context3d(); |
| 428 DCHECK(context3d); | 450 DCHECK(context3d); |
| 429 DCHECK(texture_uploader_.get()); | 451 DCHECK(texture_uploader_.get()); |
| 430 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 452 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 431 texture_uploader_->Upload(image, | 453 texture_uploader_->Upload(image, |
| 432 image_rect, | 454 image_rect, |
| 433 source_rect, | 455 source_rect, |
| 434 dest_offset, | 456 dest_offset, |
| 435 resource->format, | 457 resource->texture_format, |
| 436 resource->size); | 458 resource->size); |
| 437 } | 459 } |
| 438 | 460 |
| 439 if (resource->pixels) { | 461 if (resource->pixels) { |
| 440 DCHECK(resource->allocated); | 462 DCHECK(resource->allocated); |
| 441 DCHECK(resource->format == GL_RGBA); | 463 DCHECK(resource->texture_format == RGBA_8888); |
| 442 SkBitmap src_full; | 464 SkBitmap src_full; |
| 443 src_full.setConfig( | 465 src_full.setConfig( |
| 444 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); | 466 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); |
| 445 src_full.setPixels(const_cast<uint8_t*>(image)); | 467 src_full.setPixels(const_cast<uint8_t*>(image)); |
| 446 SkBitmap src_subset; | 468 SkBitmap src_subset; |
| 447 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), | 469 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), |
| 448 source_rect.y(), | 470 source_rect.y(), |
| 449 source_rect.width(), | 471 source_rect.width(), |
| 450 source_rect.height()); | 472 source_rect.height()); |
| 451 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); | 473 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 DCHECK(texture_id_); | 677 DCHECK(texture_id_); |
| 656 } | 678 } |
| 657 | 679 |
| 658 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 680 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
| 659 resource_provider_->UnlockForWrite(resource_id_); | 681 resource_provider_->UnlockForWrite(resource_id_); |
| 660 } | 682 } |
| 661 | 683 |
| 662 void ResourceProvider::PopulateSkBitmapWithResource( | 684 void ResourceProvider::PopulateSkBitmapWithResource( |
| 663 SkBitmap* sk_bitmap, const Resource* resource) { | 685 SkBitmap* sk_bitmap, const Resource* resource) { |
| 664 DCHECK(resource->pixels); | 686 DCHECK(resource->pixels); |
| 665 DCHECK(resource->format == GL_RGBA); | 687 DCHECK(resource->texture_format == RGBA_8888); |
| 666 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 688 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 667 resource->size.width(), | 689 resource->size.width(), |
| 668 resource->size.height()); | 690 resource->size.height()); |
| 669 sk_bitmap->setPixels(resource->pixels); | 691 sk_bitmap->setPixels(resource->pixels); |
| 670 } | 692 } |
| 671 | 693 |
| 672 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 694 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 673 ResourceProvider* resource_provider, | 695 ResourceProvider* resource_provider, |
| 674 ResourceProvider::ResourceId resource_id) | 696 ResourceProvider::ResourceId resource_id) |
| 675 : resource_provider_(resource_provider), | 697 : resource_provider_(resource_provider), |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 701 : output_surface_(output_surface), | 723 : output_surface_(output_surface), |
| 702 lost_output_surface_(false), | 724 lost_output_surface_(false), |
| 703 highp_threshold_min_(highp_threshold_min), | 725 highp_threshold_min_(highp_threshold_min), |
| 704 next_id_(1), | 726 next_id_(1), |
| 705 next_child_(1), | 727 next_child_(1), |
| 706 default_resource_type_(InvalidType), | 728 default_resource_type_(InvalidType), |
| 707 use_texture_storage_ext_(false), | 729 use_texture_storage_ext_(false), |
| 708 use_texture_usage_hint_(false), | 730 use_texture_usage_hint_(false), |
| 709 use_shallow_flush_(false), | 731 use_shallow_flush_(false), |
| 710 max_texture_size_(0), | 732 max_texture_size_(0), |
| 711 best_texture_format_(0) { | 733 best_texture_format_(INVALID_FORMAT) { |
| 712 DCHECK(output_surface_->HasClient()); | 734 DCHECK(output_surface_->HasClient()); |
| 713 } | 735 } |
| 714 | 736 |
| 715 void ResourceProvider::InitializeSoftware() { | 737 void ResourceProvider::InitializeSoftware() { |
| 716 DCHECK(thread_checker_.CalledOnValidThread()); | 738 DCHECK(thread_checker_.CalledOnValidThread()); |
| 717 DCHECK_NE(Bitmap, default_resource_type_); | 739 DCHECK_NE(Bitmap, default_resource_type_); |
| 718 | 740 |
| 719 CleanUpGLIfNeeded(); | 741 CleanUpGLIfNeeded(); |
| 720 | 742 |
| 721 default_resource_type_ = Bitmap; | 743 default_resource_type_ = Bitmap; |
| 722 max_texture_size_ = INT_MAX / 2; | 744 max_texture_size_ = INT_MAX / 2; |
| 723 best_texture_format_ = GL_RGBA; | 745 best_texture_format_ = RGBA_8888; |
| 724 } | 746 } |
| 725 | 747 |
| 726 bool ResourceProvider::InitializeGL() { | 748 bool ResourceProvider::InitializeGL() { |
| 727 DCHECK(thread_checker_.CalledOnValidThread()); | 749 DCHECK(thread_checker_.CalledOnValidThread()); |
| 728 DCHECK(!texture_uploader_); | 750 DCHECK(!texture_uploader_); |
| 729 DCHECK_NE(GLTexture, default_resource_type_); | 751 DCHECK_NE(GLTexture, default_resource_type_); |
| 730 | 752 |
| 731 WebGraphicsContext3D* context3d = Context3d(); | 753 WebGraphicsContext3D* context3d = Context3d(); |
| 732 DCHECK(context3d); | 754 DCHECK(context3d); |
| 733 | 755 |
| 734 if (!context3d->makeContextCurrent()) | 756 if (!context3d->makeContextCurrent()) |
| 735 return false; | 757 return false; |
| 736 | 758 |
| 737 default_resource_type_ = GLTexture; | 759 default_resource_type_ = GLTexture; |
| 738 | 760 |
| 739 const ContextProvider::Capabilities& caps = | 761 const ContextProvider::Capabilities& caps = |
| 740 output_surface_->context_provider()->ContextCapabilities(); | 762 output_surface_->context_provider()->ContextCapabilities(); |
| 741 | 763 |
| 742 bool use_map_sub = caps.map_sub; | 764 bool use_map_sub = caps.map_sub; |
| 743 bool use_bgra = caps.texture_format_bgra8888; | 765 bool use_bgra = caps.texture_format_bgra8888; |
| 744 use_texture_storage_ext_ = caps.texture_storage; | 766 use_texture_storage_ext_ = caps.texture_storage; |
| 745 use_shallow_flush_ = caps.shallow_flush; | 767 use_shallow_flush_ = caps.shallow_flush; |
| 746 use_texture_usage_hint_ = caps.texture_usage; | 768 use_texture_usage_hint_ = caps.texture_usage; |
| 747 | 769 |
| 748 texture_uploader_ = | 770 texture_uploader_ = |
| 749 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); | 771 TextureUploader::Create(context3d, |
| 772 use_map_sub, | |
| 773 use_shallow_flush_); | |
| 750 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, | 774 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, |
| 751 &max_texture_size_)); | 775 &max_texture_size_)); |
| 752 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 776 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
| 753 | 777 |
| 754 return true; | 778 return true; |
| 755 } | 779 } |
| 756 | 780 |
| 757 void ResourceProvider::CleanUpGLIfNeeded() { | 781 void ResourceProvider::CleanUpGLIfNeeded() { |
| 758 WebGraphicsContext3D* context3d = Context3d(); | 782 WebGraphicsContext3D* context3d = Context3d(); |
| 759 if (default_resource_type_ != GLTexture) { | 783 if (default_resource_type_ != GLTexture) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 // However if the parent is a renderer (e.g. browser tag), it may be ok | 928 // However if the parent is a renderer (e.g. browser tag), it may be ok |
| 905 // (and is simpler) to wait. | 929 // (and is simpler) to wait. |
| 906 if (it->sync_point) | 930 if (it->sync_point) |
| 907 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 931 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
| 908 GLC(context3d, texture_id = context3d->createTexture()); | 932 GLC(context3d, texture_id = context3d->createTexture()); |
| 909 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); | 933 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 910 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, | 934 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, |
| 911 it->mailbox.name)); | 935 it->mailbox.name)); |
| 912 ResourceId id = next_id_++; | 936 ResourceId id = next_id_++; |
| 913 Resource resource( | 937 Resource resource( |
| 914 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, | 938 texture_id, |
| 915 TextureUsageAny); | 939 it->size, |
| 940 it->filter, | |
| 941 0, | |
| 942 GL_CLAMP_TO_EDGE, | |
| 943 TextureUsageAny, | |
| 944 static_cast<TextureFormat>(it->format)); | |
|
reveman
2013/09/12 15:57:40
I think we should avoid this static_cast. Can you
kaanb
2013/09/13 00:11:08
Done.
| |
| 916 resource.mailbox.SetName(it->mailbox); | 945 resource.mailbox.SetName(it->mailbox); |
| 917 // Don't allocate a texture for a child. | 946 // Don't allocate a texture for a child. |
| 918 resource.allocated = true; | 947 resource.allocated = true; |
| 919 resource.imported_count = 1; | 948 resource.imported_count = 1; |
| 920 resources_[id] = resource; | 949 resources_[id] = resource; |
| 921 child_info.parent_to_child_map[id] = it->id; | 950 child_info.parent_to_child_map[id] = it->id; |
| 922 child_info.child_to_parent_map[it->id] = id; | 951 child_info.child_to_parent_map[it->id] = id; |
| 923 } | 952 } |
| 924 } | 953 } |
| 925 | 954 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 957 | 986 |
| 958 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, | 987 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
| 959 ResourceId id, | 988 ResourceId id, |
| 960 TransferableResource* resource) { | 989 TransferableResource* resource) { |
| 961 Resource* source = GetResource(id); | 990 Resource* source = GetResource(id); |
| 962 DCHECK(!source->locked_for_write); | 991 DCHECK(!source->locked_for_write); |
| 963 DCHECK(!source->lock_for_read_count); | 992 DCHECK(!source->lock_for_read_count); |
| 964 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); | 993 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); |
| 965 DCHECK(source->allocated); | 994 DCHECK(source->allocated); |
| 966 resource->id = id; | 995 resource->id = id; |
| 967 resource->format = source->format; | |
| 968 resource->filter = source->filter; | 996 resource->filter = source->filter; |
| 969 resource->size = source->size; | 997 resource->size = source->size; |
| 998 // TODO(kaanb): Does TransferableResource::format expect a GLenum? | |
| 999 resource->format = GetGLDataFormat(source->texture_format); | |
|
reveman
2013/09/12 15:57:40
I think this should be "resource->format = source-
kaanb
2013/09/13 00:11:08
Done.
| |
| 970 | 1000 |
| 971 // TODO(skaslev) Implement this path for shared memory resources. | 1001 // TODO(skaslev) Implement this path for shared memory resources. |
| 972 DCHECK(!source->mailbox.IsSharedMemory()); | 1002 DCHECK(!source->mailbox.IsSharedMemory()); |
| 973 | 1003 |
| 974 if (!source->mailbox.IsTexture()) { | 1004 if (!source->mailbox.IsTexture()) { |
| 975 // This is a resource allocated by the compositor, we need to produce it. | 1005 // This is a resource allocated by the compositor, we need to produce it. |
| 976 // Don't set a sync point, the caller will do it. | 1006 // Don't set a sync point, the caller will do it. |
| 977 DCHECK(source->gl_id); | 1007 DCHECK(source->gl_id); |
| 978 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); | 1008 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); |
| 979 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 1009 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 996 DCHECK(!resource->image_id); | 1026 DCHECK(!resource->image_id); |
| 997 | 1027 |
| 998 if (resource->type == GLTexture) { | 1028 if (resource->type == GLTexture) { |
| 999 WebGraphicsContext3D* context3d = Context3d(); | 1029 WebGraphicsContext3D* context3d = Context3d(); |
| 1000 DCHECK(context3d); | 1030 DCHECK(context3d); |
| 1001 if (!resource->gl_pixel_buffer_id) | 1031 if (!resource->gl_pixel_buffer_id) |
| 1002 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 1032 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
| 1003 context3d->bindBuffer( | 1033 context3d->bindBuffer( |
| 1004 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1034 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1005 resource->gl_pixel_buffer_id); | 1035 resource->gl_pixel_buffer_id); |
| 1036 size_t bytes_per_pixel = BytesPerPixel(resource->texture_format); | |
| 1006 context3d->bufferData( | 1037 context3d->bufferData( |
| 1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1038 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1008 4 * resource->size.GetArea(), | 1039 bytes_per_pixel * resource->size.GetArea(), |
| 1009 NULL, | 1040 NULL, |
| 1010 GL_DYNAMIC_DRAW); | 1041 GL_DYNAMIC_DRAW); |
| 1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1042 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1012 } | 1043 } |
| 1013 | 1044 |
| 1014 if (resource->pixels) { | 1045 if (resource->pixels) { |
| 1015 if (resource->pixel_buffer) | 1046 if (resource->pixel_buffer) |
| 1016 return; | 1047 return; |
| 1017 | 1048 |
| 1018 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1049 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1201 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1171 context3d->bindBuffer( | 1202 context3d->bindBuffer( |
| 1172 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1203 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1173 resource->gl_pixel_buffer_id); | 1204 resource->gl_pixel_buffer_id); |
| 1174 if (!resource->gl_upload_query_id) | 1205 if (!resource->gl_upload_query_id) |
| 1175 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1206 resource->gl_upload_query_id = context3d->createQueryEXT(); |
| 1176 context3d->beginQueryEXT( | 1207 context3d->beginQueryEXT( |
| 1177 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1208 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
| 1178 resource->gl_upload_query_id); | 1209 resource->gl_upload_query_id); |
| 1179 if (allocate) { | 1210 if (allocate) { |
| 1180 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1211 context3d->asyncTexImage2DCHROMIUM( |
| 1181 0, /* level */ | 1212 GL_TEXTURE_2D, |
| 1182 resource->format, | 1213 0, /* level */ |
| 1183 resource->size.width(), | 1214 GetGLDataFormat(resource->texture_format), |
|
reveman
2013/09/12 15:57:40
I think we should use a separate GetGLInternalForm
kaanb
2013/09/13 00:11:08
Done.
| |
| 1184 resource->size.height(), | 1215 resource->size.width(), |
| 1185 0, /* border */ | 1216 resource->size.height(), |
| 1186 resource->format, | 1217 0, /* border */ |
| 1187 GL_UNSIGNED_BYTE, | 1218 GetGLDataFormat(resource->texture_format), |
| 1188 NULL); | 1219 GetGLDataType(resource->texture_format), |
| 1220 NULL); | |
| 1189 } else { | 1221 } else { |
| 1190 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1222 context3d->asyncTexSubImage2DCHROMIUM( |
| 1191 0, /* level */ | 1223 GL_TEXTURE_2D, |
| 1192 0, /* x */ | 1224 0, /* level */ |
| 1193 0, /* y */ | 1225 0, /* x */ |
| 1194 resource->size.width(), | 1226 0, /* y */ |
| 1195 resource->size.height(), | 1227 resource->size.width(), |
| 1196 resource->format, | 1228 resource->size.height(), |
| 1197 GL_UNSIGNED_BYTE, | 1229 GetGLDataFormat(resource->texture_format), |
| 1198 NULL); | 1230 GetGLDataType(resource->texture_format), |
| 1231 NULL); | |
| 1199 } | 1232 } |
| 1200 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1233 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
| 1201 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1234 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1202 } | 1235 } |
| 1203 | 1236 |
| 1204 if (resource->pixels) { | 1237 if (resource->pixels) { |
| 1205 DCHECK(!resource->mailbox.IsValid()); | 1238 DCHECK(!resource->mailbox.IsValid()); |
| 1206 DCHECK(resource->pixel_buffer); | 1239 DCHECK(resource->pixel_buffer); |
| 1207 DCHECK(resource->format == GL_RGBA); | 1240 DCHECK(resource->texture_format == RGBA_8888); |
| 1208 | 1241 |
| 1209 std::swap(resource->pixels, resource->pixel_buffer); | 1242 std::swap(resource->pixels, resource->pixel_buffer); |
| 1210 delete[] resource->pixel_buffer; | 1243 delete[] resource->pixel_buffer; |
| 1211 resource->pixel_buffer = NULL; | 1244 resource->pixel_buffer = NULL; |
| 1212 } | 1245 } |
| 1213 | 1246 |
| 1214 resource->pending_set_pixels = true; | 1247 resource->pending_set_pixels = true; |
| 1215 resource->set_pixels_completion_forced = false; | 1248 resource->set_pixels_completion_forced = false; |
| 1216 } | 1249 } |
| 1217 | 1250 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1303 void ResourceProvider::LazyAllocate(Resource* resource) { | 1336 void ResourceProvider::LazyAllocate(Resource* resource) { |
| 1304 DCHECK(resource); | 1337 DCHECK(resource); |
| 1305 LazyCreate(resource); | 1338 LazyCreate(resource); |
| 1306 | 1339 |
| 1307 DCHECK(resource->gl_id || resource->allocated); | 1340 DCHECK(resource->gl_id || resource->allocated); |
| 1308 if (resource->allocated || !resource->gl_id) | 1341 if (resource->allocated || !resource->gl_id) |
| 1309 return; | 1342 return; |
| 1310 resource->allocated = true; | 1343 resource->allocated = true; |
| 1311 WebGraphicsContext3D* context3d = Context3d(); | 1344 WebGraphicsContext3D* context3d = Context3d(); |
| 1312 gfx::Size& size = resource->size; | 1345 gfx::Size& size = resource->size; |
| 1313 GLenum format = resource->format; | 1346 TextureFormat format = resource->texture_format; |
| 1314 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1347 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 1315 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1348 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { |
| 1316 GLenum storage_format = TextureToStorageFormat(format); | 1349 GLenum storage_format = TextureToStorageFormat(format); |
| 1317 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1350 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
| 1318 1, | 1351 1, |
| 1319 storage_format, | 1352 storage_format, |
| 1320 size.width(), | 1353 size.width(), |
| 1321 size.height())); | 1354 size.height())); |
| 1322 } else { | 1355 } else { |
| 1323 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1356 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
| 1324 0, | 1357 0, |
| 1325 format, | 1358 GetGLDataFormat(format), |
|
reveman
2013/09/12 15:57:40
GetGLInternalFormat
kaanb
2013/09/13 00:11:08
Done.
| |
| 1326 size.width(), | 1359 size.width(), |
| 1327 size.height(), | 1360 size.height(), |
| 1328 0, | 1361 0, |
| 1329 format, | 1362 GetGLDataFormat(format), |
| 1330 GL_UNSIGNED_BYTE, | 1363 GetGLDataType(format), |
| 1331 NULL)); | 1364 NULL)); |
| 1332 } | 1365 } |
| 1333 } | 1366 } |
| 1334 | 1367 |
| 1335 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1368 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
| 1336 bool enable) { | 1369 bool enable) { |
| 1337 Resource* resource = GetResource(id); | 1370 Resource* resource = GetResource(id); |
| 1338 resource->enable_read_lock_fences = enable; | 1371 resource->enable_read_lock_fences = enable; |
| 1339 } | 1372 } |
| 1340 | 1373 |
| 1341 void ResourceProvider::AcquireImage(ResourceId id) { | 1374 void ResourceProvider::AcquireImage(ResourceId id) { |
| 1342 Resource* resource = GetResource(id); | 1375 Resource* resource = GetResource(id); |
| 1343 DCHECK(!resource->external); | 1376 DCHECK(!resource->external); |
| 1344 DCHECK_EQ(resource->exported_count, 0); | 1377 DCHECK_EQ(resource->exported_count, 0); |
| 1345 | 1378 |
| 1346 if (resource->type != GLTexture) | 1379 if (resource->type != GLTexture) |
| 1347 return; | 1380 return; |
| 1348 | 1381 |
| 1349 if (resource->image_id) | 1382 if (resource->image_id) |
| 1350 return; | 1383 return; |
| 1351 | 1384 |
| 1352 resource->allocated = true; | 1385 resource->allocated = true; |
| 1353 WebGraphicsContext3D* context3d = Context3d(); | 1386 WebGraphicsContext3D* context3d = Context3d(); |
| 1354 DCHECK(context3d); | 1387 DCHECK(context3d); |
| 1355 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); | 1388 DCHECK_EQ(RGBA_8888, resource->texture_format); |
| 1356 resource->image_id = context3d->createImageCHROMIUM( | 1389 resource->image_id = context3d->createImageCHROMIUM( |
| 1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | 1390 resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
| 1358 DCHECK(resource->image_id); | 1391 DCHECK(resource->image_id); |
| 1359 } | 1392 } |
| 1360 | 1393 |
| 1361 void ResourceProvider::ReleaseImage(ResourceId id) { | 1394 void ResourceProvider::ReleaseImage(ResourceId id) { |
| 1362 Resource* resource = GetResource(id); | 1395 Resource* resource = GetResource(id); |
| 1363 DCHECK(!resource->external); | 1396 DCHECK(!resource->external); |
| 1364 DCHECK_EQ(resource->exported_count, 0); | 1397 DCHECK_EQ(resource->exported_count, 0); |
| 1365 | 1398 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1425 GLint active_unit = 0; | 1458 GLint active_unit = 0; |
| 1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1459 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1427 return active_unit; | 1460 return active_unit; |
| 1428 } | 1461 } |
| 1429 | 1462 |
| 1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1463 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1431 ContextProvider* context_provider = output_surface_->context_provider(); | 1464 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1432 return context_provider ? context_provider->Context3d() : NULL; | 1465 return context_provider ? context_provider->Context3d() : NULL; |
| 1433 } | 1466 } |
| 1434 | 1467 |
| 1468 size_t ResourceProvider::BytesPerPixel(TextureFormat format) { | |
| 1469 size_t components_per_pixel = 0; | |
| 1470 switch (format) { | |
| 1471 case RGBA_8888: | |
| 1472 case RGBA_4444: | |
| 1473 case BGRA_8888: | |
| 1474 components_per_pixel = 4; | |
| 1475 break; | |
| 1476 case LUMINANCE_8: | |
| 1477 components_per_pixel = 1; | |
| 1478 break; | |
| 1479 default: | |
|
reveman
2013/09/12 15:57:40
remove "default:" case after removing INVALID_FORM
kaanb
2013/09/13 00:11:08
Done.
| |
| 1480 NOTREACHED(); | |
| 1481 } | |
| 1482 size_t bits_per_component = 0; | |
| 1483 switch (format) { | |
| 1484 case RGBA_8888: | |
| 1485 case BGRA_8888: | |
| 1486 case LUMINANCE_8: | |
| 1487 bits_per_component = 8; | |
| 1488 break; | |
| 1489 case RGBA_4444: | |
| 1490 bits_per_component = 4; | |
| 1491 break; | |
| 1492 default: | |
|
reveman
2013/09/12 15:57:40
remove "default:" case after removing INVALID_FORM
kaanb
2013/09/13 00:11:08
Done.
| |
| 1493 NOTREACHED(); | |
| 1494 } | |
| 1495 const size_t kBitsPerByte = 8; | |
| 1496 return (components_per_pixel * bits_per_component) / kBitsPerByte; | |
| 1497 } | |
| 1498 | |
| 1499 GLenum ResourceProvider::GetGLDataType(TextureFormat format) { | |
| 1500 GLenum texture_data_type = GL_UNSIGNED_BYTE; | |
| 1501 switch (format) { | |
| 1502 case RGBA_4444: | |
| 1503 texture_data_type = GL_UNSIGNED_SHORT_4_4_4_4; | |
| 1504 break; | |
| 1505 case RGBA_8888: | |
| 1506 case BGRA_8888: | |
| 1507 case LUMINANCE_8: | |
| 1508 texture_data_type = GL_UNSIGNED_BYTE; | |
| 1509 break; | |
| 1510 default: | |
|
reveman
2013/09/12 15:57:40
remove "default:" case after removing INVALID_FORM
kaanb
2013/09/13 00:11:08
Done.
| |
| 1511 NOTREACHED(); | |
| 1512 break; | |
| 1513 } | |
| 1514 return texture_data_type; | |
| 1515 } | |
| 1516 | |
| 1517 GLenum ResourceProvider::GetGLDataFormat(TextureFormat format) { | |
| 1518 GLenum data_format = GL_RGBA; | |
| 1519 switch (format) { | |
| 1520 case RGBA_8888: | |
| 1521 case RGBA_4444: | |
| 1522 data_format = GL_RGBA; | |
| 1523 break; | |
| 1524 case BGRA_8888: | |
| 1525 data_format = GL_BGRA_EXT; | |
| 1526 break; | |
| 1527 case LUMINANCE_8: | |
| 1528 data_format = GL_LUMINANCE; | |
| 1529 break; | |
| 1530 default: | |
|
reveman
2013/09/12 15:57:40
remove "default:" case after removing INVALID_FORM
kaanb
2013/09/13 00:11:08
Done.
| |
| 1531 NOTREACHED(); | |
| 1532 } | |
| 1533 return data_format; | |
| 1534 } | |
| 1535 | |
| 1435 } // namespace cc | 1536 } // namespace cc |
| OLD | NEW |