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

Side by Side Diff: Source/modules/webgl/WebGLRenderingContextBase.h

Issue 1300573002: WebGL 2: add readPixels API to read pixels into pixel pack buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: move the new readPixels to WebGL 2 Created 5 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
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 struct FormatTypeCompare { 115 struct FormatTypeCompare {
116 bool operator() (const FormatType& lhs, const FormatType& rhs) const 116 bool operator() (const FormatType& lhs, const FormatType& rhs) const
117 { 117 {
118 return (lhs.internalformat < rhs.internalformat 118 return (lhs.internalformat < rhs.internalformat
119 || ((lhs.internalformat == rhs.internalformat) && (lhs.format < rhs. format)) 119 || ((lhs.internalformat == rhs.internalformat) && (lhs.format < rhs. format))
120 || ((lhs.internalformat == rhs.internalformat) && (lhs.format == rhs .format) && (lhs.type < rhs.type))); 120 || ((lhs.internalformat == rhs.internalformat) && (lhs.format == rhs .format) && (lhs.type < rhs.type)));
121 } 121 }
122 }; 122 };
123 123
124 // ScopedDrawingBufferBinder is used for ReadPixels/CopyTexImage2D/CopySubImage2 D to read from
125 // a multisampled DrawingBuffer. In this situation, we need to blit to a single sampled buffer
126 // for reading, during which the bindings could be changed and need to be recove red.
127 class ScopedDrawingBufferBinder {
yunchao 2015/08/18 05:40:16 I'd like to move ScopedDrawingBufferBinder from We
128 STACK_ALLOCATED();
129 public:
130 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, WebGLFramebuffer* fr amebufferBinding)
131 : m_drawingBuffer(drawingBuffer)
132 , m_readFramebufferBinding(framebufferBinding)
133 {
134 // Commit DrawingBuffer if needed (e.g., for multisampling)
135 if (!m_readFramebufferBinding && m_drawingBuffer)
136 m_drawingBuffer->commit();
137 }
138
139 ~ScopedDrawingBufferBinder()
140 {
141 // Restore DrawingBuffer if needed
142 if (!m_readFramebufferBinding && m_drawingBuffer)
143 m_drawingBuffer->restoreFramebufferBindings();
144 }
145
146 private:
147 DrawingBuffer* m_drawingBuffer;
148 Member<WebGLFramebuffer> m_readFramebufferBinding;
149 };
150
124 class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext, public Page::MultisamplingChangedObserver { 151 class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext, public Page::MultisamplingChangedObserver {
125 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebGLRenderingContextBase); 152 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebGLRenderingContextBase);
126 public: 153 public:
127 ~WebGLRenderingContextBase() override; 154 ~WebGLRenderingContextBase() override;
128 155
129 virtual unsigned version() const = 0; 156 virtual unsigned version() const = 0;
130 virtual String contextName() const = 0; 157 virtual String contextName() const = 0;
131 virtual void registerContextExtensions() = 0; 158 virtual void registerContextExtensions() = 0;
132 159
133 virtual void initializeNewContext(); 160 virtual void initializeNewContext();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 GLboolean isFramebuffer(WebGLFramebuffer*); 269 GLboolean isFramebuffer(WebGLFramebuffer*);
243 GLboolean isProgram(WebGLProgram*); 270 GLboolean isProgram(WebGLProgram*);
244 GLboolean isRenderbuffer(WebGLRenderbuffer*); 271 GLboolean isRenderbuffer(WebGLRenderbuffer*);
245 GLboolean isShader(WebGLShader*); 272 GLboolean isShader(WebGLShader*);
246 GLboolean isTexture(WebGLTexture*); 273 GLboolean isTexture(WebGLTexture*);
247 274
248 void lineWidth(GLfloat); 275 void lineWidth(GLfloat);
249 void linkProgram(WebGLProgram*); 276 void linkProgram(WebGLProgram*);
250 void pixelStorei(GLenum pname, GLint param); 277 void pixelStorei(GLenum pname, GLint param);
251 void polygonOffset(GLfloat factor, GLfloat units); 278 void polygonOffset(GLfloat factor, GLfloat units);
252 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum form at, GLenum type, DOMArrayBufferView* pixels); 279 virtual void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLe num format, GLenum type, DOMArrayBufferView* pixels);
253 void renderbufferStorage(GLenum target, GLenum internalformat, GLsizei width , GLsizei height); 280 void renderbufferStorage(GLenum target, GLenum internalformat, GLsizei width , GLsizei height);
254 void sampleCoverage(GLfloat value, GLboolean invert); 281 void sampleCoverage(GLfloat value, GLboolean invert);
255 void scissor(GLint x, GLint y, GLsizei width, GLsizei height); 282 void scissor(GLint x, GLint y, GLsizei width, GLsizei height);
256 void shaderSource(WebGLShader*, const String&); 283 void shaderSource(WebGLShader*, const String&);
257 void stencilFunc(GLenum func, GLint ref, GLuint mask); 284 void stencilFunc(GLenum func, GLint ref, GLuint mask);
258 void stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask); 285 void stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
259 void stencilMask(GLuint); 286 void stencilMask(GLuint);
260 void stencilMaskSeparate(GLenum face, GLuint mask); 287 void stencilMaskSeparate(GLenum face, GLuint mask);
261 void stencilOp(GLenum fail, GLenum zfail, GLenum zpass); 288 void stencilOp(GLenum fail, GLenum zfail, GLenum zpass);
262 void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) ; 289 void stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) ;
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 // Generates INVALID_ENUM and returns false if parameters are invalid. 841 // Generates INVALID_ENUM and returns false if parameters are invalid.
815 virtual bool validateReadPixelsFormatAndType(GLenum format, GLenum type); 842 virtual bool validateReadPixelsFormatAndType(GLenum format, GLenum type);
816 843
817 // Helper function to get expected ArrayBuffer view type for readPixels. 844 // Helper function to get expected ArrayBuffer view type for readPixels.
818 virtual DOMArrayBufferView::ViewType readPixelsExpectedArrayBufferViewType(G Lenum type); 845 virtual DOMArrayBufferView::ViewType readPixelsExpectedArrayBufferViewType(G Lenum type);
819 846
820 // Helper function to check format/type combination for readPixels. 847 // Helper function to check format/type combination for readPixels.
821 // Generates INVALID_OPERATION and returns false if the combination is unsup ported. 848 // Generates INVALID_OPERATION and returns false if the combination is unsup ported.
822 bool validateReadPixelsFormatTypeCombination(GLenum format, GLenum type, GLe num readBufferInternalFormat, GLenum readBufferType); 849 bool validateReadPixelsFormatTypeCombination(GLenum format, GLenum type, GLe num readBufferInternalFormat, GLenum readBufferType);
823 850
851 // Helper function to check parameters of readPixels. Returns true if all pa rameters
852 // are valid. Otherwise, generates appropriate error and returns false.
853 bool validateReadPixelsFuncParameters(GLsizei width, GLsizei height, GLenum format, GLenum type, unsigned domArrayBufferLength, WebGLFramebuffer*& readFrame bufferBinding);
854
855 // Helper function to readPixels in WebGLRenderingContext and WebGL2Renderin gContext
856 void readPixelsImpl(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* data, unsigned domArrayBufferLength);
Zhenyao Mo 2015/08/18 21:48:39 Just name it bufferSize, so it can cover the case
857
824 virtual GLint getMaxTextureLevelForTarget(GLenum target); 858 virtual GLint getMaxTextureLevelForTarget(GLenum target);
825 859
826 // Helper function to check input level for functions {copy}Tex{Sub}Image. 860 // Helper function to check input level for functions {copy}Tex{Sub}Image.
827 // Generates GL error and returns false if level is invalid. 861 // Generates GL error and returns false if level is invalid.
828 bool validateTexFuncLevel(const char* functionName, GLenum target, GLint lev el); 862 bool validateTexFuncLevel(const char* functionName, GLenum target, GLint lev el);
829 863
830 // Helper function to check if a 64-bit value is non-negative and can fit in to a 32-bit integer. 864 // Helper function to check if a 64-bit value is non-negative and can fit in to a 32-bit integer.
831 // Generates GL error and returns false if not. 865 // Generates GL error and returns false if not.
832 bool validateValueFitNonNegInt32(const char* functionName, const char* param Name, long long value); 866 bool validateValueFitNonNegInt32(const char* functionName, const char* param Name, long long value);
833 867
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 static IntSize oldestContextSize(); 1073 static IntSize oldestContextSize();
1040 }; 1074 };
1041 1075
1042 DEFINE_TYPE_CASTS(WebGLRenderingContextBase, CanvasRenderingContext, context, co ntext->is3d(), context.is3d()); 1076 DEFINE_TYPE_CASTS(WebGLRenderingContextBase, CanvasRenderingContext, context, co ntext->is3d(), context.is3d());
1043 1077
1044 } // namespace blink 1078 } // namespace blink
1045 1079
1046 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::WebGLRenderingContextB ase::TextureUnitState); 1080 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::WebGLRenderingContextB ase::TextureUnitState);
1047 1081
1048 #endif // WebGLRenderingContextBase_h 1082 #endif // WebGLRenderingContextBase_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698