Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: webkit/gpu/webgraphicscontext3d_in_process_impl.cc

Issue 7566046: Add WebGraphicsContext support for readbacks from any framebuffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/gpu/webgraphicscontext3d_in_process_impl.h" 5 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 // user specifies the "premultiplyAlpha" flag in the context 581 // user specifies the "premultiplyAlpha" flag in the context
582 // creation attributes. 582 // creation attributes.
583 memcpy(scanline, row_b, row_bytes); 583 memcpy(scanline, row_b, row_bytes);
584 memcpy(row_b, row_a, row_bytes); 584 memcpy(row_b, row_a, row_bytes);
585 memcpy(row_a, scanline, row_bytes); 585 memcpy(row_a, scanline, row_bytes);
586 } 586 }
587 } 587 }
588 #endif 588 #endif
589 589
590 bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer( 590 bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
591 unsigned char* pixels, size_t bufferSize) { 591 unsigned char* pixels, int width, int height,
592 if (bufferSize != static_cast<size_t>(4 * width() * height())) 592 size_t bufferSize, WebGLId framebuffer) {
593 if (bufferSize != static_cast<size_t>(4 * width * height))
593 return false; 594 return false;
594 595
595 makeContextCurrent(); 596 makeContextCurrent();
596 597
597 // Earlier versions of this code used the GPU to flip the 598 // Earlier versions of this code used the GPU to flip the
598 // framebuffer vertically before reading it back for compositing 599 // framebuffer vertically before reading it back for compositing
599 // via software. This code was quite complicated, used a lot of 600 // via software. This code was quite complicated, used a lot of
600 // GPU memory, and didn't provide an obvious speedup. Since this 601 // GPU memory, and didn't provide an obvious speedup. Since this
601 // vertical flip is only a temporary solution anyway until Chrome 602 // vertical flip is only a temporary solution anyway until Chrome
602 // is fully GPU composited, it wasn't worth the complexity. 603 // is fully GPU composited, it wasn't worth the complexity.
603 604
604 ResolveMultisampledFramebuffer(0, 0, cached_width_, cached_height_); 605 if (framebuffer == fbo_)
605 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_); 606 ResolveMultisampledFramebuffer(0, 0, width, height);
607 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
606 608
607 GLint pack_alignment = 4; 609 GLint pack_alignment = 4;
608 bool must_restore_pack_alignment = false; 610 bool must_restore_pack_alignment = false;
609 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); 611 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment);
610 if (pack_alignment > 4) { 612 if (pack_alignment > 4) {
611 glPixelStorei(GL_PACK_ALIGNMENT, 4); 613 glPixelStorei(GL_PACK_ALIGNMENT, 4);
612 must_restore_pack_alignment = true; 614 must_restore_pack_alignment = true;
613 } 615 }
614 616
615 if (is_gles2_) { 617 if (is_gles2_) {
616 // FIXME: consider testing for presence of GL_OES_read_format 618 // FIXME: consider testing for presence of GL_OES_read_format
617 // and GL_EXT_read_format_bgra, and using GL_BGRA_EXT here 619 // and GL_EXT_read_format_bgra, and using GL_BGRA_EXT here
618 // directly. 620 // directly.
619 glReadPixels(0, 0, cached_width_, cached_height_, 621 glReadPixels(0, 0, width, height,
620 GL_RGBA, GL_UNSIGNED_BYTE, pixels); 622 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
621 for (size_t i = 0; i < bufferSize; i += 4) { 623 for (size_t i = 0; i < bufferSize; i += 4) {
622 std::swap(pixels[i], pixels[i + 2]); 624 std::swap(pixels[i], pixels[i + 2]);
623 } 625 }
624 } else { 626 } else {
625 glReadPixels(0, 0, cached_width_, cached_height_, 627 glReadPixels(0, 0, width, height,
626 GL_BGRA, GL_UNSIGNED_BYTE, pixels); 628 GL_BGRA, GL_UNSIGNED_BYTE, pixels);
627 } 629 }
628 630
629 if (must_restore_pack_alignment) 631 if (must_restore_pack_alignment)
630 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); 632 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment);
631 633
632 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); 634 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_);
633 635
634 #ifdef FLIP_FRAMEBUFFER_VERTICALLY 636 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
635 if (pixels) 637 if (pixels)
636 FlipVertically(pixels, cached_width_, cached_height_); 638 FlipVertically(pixels, width, height);
637 #endif 639 #endif
638 640
639 return true; 641 return true;
640 } 642 }
641 643
644 bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
645 unsigned char* pixels, size_t bufferSize) {
646 return readBackFramebuffer(pixels, width(), height(), bufferSize, fbo_);
647 }
648
642 void WebGraphicsContext3DInProcessImpl::synthesizeGLError(WGC3Denum error) { 649 void WebGraphicsContext3DInProcessImpl::synthesizeGLError(WGC3Denum error) {
643 if (synthetic_errors_set_.find(error) == synthetic_errors_set_.end()) { 650 if (synthetic_errors_set_.find(error) == synthetic_errors_set_.end()) {
644 synthetic_errors_set_.insert(error); 651 synthetic_errors_set_.insert(error);
645 synthetic_errors_list_.push_back(error); 652 synthetic_errors_list_.push_back(error);
646 } 653 }
647 } 654 }
648 655
649 void* WebGraphicsContext3DInProcessImpl::mapBufferSubDataCHROMIUM( 656 void* WebGraphicsContext3DInProcessImpl::mapBufferSubDataCHROMIUM(
650 WGC3Denum target, WGC3Dintptr offset, 657 WGC3Denum target, WGC3Dintptr offset,
651 WGC3Dsizeiptr size, WGC3Denum access) { 658 WGC3Dsizeiptr size, WGC3Denum access) {
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 if (length > 1) { 1645 if (length > 1) {
1639 entry->translated_source.reset(new char[length]); 1646 entry->translated_source.reset(new char[length]);
1640 ShGetObjectCode(compiler, entry->translated_source.get()); 1647 ShGetObjectCode(compiler, entry->translated_source.get());
1641 } 1648 }
1642 entry->is_valid = true; 1649 entry->is_valid = true;
1643 return true; 1650 return true;
1644 } 1651 }
1645 1652
1646 } // namespace gpu 1653 } // namespace gpu
1647 } // namespace webkit 1654 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698