| 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(ResourceFormat 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 RGBA_8888: |
| 41 case RGBA_4444: |
| 42 case LUMINANCE_8: |
| 41 break; | 43 break; |
| 42 case GL_BGRA_EXT: | 44 case BGRA_8888: |
| 43 storage_format = GL_BGRA8_EXT; | 45 storage_format = GL_BGRA8_EXT; |
| 44 break; | 46 break; |
| 45 default: | |
| 46 NOTREACHED(); | |
| 47 break; | |
| 48 } | 47 } |
| 49 | 48 |
| 50 return storage_format; | 49 return storage_format; |
| 51 } | 50 } |
| 52 | 51 |
| 53 bool IsTextureFormatSupportedForStorage(GLenum format) { | 52 bool IsFormatSupportedForStorage(ResourceFormat format) { |
| 54 return (format == GL_RGBA || format == GL_BGRA_EXT); | 53 switch (format) { |
| 54 case RGBA_8888: |
| 55 case BGRA_8888: |
| 56 return true; |
| 57 case RGBA_4444: |
| 58 case LUMINANCE_8: |
| 59 return false; |
| 60 } |
| 61 return false; |
| 55 } | 62 } |
| 56 | 63 |
| 57 class ScopedSetActiveTexture { | 64 class ScopedSetActiveTexture { |
| 58 public: | 65 public: |
| 59 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) | 66 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) |
| 60 : context3d_(context3d), unit_(unit) { | 67 : context3d_(context3d), unit_(unit) { |
| 61 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); | 68 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); |
| 62 | 69 |
| 63 if (unit_ != GL_TEXTURE0) | 70 if (unit_ != GL_TEXTURE0) |
| 64 GLC(context3d_, context3d_->activeTexture(unit_)); | 71 GLC(context3d_, context3d_->activeTexture(unit_)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 exported_count(0), | 95 exported_count(0), |
| 89 locked_for_write(false), | 96 locked_for_write(false), |
| 90 external(false), | 97 external(false), |
| 91 marked_for_deletion(false), | 98 marked_for_deletion(false), |
| 92 pending_set_pixels(false), | 99 pending_set_pixels(false), |
| 93 set_pixels_completion_forced(false), | 100 set_pixels_completion_forced(false), |
| 94 allocated(false), | 101 allocated(false), |
| 95 enable_read_lock_fences(false), | 102 enable_read_lock_fences(false), |
| 96 read_lock_fence(NULL), | 103 read_lock_fence(NULL), |
| 97 size(), | 104 size(), |
| 98 format(0), | |
| 99 filter(0), | 105 filter(0), |
| 100 image_id(0), | 106 image_id(0), |
| 101 texture_pool(0), | 107 texture_pool(0), |
| 102 wrap_mode(0), | 108 wrap_mode(0), |
| 103 hint(TextureUsageAny), | 109 hint(TextureUsageAny), |
| 104 type(static_cast<ResourceType>(0)) {} | 110 type(static_cast<ResourceType>(0)), |
| 111 format(RGBA_8888) {} |
| 105 | 112 |
| 106 ResourceProvider::Resource::~Resource() {} | 113 ResourceProvider::Resource::~Resource() {} |
| 107 | 114 |
| 108 ResourceProvider::Resource::Resource( | 115 ResourceProvider::Resource::Resource( |
| 109 unsigned texture_id, | 116 unsigned texture_id, |
| 110 gfx::Size size, | 117 gfx::Size size, |
| 111 GLenum format, | |
| 112 GLenum filter, | 118 GLenum filter, |
| 113 GLenum texture_pool, | 119 GLenum texture_pool, |
| 114 GLint wrap_mode, | 120 GLint wrap_mode, |
| 115 TextureUsageHint hint) | 121 TextureUsageHint hint, |
| 122 ResourceFormat format) |
| 116 : gl_id(texture_id), | 123 : gl_id(texture_id), |
| 117 gl_pixel_buffer_id(0), | 124 gl_pixel_buffer_id(0), |
| 118 gl_upload_query_id(0), | 125 gl_upload_query_id(0), |
| 119 pixels(NULL), | 126 pixels(NULL), |
| 120 pixel_buffer(NULL), | 127 pixel_buffer(NULL), |
| 121 lock_for_read_count(0), | 128 lock_for_read_count(0), |
| 122 imported_count(0), | 129 imported_count(0), |
| 123 exported_count(0), | 130 exported_count(0), |
| 124 locked_for_write(false), | 131 locked_for_write(false), |
| 125 external(false), | 132 external(false), |
| 126 marked_for_deletion(false), | 133 marked_for_deletion(false), |
| 127 pending_set_pixels(false), | 134 pending_set_pixels(false), |
| 128 set_pixels_completion_forced(false), | 135 set_pixels_completion_forced(false), |
| 129 allocated(false), | 136 allocated(false), |
| 130 enable_read_lock_fences(false), | 137 enable_read_lock_fences(false), |
| 131 read_lock_fence(NULL), | 138 read_lock_fence(NULL), |
| 132 size(size), | 139 size(size), |
| 133 format(format), | |
| 134 filter(filter), | 140 filter(filter), |
| 135 image_id(0), | 141 image_id(0), |
| 136 texture_pool(texture_pool), | 142 texture_pool(texture_pool), |
| 137 wrap_mode(wrap_mode), | 143 wrap_mode(wrap_mode), |
| 138 hint(hint), | 144 hint(hint), |
| 139 type(GLTexture) { | 145 type(GLTexture), |
| 146 format(format) { |
| 140 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 147 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 141 } | 148 } |
| 142 | 149 |
| 143 ResourceProvider::Resource::Resource( | 150 ResourceProvider::Resource::Resource( |
| 144 uint8_t* pixels, | 151 uint8_t* pixels, |
| 145 gfx::Size size, | 152 gfx::Size size, |
| 146 GLenum format, | |
| 147 GLenum filter, | 153 GLenum filter, |
| 148 GLint wrap_mode) | 154 GLint wrap_mode) |
| 149 : gl_id(0), | 155 : gl_id(0), |
| 150 gl_pixel_buffer_id(0), | 156 gl_pixel_buffer_id(0), |
| 151 gl_upload_query_id(0), | 157 gl_upload_query_id(0), |
| 152 pixels(pixels), | 158 pixels(pixels), |
| 153 pixel_buffer(NULL), | 159 pixel_buffer(NULL), |
| 154 lock_for_read_count(0), | 160 lock_for_read_count(0), |
| 155 imported_count(0), | 161 imported_count(0), |
| 156 exported_count(0), | 162 exported_count(0), |
| 157 locked_for_write(false), | 163 locked_for_write(false), |
| 158 external(false), | 164 external(false), |
| 159 marked_for_deletion(false), | 165 marked_for_deletion(false), |
| 160 pending_set_pixels(false), | 166 pending_set_pixels(false), |
| 161 set_pixels_completion_forced(false), | 167 set_pixels_completion_forced(false), |
| 162 allocated(false), | 168 allocated(false), |
| 163 enable_read_lock_fences(false), | 169 enable_read_lock_fences(false), |
| 164 read_lock_fence(NULL), | 170 read_lock_fence(NULL), |
| 165 size(size), | 171 size(size), |
| 166 format(format), | |
| 167 filter(filter), | 172 filter(filter), |
| 168 image_id(0), | 173 image_id(0), |
| 169 texture_pool(0), | 174 texture_pool(0), |
| 170 wrap_mode(wrap_mode), | 175 wrap_mode(wrap_mode), |
| 171 hint(TextureUsageAny), | 176 hint(TextureUsageAny), |
| 172 type(Bitmap) { | 177 type(Bitmap), |
| 178 format(RGBA_8888) { |
| 173 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 179 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 174 } | 180 } |
| 175 | 181 |
| 176 ResourceProvider::Child::Child() {} | 182 ResourceProvider::Child::Child() {} |
| 177 | 183 |
| 178 ResourceProvider::Child::~Child() {} | 184 ResourceProvider::Child::~Child() {} |
| 179 | 185 |
| 180 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 186 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| 181 OutputSurface* output_surface, | 187 OutputSurface* output_surface, |
| 182 int highp_threshold_min) { | 188 int highp_threshold_min, |
| 189 bool use_rgba_4444_tiles, |
| 190 bool force_rgba_tiles) { |
| 183 scoped_ptr<ResourceProvider> resource_provider( | 191 scoped_ptr<ResourceProvider> resource_provider( |
| 184 new ResourceProvider(output_surface, highp_threshold_min)); | 192 new ResourceProvider(output_surface, |
| 193 highp_threshold_min, |
| 194 use_rgba_4444_tiles, |
| 195 force_rgba_tiles)); |
| 185 | 196 |
| 186 bool success = false; | 197 bool success = false; |
| 187 if (resource_provider->Context3d()) { | 198 if (resource_provider->Context3d()) { |
| 188 success = resource_provider->InitializeGL(); | 199 success = resource_provider->InitializeGL(); |
| 189 } else { | 200 } else { |
| 190 resource_provider->InitializeSoftware(); | 201 resource_provider->InitializeSoftware(); |
| 191 success = true; | 202 success = true; |
| 192 } | 203 } |
| 193 | 204 |
| 194 if (!success) | 205 if (!success) |
| 195 return scoped_ptr<ResourceProvider>(); | 206 return scoped_ptr<ResourceProvider>(); |
| 196 | 207 |
| 197 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); | 208 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); |
| 198 return resource_provider.Pass(); | 209 return resource_provider.Pass(); |
| 199 } | 210 } |
| 200 | 211 |
| 201 ResourceProvider::~ResourceProvider() { | 212 ResourceProvider::~ResourceProvider() { |
| 202 while (!resources_.empty()) | 213 while (!resources_.empty()) |
| 203 DeleteResourceInternal(resources_.begin(), ForShutdown); | 214 DeleteResourceInternal(resources_.begin(), ForShutdown); |
| 204 | 215 |
| 205 CleanUpGLIfNeeded(); | 216 CleanUpGLIfNeeded(); |
| 206 } | 217 } |
| 207 | 218 |
| 208 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 219 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
| 209 Resource* resource = GetResource(id); | 220 Resource* resource = GetResource(id); |
| 210 return resource->lock_for_read_count > 0 || resource->exported_count > 0; | 221 return resource->lock_for_read_count > 0 || resource->exported_count > 0; |
| 211 } | 222 } |
| 212 | 223 |
| 213 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 224 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
| 214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 225 gfx::Size size, |
| 226 GLint wrap_mode, |
| 227 TextureUsageHint hint, |
| 228 ResourceFormat format) { |
| 215 DCHECK(!size.IsEmpty()); | 229 DCHECK(!size.IsEmpty()); |
| 216 switch (default_resource_type_) { | 230 switch (default_resource_type_) { |
| 217 case GLTexture: | 231 case GLTexture: |
| 218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 232 return CreateGLTexture(size, |
| 219 wrap_mode, hint); | 233 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 234 wrap_mode, |
| 235 hint, |
| 236 format); |
| 220 case Bitmap: | 237 case Bitmap: |
| 221 // The only wrap_mode currently implemented in software mode is | 238 DCHECK_EQ(RGBA_8888, format); |
| 222 // GL_CLAMP_TO_EDGE. | |
| 223 // http://crbug.com/284796 | |
| 224 DCHECK(format == GL_RGBA); | |
| 225 return CreateBitmap(size); | 239 return CreateBitmap(size); |
| 226 case InvalidType: | 240 case InvalidType: |
| 227 break; | 241 break; |
| 228 } | 242 } |
| 229 | 243 |
| 230 LOG(FATAL) << "Invalid default resource type."; | 244 LOG(FATAL) << "Invalid default resource type."; |
| 231 return 0; | 245 return 0; |
| 232 } | 246 } |
| 233 | 247 |
| 234 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 248 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
| 235 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 249 gfx::Size size, |
| 250 GLint wrap_mode, |
| 251 TextureUsageHint hint, |
| 252 ResourceFormat format) { |
| 236 DCHECK(!size.IsEmpty()); | 253 DCHECK(!size.IsEmpty()); |
| 237 switch (default_resource_type_) { | 254 switch (default_resource_type_) { |
| 238 case GLTexture: | 255 case GLTexture: |
| 239 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, | 256 return CreateGLTexture(size, |
| 240 wrap_mode, hint); | 257 GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
| 258 wrap_mode, |
| 259 hint, |
| 260 format); |
| 241 case Bitmap: | 261 case Bitmap: |
| 242 DCHECK(format == GL_RGBA); | 262 DCHECK_EQ(RGBA_8888, format); |
| 243 return CreateBitmap(size); | 263 return CreateBitmap(size); |
| 244 case InvalidType: | 264 case InvalidType: |
| 245 break; | 265 break; |
| 246 } | 266 } |
| 247 | 267 |
| 248 LOG(FATAL) << "Invalid default resource type."; | 268 LOG(FATAL) << "Invalid default resource type."; |
| 249 return 0; | 269 return 0; |
| 250 } | 270 } |
| 251 | 271 |
| 252 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 272 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
| 253 gfx::Size size, | 273 gfx::Size size, |
| 254 GLenum format, | |
| 255 GLenum texture_pool, | 274 GLenum texture_pool, |
| 256 GLint wrap_mode, | 275 GLint wrap_mode, |
| 257 TextureUsageHint hint) { | 276 TextureUsageHint hint, |
| 277 ResourceFormat format) { |
| 258 DCHECK_LE(size.width(), max_texture_size_); | 278 DCHECK_LE(size.width(), max_texture_size_); |
| 259 DCHECK_LE(size.height(), max_texture_size_); | 279 DCHECK_LE(size.height(), max_texture_size_); |
| 260 DCHECK(thread_checker_.CalledOnValidThread()); | 280 DCHECK(thread_checker_.CalledOnValidThread()); |
| 261 | 281 |
| 262 ResourceId id = next_id_++; | 282 ResourceId id = next_id_++; |
| 263 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); | 283 Resource resource(0, size, GL_LINEAR, texture_pool, wrap_mode, hint, format); |
| 264 resource.allocated = false; | 284 resource.allocated = false; |
| 265 resources_[id] = resource; | 285 resources_[id] = resource; |
| 266 return id; | 286 return id; |
| 267 } | 287 } |
| 268 | 288 |
| 269 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { | 289 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { |
| 270 DCHECK(thread_checker_.CalledOnValidThread()); | 290 DCHECK(thread_checker_.CalledOnValidThread()); |
| 271 | 291 |
| 272 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; | 292 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; |
| 273 | 293 |
| 274 ResourceId id = next_id_++; | 294 ResourceId id = next_id_++; |
| 275 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 295 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 276 resource.allocated = true; | 296 resource.allocated = true; |
| 277 resources_[id] = resource; | 297 resources_[id] = resource; |
| 278 return id; | 298 return id; |
| 279 } | 299 } |
| 280 | 300 |
| 281 ResourceProvider::ResourceId | 301 ResourceProvider::ResourceId |
| 282 ResourceProvider::CreateResourceFromExternalTexture( | 302 ResourceProvider::CreateResourceFromExternalTexture( |
| 283 unsigned texture_target, | 303 unsigned texture_target, |
| 284 unsigned texture_id) { | 304 unsigned texture_id) { |
| 285 DCHECK(thread_checker_.CalledOnValidThread()); | 305 DCHECK(thread_checker_.CalledOnValidThread()); |
| 286 | 306 |
| 287 WebGraphicsContext3D* context3d = Context3d(); | 307 WebGraphicsContext3D* context3d = Context3d(); |
| 288 DCHECK(context3d); | 308 DCHECK(context3d); |
| 289 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); | 309 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); |
| 290 GLC(context3d, context3d->texParameteri( | 310 GLC(context3d, context3d->texParameteri( |
| 291 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 311 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 292 GLC(context3d, context3d->texParameteri( | 312 GLC(context3d, context3d->texParameteri( |
| 293 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 313 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 294 GLC(context3d, context3d->texParameteri( | 314 GLC(context3d, context3d->texParameteri( |
| 295 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 315 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 296 GLC(context3d, context3d->texParameteri( | 316 GLC(context3d, context3d->texParameteri( |
| 297 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 317 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 298 | 318 |
| 299 ResourceId id = next_id_++; | 319 ResourceId id = next_id_++; |
| 300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 320 Resource resource(texture_id, |
| 301 TextureUsageAny); | 321 gfx::Size(), |
| 322 GL_LINEAR, |
| 323 0, |
| 324 GL_CLAMP_TO_EDGE, |
| 325 TextureUsageAny, |
| 326 RGBA_8888); |
| 302 resource.external = true; | 327 resource.external = true; |
| 303 resource.allocated = true; | 328 resource.allocated = true; |
| 304 resources_[id] = resource; | 329 resources_[id] = resource; |
| 305 return id; | 330 return id; |
| 306 } | 331 } |
| 307 | 332 |
| 308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 333 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 309 const TextureMailbox& mailbox) { | 334 const TextureMailbox& mailbox) { |
| 310 DCHECK(thread_checker_.CalledOnValidThread()); | 335 DCHECK(thread_checker_.CalledOnValidThread()); |
| 311 // Just store the information. Mailbox will be consumed in LockForRead(). | 336 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 312 ResourceId id = next_id_++; | 337 ResourceId id = next_id_++; |
| 313 DCHECK(mailbox.IsValid()); | 338 DCHECK(mailbox.IsValid()); |
| 314 Resource& resource = resources_[id]; | 339 Resource& resource = resources_[id]; |
| 315 if (mailbox.IsTexture()) { | 340 if (mailbox.IsTexture()) { |
| 316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 341 resource = Resource(0, |
| 317 TextureUsageAny); | 342 gfx::Size(), |
| 343 GL_LINEAR, |
| 344 0, |
| 345 GL_CLAMP_TO_EDGE, |
| 346 TextureUsageAny, |
| 347 RGBA_8888); |
| 318 } else { | 348 } else { |
| 319 DCHECK(mailbox.IsSharedMemory()); | 349 DCHECK(mailbox.IsSharedMemory()); |
| 320 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 350 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
| 321 DCHECK(shared_memory->memory()); | 351 DCHECK(shared_memory->memory()); |
| 322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 352 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
| 323 resource = Resource(pixels, mailbox.shared_memory_size(), | 353 resource = Resource( |
| 324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 354 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 325 } | 355 } |
| 326 resource.external = true; | 356 resource.external = true; |
| 327 resource.allocated = true; | 357 resource.allocated = true; |
| 328 resource.mailbox = mailbox; | 358 resource.mailbox = mailbox; |
| 329 return id; | 359 return id; |
| 330 } | 360 } |
| 331 | 361 |
| 332 void ResourceProvider::DeleteResource(ResourceId id) { | 362 void ResourceProvider::DeleteResource(ResourceId id) { |
| 333 DCHECK(thread_checker_.CalledOnValidThread()); | 363 DCHECK(thread_checker_.CalledOnValidThread()); |
| 334 ResourceMap::iterator it = resources_.find(id); | 364 ResourceMap::iterator it = resources_.find(id); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 texture_uploader_->Upload(image, | 461 texture_uploader_->Upload(image, |
| 432 image_rect, | 462 image_rect, |
| 433 source_rect, | 463 source_rect, |
| 434 dest_offset, | 464 dest_offset, |
| 435 resource->format, | 465 resource->format, |
| 436 resource->size); | 466 resource->size); |
| 437 } | 467 } |
| 438 | 468 |
| 439 if (resource->pixels) { | 469 if (resource->pixels) { |
| 440 DCHECK(resource->allocated); | 470 DCHECK(resource->allocated); |
| 441 DCHECK(resource->format == GL_RGBA); | 471 DCHECK_EQ(RGBA_8888, resource->format); |
| 442 SkBitmap src_full; | 472 SkBitmap src_full; |
| 443 src_full.setConfig( | 473 src_full.setConfig( |
| 444 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); | 474 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); |
| 445 src_full.setPixels(const_cast<uint8_t*>(image)); | 475 src_full.setPixels(const_cast<uint8_t*>(image)); |
| 446 SkBitmap src_subset; | 476 SkBitmap src_subset; |
| 447 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), | 477 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), |
| 448 source_rect.y(), | 478 source_rect.y(), |
| 449 source_rect.width(), | 479 source_rect.width(), |
| 450 source_rect.height()); | 480 source_rect.height()); |
| 451 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); | 481 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_); | 685 DCHECK(texture_id_); |
| 656 } | 686 } |
| 657 | 687 |
| 658 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 688 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
| 659 resource_provider_->UnlockForWrite(resource_id_); | 689 resource_provider_->UnlockForWrite(resource_id_); |
| 660 } | 690 } |
| 661 | 691 |
| 662 void ResourceProvider::PopulateSkBitmapWithResource( | 692 void ResourceProvider::PopulateSkBitmapWithResource( |
| 663 SkBitmap* sk_bitmap, const Resource* resource) { | 693 SkBitmap* sk_bitmap, const Resource* resource) { |
| 664 DCHECK(resource->pixels); | 694 DCHECK(resource->pixels); |
| 665 DCHECK(resource->format == GL_RGBA); | 695 DCHECK_EQ(RGBA_8888, resource->format); |
| 666 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 696 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 667 resource->size.width(), | 697 resource->size.width(), |
| 668 resource->size.height()); | 698 resource->size.height()); |
| 669 sk_bitmap->setPixels(resource->pixels); | 699 sk_bitmap->setPixels(resource->pixels); |
| 670 } | 700 } |
| 671 | 701 |
| 672 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 702 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 673 ResourceProvider* resource_provider, | 703 ResourceProvider* resource_provider, |
| 674 ResourceProvider::ResourceId resource_id) | 704 ResourceProvider::ResourceId resource_id) |
| 675 : resource_provider_(resource_provider), | 705 : resource_provider_(resource_provider), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 690 ResourceProvider::PopulateSkBitmapWithResource( | 720 ResourceProvider::PopulateSkBitmapWithResource( |
| 691 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); | 721 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); |
| 692 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); | 722 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); |
| 693 } | 723 } |
| 694 | 724 |
| 695 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 725 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| 696 resource_provider_->UnlockForWrite(resource_id_); | 726 resource_provider_->UnlockForWrite(resource_id_); |
| 697 } | 727 } |
| 698 | 728 |
| 699 ResourceProvider::ResourceProvider(OutputSurface* output_surface, | 729 ResourceProvider::ResourceProvider(OutputSurface* output_surface, |
| 700 int highp_threshold_min) | 730 int highp_threshold_min, |
| 731 bool use_rgba_4444_tiles, |
| 732 bool force_rgba_tiles) |
| 701 : output_surface_(output_surface), | 733 : output_surface_(output_surface), |
| 702 lost_output_surface_(false), | 734 lost_output_surface_(false), |
| 703 highp_threshold_min_(highp_threshold_min), | 735 highp_threshold_min_(highp_threshold_min), |
| 704 next_id_(1), | 736 next_id_(1), |
| 705 next_child_(1), | 737 next_child_(1), |
| 706 default_resource_type_(InvalidType), | 738 default_resource_type_(InvalidType), |
| 707 use_texture_storage_ext_(false), | 739 use_texture_storage_ext_(false), |
| 708 use_texture_usage_hint_(false), | 740 use_texture_usage_hint_(false), |
| 709 use_shallow_flush_(false), | 741 use_shallow_flush_(false), |
| 710 max_texture_size_(0), | 742 max_texture_size_(0), |
| 711 best_texture_format_(0) { | 743 best_texture_format_(RGBA_8888), |
| 744 use_rgba_4444_tiles_(use_rgba_4444_tiles), |
| 745 force_rgba_tiles_(force_rgba_tiles) { |
| 712 DCHECK(output_surface_->HasClient()); | 746 DCHECK(output_surface_->HasClient()); |
| 713 } | 747 } |
| 714 | 748 |
| 715 void ResourceProvider::InitializeSoftware() { | 749 void ResourceProvider::InitializeSoftware() { |
| 716 DCHECK(thread_checker_.CalledOnValidThread()); | 750 DCHECK(thread_checker_.CalledOnValidThread()); |
| 717 DCHECK_NE(Bitmap, default_resource_type_); | 751 DCHECK_NE(Bitmap, default_resource_type_); |
| 718 | 752 |
| 719 CleanUpGLIfNeeded(); | 753 CleanUpGLIfNeeded(); |
| 720 | 754 |
| 721 default_resource_type_ = Bitmap; | 755 default_resource_type_ = Bitmap; |
| 722 max_texture_size_ = INT_MAX / 2; | 756 max_texture_size_ = INT_MAX / 2; |
| 723 best_texture_format_ = GL_RGBA; | 757 best_texture_format_ = RGBA_8888; |
| 724 } | 758 } |
| 725 | 759 |
| 726 bool ResourceProvider::InitializeGL() { | 760 bool ResourceProvider::InitializeGL() { |
| 727 DCHECK(thread_checker_.CalledOnValidThread()); | 761 DCHECK(thread_checker_.CalledOnValidThread()); |
| 728 DCHECK(!texture_uploader_); | 762 DCHECK(!texture_uploader_); |
| 729 DCHECK_NE(GLTexture, default_resource_type_); | 763 DCHECK_NE(GLTexture, default_resource_type_); |
| 730 | 764 |
| 731 WebGraphicsContext3D* context3d = Context3d(); | 765 WebGraphicsContext3D* context3d = Context3d(); |
| 732 DCHECK(context3d); | 766 DCHECK(context3d); |
| 733 | 767 |
| 734 if (!context3d->makeContextCurrent()) | 768 if (!context3d->makeContextCurrent()) |
| 735 return false; | 769 return false; |
| 736 | 770 |
| 737 default_resource_type_ = GLTexture; | 771 default_resource_type_ = GLTexture; |
| 738 | 772 |
| 739 const ContextProvider::Capabilities& caps = | 773 const ContextProvider::Capabilities& caps = |
| 740 output_surface_->context_provider()->ContextCapabilities(); | 774 output_surface_->context_provider()->ContextCapabilities(); |
| 741 | 775 |
| 742 bool use_map_sub = caps.map_sub; | 776 bool use_map_sub = caps.map_sub; |
| 743 bool use_bgra = caps.texture_format_bgra8888; | 777 bool use_bgra = caps.texture_format_bgra8888; |
| 744 use_texture_storage_ext_ = caps.texture_storage; | 778 use_texture_storage_ext_ = caps.texture_storage; |
| 745 use_shallow_flush_ = caps.shallow_flush; | 779 use_shallow_flush_ = caps.shallow_flush; |
| 746 use_texture_usage_hint_ = caps.texture_usage; | 780 use_texture_usage_hint_ = caps.texture_usage; |
| 747 | 781 |
| 748 texture_uploader_ = | 782 texture_uploader_ = |
| 749 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); | 783 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); |
| 750 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, | 784 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, |
| 751 &max_texture_size_)); | 785 &max_texture_size_)); |
| 786 if (force_rgba_tiles_) |
| 787 use_bgra = false; |
| 752 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 788 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
| 753 | 789 |
| 754 return true; | 790 return true; |
| 755 } | 791 } |
| 756 | 792 |
| 757 void ResourceProvider::CleanUpGLIfNeeded() { | 793 void ResourceProvider::CleanUpGLIfNeeded() { |
| 758 WebGraphicsContext3D* context3d = Context3d(); | 794 WebGraphicsContext3D* context3d = Context3d(); |
| 759 if (default_resource_type_ != GLTexture) { | 795 if (default_resource_type_ != GLTexture) { |
| 760 // We are not in GL mode, but double check before returning. | 796 // We are not in GL mode, but double check before returning. |
| 761 DCHECK(!context3d); | 797 DCHECK(!context3d); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 // deadlocks and/or security issues. The caller is responsible for | 938 // deadlocks and/or security issues. The caller is responsible for |
| 903 // waiting asynchronously, and resetting sync_point before calling this. | 939 // waiting asynchronously, and resetting sync_point before calling this. |
| 904 // However if the parent is a renderer (e.g. browser tag), it may be ok | 940 // However if the parent is a renderer (e.g. browser tag), it may be ok |
| 905 // (and is simpler) to wait. | 941 // (and is simpler) to wait. |
| 906 if (it->sync_point) | 942 if (it->sync_point) |
| 907 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 943 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
| 908 GLC(context3d, texture_id = context3d->createTexture()); | 944 GLC(context3d, texture_id = context3d->createTexture()); |
| 909 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); | 945 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 910 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, | 946 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, |
| 911 it->mailbox.name)); | 947 it->mailbox.name)); |
| 948 |
| 912 ResourceId id = next_id_++; | 949 ResourceId id = next_id_++; |
| 913 Resource resource( | 950 Resource resource( |
| 914 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, | 951 texture_id, |
| 915 TextureUsageAny); | 952 it->size, |
| 953 it->filter, |
| 954 0, |
| 955 GL_CLAMP_TO_EDGE, |
| 956 TextureUsageAny, |
| 957 it->format); |
| 916 resource.mailbox.SetName(it->mailbox); | 958 resource.mailbox.SetName(it->mailbox); |
| 917 // Don't allocate a texture for a child. | 959 // Don't allocate a texture for a child. |
| 918 resource.allocated = true; | 960 resource.allocated = true; |
| 919 resource.imported_count = 1; | 961 resource.imported_count = 1; |
| 920 resources_[id] = resource; | 962 resources_[id] = resource; |
| 921 child_info.parent_to_child_map[id] = it->id; | 963 child_info.parent_to_child_map[id] = it->id; |
| 922 child_info.child_to_parent_map[it->id] = id; | 964 child_info.child_to_parent_map[it->id] = id; |
| 923 } | 965 } |
| 924 } | 966 } |
| 925 | 967 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 DCHECK(!resource->image_id); | 1038 DCHECK(!resource->image_id); |
| 997 | 1039 |
| 998 if (resource->type == GLTexture) { | 1040 if (resource->type == GLTexture) { |
| 999 WebGraphicsContext3D* context3d = Context3d(); | 1041 WebGraphicsContext3D* context3d = Context3d(); |
| 1000 DCHECK(context3d); | 1042 DCHECK(context3d); |
| 1001 if (!resource->gl_pixel_buffer_id) | 1043 if (!resource->gl_pixel_buffer_id) |
| 1002 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 1044 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
| 1003 context3d->bindBuffer( | 1045 context3d->bindBuffer( |
| 1004 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1046 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1005 resource->gl_pixel_buffer_id); | 1047 resource->gl_pixel_buffer_id); |
| 1048 size_t bytes_per_pixel = BytesPerPixel(resource->format); |
| 1006 context3d->bufferData( | 1049 context3d->bufferData( |
| 1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1050 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1008 4 * resource->size.GetArea(), | 1051 bytes_per_pixel * resource->size.GetArea(), |
| 1009 NULL, | 1052 NULL, |
| 1010 GL_DYNAMIC_DRAW); | 1053 GL_DYNAMIC_DRAW); |
| 1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1054 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1012 } | 1055 } |
| 1013 | 1056 |
| 1014 if (resource->pixels) { | 1057 if (resource->pixels) { |
| 1015 if (resource->pixel_buffer) | 1058 if (resource->pixel_buffer) |
| 1016 return; | 1059 return; |
| 1017 | 1060 |
| 1018 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1061 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 DCHECK(resource->gl_pixel_buffer_id); | 1212 DCHECK(resource->gl_pixel_buffer_id); |
| 1170 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1213 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1171 context3d->bindBuffer( | 1214 context3d->bindBuffer( |
| 1172 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1215 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1173 resource->gl_pixel_buffer_id); | 1216 resource->gl_pixel_buffer_id); |
| 1174 if (!resource->gl_upload_query_id) | 1217 if (!resource->gl_upload_query_id) |
| 1175 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1218 resource->gl_upload_query_id = context3d->createQueryEXT(); |
| 1176 context3d->beginQueryEXT( | 1219 context3d->beginQueryEXT( |
| 1177 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1220 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
| 1178 resource->gl_upload_query_id); | 1221 resource->gl_upload_query_id); |
| 1222 DCHECK(resource->format != RGBA_4444 || |
| 1223 (resource->size.width() % 2) == 0); |
| 1179 if (allocate) { | 1224 if (allocate) { |
| 1180 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1225 context3d->asyncTexImage2DCHROMIUM( |
| 1181 0, /* level */ | 1226 GL_TEXTURE_2D, |
| 1182 resource->format, | 1227 0, /* level */ |
| 1183 resource->size.width(), | 1228 GetGLInternalFormat(resource->format), |
| 1184 resource->size.height(), | 1229 resource->size.width(), |
| 1185 0, /* border */ | 1230 resource->size.height(), |
| 1186 resource->format, | 1231 0, /* border */ |
| 1187 GL_UNSIGNED_BYTE, | 1232 GetGLDataFormat(resource->format), |
| 1188 NULL); | 1233 GetGLDataType(resource->format), |
| 1234 NULL); |
| 1189 } else { | 1235 } else { |
| 1190 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1236 context3d->asyncTexSubImage2DCHROMIUM( |
| 1191 0, /* level */ | 1237 GL_TEXTURE_2D, |
| 1192 0, /* x */ | 1238 0, /* level */ |
| 1193 0, /* y */ | 1239 0, /* x */ |
| 1194 resource->size.width(), | 1240 0, /* y */ |
| 1195 resource->size.height(), | 1241 resource->size.width(), |
| 1196 resource->format, | 1242 resource->size.height(), |
| 1197 GL_UNSIGNED_BYTE, | 1243 GetGLDataFormat(resource->format), |
| 1198 NULL); | 1244 GetGLDataType(resource->format), |
| 1245 NULL); |
| 1199 } | 1246 } |
| 1200 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1247 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
| 1201 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1248 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1202 } | 1249 } |
| 1203 | 1250 |
| 1204 if (resource->pixels) { | 1251 if (resource->pixels) { |
| 1205 DCHECK(!resource->mailbox.IsValid()); | 1252 DCHECK(!resource->mailbox.IsValid()); |
| 1206 DCHECK(resource->pixel_buffer); | 1253 DCHECK(resource->pixel_buffer); |
| 1207 DCHECK(resource->format == GL_RGBA); | 1254 DCHECK_EQ(RGBA_8888, resource->format); |
| 1208 | 1255 |
| 1209 std::swap(resource->pixels, resource->pixel_buffer); | 1256 std::swap(resource->pixels, resource->pixel_buffer); |
| 1210 delete[] resource->pixel_buffer; | 1257 delete[] resource->pixel_buffer; |
| 1211 resource->pixel_buffer = NULL; | 1258 resource->pixel_buffer = NULL; |
| 1212 } | 1259 } |
| 1213 | 1260 |
| 1214 resource->pending_set_pixels = true; | 1261 resource->pending_set_pixels = true; |
| 1215 resource->set_pixels_completion_forced = false; | 1262 resource->set_pixels_completion_forced = false; |
| 1216 } | 1263 } |
| 1217 | 1264 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 void ResourceProvider::LazyAllocate(Resource* resource) { | 1350 void ResourceProvider::LazyAllocate(Resource* resource) { |
| 1304 DCHECK(resource); | 1351 DCHECK(resource); |
| 1305 LazyCreate(resource); | 1352 LazyCreate(resource); |
| 1306 | 1353 |
| 1307 DCHECK(resource->gl_id || resource->allocated); | 1354 DCHECK(resource->gl_id || resource->allocated); |
| 1308 if (resource->allocated || !resource->gl_id) | 1355 if (resource->allocated || !resource->gl_id) |
| 1309 return; | 1356 return; |
| 1310 resource->allocated = true; | 1357 resource->allocated = true; |
| 1311 WebGraphicsContext3D* context3d = Context3d(); | 1358 WebGraphicsContext3D* context3d = Context3d(); |
| 1312 gfx::Size& size = resource->size; | 1359 gfx::Size& size = resource->size; |
| 1313 GLenum format = resource->format; | 1360 ResourceFormat format = resource->format; |
| 1314 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1361 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 1315 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1362 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) { |
| 1316 GLenum storage_format = TextureToStorageFormat(format); | 1363 GLenum storage_format = TextureToStorageFormat(format); |
| 1317 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1364 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
| 1318 1, | 1365 1, |
| 1319 storage_format, | 1366 storage_format, |
| 1320 size.width(), | 1367 size.width(), |
| 1321 size.height())); | 1368 size.height())); |
| 1322 } else { | 1369 } else { |
| 1323 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1370 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
| 1324 0, | 1371 0, |
| 1325 format, | 1372 GetGLInternalFormat(format), |
| 1326 size.width(), | 1373 size.width(), |
| 1327 size.height(), | 1374 size.height(), |
| 1328 0, | 1375 0, |
| 1329 format, | 1376 GetGLDataFormat(format), |
| 1330 GL_UNSIGNED_BYTE, | 1377 GetGLDataType(format), |
| 1331 NULL)); | 1378 NULL)); |
| 1332 } | 1379 } |
| 1333 } | 1380 } |
| 1334 | 1381 |
| 1335 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1382 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
| 1336 bool enable) { | 1383 bool enable) { |
| 1337 Resource* resource = GetResource(id); | 1384 Resource* resource = GetResource(id); |
| 1338 resource->enable_read_lock_fences = enable; | 1385 resource->enable_read_lock_fences = enable; |
| 1339 } | 1386 } |
| 1340 | 1387 |
| 1341 void ResourceProvider::AcquireImage(ResourceId id) { | 1388 void ResourceProvider::AcquireImage(ResourceId id) { |
| 1342 Resource* resource = GetResource(id); | 1389 Resource* resource = GetResource(id); |
| 1343 DCHECK(!resource->external); | 1390 DCHECK(!resource->external); |
| 1344 DCHECK_EQ(resource->exported_count, 0); | 1391 DCHECK_EQ(resource->exported_count, 0); |
| 1345 | 1392 |
| 1346 if (resource->type != GLTexture) | 1393 if (resource->type != GLTexture) |
| 1347 return; | 1394 return; |
| 1348 | 1395 |
| 1349 if (resource->image_id) | 1396 if (resource->image_id) |
| 1350 return; | 1397 return; |
| 1351 | 1398 |
| 1352 resource->allocated = true; | 1399 resource->allocated = true; |
| 1353 WebGraphicsContext3D* context3d = Context3d(); | 1400 WebGraphicsContext3D* context3d = Context3d(); |
| 1354 DCHECK(context3d); | 1401 DCHECK(context3d); |
| 1355 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); | 1402 DCHECK_EQ(RGBA_8888, resource->format); |
| 1356 resource->image_id = context3d->createImageCHROMIUM( | 1403 resource->image_id = context3d->createImageCHROMIUM( |
| 1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | 1404 resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
| 1358 DCHECK(resource->image_id); | 1405 DCHECK(resource->image_id); |
| 1359 } | 1406 } |
| 1360 | 1407 |
| 1361 void ResourceProvider::ReleaseImage(ResourceId id) { | 1408 void ResourceProvider::ReleaseImage(ResourceId id) { |
| 1362 Resource* resource = GetResource(id); | 1409 Resource* resource = GetResource(id); |
| 1363 DCHECK(!resource->external); | 1410 DCHECK(!resource->external); |
| 1364 DCHECK_EQ(resource->exported_count, 0); | 1411 DCHECK_EQ(resource->exported_count, 0); |
| 1365 | 1412 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 GLint active_unit = 0; | 1472 GLint active_unit = 0; |
| 1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1473 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1427 return active_unit; | 1474 return active_unit; |
| 1428 } | 1475 } |
| 1429 | 1476 |
| 1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1477 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1431 ContextProvider* context_provider = output_surface_->context_provider(); | 1478 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1432 return context_provider ? context_provider->Context3d() : NULL; | 1479 return context_provider ? context_provider->Context3d() : NULL; |
| 1433 } | 1480 } |
| 1434 | 1481 |
| 1482 size_t ResourceProvider::BytesPerPixel(ResourceFormat format) { |
| 1483 size_t components_per_pixel = 0; |
| 1484 switch (format) { |
| 1485 case RGBA_8888: |
| 1486 case RGBA_4444: |
| 1487 case BGRA_8888: |
| 1488 components_per_pixel = 4; |
| 1489 break; |
| 1490 case LUMINANCE_8: |
| 1491 components_per_pixel = 1; |
| 1492 break; |
| 1493 } |
| 1494 size_t bits_per_component = 0; |
| 1495 switch (format) { |
| 1496 case RGBA_8888: |
| 1497 case BGRA_8888: |
| 1498 case LUMINANCE_8: |
| 1499 bits_per_component = 8; |
| 1500 break; |
| 1501 case RGBA_4444: |
| 1502 bits_per_component = 4; |
| 1503 break; |
| 1504 } |
| 1505 const size_t kBitsPerByte = 8; |
| 1506 return (components_per_pixel * bits_per_component) / kBitsPerByte; |
| 1507 } |
| 1508 |
| 1509 GLenum ResourceProvider::GetGLDataType(ResourceFormat format) { |
| 1510 switch (format) { |
| 1511 case RGBA_4444: |
| 1512 return GL_UNSIGNED_SHORT_4_4_4_4; |
| 1513 case RGBA_8888: |
| 1514 case BGRA_8888: |
| 1515 case LUMINANCE_8: |
| 1516 return GL_UNSIGNED_BYTE; |
| 1517 } |
| 1518 NOTREACHED(); |
| 1519 return GL_UNSIGNED_BYTE; |
| 1520 } |
| 1521 |
| 1522 GLenum ResourceProvider::GetGLDataFormat(ResourceFormat format) { |
| 1523 switch (format) { |
| 1524 case RGBA_8888: |
| 1525 case RGBA_4444: |
| 1526 return GL_RGBA; |
| 1527 case BGRA_8888: |
| 1528 return GL_BGRA_EXT; |
| 1529 case LUMINANCE_8: |
| 1530 return GL_LUMINANCE; |
| 1531 } |
| 1532 NOTREACHED(); |
| 1533 return GL_RGBA; |
| 1534 } |
| 1535 |
| 1536 GLenum ResourceProvider::GetGLInternalFormat(ResourceFormat format) { |
| 1537 return GetGLDataFormat(format); |
| 1538 } |
| 1539 |
| 1435 } // namespace cc | 1540 } // namespace cc |
| OLD | NEW |