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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2602253002: Fixed WebglRenderingContextBase toImageData (Closed)
Patch Set: fix error Created 3 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #include "modules/webgl/WebGLUniformLocation.h" 85 #include "modules/webgl/WebGLUniformLocation.h"
86 #include "modules/webgl/WebGLVertexArrayObject.h" 86 #include "modules/webgl/WebGLVertexArrayObject.h"
87 #include "modules/webgl/WebGLVertexArrayObjectOES.h" 87 #include "modules/webgl/WebGLVertexArrayObjectOES.h"
88 #include "platform/CrossThreadFunctional.h" 88 #include "platform/CrossThreadFunctional.h"
89 #include "platform/RuntimeEnabledFeatures.h" 89 #include "platform/RuntimeEnabledFeatures.h"
90 #include "platform/WaitableEvent.h" 90 #include "platform/WaitableEvent.h"
91 #include "platform/geometry/IntSize.h" 91 #include "platform/geometry/IntSize.h"
92 #include "platform/graphics/GraphicsContext.h" 92 #include "platform/graphics/GraphicsContext.h"
93 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 93 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
94 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" 94 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h"
95 #include "platform/graphics/gpu/SharedGpuContext.h"
95 #include "public/platform/Platform.h" 96 #include "public/platform/Platform.h"
97 #include "skia/ext/texture_handle.h"
96 #include "wtf/CheckedNumeric.h" 98 #include "wtf/CheckedNumeric.h"
97 #include "wtf/Functional.h" 99 #include "wtf/Functional.h"
98 #include "wtf/PtrUtil.h" 100 #include "wtf/PtrUtil.h"
99 #include "wtf/text/StringBuilder.h" 101 #include "wtf/text/StringBuilder.h"
100 #include "wtf/text/StringUTF8Adaptor.h" 102 #include "wtf/text/StringUTF8Adaptor.h"
101 #include "wtf/typed_arrays/ArrayBufferContents.h" 103 #include "wtf/typed_arrays/ArrayBufferContents.h"
102 #include <memory> 104 #include <memory>
103 105
104 namespace blink { 106 namespace blink {
105 107
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 BackBuffer)) { 763 BackBuffer)) {
762 // copyRenderingResultsFromDrawingBuffer is expected to always succeed 764 // copyRenderingResultsFromDrawingBuffer is expected to always succeed
763 // because we've explicitly created an Accelerated surface and have already 765 // because we've explicitly created an Accelerated surface and have already
764 // validated it. 766 // validated it.
765 NOTREACHED(); 767 NOTREACHED();
766 return nullptr; 768 return nullptr;
767 } 769 }
768 return buffer->newImageSnapshot(hint, reason); 770 return buffer->newImageSnapshot(hint, reason);
769 } 771 }
770 772
771 ImageData* WebGLRenderingContextBase::toImageData(SnapshotReason reason) const { 773 ImageData* WebGLRenderingContextBase::toImageData(SnapshotReason reason) {
772 // TODO: Furnish toImageData in webgl renderingcontext for jpeg and webp
773 // images. See crbug.com/657531.
774 ImageData* imageData = nullptr; 774 ImageData* imageData = nullptr;
775 // TODO(ccameron): WebGL should produce sRGB images. 775 // TODO(ccameron): WebGL should produce sRGB images.
776 // https://crbug.com/672299 776 // https://crbug.com/672299
777 if (this->drawingBuffer()) { 777 if (drawingBuffer()) {
778 sk_sp<SkImage> snapshot = 778 // For un-premultiplied data
779 this->drawingBuffer() 779 imageData = paintRenderingResultsToImageData(BackBuffer);
780 ->transferToStaticBitmapImage() 780 if (imageData) {
781 ->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); 781 return imageData;
782 }
783
784 int width = drawingBuffer()->size().width();
785 int height = drawingBuffer()->size().height();
786 OpacityMode opacityMode = creationAttributes().alpha() ? NonOpaque : Opaque;
787
788 drawingBuffer()->resolveAndBindForReadAndDraw();
789 gpu::gles2::GLES2Interface* gl = SharedGpuContext::gl();
xlai (Olivia) 2017/01/02 22:50:04 This one works for both main and worker threads.
Ken Russell (switch to Gerrit) 2017/01/04 04:01:12 Acknowledged.
790 SkImageInfo imageInfo = SkImageInfo::Make(
791 width, height, kRGBA_8888_SkColorType,
792 Opaque == opacityMode ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
793 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry);
794 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(
795 SharedGpuContext::gr(), SkBudgeted::kYes, imageInfo, 0,
796 Opaque == opacityMode ? nullptr : &disableLCDProps);
797 GLuint textureId = skia::GrBackendObjectToGrGLTextureInfo(
798 surface->getTextureHandle(
799 SkSurface::kDiscardWrite_TextureHandleAccess))
800 ->fID;
801
802 drawingBuffer()->copyToPlatformTexture(
803 gl, textureId, GL_RGBA, GL_UNSIGNED_BYTE, 0, true, false,
804 IntPoint(0, 0), IntRect(IntPoint(0, 0), drawingBuffer()->size()),
805 BackBuffer);
806 sk_sp<SkImage> snapshot = surface->makeImageSnapshot();
782 if (snapshot) { 807 if (snapshot) {
783 imageData = ImageData::create(this->getOffscreenCanvas()->size()); 808 imageData = ImageData::create(drawingBuffer()->size());
784 SkImageInfo imageInfo = SkImageInfo::Make(
785 this->drawingBufferWidth(), this->drawingBufferHeight(),
786 kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
787 snapshot->readPixels(imageInfo, imageData->data()->data(), 809 snapshot->readPixels(imageInfo, imageData->data()->data(),
788 imageInfo.minRowBytes(), 0, 0); 810 imageInfo.minRowBytes(), 0, 0);
789 } 811 }
790 } 812 }
791 return imageData; 813 return imageData;
792 } 814 }
793 815
794 namespace { 816 namespace {
795 817
796 // Exposed by GL_ANGLE_depth_texture 818 // Exposed by GL_ANGLE_depth_texture
(...skipping 6977 matching lines...) Expand 10 before | Expand all | Expand 10 after
7774 7796
7775 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7797 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7776 HTMLCanvasElementOrOffscreenCanvas& result) const { 7798 HTMLCanvasElementOrOffscreenCanvas& result) const {
7777 if (canvas()) 7799 if (canvas())
7778 result.setHTMLCanvasElement(canvas()); 7800 result.setHTMLCanvasElement(canvas());
7779 else 7801 else
7780 result.setOffscreenCanvas(getOffscreenCanvas()); 7802 result.setOffscreenCanvas(getOffscreenCanvas());
7781 } 7803 }
7782 7804
7783 } // namespace blink 7805 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698