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

Unified Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2627793003: Make OffscreenCanvas Webgl Context work with preserveDrawingBuffer flag (Closed)
Patch Set: fix based on reviewer feedback 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
diff --git a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
index 8640a99c01c8f48c942bbb4828c555ca238d1aa8..3807e6db60af008c9ca66a598604ffff3475087a 100644
--- a/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
+++ b/third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp
@@ -749,10 +749,22 @@ ScriptPromise WebGLRenderingContextBase::commit(
if (!drawingBuffer()) {
return offscreenCanvas()->commit(nullptr, false, scriptState);
}
- // TODO(crbug.com/646864): Make commit() work correctly with
- // { preserveDrawingBuffer : true }.
+
+ RefPtr<StaticBitmapImage> image;
+ if (creationAttributes().preserveDrawingBuffer()) {
+ int width = drawingBuffer()->size().width();
+ int height = drawingBuffer()->size().height();
+ SkImageInfo imageInfo =
+ SkImageInfo::Make(width, height, kRGBA_8888_SkColorType,
+ creationAttributes().alpha() ? kPremul_SkAlphaType
+ : kOpaque_SkAlphaType);
+ image = StaticBitmapImage::create(makeImageSnapshot(imageInfo));
+ } else {
+ image = drawingBuffer()->transferToStaticBitmapImage();
+ }
+
return offscreenCanvas()->commit(
- std::move(drawingBuffer()->transferToStaticBitmapImage()),
+ std::move(image),
drawingBuffer()->contextProvider()->isSoftwareRendering(), scriptState);
}
@@ -782,6 +794,27 @@ PassRefPtr<Image> WebGLRenderingContextBase::getImage(
return buffer->newImageSnapshot(hint, reason);
}
+sk_sp<SkImage> WebGLRenderingContextBase::makeImageSnapshot(
+ SkImageInfo& imageInfo) {
+ drawingBuffer()->resolveAndBindForReadAndDraw();
+ gpu::gles2::GLES2Interface* gl = SharedGpuContext::gl();
+
+ SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry);
+ sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(
+ SharedGpuContext::gr(), SkBudgeted::kYes, imageInfo, 0,
+ imageInfo.alphaType() == kOpaque_SkAlphaType ? nullptr
+ : &disableLCDProps);
+ GLuint textureId = skia::GrBackendObjectToGrGLTextureInfo(
+ surface->getTextureHandle(
+ SkSurface::kDiscardWrite_TextureHandleAccess))
+ ->fID;
+
+ drawingBuffer()->copyToPlatformTexture(
+ gl, textureId, GL_RGBA, GL_UNSIGNED_BYTE, 0, true, false, IntPoint(0, 0),
+ IntRect(IntPoint(0, 0), drawingBuffer()->size()), BackBuffer);
+ return surface->makeImageSnapshot();
+}
+
ImageData* WebGLRenderingContextBase::toImageData(SnapshotReason reason) {
ImageData* imageData = nullptr;
// TODO(ccameron): WebGL should produce sRGB images.
@@ -795,27 +828,11 @@ ImageData* WebGLRenderingContextBase::toImageData(SnapshotReason reason) {
int width = drawingBuffer()->size().width();
int height = drawingBuffer()->size().height();
- OpacityMode opacityMode = creationAttributes().alpha() ? NonOpaque : Opaque;
-
- drawingBuffer()->resolveAndBindForReadAndDraw();
- gpu::gles2::GLES2Interface* gl = SharedGpuContext::gl();
- SkImageInfo imageInfo = SkImageInfo::Make(
- width, height, kRGBA_8888_SkColorType,
- Opaque == opacityMode ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
- SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry);
- sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(
- SharedGpuContext::gr(), SkBudgeted::kYes, imageInfo, 0,
- Opaque == opacityMode ? nullptr : &disableLCDProps);
- GLuint textureId = skia::GrBackendObjectToGrGLTextureInfo(
- surface->getTextureHandle(
- SkSurface::kDiscardWrite_TextureHandleAccess))
- ->fID;
-
- drawingBuffer()->copyToPlatformTexture(
- gl, textureId, GL_RGBA, GL_UNSIGNED_BYTE, 0, true, false,
- IntPoint(0, 0), IntRect(IntPoint(0, 0), drawingBuffer()->size()),
- BackBuffer);
- sk_sp<SkImage> snapshot = surface->makeImageSnapshot();
+ SkImageInfo imageInfo =
+ SkImageInfo::Make(width, height, kRGBA_8888_SkColorType,
+ creationAttributes().alpha() ? kPremul_SkAlphaType
+ : kOpaque_SkAlphaType);
+ sk_sp<SkImage> snapshot = makeImageSnapshot(imageInfo);
if (snapshot) {
imageData = ImageData::create(drawingBuffer()->size());
snapshot->readPixels(imageInfo, imageData->data()->data(),
@@ -4118,7 +4135,8 @@ void WebGLRenderingContextBase::readPixelsHelper(GLint x,
return;
// Due to WebGL's same-origin restrictions, it is not possible to
// taint the origin using the WebGL API.
- ASSERT(canvas()->originClean());
+ DCHECK(canvas() ? canvas()->originClean() : offscreenCanvas()->originClean());
+
// Validate input parameters.
if (!pixels) {
synthesizeGLError(GL_INVALID_VALUE, "readPixels",
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698