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

Side by Side Diff: Source/core/html/canvas/WebGLRenderingContextBase.cpp

Issue 805273005: WebGL: paintRenderingResultsToImageData() must restore FBO. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add layout test Created 5 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 499
500 ~ScopedTexture2DRestorer() 500 ~ScopedTexture2DRestorer()
501 { 501 {
502 m_context->restoreCurrentTexture2D(); 502 m_context->restoreCurrentTexture2D();
503 } 503 }
504 504
505 private: 505 private:
506 RawPtrWillBeMember<WebGLRenderingContextBase> m_context; 506 RawPtrWillBeMember<WebGLRenderingContextBase> m_context;
507 }; 507 };
508 508
509 class ScopedFramebufferRestorer {
510 STACK_ALLOCATED();
511 public:
512 explicit ScopedFramebufferRestorer(WebGLRenderingContextBase* context)
513 : m_context(context)
514 {
515 }
516
517 ~ScopedFramebufferRestorer()
518 {
519 m_context->restoreCurrentFramebuffer();
520 }
521
522 private:
523 RawPtrWillBeMember<WebGLRenderingContextBase> m_context;
524 };
525
509 class WebGLRenderingContextLostCallback final : public NoBaseWillBeGarbageCollec tedFinalized<WebGLRenderingContextLostCallback>, public blink::WebGraphicsContex t3D::WebGraphicsContextLostCallback { 526 class WebGLRenderingContextLostCallback final : public NoBaseWillBeGarbageCollec tedFinalized<WebGLRenderingContextLostCallback>, public blink::WebGraphicsContex t3D::WebGraphicsContextLostCallback {
510 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; 527 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
511 public: 528 public:
512 static PassOwnPtrWillBeRawPtr<WebGLRenderingContextLostCallback> create(WebG LRenderingContextBase* context) 529 static PassOwnPtrWillBeRawPtr<WebGLRenderingContextLostCallback> create(WebG LRenderingContextBase* context)
513 { 530 {
514 return adoptPtrWillBeNoop(new WebGLRenderingContextLostCallback(context) ); 531 return adoptPtrWillBeNoop(new WebGLRenderingContextLostCallback(context) );
515 } 532 }
516 533
517 virtual ~WebGLRenderingContextLostCallback() { } 534 virtual ~WebGLRenderingContextLostCallback() { }
518 535
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 return false; 923 return false;
907 924
908 bool mustClearNow = clearIfComposited() != Skipped; 925 bool mustClearNow = clearIfComposited() != Skipped;
909 if (!m_markedCanvasDirty && !mustClearNow) 926 if (!m_markedCanvasDirty && !mustClearNow)
910 return false; 927 return false;
911 928
912 canvas()->clearCopiedImage(); 929 canvas()->clearCopiedImage();
913 m_markedCanvasDirty = false; 930 m_markedCanvasDirty = false;
914 931
915 ScopedTexture2DRestorer restorer(this); 932 ScopedTexture2DRestorer restorer(this);
933 ScopedFramebufferRestorer fboRestorer(this);
916 934
917 drawingBuffer()->commit(); 935 drawingBuffer()->commit();
918 if (!canvas()->buffer()->copyRenderingResultsFromDrawingBuffer(drawingBuffer (), sourceBuffer)) { 936 if (!canvas()->buffer()->copyRenderingResultsFromDrawingBuffer(drawingBuffer (), sourceBuffer)) {
919 canvas()->ensureUnacceleratedImageBuffer(); 937 canvas()->ensureUnacceleratedImageBuffer();
920 if (canvas()->hasImageBuffer()) 938 if (canvas()->hasImageBuffer())
921 drawingBuffer()->paintRenderingResultsToCanvas(canvas()->buffer()); 939 drawingBuffer()->paintRenderingResultsToCanvas(canvas()->buffer());
922 } 940 }
923 941
924 restoreCurrentFramebuffer();
925 return true; 942 return true;
926 } 943 }
927 944
928 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul tsToImageData(SourceDrawingBuffer sourceBuffer) 945 PassRefPtrWillBeRawPtr<ImageData> WebGLRenderingContextBase::paintRenderingResul tsToImageData(SourceDrawingBuffer sourceBuffer)
929 { 946 {
930 if (isContextLost()) 947 if (isContextLost())
931 return nullptr; 948 return nullptr;
949 if (m_requestedAttributes.premultipliedAlpha())
950 return nullptr;
dshwang 2015/01/08 15:44:59 add optimization not to bind fbo unnecessary.
932 951
933 clearIfComposited(); 952 clearIfComposited();
934 drawingBuffer()->commit(); 953 drawingBuffer()->commit();
954 ScopedFramebufferRestorer restorer(this);
935 int width, height; 955 int width, height;
936 WTF::ArrayBufferContents contents; 956 WTF::ArrayBufferContents contents;
937 if (!drawingBuffer()->paintRenderingResultsToImageData(width, height, source Buffer, contents)) 957 if (!drawingBuffer()->paintRenderingResultsToImageData(width, height, source Buffer, contents))
938 return nullptr; 958 return nullptr;
939 RefPtr<DOMArrayBuffer> imageDataPixels = DOMArrayBuffer::create(contents); 959 RefPtr<DOMArrayBuffer> imageDataPixels = DOMArrayBuffer::create(contents);
940 960
941 return ImageData::create( 961 return ImageData::create(
942 IntSize(width, height), 962 IntSize(width, height),
943 DOMUint8ClampedArray::create(imageDataPixels, 0, imageDataPixels->byteLe ngth())); 963 DOMUint8ClampedArray::create(imageDataPixels, 0, imageDataPixels->byteLe ngth()));
944 } 964 }
(...skipping 5008 matching lines...) Expand 10 before | Expand all | Expand 10 after
5953 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB uffer() : 0; 5973 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB uffer() : 0;
5954 } 5974 }
5955 #else 5975 #else
5956 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 5976 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
5957 { 5977 {
5958 return m_drawingBuffer.get(); 5978 return m_drawingBuffer.get();
5959 } 5979 }
5960 #endif 5980 #endif
5961 5981
5962 } // namespace blink 5982 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/canvas/WebGLRenderingContextBase.h ('k') | Source/platform/graphics/gpu/DrawingBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698