| 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) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 204 | 210 |
| 205 CleanUpGLIfNeeded(); | 211 CleanUpGLIfNeeded(); |
| 206 } | 212 } |
| 207 | 213 |
| 208 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 214 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
| 209 Resource* resource = GetResource(id); | 215 Resource* resource = GetResource(id); |
| 210 return resource->lock_for_read_count > 0 || resource->exported_count > 0; | 216 return resource->lock_for_read_count > 0 || resource->exported_count > 0; |
| 211 } | 217 } |
| 212 | 218 |
| 213 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 219 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
| 214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 220 gfx::Size size, |
| 221 GLint wrap_mode, |
| 222 TextureUsageHint hint, |
| 223 ResourceFormat format) { |
| 215 DCHECK(!size.IsEmpty()); | 224 DCHECK(!size.IsEmpty()); |
| 216 switch (default_resource_type_) { | 225 switch (default_resource_type_) { |
| 217 case GLTexture: | 226 case GLTexture: |
| 218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 227 return CreateGLTexture(size, |
| 219 wrap_mode, hint); | 228 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 229 wrap_mode, |
| 230 hint, |
| 231 format); |
| 220 case Bitmap: | 232 case Bitmap: |
| 221 // The only wrap_mode currently implemented in software mode is | 233 DCHECK_EQ(RGBA_8888, format); |
| 222 // GL_CLAMP_TO_EDGE. | |
| 223 // http://crbug.com/284796 | |
| 224 DCHECK(format == GL_RGBA); | |
| 225 return CreateBitmap(size); | 234 return CreateBitmap(size); |
| 226 case InvalidType: | 235 case InvalidType: |
| 227 break; | 236 break; |
| 228 } | 237 } |
| 229 | 238 |
| 230 LOG(FATAL) << "Invalid default resource type."; | 239 LOG(FATAL) << "Invalid default resource type."; |
| 231 return 0; | 240 return 0; |
| 232 } | 241 } |
| 233 | 242 |
| 234 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 243 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
| 235 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 244 gfx::Size size, |
| 245 GLint wrap_mode, |
| 246 TextureUsageHint hint, |
| 247 ResourceFormat format) { |
| 236 DCHECK(!size.IsEmpty()); | 248 DCHECK(!size.IsEmpty()); |
| 237 switch (default_resource_type_) { | 249 switch (default_resource_type_) { |
| 238 case GLTexture: | 250 case GLTexture: |
| 239 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, | 251 return CreateGLTexture(size, |
| 240 wrap_mode, hint); | 252 GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
| 253 wrap_mode, |
| 254 hint, |
| 255 format); |
| 241 case Bitmap: | 256 case Bitmap: |
| 242 DCHECK(format == GL_RGBA); | 257 DCHECK_EQ(RGBA_8888, format); |
| 243 return CreateBitmap(size); | 258 return CreateBitmap(size); |
| 244 case InvalidType: | 259 case InvalidType: |
| 245 break; | 260 break; |
| 246 } | 261 } |
| 247 | 262 |
| 248 LOG(FATAL) << "Invalid default resource type."; | 263 LOG(FATAL) << "Invalid default resource type."; |
| 249 return 0; | 264 return 0; |
| 250 } | 265 } |
| 251 | 266 |
| 252 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 267 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
| 253 gfx::Size size, | 268 gfx::Size size, |
| 254 GLenum format, | |
| 255 GLenum texture_pool, | 269 GLenum texture_pool, |
| 256 GLint wrap_mode, | 270 GLint wrap_mode, |
| 257 TextureUsageHint hint) { | 271 TextureUsageHint hint, |
| 272 ResourceFormat format) { |
| 258 DCHECK_LE(size.width(), max_texture_size_); | 273 DCHECK_LE(size.width(), max_texture_size_); |
| 259 DCHECK_LE(size.height(), max_texture_size_); | 274 DCHECK_LE(size.height(), max_texture_size_); |
| 260 DCHECK(thread_checker_.CalledOnValidThread()); | 275 DCHECK(thread_checker_.CalledOnValidThread()); |
| 261 | 276 |
| 262 ResourceId id = next_id_++; | 277 ResourceId id = next_id_++; |
| 263 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); | 278 Resource resource(0, size, GL_LINEAR, texture_pool, wrap_mode, hint, format); |
| 264 resource.allocated = false; | 279 resource.allocated = false; |
| 265 resources_[id] = resource; | 280 resources_[id] = resource; |
| 266 return id; | 281 return id; |
| 267 } | 282 } |
| 268 | 283 |
| 269 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { | 284 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { |
| 270 DCHECK(thread_checker_.CalledOnValidThread()); | 285 DCHECK(thread_checker_.CalledOnValidThread()); |
| 271 | 286 |
| 272 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; | 287 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; |
| 273 | 288 |
| 274 ResourceId id = next_id_++; | 289 ResourceId id = next_id_++; |
| 275 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 290 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 276 resource.allocated = true; | 291 resource.allocated = true; |
| 277 resources_[id] = resource; | 292 resources_[id] = resource; |
| 278 return id; | 293 return id; |
| 279 } | 294 } |
| 280 | 295 |
| 281 ResourceProvider::ResourceId | 296 ResourceProvider::ResourceId |
| 282 ResourceProvider::CreateResourceFromExternalTexture( | 297 ResourceProvider::CreateResourceFromExternalTexture( |
| 283 unsigned texture_target, | 298 unsigned texture_target, |
| 284 unsigned texture_id) { | 299 unsigned texture_id) { |
| 285 DCHECK(thread_checker_.CalledOnValidThread()); | 300 DCHECK(thread_checker_.CalledOnValidThread()); |
| 286 | 301 |
| 287 WebGraphicsContext3D* context3d = Context3d(); | 302 WebGraphicsContext3D* context3d = Context3d(); |
| 288 DCHECK(context3d); | 303 DCHECK(context3d); |
| 289 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); | 304 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); |
| 290 GLC(context3d, context3d->texParameteri( | 305 GLC(context3d, context3d->texParameteri( |
| 291 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 306 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 292 GLC(context3d, context3d->texParameteri( | 307 GLC(context3d, context3d->texParameteri( |
| 293 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 308 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 294 GLC(context3d, context3d->texParameteri( | 309 GLC(context3d, context3d->texParameteri( |
| 295 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 310 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 296 GLC(context3d, context3d->texParameteri( | 311 GLC(context3d, context3d->texParameteri( |
| 297 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 312 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 298 | 313 |
| 299 ResourceId id = next_id_++; | 314 ResourceId id = next_id_++; |
| 300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 315 Resource resource(texture_id, |
| 301 TextureUsageAny); | 316 gfx::Size(), |
| 317 GL_LINEAR, |
| 318 0, |
| 319 GL_CLAMP_TO_EDGE, |
| 320 TextureUsageAny, |
| 321 RGBA_8888); |
| 302 resource.external = true; | 322 resource.external = true; |
| 303 resource.allocated = true; | 323 resource.allocated = true; |
| 304 resources_[id] = resource; | 324 resources_[id] = resource; |
| 305 return id; | 325 return id; |
| 306 } | 326 } |
| 307 | 327 |
| 308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 328 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 309 const TextureMailbox& mailbox) { | 329 const TextureMailbox& mailbox) { |
| 310 DCHECK(thread_checker_.CalledOnValidThread()); | 330 DCHECK(thread_checker_.CalledOnValidThread()); |
| 311 // Just store the information. Mailbox will be consumed in LockForRead(). | 331 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 312 ResourceId id = next_id_++; | 332 ResourceId id = next_id_++; |
| 313 DCHECK(mailbox.IsValid()); | 333 DCHECK(mailbox.IsValid()); |
| 314 Resource& resource = resources_[id]; | 334 Resource& resource = resources_[id]; |
| 315 if (mailbox.IsTexture()) { | 335 if (mailbox.IsTexture()) { |
| 316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 336 resource = Resource(0, |
| 317 TextureUsageAny); | 337 gfx::Size(), |
| 338 GL_LINEAR, |
| 339 0, |
| 340 GL_CLAMP_TO_EDGE, |
| 341 TextureUsageAny, |
| 342 RGBA_8888); |
| 318 } else { | 343 } else { |
| 319 DCHECK(mailbox.IsSharedMemory()); | 344 DCHECK(mailbox.IsSharedMemory()); |
| 320 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 345 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
| 321 DCHECK(shared_memory->memory()); | 346 DCHECK(shared_memory->memory()); |
| 322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 347 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
| 323 resource = Resource(pixels, mailbox.shared_memory_size(), | 348 resource = Resource( |
| 324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 349 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 325 } | 350 } |
| 326 resource.external = true; | 351 resource.external = true; |
| 327 resource.allocated = true; | 352 resource.allocated = true; |
| 328 resource.mailbox = mailbox; | 353 resource.mailbox = mailbox; |
| 329 return id; | 354 return id; |
| 330 } | 355 } |
| 331 | 356 |
| 332 void ResourceProvider::DeleteResource(ResourceId id) { | 357 void ResourceProvider::DeleteResource(ResourceId id) { |
| 333 DCHECK(thread_checker_.CalledOnValidThread()); | 358 DCHECK(thread_checker_.CalledOnValidThread()); |
| 334 ResourceMap::iterator it = resources_.find(id); | 359 ResourceMap::iterator it = resources_.find(id); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 texture_uploader_->Upload(image, | 456 texture_uploader_->Upload(image, |
| 432 image_rect, | 457 image_rect, |
| 433 source_rect, | 458 source_rect, |
| 434 dest_offset, | 459 dest_offset, |
| 435 resource->format, | 460 resource->format, |
| 436 resource->size); | 461 resource->size); |
| 437 } | 462 } |
| 438 | 463 |
| 439 if (resource->pixels) { | 464 if (resource->pixels) { |
| 440 DCHECK(resource->allocated); | 465 DCHECK(resource->allocated); |
| 441 DCHECK(resource->format == GL_RGBA); | 466 DCHECK_EQ(RGBA_8888, resource->format); |
| 442 SkBitmap src_full; | 467 SkBitmap src_full; |
| 443 src_full.setConfig( | 468 src_full.setConfig( |
| 444 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); | 469 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); |
| 445 src_full.setPixels(const_cast<uint8_t*>(image)); | 470 src_full.setPixels(const_cast<uint8_t*>(image)); |
| 446 SkBitmap src_subset; | 471 SkBitmap src_subset; |
| 447 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), | 472 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), |
| 448 source_rect.y(), | 473 source_rect.y(), |
| 449 source_rect.width(), | 474 source_rect.width(), |
| 450 source_rect.height()); | 475 source_rect.height()); |
| 451 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); | 476 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_); | 680 DCHECK(texture_id_); |
| 656 } | 681 } |
| 657 | 682 |
| 658 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 683 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
| 659 resource_provider_->UnlockForWrite(resource_id_); | 684 resource_provider_->UnlockForWrite(resource_id_); |
| 660 } | 685 } |
| 661 | 686 |
| 662 void ResourceProvider::PopulateSkBitmapWithResource( | 687 void ResourceProvider::PopulateSkBitmapWithResource( |
| 663 SkBitmap* sk_bitmap, const Resource* resource) { | 688 SkBitmap* sk_bitmap, const Resource* resource) { |
| 664 DCHECK(resource->pixels); | 689 DCHECK(resource->pixels); |
| 665 DCHECK(resource->format == GL_RGBA); | 690 DCHECK_EQ(RGBA_8888, resource->format); |
| 666 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 691 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 667 resource->size.width(), | 692 resource->size.width(), |
| 668 resource->size.height()); | 693 resource->size.height()); |
| 669 sk_bitmap->setPixels(resource->pixels); | 694 sk_bitmap->setPixels(resource->pixels); |
| 670 } | 695 } |
| 671 | 696 |
| 672 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 697 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 673 ResourceProvider* resource_provider, | 698 ResourceProvider* resource_provider, |
| 674 ResourceProvider::ResourceId resource_id) | 699 ResourceProvider::ResourceId resource_id) |
| 675 : resource_provider_(resource_provider), | 700 : resource_provider_(resource_provider), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 701 : output_surface_(output_surface), | 726 : output_surface_(output_surface), |
| 702 lost_output_surface_(false), | 727 lost_output_surface_(false), |
| 703 highp_threshold_min_(highp_threshold_min), | 728 highp_threshold_min_(highp_threshold_min), |
| 704 next_id_(1), | 729 next_id_(1), |
| 705 next_child_(1), | 730 next_child_(1), |
| 706 default_resource_type_(InvalidType), | 731 default_resource_type_(InvalidType), |
| 707 use_texture_storage_ext_(false), | 732 use_texture_storage_ext_(false), |
| 708 use_texture_usage_hint_(false), | 733 use_texture_usage_hint_(false), |
| 709 use_shallow_flush_(false), | 734 use_shallow_flush_(false), |
| 710 max_texture_size_(0), | 735 max_texture_size_(0), |
| 711 best_texture_format_(0) { | 736 best_texture_format_(RGBA_8888) { |
| 712 DCHECK(output_surface_->HasClient()); | 737 DCHECK(output_surface_->HasClient()); |
| 713 } | 738 } |
| 714 | 739 |
| 715 void ResourceProvider::InitializeSoftware() { | 740 void ResourceProvider::InitializeSoftware() { |
| 716 DCHECK(thread_checker_.CalledOnValidThread()); | 741 DCHECK(thread_checker_.CalledOnValidThread()); |
| 717 DCHECK_NE(Bitmap, default_resource_type_); | 742 DCHECK_NE(Bitmap, default_resource_type_); |
| 718 | 743 |
| 719 CleanUpGLIfNeeded(); | 744 CleanUpGLIfNeeded(); |
| 720 | 745 |
| 721 default_resource_type_ = Bitmap; | 746 default_resource_type_ = Bitmap; |
| 722 max_texture_size_ = INT_MAX / 2; | 747 max_texture_size_ = INT_MAX / 2; |
| 723 best_texture_format_ = GL_RGBA; | 748 best_texture_format_ = RGBA_8888; |
| 724 } | 749 } |
| 725 | 750 |
| 726 bool ResourceProvider::InitializeGL() { | 751 bool ResourceProvider::InitializeGL() { |
| 727 DCHECK(thread_checker_.CalledOnValidThread()); | 752 DCHECK(thread_checker_.CalledOnValidThread()); |
| 728 DCHECK(!texture_uploader_); | 753 DCHECK(!texture_uploader_); |
| 729 DCHECK_NE(GLTexture, default_resource_type_); | 754 DCHECK_NE(GLTexture, default_resource_type_); |
| 730 | 755 |
| 731 WebGraphicsContext3D* context3d = Context3d(); | 756 WebGraphicsContext3D* context3d = Context3d(); |
| 732 DCHECK(context3d); | 757 DCHECK(context3d); |
| 733 | 758 |
| 734 if (!context3d->makeContextCurrent()) | 759 if (!context3d->makeContextCurrent()) |
| 735 return false; | 760 return false; |
| 736 | 761 |
| 737 default_resource_type_ = GLTexture; | 762 default_resource_type_ = GLTexture; |
| 738 | 763 |
| 739 const ContextProvider::Capabilities& caps = | 764 const ContextProvider::Capabilities& caps = |
| 740 output_surface_->context_provider()->ContextCapabilities(); | 765 output_surface_->context_provider()->ContextCapabilities(); |
| 741 | 766 |
| 742 bool use_map_sub = caps.map_sub; | 767 bool use_map_sub = caps.map_sub; |
| 743 bool use_bgra = caps.texture_format_bgra8888; | 768 bool use_bgra = caps.texture_format_bgra8888; |
| 744 use_texture_storage_ext_ = caps.texture_storage; | 769 use_texture_storage_ext_ = caps.texture_storage; |
| 745 use_shallow_flush_ = caps.shallow_flush; | 770 use_shallow_flush_ = caps.shallow_flush; |
| 746 use_texture_usage_hint_ = caps.texture_usage; | 771 use_texture_usage_hint_ = caps.texture_usage; |
| 747 | 772 |
| 748 texture_uploader_ = | 773 texture_uploader_ = |
| 749 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); | 774 TextureUploader::Create(context3d, |
| 775 use_map_sub, |
| 776 use_shallow_flush_); |
| 750 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, | 777 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, |
| 751 &max_texture_size_)); | 778 &max_texture_size_)); |
| 752 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 779 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
| 753 | 780 |
| 754 return true; | 781 return true; |
| 755 } | 782 } |
| 756 | 783 |
| 757 void ResourceProvider::CleanUpGLIfNeeded() { | 784 void ResourceProvider::CleanUpGLIfNeeded() { |
| 758 WebGraphicsContext3D* context3d = Context3d(); | 785 WebGraphicsContext3D* context3d = Context3d(); |
| 759 if (default_resource_type_ != GLTexture) { | 786 if (default_resource_type_ != GLTexture) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 // deadlocks and/or security issues. The caller is responsible for | 929 // deadlocks and/or security issues. The caller is responsible for |
| 903 // waiting asynchronously, and resetting sync_point before calling this. | 930 // 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 | 931 // However if the parent is a renderer (e.g. browser tag), it may be ok |
| 905 // (and is simpler) to wait. | 932 // (and is simpler) to wait. |
| 906 if (it->sync_point) | 933 if (it->sync_point) |
| 907 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 934 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
| 908 GLC(context3d, texture_id = context3d->createTexture()); | 935 GLC(context3d, texture_id = context3d->createTexture()); |
| 909 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); | 936 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 910 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, | 937 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, |
| 911 it->mailbox.name)); | 938 it->mailbox.name)); |
| 939 |
| 912 ResourceId id = next_id_++; | 940 ResourceId id = next_id_++; |
| 913 Resource resource( | 941 Resource resource( |
| 914 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, | 942 texture_id, |
| 915 TextureUsageAny); | 943 it->size, |
| 944 it->filter, |
| 945 0, |
| 946 GL_CLAMP_TO_EDGE, |
| 947 TextureUsageAny, |
| 948 it->format); |
| 916 resource.mailbox.SetName(it->mailbox); | 949 resource.mailbox.SetName(it->mailbox); |
| 917 // Don't allocate a texture for a child. | 950 // Don't allocate a texture for a child. |
| 918 resource.allocated = true; | 951 resource.allocated = true; |
| 919 resource.imported_count = 1; | 952 resource.imported_count = 1; |
| 920 resources_[id] = resource; | 953 resources_[id] = resource; |
| 921 child_info.parent_to_child_map[id] = it->id; | 954 child_info.parent_to_child_map[id] = it->id; |
| 922 child_info.child_to_parent_map[it->id] = id; | 955 child_info.child_to_parent_map[it->id] = id; |
| 923 } | 956 } |
| 924 } | 957 } |
| 925 | 958 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 | 990 |
| 958 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, | 991 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
| 959 ResourceId id, | 992 ResourceId id, |
| 960 TransferableResource* resource) { | 993 TransferableResource* resource) { |
| 961 Resource* source = GetResource(id); | 994 Resource* source = GetResource(id); |
| 962 DCHECK(!source->locked_for_write); | 995 DCHECK(!source->locked_for_write); |
| 963 DCHECK(!source->lock_for_read_count); | 996 DCHECK(!source->lock_for_read_count); |
| 964 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); | 997 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); |
| 965 DCHECK(source->allocated); | 998 DCHECK(source->allocated); |
| 966 resource->id = id; | 999 resource->id = id; |
| 967 resource->format = source->format; | |
| 968 resource->filter = source->filter; | 1000 resource->filter = source->filter; |
| 969 resource->size = source->size; | 1001 resource->size = source->size; |
| 1002 resource->format = source->format; |
| 970 | 1003 |
| 971 // TODO(skaslev) Implement this path for shared memory resources. | 1004 // TODO(skaslev) Implement this path for shared memory resources. |
| 972 DCHECK(!source->mailbox.IsSharedMemory()); | 1005 DCHECK(!source->mailbox.IsSharedMemory()); |
| 973 | 1006 |
| 974 if (!source->mailbox.IsTexture()) { | 1007 if (!source->mailbox.IsTexture()) { |
| 975 // This is a resource allocated by the compositor, we need to produce it. | 1008 // 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. | 1009 // Don't set a sync point, the caller will do it. |
| 977 DCHECK(source->gl_id); | 1010 DCHECK(source->gl_id); |
| 978 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); | 1011 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); |
| 979 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 1012 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 996 DCHECK(!resource->image_id); | 1029 DCHECK(!resource->image_id); |
| 997 | 1030 |
| 998 if (resource->type == GLTexture) { | 1031 if (resource->type == GLTexture) { |
| 999 WebGraphicsContext3D* context3d = Context3d(); | 1032 WebGraphicsContext3D* context3d = Context3d(); |
| 1000 DCHECK(context3d); | 1033 DCHECK(context3d); |
| 1001 if (!resource->gl_pixel_buffer_id) | 1034 if (!resource->gl_pixel_buffer_id) |
| 1002 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 1035 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
| 1003 context3d->bindBuffer( | 1036 context3d->bindBuffer( |
| 1004 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1037 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1005 resource->gl_pixel_buffer_id); | 1038 resource->gl_pixel_buffer_id); |
| 1039 size_t bytes_per_pixel = BytesPerPixel(resource->format); |
| 1006 context3d->bufferData( | 1040 context3d->bufferData( |
| 1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1041 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1008 4 * resource->size.GetArea(), | 1042 bytes_per_pixel * resource->size.GetArea(), |
| 1009 NULL, | 1043 NULL, |
| 1010 GL_DYNAMIC_DRAW); | 1044 GL_DYNAMIC_DRAW); |
| 1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1045 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1012 } | 1046 } |
| 1013 | 1047 |
| 1014 if (resource->pixels) { | 1048 if (resource->pixels) { |
| 1015 if (resource->pixel_buffer) | 1049 if (resource->pixel_buffer) |
| 1016 return; | 1050 return; |
| 1017 | 1051 |
| 1018 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1052 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); | 1203 DCHECK(resource->gl_pixel_buffer_id); |
| 1170 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1204 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1171 context3d->bindBuffer( | 1205 context3d->bindBuffer( |
| 1172 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1206 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1173 resource->gl_pixel_buffer_id); | 1207 resource->gl_pixel_buffer_id); |
| 1174 if (!resource->gl_upload_query_id) | 1208 if (!resource->gl_upload_query_id) |
| 1175 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1209 resource->gl_upload_query_id = context3d->createQueryEXT(); |
| 1176 context3d->beginQueryEXT( | 1210 context3d->beginQueryEXT( |
| 1177 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1211 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
| 1178 resource->gl_upload_query_id); | 1212 resource->gl_upload_query_id); |
| 1213 DCHECK(resource->format != RGBA_4444 || |
| 1214 (resource->size.width() % 2) == 0); |
| 1179 if (allocate) { | 1215 if (allocate) { |
| 1180 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1216 context3d->asyncTexImage2DCHROMIUM( |
| 1181 0, /* level */ | 1217 GL_TEXTURE_2D, |
| 1182 resource->format, | 1218 0, /* level */ |
| 1183 resource->size.width(), | 1219 GetGLInternalFormat(resource->format), |
| 1184 resource->size.height(), | 1220 resource->size.width(), |
| 1185 0, /* border */ | 1221 resource->size.height(), |
| 1186 resource->format, | 1222 0, /* border */ |
| 1187 GL_UNSIGNED_BYTE, | 1223 GetGLDataFormat(resource->format), |
| 1188 NULL); | 1224 GetGLDataType(resource->format), |
| 1225 NULL); |
| 1189 } else { | 1226 } else { |
| 1190 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1227 context3d->asyncTexSubImage2DCHROMIUM( |
| 1191 0, /* level */ | 1228 GL_TEXTURE_2D, |
| 1192 0, /* x */ | 1229 0, /* level */ |
| 1193 0, /* y */ | 1230 0, /* x */ |
| 1194 resource->size.width(), | 1231 0, /* y */ |
| 1195 resource->size.height(), | 1232 resource->size.width(), |
| 1196 resource->format, | 1233 resource->size.height(), |
| 1197 GL_UNSIGNED_BYTE, | 1234 GetGLDataFormat(resource->format), |
| 1198 NULL); | 1235 GetGLDataType(resource->format), |
| 1236 NULL); |
| 1199 } | 1237 } |
| 1200 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1238 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
| 1201 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1239 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1202 } | 1240 } |
| 1203 | 1241 |
| 1204 if (resource->pixels) { | 1242 if (resource->pixels) { |
| 1205 DCHECK(!resource->mailbox.IsValid()); | 1243 DCHECK(!resource->mailbox.IsValid()); |
| 1206 DCHECK(resource->pixel_buffer); | 1244 DCHECK(resource->pixel_buffer); |
| 1207 DCHECK(resource->format == GL_RGBA); | 1245 DCHECK_EQ(RGBA_8888, resource->format); |
| 1208 | 1246 |
| 1209 std::swap(resource->pixels, resource->pixel_buffer); | 1247 std::swap(resource->pixels, resource->pixel_buffer); |
| 1210 delete[] resource->pixel_buffer; | 1248 delete[] resource->pixel_buffer; |
| 1211 resource->pixel_buffer = NULL; | 1249 resource->pixel_buffer = NULL; |
| 1212 } | 1250 } |
| 1213 | 1251 |
| 1214 resource->pending_set_pixels = true; | 1252 resource->pending_set_pixels = true; |
| 1215 resource->set_pixels_completion_forced = false; | 1253 resource->set_pixels_completion_forced = false; |
| 1216 } | 1254 } |
| 1217 | 1255 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 void ResourceProvider::LazyAllocate(Resource* resource) { | 1341 void ResourceProvider::LazyAllocate(Resource* resource) { |
| 1304 DCHECK(resource); | 1342 DCHECK(resource); |
| 1305 LazyCreate(resource); | 1343 LazyCreate(resource); |
| 1306 | 1344 |
| 1307 DCHECK(resource->gl_id || resource->allocated); | 1345 DCHECK(resource->gl_id || resource->allocated); |
| 1308 if (resource->allocated || !resource->gl_id) | 1346 if (resource->allocated || !resource->gl_id) |
| 1309 return; | 1347 return; |
| 1310 resource->allocated = true; | 1348 resource->allocated = true; |
| 1311 WebGraphicsContext3D* context3d = Context3d(); | 1349 WebGraphicsContext3D* context3d = Context3d(); |
| 1312 gfx::Size& size = resource->size; | 1350 gfx::Size& size = resource->size; |
| 1313 GLenum format = resource->format; | 1351 ResourceFormat format = resource->format; |
| 1314 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1352 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 1315 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1353 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) { |
| 1316 GLenum storage_format = TextureToStorageFormat(format); | 1354 GLenum storage_format = TextureToStorageFormat(format); |
| 1317 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1355 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
| 1318 1, | 1356 1, |
| 1319 storage_format, | 1357 storage_format, |
| 1320 size.width(), | 1358 size.width(), |
| 1321 size.height())); | 1359 size.height())); |
| 1322 } else { | 1360 } else { |
| 1323 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1361 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
| 1324 0, | 1362 0, |
| 1325 format, | 1363 GetGLInternalFormat(format), |
| 1326 size.width(), | 1364 size.width(), |
| 1327 size.height(), | 1365 size.height(), |
| 1328 0, | 1366 0, |
| 1329 format, | 1367 GetGLDataFormat(format), |
| 1330 GL_UNSIGNED_BYTE, | 1368 GetGLDataType(format), |
| 1331 NULL)); | 1369 NULL)); |
| 1332 } | 1370 } |
| 1333 } | 1371 } |
| 1334 | 1372 |
| 1335 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1373 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
| 1336 bool enable) { | 1374 bool enable) { |
| 1337 Resource* resource = GetResource(id); | 1375 Resource* resource = GetResource(id); |
| 1338 resource->enable_read_lock_fences = enable; | 1376 resource->enable_read_lock_fences = enable; |
| 1339 } | 1377 } |
| 1340 | 1378 |
| 1341 void ResourceProvider::AcquireImage(ResourceId id) { | 1379 void ResourceProvider::AcquireImage(ResourceId id) { |
| 1342 Resource* resource = GetResource(id); | 1380 Resource* resource = GetResource(id); |
| 1343 DCHECK(!resource->external); | 1381 DCHECK(!resource->external); |
| 1344 DCHECK_EQ(resource->exported_count, 0); | 1382 DCHECK_EQ(resource->exported_count, 0); |
| 1345 | 1383 |
| 1346 if (resource->type != GLTexture) | 1384 if (resource->type != GLTexture) |
| 1347 return; | 1385 return; |
| 1348 | 1386 |
| 1349 if (resource->image_id) | 1387 if (resource->image_id) |
| 1350 return; | 1388 return; |
| 1351 | 1389 |
| 1352 resource->allocated = true; | 1390 resource->allocated = true; |
| 1353 WebGraphicsContext3D* context3d = Context3d(); | 1391 WebGraphicsContext3D* context3d = Context3d(); |
| 1354 DCHECK(context3d); | 1392 DCHECK(context3d); |
| 1355 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); | 1393 DCHECK_EQ(RGBA_8888, resource->format); |
| 1356 resource->image_id = context3d->createImageCHROMIUM( | 1394 resource->image_id = context3d->createImageCHROMIUM( |
| 1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | 1395 resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
| 1358 DCHECK(resource->image_id); | 1396 DCHECK(resource->image_id); |
| 1359 } | 1397 } |
| 1360 | 1398 |
| 1361 void ResourceProvider::ReleaseImage(ResourceId id) { | 1399 void ResourceProvider::ReleaseImage(ResourceId id) { |
| 1362 Resource* resource = GetResource(id); | 1400 Resource* resource = GetResource(id); |
| 1363 DCHECK(!resource->external); | 1401 DCHECK(!resource->external); |
| 1364 DCHECK_EQ(resource->exported_count, 0); | 1402 DCHECK_EQ(resource->exported_count, 0); |
| 1365 | 1403 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 GLint active_unit = 0; | 1463 GLint active_unit = 0; |
| 1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1464 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1427 return active_unit; | 1465 return active_unit; |
| 1428 } | 1466 } |
| 1429 | 1467 |
| 1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1468 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1431 ContextProvider* context_provider = output_surface_->context_provider(); | 1469 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1432 return context_provider ? context_provider->Context3d() : NULL; | 1470 return context_provider ? context_provider->Context3d() : NULL; |
| 1433 } | 1471 } |
| 1434 | 1472 |
| 1473 size_t ResourceProvider::BytesPerPixel(ResourceFormat format) { |
| 1474 size_t components_per_pixel = 0; |
| 1475 switch (format) { |
| 1476 case RGBA_8888: |
| 1477 case RGBA_4444: |
| 1478 case BGRA_8888: |
| 1479 components_per_pixel = 4; |
| 1480 break; |
| 1481 case LUMINANCE_8: |
| 1482 components_per_pixel = 1; |
| 1483 break; |
| 1484 } |
| 1485 size_t bits_per_component = 0; |
| 1486 switch (format) { |
| 1487 case RGBA_8888: |
| 1488 case BGRA_8888: |
| 1489 case LUMINANCE_8: |
| 1490 bits_per_component = 8; |
| 1491 break; |
| 1492 case RGBA_4444: |
| 1493 bits_per_component = 4; |
| 1494 break; |
| 1495 } |
| 1496 const size_t kBitsPerByte = 8; |
| 1497 return (components_per_pixel * bits_per_component) / kBitsPerByte; |
| 1498 } |
| 1499 |
| 1500 GLenum ResourceProvider::GetGLDataType(ResourceFormat format) { |
| 1501 switch (format) { |
| 1502 case RGBA_4444: |
| 1503 return GL_UNSIGNED_SHORT_4_4_4_4; |
| 1504 case RGBA_8888: |
| 1505 case BGRA_8888: |
| 1506 case LUMINANCE_8: |
| 1507 return GL_UNSIGNED_BYTE; |
| 1508 } |
| 1509 NOTREACHED(); |
| 1510 return GL_UNSIGNED_BYTE; |
| 1511 } |
| 1512 |
| 1513 GLenum ResourceProvider::GetGLDataFormat(ResourceFormat format) { |
| 1514 switch (format) { |
| 1515 case RGBA_8888: |
| 1516 case RGBA_4444: |
| 1517 return GL_RGBA; |
| 1518 case BGRA_8888: |
| 1519 return GL_BGRA_EXT; |
| 1520 case LUMINANCE_8: |
| 1521 return GL_LUMINANCE; |
| 1522 } |
| 1523 NOTREACHED(); |
| 1524 return GL_RGBA; |
| 1525 } |
| 1526 |
| 1527 GLenum ResourceProvider::GetGLInternalFormat(ResourceFormat format) { |
| 1528 return GetGLDataFormat(format); |
| 1529 } |
| 1530 |
| 1435 } // namespace cc | 1531 } // namespace cc |
| OLD | NEW |