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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 target(0), | 183 target(0), |
| 184 original_filter(0), | 184 original_filter(0), |
| 185 filter(0), | 185 filter(0), |
| 186 image_id(0), | 186 image_id(0), |
| 187 bound_image_id(0), | 187 bound_image_id(0), |
| 188 dirty_image(false), | 188 dirty_image(false), |
| 189 texture_pool(0), | 189 texture_pool(0), |
| 190 wrap_mode(0), | 190 wrap_mode(0), |
| 191 lost(false), | 191 lost(false), |
| 192 hint(TextureUsageAny), | 192 hint(TextureUsageAny), |
| 193 type(static_cast<ResourceType>(0)), | 193 type(InvalidType), |
| 194 format(RGBA_8888), | 194 format(RGBA_8888), |
| 195 shared_bitmap(NULL) {} | 195 shared_bitmap(NULL) {} |
| 196 | 196 |
| 197 ResourceProvider::Resource::~Resource() {} | 197 ResourceProvider::Resource::~Resource() {} |
| 198 | 198 |
| 199 ResourceProvider::Resource::Resource(GLuint texture_id, | 199 ResourceProvider::Resource::Resource(GLuint texture_id, |
| 200 gfx::Size size, | 200 gfx::Size size, |
| 201 Origin origin, | |
| 201 GLenum target, | 202 GLenum target, |
| 202 GLenum filter, | 203 GLenum filter, |
| 203 GLenum texture_pool, | 204 GLenum texture_pool, |
| 204 GLint wrap_mode, | 205 GLint wrap_mode, |
| 205 TextureUsageHint hint, | 206 TextureUsageHint hint, |
| 206 ResourceFormat format) | 207 ResourceFormat format) |
| 207 : child_id(0), | 208 : child_id(0), |
| 208 gl_id(texture_id), | 209 gl_id(texture_id), |
| 209 gl_pixel_buffer_id(0), | 210 gl_pixel_buffer_id(0), |
| 210 gl_upload_query_id(0), | 211 gl_upload_query_id(0), |
| 211 pixels(NULL), | 212 pixels(NULL), |
| 212 pixel_buffer(NULL), | 213 pixel_buffer(NULL), |
| 213 lock_for_read_count(0), | 214 lock_for_read_count(0), |
| 214 imported_count(0), | 215 imported_count(0), |
| 215 exported_count(0), | 216 exported_count(0), |
| 216 locked_for_write(false), | 217 locked_for_write(false), |
| 217 origin(Internal), | 218 origin(origin), |
| 218 marked_for_deletion(false), | 219 marked_for_deletion(false), |
| 219 pending_set_pixels(false), | 220 pending_set_pixels(false), |
| 220 set_pixels_completion_forced(false), | 221 set_pixels_completion_forced(false), |
| 221 allocated(false), | 222 allocated(false), |
| 222 enable_read_lock_fences(false), | 223 enable_read_lock_fences(false), |
| 223 read_lock_fence(NULL), | 224 read_lock_fence(NULL), |
| 224 size(size), | 225 size(size), |
| 225 target(target), | 226 target(target), |
| 226 original_filter(filter), | 227 original_filter(filter), |
| 227 filter(filter), | 228 filter(filter), |
| 228 image_id(0), | 229 image_id(0), |
| 229 bound_image_id(0), | 230 bound_image_id(0), |
| 230 dirty_image(false), | 231 dirty_image(false), |
| 231 texture_pool(texture_pool), | 232 texture_pool(texture_pool), |
| 232 wrap_mode(wrap_mode), | 233 wrap_mode(wrap_mode), |
| 233 lost(false), | 234 lost(false), |
| 234 hint(hint), | 235 hint(hint), |
| 235 type(GLTexture), | 236 type(GLTexture), |
| 236 format(format), | 237 format(format), |
| 237 shared_bitmap(NULL) { | 238 shared_bitmap(NULL) { |
| 238 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 239 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 240 DCHECK_EQ(origin == Internal, !!texture_pool); | |
| 239 } | 241 } |
| 240 | 242 |
| 241 ResourceProvider::Resource::Resource(uint8_t* pixels, | 243 ResourceProvider::Resource::Resource(uint8_t* pixels, |
| 242 SharedBitmap* bitmap, | 244 SharedBitmap* bitmap, |
| 243 gfx::Size size, | 245 gfx::Size size, |
| 246 Origin origin, | |
| 244 GLenum filter, | 247 GLenum filter, |
| 245 GLint wrap_mode) | 248 GLint wrap_mode) |
| 246 : child_id(0), | 249 : child_id(0), |
| 247 gl_id(0), | 250 gl_id(0), |
| 248 gl_pixel_buffer_id(0), | 251 gl_pixel_buffer_id(0), |
| 249 gl_upload_query_id(0), | 252 gl_upload_query_id(0), |
| 250 pixels(pixels), | 253 pixels(pixels), |
| 251 pixel_buffer(NULL), | 254 pixel_buffer(NULL), |
| 252 lock_for_read_count(0), | 255 lock_for_read_count(0), |
| 253 imported_count(0), | 256 imported_count(0), |
| 254 exported_count(0), | 257 exported_count(0), |
| 255 locked_for_write(false), | 258 locked_for_write(false), |
| 256 origin(Internal), | 259 origin(origin), |
| 257 marked_for_deletion(false), | 260 marked_for_deletion(false), |
| 258 pending_set_pixels(false), | 261 pending_set_pixels(false), |
| 259 set_pixels_completion_forced(false), | 262 set_pixels_completion_forced(false), |
| 260 allocated(false), | 263 allocated(false), |
| 261 enable_read_lock_fences(false), | 264 enable_read_lock_fences(false), |
| 262 read_lock_fence(NULL), | 265 read_lock_fence(NULL), |
| 263 size(size), | 266 size(size), |
| 264 target(0), | 267 target(0), |
| 265 original_filter(filter), | 268 original_filter(filter), |
| 266 filter(filter), | 269 filter(filter), |
| 267 image_id(0), | 270 image_id(0), |
| 268 bound_image_id(0), | 271 bound_image_id(0), |
| 269 dirty_image(false), | 272 dirty_image(false), |
| 270 texture_pool(0), | 273 texture_pool(0), |
| 271 wrap_mode(wrap_mode), | 274 wrap_mode(wrap_mode), |
| 272 lost(false), | 275 lost(false), |
| 273 hint(TextureUsageAny), | 276 hint(TextureUsageAny), |
| 274 type(Bitmap), | 277 type(Bitmap), |
| 275 format(RGBA_8888), | 278 format(RGBA_8888), |
| 276 shared_bitmap(bitmap) { | 279 shared_bitmap(bitmap) { |
| 277 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 280 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 281 DCHECK(pixels); | |
|
danakj
2014/01/30 21:50:31
Reviewing a software ubercomp CL (https://coderevi
dshwang
2014/01/31 17:25:34
I still think pixel is always non-null.
See below
| |
| 278 } | 282 } |
| 279 | 283 |
| 280 ResourceProvider::Child::Child() : marked_for_deletion(false) {} | 284 ResourceProvider::Child::Child() : marked_for_deletion(false) {} |
| 281 | 285 |
| 282 ResourceProvider::Child::~Child() {} | 286 ResourceProvider::Child::~Child() {} |
| 283 | 287 |
| 284 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 288 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| 285 OutputSurface* output_surface, | 289 OutputSurface* output_surface, |
| 286 SharedBitmapManager* shared_bitmap_manager, | 290 SharedBitmapManager* shared_bitmap_manager, |
| 287 int highp_threshold_min, | 291 int highp_threshold_min, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 GLenum target, | 389 GLenum target, |
| 386 GLenum texture_pool, | 390 GLenum texture_pool, |
| 387 GLint wrap_mode, | 391 GLint wrap_mode, |
| 388 TextureUsageHint hint, | 392 TextureUsageHint hint, |
| 389 ResourceFormat format) { | 393 ResourceFormat format) { |
| 390 DCHECK_LE(size.width(), max_texture_size_); | 394 DCHECK_LE(size.width(), max_texture_size_); |
| 391 DCHECK_LE(size.height(), max_texture_size_); | 395 DCHECK_LE(size.height(), max_texture_size_); |
| 392 DCHECK(thread_checker_.CalledOnValidThread()); | 396 DCHECK(thread_checker_.CalledOnValidThread()); |
| 393 | 397 |
| 394 ResourceId id = next_id_++; | 398 ResourceId id = next_id_++; |
| 395 Resource resource( | 399 Resource resource(0, |
| 396 0, size, target, GL_LINEAR, texture_pool, wrap_mode, hint, format); | 400 size, |
| 401 Resource::Internal, | |
| 402 target, | |
| 403 GL_LINEAR, | |
| 404 texture_pool, | |
| 405 wrap_mode, | |
| 406 hint, | |
| 407 format); | |
| 397 resource.allocated = false; | 408 resource.allocated = false; |
| 398 resources_[id] = resource; | 409 resources_[id] = resource; |
| 399 return id; | 410 return id; |
| 400 } | 411 } |
| 401 | 412 |
| 402 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( | 413 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( |
| 403 gfx::Size size, GLint wrap_mode) { | 414 gfx::Size size, GLint wrap_mode) { |
| 404 DCHECK(thread_checker_.CalledOnValidThread()); | 415 DCHECK(thread_checker_.CalledOnValidThread()); |
| 405 | 416 |
| 406 scoped_ptr<SharedBitmap> bitmap; | 417 scoped_ptr<SharedBitmap> bitmap; |
| 407 if (shared_bitmap_manager_) | 418 if (shared_bitmap_manager_) |
| 408 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); | 419 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); |
| 409 | 420 |
| 410 uint8_t* pixels; | 421 uint8_t* pixels; |
| 411 if (bitmap) | 422 if (bitmap) |
| 412 pixels = bitmap->pixels(); | 423 pixels = bitmap->pixels(); |
| 413 else | 424 else |
| 414 pixels = new uint8_t[4 * size.GetArea()]; | 425 pixels = new uint8_t[4 * size.GetArea()]; |
| 415 | 426 |
| 416 ResourceId id = next_id_++; | 427 ResourceId id = next_id_++; |
| 417 Resource resource( | 428 Resource resource( |
| 418 pixels, bitmap.release(), size, GL_LINEAR, wrap_mode); | 429 pixels, bitmap.release(), size, Resource::Internal, GL_LINEAR, wrap_mode); |
| 419 resource.allocated = true; | 430 resource.allocated = true; |
| 420 resources_[id] = resource; | 431 resources_[id] = resource; |
| 421 return id; | 432 return id; |
| 422 } | 433 } |
| 423 | 434 |
| 424 ResourceProvider::ResourceId | 435 ResourceProvider::ResourceId |
| 425 ResourceProvider::CreateResourceFromExternalTexture( | 436 ResourceProvider::CreateResourceFromExternalTexture( |
| 426 GLuint texture_target, | 437 GLuint texture_target, |
| 427 GLuint texture_id) { | 438 GLuint texture_id) { |
| 428 DCHECK(thread_checker_.CalledOnValidThread()); | 439 DCHECK(thread_checker_.CalledOnValidThread()); |
| 429 | 440 |
| 441 DCHECK(texture_target); | |
| 442 DCHECK(texture_id); | |
| 430 GLES2Interface* gl = ContextGL(); | 443 GLES2Interface* gl = ContextGL(); |
| 431 DCHECK(gl); | 444 DCHECK(gl); |
| 432 GLC(gl, gl->BindTexture(texture_target, texture_id)); | 445 GLC(gl, gl->BindTexture(texture_target, texture_id)); |
| 433 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 446 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 434 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 447 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 435 GLC(gl, | 448 GLC(gl, |
| 436 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 449 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 437 GLC(gl, | 450 GLC(gl, |
| 438 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 451 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 439 | 452 |
| 440 ResourceId id = next_id_++; | 453 ResourceId id = next_id_++; |
| 441 Resource resource(texture_id, | 454 Resource resource(texture_id, |
| 442 gfx::Size(), | 455 gfx::Size(), |
| 456 Resource::External, | |
| 443 texture_target, | 457 texture_target, |
| 444 GL_LINEAR, | 458 GL_LINEAR, |
| 445 0, | 459 0, |
| 446 GL_CLAMP_TO_EDGE, | 460 GL_CLAMP_TO_EDGE, |
| 447 TextureUsageAny, | 461 TextureUsageAny, |
| 448 RGBA_8888); | 462 RGBA_8888); |
| 449 resource.origin = Resource::External; | |
| 450 resource.allocated = true; | 463 resource.allocated = true; |
| 451 resources_[id] = resource; | 464 resources_[id] = resource; |
| 452 return id; | 465 return id; |
| 453 } | 466 } |
| 454 | 467 |
| 455 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 468 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 456 const TextureMailbox& mailbox, | 469 const TextureMailbox& mailbox, |
| 457 scoped_ptr<SingleReleaseCallback> release_callback) { | 470 scoped_ptr<SingleReleaseCallback> release_callback) { |
| 458 DCHECK(thread_checker_.CalledOnValidThread()); | 471 DCHECK(thread_checker_.CalledOnValidThread()); |
| 459 // Just store the information. Mailbox will be consumed in LockForRead(). | 472 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 460 ResourceId id = next_id_++; | 473 ResourceId id = next_id_++; |
| 461 DCHECK(mailbox.IsValid()); | 474 DCHECK(mailbox.IsValid()); |
| 462 Resource& resource = resources_[id]; | 475 Resource& resource = resources_[id]; |
| 463 if (mailbox.IsTexture()) { | 476 if (mailbox.IsTexture()) { |
| 464 resource = Resource(0, | 477 resource = Resource(0, |
| 465 gfx::Size(), | 478 gfx::Size(), |
| 479 Resource::External, | |
| 466 mailbox.target(), | 480 mailbox.target(), |
| 467 GL_LINEAR, | 481 GL_LINEAR, |
| 468 0, | 482 0, |
| 469 GL_CLAMP_TO_EDGE, | 483 GL_CLAMP_TO_EDGE, |
| 470 TextureUsageAny, | 484 TextureUsageAny, |
| 471 RGBA_8888); | 485 RGBA_8888); |
| 472 } else { | 486 } else { |
| 473 DCHECK(mailbox.IsSharedMemory()); | 487 DCHECK(mailbox.IsSharedMemory()); |
| 474 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 488 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
| 475 DCHECK(shared_memory->memory()); | 489 DCHECK(shared_memory->memory()); |
| 476 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 490 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
| 477 scoped_ptr<SharedBitmap> shared_bitmap; | 491 scoped_ptr<SharedBitmap> shared_bitmap; |
| 478 if (shared_bitmap_manager_) { | 492 if (shared_bitmap_manager_) { |
| 479 shared_bitmap = | 493 shared_bitmap = |
| 480 shared_bitmap_manager_->GetBitmapForSharedMemory(shared_memory); | 494 shared_bitmap_manager_->GetBitmapForSharedMemory(shared_memory); |
| 481 } | 495 } |
| 482 resource = Resource(pixels, | 496 resource = Resource(pixels, |
| 483 shared_bitmap.release(), | 497 shared_bitmap.release(), |
| 484 mailbox.shared_memory_size(), | 498 mailbox.shared_memory_size(), |
| 499 Resource::External, | |
| 485 GL_LINEAR, | 500 GL_LINEAR, |
| 486 GL_CLAMP_TO_EDGE); | 501 GL_CLAMP_TO_EDGE); |
| 487 } | 502 } |
| 488 resource.origin = Resource::External; | |
| 489 resource.allocated = true; | 503 resource.allocated = true; |
| 490 resource.mailbox = mailbox; | 504 resource.mailbox = mailbox; |
| 491 resource.release_callback = | 505 resource.release_callback = |
| 492 base::Bind(&SingleReleaseCallback::Run, | 506 base::Bind(&SingleReleaseCallback::Run, |
| 493 base::Owned(release_callback.release())); | 507 base::Owned(release_callback.release())); |
| 494 return id; | 508 return id; |
| 495 } | 509 } |
| 496 | 510 |
| 497 void ResourceProvider::DeleteResource(ResourceId id) { | 511 void ResourceProvider::DeleteResource(ResourceId id) { |
| 498 DCHECK(thread_checker_.CalledOnValidThread()); | 512 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); | 550 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); |
| 537 } | 551 } |
| 538 if (resource->gl_pixel_buffer_id) { | 552 if (resource->gl_pixel_buffer_id) { |
| 539 DCHECK(resource->origin == Resource::Internal); | 553 DCHECK(resource->origin == Resource::Internal); |
| 540 GLES2Interface* gl = ContextGL(); | 554 GLES2Interface* gl = ContextGL(); |
| 541 DCHECK(gl); | 555 DCHECK(gl); |
| 542 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); | 556 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); |
| 543 } | 557 } |
| 544 if (resource->mailbox.IsValid() && resource->origin == Resource::External) { | 558 if (resource->mailbox.IsValid() && resource->origin == Resource::External) { |
| 545 GLuint sync_point = resource->mailbox.sync_point(); | 559 GLuint sync_point = resource->mailbox.sync_point(); |
| 546 if (resource->mailbox.IsTexture()) { | 560 if (resource->type == GLTexture) { |
| 561 DCHECK(resource->mailbox.IsTexture()); | |
| 547 lost_resource |= lost_output_surface_; | 562 lost_resource |= lost_output_surface_; |
| 548 GLES2Interface* gl = ContextGL(); | 563 GLES2Interface* gl = ContextGL(); |
| 549 DCHECK(gl); | 564 DCHECK(gl); |
| 550 if (resource->gl_id) { | 565 if (resource->gl_id) { |
| 551 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); | 566 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
| 552 resource->gl_id = 0; | 567 resource->gl_id = 0; |
| 553 if (!lost_resource) | 568 if (!lost_resource) |
| 554 sync_point = gl->InsertSyncPointCHROMIUM(); | 569 sync_point = gl->InsertSyncPointCHROMIUM(); |
| 555 } | 570 } |
| 556 } else { | 571 } else { |
| 557 DCHECK(resource->mailbox.IsSharedMemory()); | 572 DCHECK(resource->mailbox.IsSharedMemory()); |
| 558 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); | 573 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); |
| 559 if (resource->pixels && shared_memory) { | 574 if (resource->pixels && shared_memory) { |
| 560 DCHECK(shared_memory->memory() == resource->pixels); | 575 DCHECK(shared_memory->memory() == resource->pixels); |
| 561 resource->pixels = NULL; | 576 resource->pixels = NULL; |
| 562 delete resource->shared_bitmap; | 577 delete resource->shared_bitmap; |
| 563 resource->shared_bitmap = NULL; | 578 resource->shared_bitmap = NULL; |
| 564 } | 579 } |
| 565 } | 580 } |
| 566 resource->release_callback.Run(sync_point, lost_resource); | 581 resource->release_callback.Run(sync_point, lost_resource); |
| 567 } | 582 } |
| 568 if (resource->gl_id && resource->origin != Resource::External) { | 583 if (resource->gl_id && resource->origin != Resource::External) { |
| 569 GLES2Interface* gl = ContextGL(); | 584 GLES2Interface* gl = ContextGL(); |
| 570 DCHECK(gl); | 585 DCHECK(gl); |
| 571 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); | 586 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
| 572 resource->gl_id = 0; | 587 resource->gl_id = 0; |
| 573 } | 588 } |
| 574 if (resource->shared_bitmap) { | 589 if (resource->shared_bitmap) { |
| 575 DCHECK(resource->origin != Resource::External); | 590 DCHECK(resource->origin != Resource::External); |
| 591 DCHECK_EQ(Bitmap, resource->type); | |
| 576 delete resource->shared_bitmap; | 592 delete resource->shared_bitmap; |
| 577 resource->pixels = NULL; | 593 resource->pixels = NULL; |
| 578 } | 594 } |
| 579 if (resource->pixels) { | 595 if (resource->pixels) { |
| 580 DCHECK(resource->origin == Resource::Internal); | 596 DCHECK(resource->origin == Resource::Internal); |
| 581 delete[] resource->pixels; | 597 delete[] resource->pixels; |
| 582 } | 598 } |
| 583 if (resource->pixel_buffer) { | 599 if (resource->pixel_buffer) { |
| 584 DCHECK(resource->origin == Resource::Internal); | 600 DCHECK(resource->origin == Resource::Internal); |
| 585 delete[] resource->pixel_buffer; | 601 delete[] resource->pixel_buffer; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 602 const gfx::Rect& source_rect, | 618 const gfx::Rect& source_rect, |
| 603 gfx::Vector2d dest_offset) { | 619 gfx::Vector2d dest_offset) { |
| 604 Resource* resource = GetResource(id); | 620 Resource* resource = GetResource(id); |
| 605 DCHECK(!resource->locked_for_write); | 621 DCHECK(!resource->locked_for_write); |
| 606 DCHECK(!resource->lock_for_read_count); | 622 DCHECK(!resource->lock_for_read_count); |
| 607 DCHECK(resource->origin == Resource::Internal); | 623 DCHECK(resource->origin == Resource::Internal); |
| 608 DCHECK_EQ(resource->exported_count, 0); | 624 DCHECK_EQ(resource->exported_count, 0); |
| 609 DCHECK(ReadLockFenceHasPassed(resource)); | 625 DCHECK(ReadLockFenceHasPassed(resource)); |
| 610 LazyAllocate(resource); | 626 LazyAllocate(resource); |
| 611 | 627 |
| 612 if (resource->gl_id) { | 628 if (resource->type == GLTexture) { |
| 629 DCHECK(resource->gl_id); | |
| 613 DCHECK(!resource->pending_set_pixels); | 630 DCHECK(!resource->pending_set_pixels); |
| 614 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 631 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 615 GLES2Interface* gl = ContextGL(); | 632 GLES2Interface* gl = ContextGL(); |
| 616 DCHECK(gl); | 633 DCHECK(gl); |
| 617 DCHECK(texture_uploader_.get()); | 634 DCHECK(texture_uploader_.get()); |
| 618 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 635 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 619 texture_uploader_->Upload(image, | 636 texture_uploader_->Upload(image, |
| 620 image_rect, | 637 image_rect, |
| 621 source_rect, | 638 source_rect, |
| 622 dest_offset, | 639 dest_offset, |
| 623 resource->format, | 640 resource->format, |
| 624 resource->size); | 641 resource->size); |
| 625 } | 642 } else { |
| 626 | 643 DCHECK_EQ(Bitmap, resource->type); |
| 627 if (resource->pixels) { | |
| 628 DCHECK(resource->allocated); | 644 DCHECK(resource->allocated); |
| 629 DCHECK_EQ(RGBA_8888, resource->format); | 645 DCHECK_EQ(RGBA_8888, resource->format); |
| 630 SkBitmap src_full; | 646 SkBitmap src_full; |
| 631 src_full.setConfig( | 647 src_full.setConfig( |
| 632 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); | 648 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); |
| 633 src_full.setPixels(const_cast<uint8_t*>(image)); | 649 src_full.setPixels(const_cast<uint8_t*>(image)); |
| 634 SkBitmap src_subset; | 650 SkBitmap src_subset; |
| 635 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), | 651 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), |
| 636 source_rect.y(), | 652 source_rect.y(), |
| 637 source_rect.width(), | 653 source_rect.width(), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 DCHECK(!resource->locked_for_write || | 756 DCHECK(!resource->locked_for_write || |
| 741 resource->set_pixels_completion_forced) << | 757 resource->set_pixels_completion_forced) << |
| 742 "locked for write: " << resource->locked_for_write << | 758 "locked for write: " << resource->locked_for_write << |
| 743 " pixels completion forced: " << resource->set_pixels_completion_forced; | 759 " pixels completion forced: " << resource->set_pixels_completion_forced; |
| 744 DCHECK_EQ(resource->exported_count, 0); | 760 DCHECK_EQ(resource->exported_count, 0); |
| 745 // Uninitialized! Call SetPixels or LockForWrite first. | 761 // Uninitialized! Call SetPixels or LockForWrite first. |
| 746 DCHECK(resource->allocated); | 762 DCHECK(resource->allocated); |
| 747 | 763 |
| 748 LazyCreate(resource); | 764 LazyCreate(resource); |
| 749 | 765 |
| 750 if (!resource->gl_id && resource->mailbox.IsTexture()) { | 766 if (resource->type == GLTexture && !resource->gl_id) { |
| 751 DCHECK(resource->origin != Resource::Internal); | 767 DCHECK(resource->origin != Resource::Internal); |
| 768 DCHECK(resource->mailbox.IsTexture()); | |
| 752 GLES2Interface* gl = ContextGL(); | 769 GLES2Interface* gl = ContextGL(); |
| 753 DCHECK(gl); | 770 DCHECK(gl); |
| 754 if (resource->mailbox.sync_point()) { | 771 if (resource->mailbox.sync_point()) { |
| 755 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); | 772 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); |
| 756 resource->mailbox.ResetSyncPoint(); | 773 resource->mailbox.ResetSyncPoint(); |
| 757 } | 774 } |
| 758 resource->gl_id = texture_id_allocator_->NextId(); | 775 resource->gl_id = texture_id_allocator_->NextId(); |
| 759 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); | 776 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); |
| 760 GLC(gl, | 777 GLC(gl, |
| 761 gl->ConsumeTextureCHROMIUM(resource->target, | 778 gl->ConsumeTextureCHROMIUM(resource->target, |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 scoped_ptr<SharedBitmap> bitmap; | 1086 scoped_ptr<SharedBitmap> bitmap; |
| 1070 uint8_t* pixels = NULL; | 1087 uint8_t* pixels = NULL; |
| 1071 if (it->is_software) { | 1088 if (it->is_software) { |
| 1072 if (shared_bitmap_manager_) | 1089 if (shared_bitmap_manager_) |
| 1073 bitmap = shared_bitmap_manager_->GetSharedBitmapFromId(it->size, | 1090 bitmap = shared_bitmap_manager_->GetSharedBitmapFromId(it->size, |
| 1074 it->mailbox); | 1091 it->mailbox); |
| 1075 if (bitmap) | 1092 if (bitmap) |
| 1076 pixels = bitmap->pixels(); | 1093 pixels = bitmap->pixels(); |
| 1077 } | 1094 } |
| 1078 | 1095 |
| 1079 if ((!it->is_software && !gl) || (it->is_software && !pixels)) { | 1096 if ((!it->is_software && !gl) || (it->is_software && !pixels)) { |
|
dshwang
2014/01/31 17:25:34
if pixels is null, the child returns early instead
danakj
2014/01/31 17:42:19
Oh, hm. I need to bring this up over there then. C
| |
| 1080 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); | 1097 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); |
| 1081 ReturnedResourceArray to_return; | 1098 ReturnedResourceArray to_return; |
| 1082 to_return.push_back(it->ToReturnedResource()); | 1099 to_return.push_back(it->ToReturnedResource()); |
| 1083 child_info.return_callback.Run(to_return); | 1100 child_info.return_callback.Run(to_return); |
| 1084 continue; | 1101 continue; |
| 1085 } | 1102 } |
| 1086 | 1103 |
| 1087 ResourceId local_id = next_id_++; | 1104 ResourceId local_id = next_id_++; |
| 1088 Resource& resource = resources_[local_id]; | 1105 Resource& resource = resources_[local_id]; |
| 1089 if (it->is_software) { | 1106 if (it->is_software) { |
| 1090 resource = Resource( | 1107 resource = Resource(pixels, |
| 1091 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE); | 1108 bitmap.release(), |
| 1109 it->size, | |
| 1110 Resource::Delegated, | |
| 1111 GL_LINEAR, | |
| 1112 GL_CLAMP_TO_EDGE); | |
| 1092 } else { | 1113 } else { |
| 1093 resource = Resource(0, | 1114 resource = Resource(0, |
| 1094 it->size, | 1115 it->size, |
| 1116 Resource::Delegated, | |
| 1095 it->target, | 1117 it->target, |
| 1096 it->filter, | 1118 it->filter, |
| 1097 0, | 1119 0, |
| 1098 GL_CLAMP_TO_EDGE, | 1120 GL_CLAMP_TO_EDGE, |
| 1099 TextureUsageAny, | 1121 TextureUsageAny, |
| 1100 it->format); | 1122 it->format); |
| 1101 resource.mailbox = | 1123 resource.mailbox = |
| 1102 TextureMailbox(it->mailbox, it->target, it->sync_point); | 1124 TextureMailbox(it->mailbox, it->target, it->sync_point); |
| 1103 } | 1125 } |
| 1104 resource.child_id = child; | 1126 resource.child_id = child; |
| 1105 resource.origin = Resource::Delegated; | |
| 1106 // Don't allocate a texture for a child. | 1127 // Don't allocate a texture for a child. |
| 1107 resource.allocated = true; | 1128 resource.allocated = true; |
| 1108 resource.imported_count = 1; | 1129 resource.imported_count = 1; |
| 1109 child_info.parent_to_child_map[local_id] = it->id; | 1130 child_info.parent_to_child_map[local_id] = it->id; |
| 1110 child_info.child_to_parent_map[it->id] = local_id; | 1131 child_info.child_to_parent_map[it->id] = local_id; |
| 1111 } | 1132 } |
| 1112 } | 1133 } |
| 1113 | 1134 |
| 1114 void ResourceProvider::DeclareUsedResourcesFromChild( | 1135 void ResourceProvider::DeclareUsedResourcesFromChild( |
| 1115 int child, | 1136 int child, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 source->origin == Resource::Delegated || | 1286 source->origin == Resource::Delegated || |
| 1266 (source->origin == Resource::External && source->mailbox.IsValid())); | 1287 (source->origin == Resource::External && source->mailbox.IsValid())); |
| 1267 DCHECK(source->allocated); | 1288 DCHECK(source->allocated); |
| 1268 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); | 1289 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); |
| 1269 resource->id = id; | 1290 resource->id = id; |
| 1270 resource->format = source->format; | 1291 resource->format = source->format; |
| 1271 resource->target = source->target; | 1292 resource->target = source->target; |
| 1272 resource->filter = source->filter; | 1293 resource->filter = source->filter; |
| 1273 resource->size = source->size; | 1294 resource->size = source->size; |
| 1274 | 1295 |
| 1275 if (source->shared_bitmap) { | 1296 if (source->type == Bitmap) { |
| 1297 // Currently, this routine is used by only unittests. | |
|
danakj
2014/01/30 21:50:31
I don't think you need this, we'll just have to re
dshwang
2014/01/31 17:25:34
indeed, i removed it.
| |
| 1276 resource->mailbox = source->shared_bitmap->id(); | 1298 resource->mailbox = source->shared_bitmap->id(); |
| 1277 resource->is_software = true; | 1299 resource->is_software = true; |
| 1278 } else if (!source->mailbox.IsValid()) { | 1300 } else if (!source->mailbox.IsValid()) { |
| 1279 LazyCreate(source); | 1301 LazyCreate(source); |
| 1280 DCHECK(source->gl_id); | 1302 DCHECK(source->gl_id); |
| 1281 DCHECK(source->origin == Resource::Internal); | 1303 DCHECK(source->origin == Resource::Internal); |
| 1282 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); | 1304 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); |
| 1283 if (source->image_id) { | 1305 if (source->image_id) { |
| 1284 DCHECK(source->dirty_image); | 1306 DCHECK(source->dirty_image); |
| 1285 BindImageForSampling(source); | 1307 BindImageForSampling(source); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1330 | 1352 |
| 1331 DCHECK(!resource.locked_for_write); | 1353 DCHECK(!resource.locked_for_write); |
| 1332 DCHECK(!resource.lock_for_read_count); | 1354 DCHECK(!resource.lock_for_read_count); |
| 1333 DCHECK_EQ(0u, child_info->in_use_resources.count(local_id)); | 1355 DCHECK_EQ(0u, child_info->in_use_resources.count(local_id)); |
| 1334 DCHECK(child_info->parent_to_child_map.count(local_id)); | 1356 DCHECK(child_info->parent_to_child_map.count(local_id)); |
| 1335 | 1357 |
| 1336 ResourceId child_id = child_info->parent_to_child_map[local_id]; | 1358 ResourceId child_id = child_info->parent_to_child_map[local_id]; |
| 1337 DCHECK(child_info->child_to_parent_map.count(child_id)); | 1359 DCHECK(child_info->child_to_parent_map.count(child_id)); |
| 1338 | 1360 |
| 1339 bool is_lost = | 1361 bool is_lost = |
| 1340 resource.lost || (!resource.shared_bitmap && lost_output_surface_); | 1362 resource.lost || |
| 1363 (resource.type == GLTexture && lost_output_surface_); | |
| 1341 if (resource.exported_count > 0) { | 1364 if (resource.exported_count > 0) { |
| 1342 if (style != ForShutdown) { | 1365 if (style != ForShutdown) { |
| 1343 // Defer this until we receive the resource back from the parent. | 1366 // Defer this until we receive the resource back from the parent. |
| 1344 resource.marked_for_deletion = true; | 1367 resource.marked_for_deletion = true; |
| 1345 continue; | 1368 continue; |
| 1346 } | 1369 } |
| 1347 | 1370 |
| 1348 // We still have an exported_count, so we'll have to lose it. | 1371 // We still have an exported_count, so we'll have to lose it. |
| 1349 is_lost = true; | 1372 is_lost = true; |
| 1350 } | 1373 } |
| 1351 | 1374 |
| 1352 if (gl && resource.filter != resource.original_filter) { | 1375 if (gl && resource.filter != resource.original_filter) { |
| 1353 DCHECK(resource.target); | 1376 DCHECK(resource.target); |
| 1354 DCHECK(resource.gl_id); | 1377 DCHECK(resource.gl_id); |
| 1355 | 1378 |
| 1356 GLC(gl, gl->BindTexture(resource.target, resource.gl_id)); | 1379 GLC(gl, gl->BindTexture(resource.target, resource.gl_id)); |
| 1357 GLC(gl, | 1380 GLC(gl, |
| 1358 gl->TexParameteri(resource.target, | 1381 gl->TexParameteri(resource.target, |
| 1359 GL_TEXTURE_MIN_FILTER, | 1382 GL_TEXTURE_MIN_FILTER, |
| 1360 resource.original_filter)); | 1383 resource.original_filter)); |
| 1361 GLC(gl, | 1384 GLC(gl, |
| 1362 gl->TexParameteri(resource.target, | 1385 gl->TexParameteri(resource.target, |
| 1363 GL_TEXTURE_MAG_FILTER, | 1386 GL_TEXTURE_MAG_FILTER, |
| 1364 resource.original_filter)); | 1387 resource.original_filter)); |
| 1365 } | 1388 } |
| 1366 | 1389 |
| 1367 ReturnedResource returned; | 1390 ReturnedResource returned; |
| 1368 returned.id = child_id; | 1391 returned.id = child_id; |
| 1369 returned.sync_point = resource.mailbox.sync_point(); | 1392 returned.sync_point = resource.mailbox.sync_point(); |
| 1370 if (!returned.sync_point && !resource.shared_bitmap) | 1393 if (!returned.sync_point && resource.type == GLTexture) |
| 1371 need_sync_point = true; | 1394 need_sync_point = true; |
| 1372 returned.count = resource.imported_count; | 1395 returned.count = resource.imported_count; |
| 1373 returned.lost = is_lost; | 1396 returned.lost = is_lost; |
| 1374 to_return.push_back(returned); | 1397 to_return.push_back(returned); |
| 1375 | 1398 |
| 1376 child_info->parent_to_child_map.erase(local_id); | 1399 child_info->parent_to_child_map.erase(local_id); |
| 1377 child_info->child_to_parent_map.erase(child_id); | 1400 child_info->child_to_parent_map.erase(child_id); |
| 1378 resource.imported_count = 0; | 1401 resource.imported_count = 0; |
| 1379 DeleteResourceInternal(it, style); | 1402 DeleteResourceInternal(it, style); |
| 1380 } | 1403 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1411 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); | 1434 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
| 1412 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1435 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1413 resource->gl_pixel_buffer_id); | 1436 resource->gl_pixel_buffer_id); |
| 1414 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; | 1437 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; |
| 1415 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1438 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1416 resource->size.height() * | 1439 resource->size.height() * |
| 1417 RoundUp(bytes_per_pixel * resource->size.width(), 4u), | 1440 RoundUp(bytes_per_pixel * resource->size.width(), 4u), |
| 1418 NULL, | 1441 NULL, |
| 1419 GL_DYNAMIC_DRAW); | 1442 GL_DYNAMIC_DRAW); |
| 1420 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1443 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1421 } | 1444 } else { |
| 1422 | 1445 DCHECK_EQ(Bitmap, resource->type); |
| 1423 if (resource->pixels) { | |
| 1424 if (resource->pixel_buffer) | 1446 if (resource->pixel_buffer) |
| 1425 return; | 1447 return; |
| 1426 | 1448 |
| 1427 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1449 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; |
| 1428 } | 1450 } |
| 1429 } | 1451 } |
| 1430 | 1452 |
| 1431 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 1453 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
| 1432 Resource* resource = GetResource(id); | 1454 Resource* resource = GetResource(id); |
| 1433 DCHECK(resource->origin == Resource::Internal); | 1455 DCHECK(resource->origin == Resource::Internal); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1449 if (resource->type == GLTexture) { | 1471 if (resource->type == GLTexture) { |
| 1450 if (!resource->gl_pixel_buffer_id) | 1472 if (!resource->gl_pixel_buffer_id) |
| 1451 return; | 1473 return; |
| 1452 GLES2Interface* gl = ContextGL(); | 1474 GLES2Interface* gl = ContextGL(); |
| 1453 DCHECK(gl); | 1475 DCHECK(gl); |
| 1454 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1476 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1455 resource->gl_pixel_buffer_id); | 1477 resource->gl_pixel_buffer_id); |
| 1456 gl->BufferData( | 1478 gl->BufferData( |
| 1457 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); | 1479 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); |
| 1458 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1480 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1459 } | 1481 } else { |
| 1460 | 1482 DCHECK_EQ(Bitmap, resource->type); |
| 1461 if (resource->pixels) { | |
| 1462 if (!resource->pixel_buffer) | 1483 if (!resource->pixel_buffer) |
| 1463 return; | 1484 return; |
| 1464 delete[] resource->pixel_buffer; | 1485 delete[] resource->pixel_buffer; |
| 1465 resource->pixel_buffer = NULL; | 1486 resource->pixel_buffer = NULL; |
| 1466 } | 1487 } |
| 1467 } | 1488 } |
| 1468 | 1489 |
| 1469 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { | 1490 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
| 1470 Resource* resource = GetResource(id); | 1491 Resource* resource = GetResource(id); |
| 1471 DCHECK(resource->origin == Resource::Internal); | 1492 DCHECK(resource->origin == Resource::Internal); |
| 1472 DCHECK_EQ(resource->exported_count, 0); | 1493 DCHECK_EQ(resource->exported_count, 0); |
| 1473 DCHECK(!resource->image_id); | 1494 DCHECK(!resource->image_id); |
| 1474 | 1495 |
| 1475 if (resource->type == GLTexture) { | 1496 if (resource->type == GLTexture) { |
| 1476 GLES2Interface* gl = ContextGL(); | 1497 GLES2Interface* gl = ContextGL(); |
| 1477 DCHECK(gl); | 1498 DCHECK(gl); |
| 1478 DCHECK(resource->gl_pixel_buffer_id); | 1499 DCHECK(resource->gl_pixel_buffer_id); |
| 1479 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1500 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1480 resource->gl_pixel_buffer_id); | 1501 resource->gl_pixel_buffer_id); |
| 1481 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( | 1502 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( |
| 1482 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 1503 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
| 1483 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1504 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1484 // Buffer is required to be 4-byte aligned. | 1505 // Buffer is required to be 4-byte aligned. |
| 1485 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); | 1506 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); |
| 1486 return image; | 1507 return image; |
| 1487 } | 1508 } |
| 1488 | 1509 DCHECK_EQ(Bitmap, resource->type); |
| 1489 if (resource->pixels) | 1510 return resource->pixel_buffer; |
| 1490 return resource->pixel_buffer; | |
| 1491 | |
| 1492 return NULL; | |
| 1493 } | 1511 } |
| 1494 | 1512 |
| 1495 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | 1513 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
| 1496 Resource* resource = GetResource(id); | 1514 Resource* resource = GetResource(id); |
| 1497 DCHECK(resource->origin == Resource::Internal); | 1515 DCHECK(resource->origin == Resource::Internal); |
| 1498 DCHECK_EQ(resource->exported_count, 0); | 1516 DCHECK_EQ(resource->exported_count, 0); |
| 1499 DCHECK(!resource->image_id); | 1517 DCHECK(!resource->image_id); |
| 1500 | 1518 |
| 1501 if (resource->type == GLTexture) { | 1519 if (resource->type == GLTexture) { |
| 1502 GLES2Interface* gl = ContextGL(); | 1520 GLES2Interface* gl = ContextGL(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1534 BindImageForSampling(resource); | 1552 BindImageForSampling(resource); |
| 1535 | 1553 |
| 1536 return target; | 1554 return target; |
| 1537 } | 1555 } |
| 1538 | 1556 |
| 1539 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1557 void ResourceProvider::BeginSetPixels(ResourceId id) { |
| 1540 Resource* resource = GetResource(id); | 1558 Resource* resource = GetResource(id); |
| 1541 DCHECK(!resource->pending_set_pixels); | 1559 DCHECK(!resource->pending_set_pixels); |
| 1542 | 1560 |
| 1543 LazyCreate(resource); | 1561 LazyCreate(resource); |
| 1562 DCHECK(resource->origin == Resource::Internal); | |
| 1544 DCHECK(resource->gl_id || resource->allocated); | 1563 DCHECK(resource->gl_id || resource->allocated); |
| 1545 DCHECK(ReadLockFenceHasPassed(resource)); | 1564 DCHECK(ReadLockFenceHasPassed(resource)); |
| 1546 DCHECK(!resource->image_id); | 1565 DCHECK(!resource->image_id); |
| 1547 | 1566 |
| 1548 bool allocate = !resource->allocated; | 1567 bool allocate = !resource->allocated; |
| 1549 resource->allocated = true; | 1568 resource->allocated = true; |
| 1550 LockForWrite(id); | 1569 LockForWrite(id); |
| 1551 | 1570 |
| 1552 if (resource->gl_id) { | 1571 if (resource->type == GLTexture) { |
| 1572 DCHECK(resource->gl_id); | |
| 1553 GLES2Interface* gl = ContextGL(); | 1573 GLES2Interface* gl = ContextGL(); |
| 1554 DCHECK(gl); | 1574 DCHECK(gl); |
| 1555 DCHECK(resource->gl_pixel_buffer_id); | 1575 DCHECK(resource->gl_pixel_buffer_id); |
| 1556 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 1576 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 1557 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 1577 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1558 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1578 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1559 resource->gl_pixel_buffer_id); | 1579 resource->gl_pixel_buffer_id); |
| 1560 if (!resource->gl_upload_query_id) | 1580 if (!resource->gl_upload_query_id) |
| 1561 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); | 1581 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); |
| 1562 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1582 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1577 0, /* x */ | 1597 0, /* x */ |
| 1578 0, /* y */ | 1598 0, /* y */ |
| 1579 resource->size.width(), | 1599 resource->size.width(), |
| 1580 resource->size.height(), | 1600 resource->size.height(), |
| 1581 GLDataFormat(resource->format), | 1601 GLDataFormat(resource->format), |
| 1582 GLDataType(resource->format), | 1602 GLDataType(resource->format), |
| 1583 NULL); | 1603 NULL); |
| 1584 } | 1604 } |
| 1585 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1605 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
| 1586 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1606 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1587 } | 1607 } else { |
| 1588 | 1608 DCHECK_EQ(Bitmap, resource->type); |
| 1589 if (resource->pixels) { | |
| 1590 DCHECK(!resource->mailbox.IsValid()); | 1609 DCHECK(!resource->mailbox.IsValid()); |
| 1591 DCHECK(resource->pixel_buffer); | 1610 DCHECK(resource->pixel_buffer); |
| 1592 DCHECK_EQ(RGBA_8888, resource->format); | 1611 DCHECK_EQ(RGBA_8888, resource->format); |
| 1593 | 1612 |
| 1594 std::swap(resource->pixels, resource->pixel_buffer); | 1613 std::swap(resource->pixels, resource->pixel_buffer); |
| 1595 delete[] resource->pixel_buffer; | 1614 delete[] resource->pixel_buffer; |
| 1596 resource->pixel_buffer = NULL; | 1615 resource->pixel_buffer = NULL; |
| 1597 } | 1616 } |
| 1598 | 1617 |
| 1599 resource->pending_set_pixels = true; | 1618 resource->pending_set_pixels = true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1641 void ResourceProvider::CreateForTesting(ResourceId id) { | 1660 void ResourceProvider::CreateForTesting(ResourceId id) { |
| 1642 LazyCreate(GetResource(id)); | 1661 LazyCreate(GetResource(id)); |
| 1643 } | 1662 } |
| 1644 | 1663 |
| 1645 GLenum ResourceProvider::TargetForTesting(ResourceId id) { | 1664 GLenum ResourceProvider::TargetForTesting(ResourceId id) { |
| 1646 Resource* resource = GetResource(id); | 1665 Resource* resource = GetResource(id); |
| 1647 return resource->target; | 1666 return resource->target; |
| 1648 } | 1667 } |
| 1649 | 1668 |
| 1650 void ResourceProvider::LazyCreate(Resource* resource) { | 1669 void ResourceProvider::LazyCreate(Resource* resource) { |
| 1651 if (resource->type != GLTexture || resource->gl_id != 0) | 1670 if (resource->type != GLTexture || resource->origin != Resource::Internal) |
| 1652 return; | 1671 return; |
| 1653 | 1672 |
| 1654 // Early out for resources that don't require texture creation. | 1673 if (resource->gl_id) |
| 1655 if (resource->texture_pool == 0) | |
| 1656 return; | 1674 return; |
| 1657 | 1675 |
| 1676 DCHECK(resource->texture_pool); | |
| 1658 DCHECK(resource->origin == Resource::Internal); | 1677 DCHECK(resource->origin == Resource::Internal); |
| 1659 DCHECK(!resource->mailbox.IsValid()); | 1678 DCHECK(!resource->mailbox.IsValid()); |
| 1660 resource->gl_id = texture_id_allocator_->NextId(); | 1679 resource->gl_id = texture_id_allocator_->NextId(); |
| 1661 | 1680 |
| 1662 GLES2Interface* gl = ContextGL(); | 1681 GLES2Interface* gl = ContextGL(); |
| 1663 DCHECK(gl); | 1682 DCHECK(gl); |
| 1664 | 1683 |
| 1665 // Create and set texture properties. Allocation is delayed until needed. | 1684 // Create and set texture properties. Allocation is delayed until needed. |
| 1666 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); | 1685 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); |
| 1667 GLC(gl, | 1686 GLC(gl, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1781 resource->dirty_image = false; | 1800 resource->dirty_image = false; |
| 1782 resource->allocated = false; | 1801 resource->allocated = false; |
| 1783 } | 1802 } |
| 1784 | 1803 |
| 1785 uint8_t* ResourceProvider::MapImage(ResourceId id) { | 1804 uint8_t* ResourceProvider::MapImage(ResourceId id) { |
| 1786 Resource* resource = GetResource(id); | 1805 Resource* resource = GetResource(id); |
| 1787 DCHECK(ReadLockFenceHasPassed(resource)); | 1806 DCHECK(ReadLockFenceHasPassed(resource)); |
| 1788 DCHECK(resource->origin == Resource::Internal); | 1807 DCHECK(resource->origin == Resource::Internal); |
| 1789 DCHECK_EQ(resource->exported_count, 0); | 1808 DCHECK_EQ(resource->exported_count, 0); |
| 1790 | 1809 |
| 1791 if (resource->image_id) { | 1810 if (resource->type == GLTexture) { |
| 1811 DCHECK(resource->image_id); | |
| 1792 GLES2Interface* gl = ContextGL(); | 1812 GLES2Interface* gl = ContextGL(); |
| 1793 DCHECK(gl); | 1813 DCHECK(gl); |
| 1794 return static_cast<uint8_t*>( | 1814 return static_cast<uint8_t*>( |
| 1795 gl->MapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); | 1815 gl->MapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); |
| 1796 } | 1816 } |
| 1797 | 1817 DCHECK_EQ(Bitmap, resource->type); |
| 1798 if (resource->pixels) | 1818 return resource->pixels; |
| 1799 return resource->pixels; | |
| 1800 | |
| 1801 return NULL; | |
| 1802 } | 1819 } |
| 1803 | 1820 |
| 1804 void ResourceProvider::UnmapImage(ResourceId id) { | 1821 void ResourceProvider::UnmapImage(ResourceId id) { |
| 1805 Resource* resource = GetResource(id); | 1822 Resource* resource = GetResource(id); |
| 1806 DCHECK(resource->origin == Resource::Internal); | 1823 DCHECK(resource->origin == Resource::Internal); |
| 1807 DCHECK_EQ(resource->exported_count, 0); | 1824 DCHECK_EQ(resource->exported_count, 0); |
| 1808 | 1825 |
| 1809 if (resource->image_id) { | 1826 if (resource->image_id) { |
| 1810 GLES2Interface* gl = ContextGL(); | 1827 GLES2Interface* gl = ContextGL(); |
| 1811 DCHECK(gl); | 1828 DCHECK(gl); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1863 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1847 return active_unit; | 1864 return active_unit; |
| 1848 } | 1865 } |
| 1849 | 1866 |
| 1850 GLES2Interface* ResourceProvider::ContextGL() const { | 1867 GLES2Interface* ResourceProvider::ContextGL() const { |
| 1851 ContextProvider* context_provider = output_surface_->context_provider(); | 1868 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1852 return context_provider ? context_provider->ContextGL() : NULL; | 1869 return context_provider ? context_provider->ContextGL() : NULL; |
| 1853 } | 1870 } |
| 1854 | 1871 |
| 1855 } // namespace cc | 1872 } // namespace cc |
| OLD | NEW |