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

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: fix in-process default framebuffer 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
« no previous file with comments | « webkit/gpu/webgraphicscontext3d_in_process_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, size_t bufferSize, WebGLId framebuffer,
592 if (bufferSize != static_cast<size_t>(4 * width() * height())) 592 int width, int height) {
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 // In this implementation fbo_, not 0, is the drawing buffer, so
605 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_); 606 // special-case that.
607 if (framebuffer == 0)
608 framebuffer = fbo_;
609
610 if (framebuffer == fbo_)
611 ResolveMultisampledFramebuffer(0, 0, width, height);
612 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
606 613
607 GLint pack_alignment = 4; 614 GLint pack_alignment = 4;
608 bool must_restore_pack_alignment = false; 615 bool must_restore_pack_alignment = false;
609 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment); 616 glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment);
610 if (pack_alignment > 4) { 617 if (pack_alignment > 4) {
611 glPixelStorei(GL_PACK_ALIGNMENT, 4); 618 glPixelStorei(GL_PACK_ALIGNMENT, 4);
612 must_restore_pack_alignment = true; 619 must_restore_pack_alignment = true;
613 } 620 }
614 621
615 if (is_gles2_) { 622 if (is_gles2_) {
616 // FIXME: consider testing for presence of GL_OES_read_format 623 // FIXME: consider testing for presence of GL_OES_read_format
617 // and GL_EXT_read_format_bgra, and using GL_BGRA_EXT here 624 // and GL_EXT_read_format_bgra, and using GL_BGRA_EXT here
618 // directly. 625 // directly.
619 glReadPixels(0, 0, cached_width_, cached_height_, 626 glReadPixels(0, 0, width, height,
620 GL_RGBA, GL_UNSIGNED_BYTE, pixels); 627 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
621 for (size_t i = 0; i < bufferSize; i += 4) { 628 for (size_t i = 0; i < bufferSize; i += 4) {
622 std::swap(pixels[i], pixels[i + 2]); 629 std::swap(pixels[i], pixels[i + 2]);
623 } 630 }
624 } else { 631 } else {
625 glReadPixels(0, 0, cached_width_, cached_height_, 632 glReadPixels(0, 0, width, height,
626 GL_BGRA, GL_UNSIGNED_BYTE, pixels); 633 GL_BGRA, GL_UNSIGNED_BYTE, pixels);
627 } 634 }
628 635
629 if (must_restore_pack_alignment) 636 if (must_restore_pack_alignment)
630 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); 637 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment);
631 638
632 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_); 639 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bound_fbo_);
633 640
634 #ifdef FLIP_FRAMEBUFFER_VERTICALLY 641 #ifdef FLIP_FRAMEBUFFER_VERTICALLY
635 if (pixels) 642 if (pixels)
636 FlipVertically(pixels, cached_width_, cached_height_); 643 FlipVertically(pixels, width, height);
637 #endif 644 #endif
638 645
639 return true; 646 return true;
640 } 647 }
641 648
649 bool WebGraphicsContext3DInProcessImpl::readBackFramebuffer(
650 unsigned char* pixels, size_t bufferSize) {
651 return readBackFramebuffer(pixels, bufferSize, fbo_, width(), height());
652 }
653
642 void WebGraphicsContext3DInProcessImpl::synthesizeGLError(WGC3Denum error) { 654 void WebGraphicsContext3DInProcessImpl::synthesizeGLError(WGC3Denum error) {
643 if (synthetic_errors_set_.find(error) == synthetic_errors_set_.end()) { 655 if (synthetic_errors_set_.find(error) == synthetic_errors_set_.end()) {
644 synthetic_errors_set_.insert(error); 656 synthetic_errors_set_.insert(error);
645 synthetic_errors_list_.push_back(error); 657 synthetic_errors_list_.push_back(error);
646 } 658 }
647 } 659 }
648 660
649 void* WebGraphicsContext3DInProcessImpl::mapBufferSubDataCHROMIUM( 661 void* WebGraphicsContext3DInProcessImpl::mapBufferSubDataCHROMIUM(
650 WGC3Denum target, WGC3Dintptr offset, 662 WGC3Denum target, WGC3Dintptr offset,
651 WGC3Dsizeiptr size, WGC3Denum access) { 663 WGC3Dsizeiptr size, WGC3Denum access) {
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 if (length > 1) { 1650 if (length > 1) {
1639 entry->translated_source.reset(new char[length]); 1651 entry->translated_source.reset(new char[length]);
1640 ShGetObjectCode(compiler, entry->translated_source.get()); 1652 ShGetObjectCode(compiler, entry->translated_source.get());
1641 } 1653 }
1642 entry->is_valid = true; 1654 entry->is_valid = true;
1643 return true; 1655 return true;
1644 } 1656 }
1645 1657
1646 } // namespace gpu 1658 } // namespace gpu
1647 } // namespace webkit 1659 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/gpu/webgraphicscontext3d_in_process_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698