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 <queue> | 7 #include <queue> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 : texture_(gl), framebuffer_(gl), size_(size) { | 51 : texture_(gl), framebuffer_(gl), size_(size) { |
52 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, texture_); | 52 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, texture_); |
53 gl->TexImage2D(GL_TEXTURE_2D, | 53 gl->TexImage2D(GL_TEXTURE_2D, |
54 0, | 54 0, |
55 GL_RGBA, | 55 GL_RGBA, |
56 size.width(), | 56 size.width(), |
57 size.height(), | 57 size.height(), |
58 0, | 58 0, |
59 GL_RGBA, | 59 GL_RGBA, |
60 GL_UNSIGNED_BYTE, | 60 GL_UNSIGNED_BYTE, |
61 NULL); | 61 nullptr); |
62 content::ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder( | 62 content::ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder( |
63 gl, framebuffer_); | 63 gl, framebuffer_); |
64 gl->FramebufferTexture2D( | 64 gl->FramebufferTexture2D( |
65 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_, 0); | 65 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_, 0); |
66 } | 66 } |
67 | 67 |
68 GLuint texture() const { return texture_.id(); } | 68 GLuint texture() const { return texture_.id(); } |
69 GLuint framebuffer() const { return framebuffer_.id(); } | 69 GLuint framebuffer() const { return framebuffer_.id(); } |
70 gfx::Size size() const { return size_; } | 70 gfx::Size size() const { return size_; } |
71 | 71 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 404 } |
405 | 405 |
406 gl_->TexImage2D(GL_TEXTURE_2D, | 406 gl_->TexImage2D(GL_TEXTURE_2D, |
407 0, | 407 0, |
408 format, | 408 format, |
409 dst_size.width(), | 409 dst_size.width(), |
410 dst_size.height(), | 410 dst_size.height(), |
411 0, | 411 0, |
412 format, | 412 format, |
413 type, | 413 type, |
414 NULL); | 414 nullptr); |
415 } | 415 } |
416 scoped_ptr<ScalerInterface> scaler( | 416 scoped_ptr<ScalerInterface> scaler( |
417 helper_->CreateScaler(quality, | 417 helper_->CreateScaler(quality, |
418 src_size, | 418 src_size, |
419 src_subrect, | 419 src_subrect, |
420 dst_size, | 420 dst_size, |
421 vertically_flip_texture, | 421 vertically_flip_texture, |
422 swizzle)); | 422 swizzle)); |
423 scaler->Scale(src_texture, dst_texture); | 423 scaler->Scale(src_texture, dst_texture); |
424 return dst_texture; | 424 return dst_texture; |
(...skipping 13 matching lines...) Expand all Loading... |
438 { | 438 { |
439 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 439 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
440 gl_->TexImage2D(GL_TEXTURE_2D, | 440 gl_->TexImage2D(GL_TEXTURE_2D, |
441 0, | 441 0, |
442 GL_RGBA, | 442 GL_RGBA, |
443 encoded_texture_size->width(), | 443 encoded_texture_size->width(), |
444 encoded_texture_size->height(), | 444 encoded_texture_size->height(), |
445 0, | 445 0, |
446 GL_RGBA, | 446 GL_RGBA, |
447 GL_UNSIGNED_BYTE, | 447 GL_UNSIGNED_BYTE, |
448 NULL); | 448 nullptr); |
449 } | 449 } |
450 | 450 |
451 helper_->InitScalerImpl(); | 451 helper_->InitScalerImpl(); |
452 scoped_ptr<ScalerInterface> grayscale_scaler( | 452 scoped_ptr<ScalerInterface> grayscale_scaler( |
453 helper_->scaler_impl_.get()->CreatePlanarScaler( | 453 helper_->scaler_impl_.get()->CreatePlanarScaler( |
454 src_size, | 454 src_size, |
455 gfx::Rect(0, 0, (src_size.width() + 3) & ~3, src_size.height()), | 455 gfx::Rect(0, 0, (src_size.width() + 3) & ~3, src_size.height()), |
456 *encoded_texture_size, | 456 *encoded_texture_size, |
457 vertically_flip_texture, | 457 vertically_flip_texture, |
458 swizzle, | 458 swizzle, |
(...skipping 14 matching lines...) Expand all Loading... |
473 TRACE_EVENT0("mirror", "GLHelper::CopyTextureToImpl::ReadbackAsync"); | 473 TRACE_EVENT0("mirror", "GLHelper::CopyTextureToImpl::ReadbackAsync"); |
474 Request* request = | 474 Request* request = |
475 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); | 475 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); |
476 request_queue_.push(request); | 476 request_queue_.push(request); |
477 request->buffer = 0u; | 477 request->buffer = 0u; |
478 | 478 |
479 gl_->GenBuffers(1, &request->buffer); | 479 gl_->GenBuffers(1, &request->buffer); |
480 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); | 480 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); |
481 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 481 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
482 bytes_per_pixel * dst_size.GetArea(), | 482 bytes_per_pixel * dst_size.GetArea(), |
483 NULL, | 483 nullptr, |
484 GL_STREAM_READ); | 484 GL_STREAM_READ); |
485 | 485 |
486 request->query = 0u; | 486 request->query = 0u; |
487 gl_->GenQueriesEXT(1, &request->query); | 487 gl_->GenQueriesEXT(1, &request->query); |
488 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, request->query); | 488 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, request->query); |
489 gl_->ReadPixels(0, | 489 gl_->ReadPixels(0, |
490 0, | 490 0, |
491 dst_size.width(), | 491 dst_size.width(), |
492 dst_size.height(), | 492 dst_size.height(), |
493 format, | 493 format, |
494 type, | 494 type, |
495 NULL); | 495 nullptr); |
496 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); | 496 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); |
497 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | 497 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
498 context_support_->SignalQuery( | 498 context_support_->SignalQuery( |
499 request->query, | 499 request->query, |
500 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), | 500 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), |
501 request, bytes_per_pixel)); | 501 request, bytes_per_pixel)); |
502 } | 502 } |
503 | 503 |
504 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( | 504 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( |
505 GLuint src_texture, | 505 GLuint src_texture, |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) { | 959 void GLHelper::ResizeTexture(GLuint texture, const gfx::Size& size) { |
960 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 960 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
961 gl_->TexImage2D(GL_TEXTURE_2D, | 961 gl_->TexImage2D(GL_TEXTURE_2D, |
962 0, | 962 0, |
963 GL_RGB, | 963 GL_RGB, |
964 size.width(), | 964 size.width(), |
965 size.height(), | 965 size.height(), |
966 0, | 966 0, |
967 GL_RGB, | 967 GL_RGB, |
968 GL_UNSIGNED_BYTE, | 968 GL_UNSIGNED_BYTE, |
969 NULL); | 969 nullptr); |
970 } | 970 } |
971 | 971 |
972 void GLHelper::CopyTextureSubImage(GLuint texture, const gfx::Rect& rect) { | 972 void GLHelper::CopyTextureSubImage(GLuint texture, const gfx::Rect& rect) { |
973 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 973 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
974 gl_->CopyTexSubImage2D(GL_TEXTURE_2D, | 974 gl_->CopyTexSubImage2D(GL_TEXTURE_2D, |
975 0, | 975 0, |
976 rect.x(), | 976 rect.x(), |
977 rect.y(), | 977 rect.y(), |
978 rect.x(), | 978 rect.x(), |
979 rect.y(), | 979 rect.y(), |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 | 1203 |
1204 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, uv_); | 1204 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl, uv_); |
1205 gl->TexImage2D(GL_TEXTURE_2D, | 1205 gl->TexImage2D(GL_TEXTURE_2D, |
1206 0, | 1206 0, |
1207 GL_RGBA, | 1207 GL_RGBA, |
1208 (dst_subrect.width() + 3) / 4, | 1208 (dst_subrect.width() + 3) / 4, |
1209 dst_subrect.height(), | 1209 dst_subrect.height(), |
1210 0, | 1210 0, |
1211 GL_RGBA, | 1211 GL_RGBA, |
1212 GL_UNSIGNED_BYTE, | 1212 GL_UNSIGNED_BYTE, |
1213 NULL); | 1213 nullptr); |
1214 | 1214 |
1215 DCHECK(!(dst_size.width() & 1)); | 1215 DCHECK(!(dst_size.width() & 1)); |
1216 DCHECK(!(dst_size.height() & 1)); | 1216 DCHECK(!(dst_size.height() & 1)); |
1217 DCHECK(!(dst_subrect.width() & 1)); | 1217 DCHECK(!(dst_subrect.width() & 1)); |
1218 DCHECK(!(dst_subrect.height() & 1)); | 1218 DCHECK(!(dst_subrect.height() & 1)); |
1219 DCHECK(!(dst_subrect.x() & 1)); | 1219 DCHECK(!(dst_subrect.x() & 1)); |
1220 DCHECK(!(dst_subrect.y() & 1)); | 1220 DCHECK(!(dst_subrect.y() & 1)); |
1221 } | 1221 } |
1222 | 1222 |
1223 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( | 1223 void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1354 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
1355 src_size, | 1355 src_size, |
1356 src_subrect, | 1356 src_subrect, |
1357 dst_size, | 1357 dst_size, |
1358 dst_subrect, | 1358 dst_subrect, |
1359 flip_vertically, | 1359 flip_vertically, |
1360 use_mrt); | 1360 use_mrt); |
1361 } | 1361 } |
1362 | 1362 |
1363 } // namespace content | 1363 } // namespace content |
OLD | NEW |