Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/common/gpu/client/gl_helper.h" | 5 #include "content/common/gpu/client/gl_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 7 #include <queue> | 8 #include <queue> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 const gfx::Rect& src_subrect, | 172 const gfx::Rect& src_subrect, |
| 172 const gfx::Size& dst_size, | 173 const gfx::Size& dst_size, |
| 173 const gfx::Rect& dst_subrect, | 174 const gfx::Rect& dst_subrect, |
| 174 bool flip_vertically, | 175 bool flip_vertically, |
| 175 bool use_mrt); | 176 bool use_mrt); |
| 176 | 177 |
| 177 // Returns the maximum number of draw buffers available, | 178 // Returns the maximum number of draw buffers available, |
| 178 // 0 if GL_EXT_draw_buffers is not available. | 179 // 0 if GL_EXT_draw_buffers is not available. |
| 179 GLint MaxDrawBuffers() const { return max_draw_buffers_; } | 180 GLint MaxDrawBuffers() const { return max_draw_buffers_; } |
| 180 | 181 |
| 182 bool IsReadBackConfigSupported(SkBitmap::Config bitmap_config); | |
| 183 | |
| 181 private: | 184 private: |
| 182 // A single request to CropScaleReadbackAndCleanTexture. | 185 // A single request to CropScaleReadbackAndCleanTexture. |
| 183 // The main thread can cancel the request, before it's handled by the helper | 186 // The main thread can cancel the request, before it's handled by the helper |
| 184 // thread, by resetting the texture and pixels fields. Alternatively, the | 187 // thread, by resetting the texture and pixels fields. Alternatively, the |
| 185 // thread marks that it handles the request by resetting the pixels field | 188 // thread marks that it handles the request by resetting the pixels field |
| 186 // (meaning it guarantees that the callback with be called). | 189 // (meaning it guarantees that the callback with be called). |
| 187 // In either case, the callback must be called exactly once, and the texture | 190 // In either case, the callback must be called exactly once, and the texture |
| 188 // must be deleted by the main thread gl. | 191 // must be deleted by the main thread gl. |
| 189 struct Request { | 192 struct Request { |
| 190 Request(const gfx::Size& size_, | 193 Request(const gfx::Size& size_, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 swizzle); | 337 swizzle); |
| 335 } | 338 } |
| 336 | 339 |
| 337 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( | 340 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( |
| 338 GLuint src_texture, | 341 GLuint src_texture, |
| 339 const gfx::Size& src_size, | 342 const gfx::Size& src_size, |
| 340 const gfx::Rect& src_subrect, | 343 const gfx::Rect& src_subrect, |
| 341 const gfx::Size& dst_size, | 344 const gfx::Size& dst_size, |
| 342 bool vertically_flip_texture, | 345 bool vertically_flip_texture, |
| 343 bool swizzle, | 346 bool swizzle, |
| 344 SkBitmap::Config config, | 347 SkBitmap::Config bitmap_config, |
| 345 GLHelper::ScalerQuality quality) { | 348 GLHelper::ScalerQuality quality) { |
| 346 | 349 |
| 347 bool format_support = ((config == SkBitmap::kRGB_565_Config) || | 350 if (!IsReadBackConfigSupported(bitmap_config)) |
| 348 (config == SkBitmap::kARGB_8888_Config)); | |
| 349 if (!format_support) { | |
| 350 DCHECK(format_support); | |
| 351 return 0; | 351 return 0; |
| 352 } | 352 |
| 353 scoped_ptr<ScalerInterface> scaler( | 353 scoped_ptr<ScalerInterface> scaler( |
| 354 helper_->CreateScaler(quality, | 354 helper_->CreateScaler(quality, |
| 355 src_size, | 355 src_size, |
| 356 src_subrect, | 356 src_subrect, |
| 357 dst_size, | 357 dst_size, |
| 358 vertically_flip_texture, | 358 vertically_flip_texture, |
| 359 swizzle)); | 359 swizzle)); |
| 360 GLuint dst_texture = 0u; | 360 GLuint dst_texture = 0u; |
| 361 // Start with ARGB8888 params as any other format which is not | 361 // Start with ARGB8888 params as any other format which is not |
| 362 // supported is already asserted above. | 362 // supported is already asserted above. |
| 363 GLenum format = GL_RGBA , type = GL_UNSIGNED_BYTE; | 363 GLenum format = GL_RGBA , type = GL_UNSIGNED_BYTE; |
| 364 gl_->GenTextures(1, &dst_texture); | 364 gl_->GenTextures(1, &dst_texture); |
| 365 { | 365 { |
| 366 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 366 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
| 367 switch (config) { | 367 switch (bitmap_config) { |
| 368 case SkBitmap::kARGB_8888_Config: | 368 case SkBitmap::kARGB_8888_Config: |
| 369 // Do nothing params already set. | 369 // Do nothing params already set. |
| 370 break; | 370 break; |
| 371 case SkBitmap::kRGB_565_Config: | 371 case SkBitmap::kRGB_565_Config: |
| 372 format = GL_RGB; | 372 format = GL_RGB; |
| 373 type = GL_UNSIGNED_SHORT_5_6_5; | 373 type = GL_UNSIGNED_SHORT_5_6_5; |
| 374 break; | 374 break; |
| 375 default: | 375 default: |
| 376 NOTREACHED(); | 376 NOTREACHED(); |
| 377 break; | 377 break; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 388 } | 388 } |
| 389 scaler->Scale(src_texture, dst_texture); | 389 scaler->Scale(src_texture, dst_texture); |
| 390 return dst_texture; | 390 return dst_texture; |
| 391 } | 391 } |
| 392 | 392 |
| 393 void GLHelper::CopyTextureToImpl::ReadbackAsync( | 393 void GLHelper::CopyTextureToImpl::ReadbackAsync( |
| 394 const gfx::Size& dst_size, | 394 const gfx::Size& dst_size, |
| 395 int32 bytes_per_row, | 395 int32 bytes_per_row, |
| 396 int32 row_stride_bytes, | 396 int32 row_stride_bytes, |
| 397 unsigned char* out, | 397 unsigned char* out, |
| 398 const SkBitmap::Config config, | 398 const SkBitmap::Config bitmap_config, |
| 399 const base::Callback<void(bool)>& callback) { | 399 const base::Callback<void(bool)>& callback) { |
| 400 bool format_support = ((config == SkBitmap::kRGB_565_Config) || | 400 |
| 401 (config == SkBitmap::kARGB_8888_Config)); | 401 if (!IsReadBackConfigSupported(bitmap_config)) { |
|
no sievers
2014/02/18 19:35:44
See comment in ReadbackTextureAsync().
sivag
2014/02/19 15:49:04
Replied at ReadbackTextureAsync.
| |
| 402 if (!format_support) { | |
| 403 DCHECK(format_support); | |
| 404 callback.Run(false); | 402 callback.Run(false); |
| 405 return; | 403 return; |
| 406 } | 404 } |
| 407 Request* request = | 405 Request* request = |
| 408 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); | 406 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); |
| 409 request_queue_.push(request); | 407 request_queue_.push(request); |
| 410 request->buffer = 0u; | 408 request->buffer = 0u; |
| 411 // Start with ARGB8888 params as any other format which is not | 409 // Start with ARGB8888 params as any other format which is not |
| 412 // supported is already asserted above. | 410 // supported is already asserted above. |
| 413 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; | 411 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; |
| 414 int bytes_per_pixel = 4; | 412 int bytes_per_pixel = 4; |
| 415 | 413 |
| 416 switch (config) { | 414 switch (bitmap_config) { |
| 417 case SkBitmap::kARGB_8888_Config: | 415 case SkBitmap::kARGB_8888_Config: |
| 418 // Do nothing params already set. | 416 // Do nothing params already set. |
| 419 break; | 417 break; |
| 420 case SkBitmap::kRGB_565_Config: | 418 case SkBitmap::kRGB_565_Config: |
| 421 format = GL_RGB; | 419 format = GL_RGB; |
| 422 type = GL_UNSIGNED_SHORT_5_6_5; | 420 type = GL_UNSIGNED_SHORT_5_6_5; |
| 423 bytes_per_pixel = 2; | 421 bytes_per_pixel = 2; |
| 424 break; | 422 break; |
| 425 default: | 423 default: |
| 426 NOTREACHED(); | 424 NOTREACHED(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 452 } | 450 } |
| 453 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( | 451 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( |
| 454 GLuint src_texture, | 452 GLuint src_texture, |
| 455 const gfx::Size& src_size, | 453 const gfx::Size& src_size, |
| 456 const gfx::Rect& src_subrect, | 454 const gfx::Rect& src_subrect, |
| 457 const gfx::Size& dst_size, | 455 const gfx::Size& dst_size, |
| 458 unsigned char* out, | 456 unsigned char* out, |
| 459 const SkBitmap::Config bitmap_config, | 457 const SkBitmap::Config bitmap_config, |
| 460 const base::Callback<void(bool)>& callback, | 458 const base::Callback<void(bool)>& callback, |
| 461 GLHelper::ScalerQuality quality) { | 459 GLHelper::ScalerQuality quality) { |
| 462 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || | 460 |
| 463 (bitmap_config == SkBitmap::kARGB_8888_Config)); | 461 if (!IsReadBackConfigSupported(bitmap_config)) { |
| 464 if (!format_support) { | |
| 465 DCHECK(format_support); | |
| 466 callback.Run(false); | 462 callback.Run(false); |
| 467 return; | 463 return; |
| 468 } | 464 } |
| 469 GLuint texture = ScaleTexture(src_texture, | 465 GLuint texture = ScaleTexture(src_texture, |
| 470 src_size, | 466 src_size, |
| 471 src_subrect, | 467 src_subrect, |
| 472 dst_size, | 468 dst_size, |
| 473 true, | 469 true, |
| 474 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | 470 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT |
| 475 true, | 471 true, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 bitmap_config, | 503 bitmap_config, |
| 508 callback); | 504 callback); |
| 509 gl_->DeleteTextures(1, &texture); | 505 gl_->DeleteTextures(1, &texture); |
| 510 } | 506 } |
| 511 | 507 |
| 512 void GLHelper::CopyTextureToImpl::ReadbackTextureSync(GLuint texture, | 508 void GLHelper::CopyTextureToImpl::ReadbackTextureSync(GLuint texture, |
| 513 const gfx::Rect& src_rect, | 509 const gfx::Rect& src_rect, |
| 514 unsigned char* out, | 510 unsigned char* out, |
| 515 SkBitmap::Config config) { | 511 SkBitmap::Config config) { |
| 516 DCHECK((config == SkBitmap::kRGB_565_Config) || | 512 DCHECK((config == SkBitmap::kRGB_565_Config) || |
| 517 (config == SkBitmap::kARGB_8888_Config)); | 513 (config == SkBitmap::kARGB_8888_Config)); |
|
no sievers
2014/02/18 19:35:44
See comment below. The check here should be consis
sivag
2014/02/19 15:49:04
Done.
| |
| 518 ScopedFramebuffer dst_framebuffer(gl_); | 514 ScopedFramebuffer dst_framebuffer(gl_); |
| 519 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 515 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| 520 dst_framebuffer); | 516 dst_framebuffer); |
| 521 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 517 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 522 gl_->FramebufferTexture2D( | 518 gl_->FramebufferTexture2D( |
| 523 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); | 519 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 524 GLenum format = (config == SkBitmap::kRGB_565_Config) ? | 520 GLenum format = (config == SkBitmap::kRGB_565_Config) ? |
| 525 GL_RGB : | 521 GL_RGB : |
| 526 GL_RGBA; | 522 GL_RGBA; |
| 527 GLenum type = (config == SkBitmap::kRGB_565_Config) ? | 523 GLenum type = (config == SkBitmap::kRGB_565_Config) ? |
| 528 GL_UNSIGNED_SHORT_5_6_5 : | 524 GL_UNSIGNED_SHORT_5_6_5 : |
| 529 GL_UNSIGNED_BYTE; | 525 GL_UNSIGNED_BYTE; |
| 530 gl_->ReadPixels(src_rect.x(), | 526 gl_->ReadPixels(src_rect.x(), |
| 531 src_rect.y(), | 527 src_rect.y(), |
| 532 src_rect.width(), | 528 src_rect.width(), |
| 533 src_rect.height(), | 529 src_rect.height(), |
| 534 format, | 530 format, |
| 535 type, | 531 type, |
| 536 out); | 532 out); |
| 537 } | 533 } |
| 538 | 534 |
| 539 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( | 535 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( |
| 540 GLuint texture, | 536 GLuint texture, |
| 541 const gfx::Size& dst_size, | 537 const gfx::Size& dst_size, |
| 542 unsigned char* out, | 538 unsigned char* out, |
| 543 SkBitmap::Config config, | 539 SkBitmap::Config bitmap_config, |
| 544 const base::Callback<void(bool)>& callback) { | 540 const base::Callback<void(bool)>& callback) { |
| 545 // Only ARGB888 and RGB565 supported as of now. | 541 |
| 546 bool format_support = ((config == SkBitmap::kRGB_565_Config) || | 542 if (!IsReadBackConfigSupported(bitmap_config)) |
|
no sievers
2014/02/18 19:35:44
This check is actually not sufficient.
IsReadBackC
sivag
2014/02/19 15:49:04
I think then we should actually validate the textu
no sievers
2014/02/19 19:09:38
Sounds good. Feel free to try as a follow-up since
sivag
2014/02/21 11:40:50
When i checked , there is no such support in the a
| |
| 547 (config == SkBitmap::kARGB_8888_Config)); | |
| 548 if (!format_support) { | |
| 549 DCHECK(format_support); | |
| 550 return; | 543 return; |
| 551 } | 544 |
| 552 ScopedFramebuffer dst_framebuffer(gl_); | 545 ScopedFramebuffer dst_framebuffer(gl_); |
| 553 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 546 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| 554 dst_framebuffer); | 547 dst_framebuffer); |
| 555 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 548 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 556 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 549 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
| 557 GL_COLOR_ATTACHMENT0, | 550 GL_COLOR_ATTACHMENT0, |
| 558 GL_TEXTURE_2D, | 551 GL_TEXTURE_2D, |
| 559 texture, | 552 texture, |
| 560 0); | 553 0); |
| 561 int bytes_per_pixel = (config == SkBitmap::kRGB_565_Config) ? 2 : 4; | 554 int bytes_per_pixel = (bitmap_config == SkBitmap::kRGB_565_Config) ? 2 : 4; |
| 562 ReadbackAsync(dst_size, | 555 ReadbackAsync(dst_size, |
| 563 dst_size.width() * bytes_per_pixel, | 556 dst_size.width() * bytes_per_pixel, |
| 564 dst_size.width() * bytes_per_pixel, | 557 dst_size.width() * bytes_per_pixel, |
| 565 out, | 558 out, |
| 566 config, | 559 bitmap_config, |
| 567 callback); | 560 callback); |
| 568 } | 561 } |
| 569 | 562 |
| 570 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 563 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
| 571 GLuint src_texture, | 564 GLuint src_texture, |
| 572 const gfx::Size& src_size, | 565 const gfx::Size& src_size, |
| 573 const gfx::Size& dst_size, | 566 const gfx::Size& dst_size, |
| 574 bool vertically_flip_texture, | 567 bool vertically_flip_texture, |
| 575 GLHelper::ScalerQuality quality) { | 568 GLHelper::ScalerQuality quality) { |
| 576 return ScaleTexture(src_texture, | 569 return ScaleTexture(src_texture, |
| 577 src_size, | 570 src_size, |
| 578 gfx::Rect(src_size), | 571 gfx::Rect(src_size), |
| 579 dst_size, | 572 dst_size, |
| 580 vertically_flip_texture, | 573 vertically_flip_texture, |
| 581 false, | 574 false, |
| 582 SkBitmap::kARGB_8888_Config, | 575 SkBitmap::kARGB_8888_Config, |
| 583 quality); | 576 quality); |
| 584 } | 577 } |
| 585 | 578 |
| 579 bool GLHelper::CopyTextureToImpl::IsReadBackConfigSupported( | |
| 580 SkBitmap::Config bitmap_config) { | |
| 581 if(!helper_){ | |
|
piman
2014/02/18 22:23:15
nit: spaces
Try git cl format.
sivag
2014/02/19 15:49:04
Done.
| |
| 582 NOTREACHED(); | |
| 583 return false; | |
| 584 } | |
| 585 return helper_->IsReadBackConfigSupported(bitmap_config); | |
| 586 } | |
| 587 | |
| 586 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, | 588 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, |
| 587 int bytes_per_pixel) { | 589 int bytes_per_pixel) { |
| 588 TRACE_EVENT0("mirror", | 590 TRACE_EVENT0("mirror", |
| 589 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); | 591 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); |
| 590 finished_request->done = true; | 592 finished_request->done = true; |
| 591 | 593 |
| 592 // We process transfer requests in the order they were received, regardless | 594 // We process transfer requests in the order they were received, regardless |
| 593 // of the order we get the callbacks in. | 595 // of the order we get the callbacks in. |
| 594 while (!request_queue_.empty()) { | 596 while (!request_queue_.empty()) { |
| 595 Request* request = request_queue_.front(); | 597 Request* request = request_queue_.front(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 | 645 |
| 644 void GLHelper::CopyTextureToImpl::CancelRequests() { | 646 void GLHelper::CopyTextureToImpl::CancelRequests() { |
| 645 while (!request_queue_.empty()) { | 647 while (!request_queue_.empty()) { |
| 646 Request* request = request_queue_.front(); | 648 Request* request = request_queue_.front(); |
| 647 FinishRequest(request, false); | 649 FinishRequest(request, false); |
| 648 } | 650 } |
| 649 } | 651 } |
| 650 | 652 |
| 651 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) | 653 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) |
| 652 : gl_(gl), | 654 : gl_(gl), |
| 653 context_support_(context_support), | 655 context_support_(context_support) {} |
| 654 initialized_565_format_check_(false), | |
| 655 support_565_format_(false) {} | |
| 656 | 656 |
| 657 GLHelper::~GLHelper() {} | 657 GLHelper::~GLHelper() {} |
| 658 | 658 |
| 659 void GLHelper::CropScaleReadbackAndCleanTexture( | 659 void GLHelper::CropScaleReadbackAndCleanTexture( |
| 660 GLuint src_texture, | 660 GLuint src_texture, |
| 661 const gfx::Size& src_size, | 661 const gfx::Size& src_size, |
| 662 const gfx::Rect& src_subrect, | 662 const gfx::Rect& src_subrect, |
| 663 const gfx::Size& dst_size, | 663 const gfx::Size& dst_size, |
| 664 unsigned char* out, | 664 unsigned char* out, |
| 665 const SkBitmap::Config config, | 665 const SkBitmap::Config config, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 rect.width(), | 868 rect.width(), |
| 869 rect.height()); | 869 rect.height()); |
| 870 } | 870 } |
| 871 | 871 |
| 872 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { | 872 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { |
| 873 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 873 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 874 gl_->CopyTexImage2D( | 874 gl_->CopyTexImage2D( |
| 875 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0); | 875 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0); |
| 876 } | 876 } |
| 877 | 877 |
| 878 bool GLHelper::CanUseRgb565Readback() { | 878 bool GLHelper::SupportsFormat(GLint format, GLint type) { |
| 879 if(initialized_565_format_check_){ | |
| 880 return support_565_format_; | |
| 881 } | |
| 882 const int kTestSize = 64; | 879 const int kTestSize = 64; |
| 883 GLuint dst_texture = 0u; | 880 GLuint dst_texture = 0u; |
| 881 bool supports_format = false; | |
| 884 gl_->GenTextures(1, &dst_texture); | 882 gl_->GenTextures(1, &dst_texture); |
| 885 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 883 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
| 886 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 884 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 887 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 885 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 888 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 886 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 889 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 887 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 890 gl_->TexImage2D(GL_TEXTURE_2D, | 888 gl_->TexImage2D(GL_TEXTURE_2D, |
| 891 0, | 889 0, |
| 892 GL_RGB, | 890 format, |
| 893 kTestSize, | 891 kTestSize, |
| 894 kTestSize, | 892 kTestSize, |
| 895 0, | 893 0, |
| 896 GL_RGB, | 894 format, |
| 897 GL_UNSIGNED_SHORT_5_6_5, | 895 type, |
| 898 NULL); | 896 NULL); |
| 899 ScopedFramebuffer dst_framebuffer(gl_); | 897 ScopedFramebuffer dst_framebuffer(gl_); |
| 900 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 898 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| 901 dst_framebuffer); | 899 dst_framebuffer); |
| 902 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 900 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
| 903 GL_COLOR_ATTACHMENT0, | 901 GL_COLOR_ATTACHMENT0, |
| 904 GL_TEXTURE_2D, | 902 GL_TEXTURE_2D, |
| 905 dst_texture, | 903 dst_texture, |
| 906 0); | 904 0); |
| 907 GLint ext_format = 0, ext_type = 0; | 905 GLint ext_format = 0, ext_type = 0; |
| 908 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); | 906 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); |
| 909 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); | 907 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); |
| 910 gl_->DeleteTextures(1, &dst_texture); | 908 gl_->DeleteTextures(1, &dst_texture); |
| 911 if ((ext_format == GL_RGB) && (ext_type == GL_UNSIGNED_SHORT_5_6_5)) { | 909 if ((ext_format == format) && (ext_type == type)) { |
| 912 support_565_format_ = true; | 910 supports_format = true; |
| 913 } | 911 } |
| 914 initialized_565_format_check_ = true; | 912 return supports_format; |
| 915 return support_565_format_; | 913 } |
| 914 | |
| 915 bool GLHelper::IsReadBackConfigSupported( | |
| 916 const SkBitmap::Config& texture_format) { | |
|
no sievers
2014/02/18 19:35:44
nit: bitmap_format
sivag
2014/02/19 15:49:04
Done.
| |
| 917 | |
| 918 std::map<SkBitmap::Config, bool>::iterator find_format = | |
| 919 config_map_.find(texture_format); | |
| 920 if (find_format != config_map_.end()) | |
| 921 return find_format->second; | |
| 922 | |
| 923 switch (texture_format) { | |
| 924 case SkBitmap::kRGB_565_Config: | |
| 925 return config_map_[texture_format] = SupportsFormat(GL_RGB, | |
| 926 GL_UNSIGNED_SHORT_5_6_5); | |
|
no sievers
2014/02/18 19:35:44
nit: indent
sivag
2014/02/19 15:49:04
Done.
| |
| 927 | |
| 928 case SkBitmap::kARGB_8888_Config: | |
| 929 return config_map_[texture_format] = SupportsFormat(GL_RGBA, | |
| 930 GL_UNSIGNED_BYTE); | |
| 931 case SkBitmap::kA8_Config: | |
| 932 case SkBitmap::kARGB_4444_Config: | |
| 933 default: | |
| 934 NOTREACHED(); | |
| 935 return config_map_[texture_format] = false; | |
| 936 } | |
| 916 } | 937 } |
| 917 | 938 |
| 918 void GLHelper::CopyTextureToImpl::ReadbackPlane( | 939 void GLHelper::CopyTextureToImpl::ReadbackPlane( |
| 919 TextureFrameBufferPair* source, | 940 TextureFrameBufferPair* source, |
| 920 const scoped_refptr<media::VideoFrame>& target, | 941 const scoped_refptr<media::VideoFrame>& target, |
| 921 int plane, | 942 int plane, |
| 922 int size_shift, | 943 int size_shift, |
| 923 const gfx::Rect& dst_subrect, | 944 const gfx::Rect& dst_subrect, |
| 924 const base::Callback<void(bool)>& callback) { | 945 const base::Callback<void(bool)>& callback) { |
| 925 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); | 946 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1233 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1254 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
| 1234 src_size, | 1255 src_size, |
| 1235 src_subrect, | 1256 src_subrect, |
| 1236 dst_size, | 1257 dst_size, |
| 1237 dst_subrect, | 1258 dst_subrect, |
| 1238 flip_vertically, | 1259 flip_vertically, |
| 1239 use_mrt); | 1260 use_mrt); |
| 1240 } | 1261 } |
| 1241 | 1262 |
| 1242 } // namespace content | 1263 } // namespace content |
| OLD | NEW |