Commit 11401539 authored by xidachen's avatar xidachen Committed by Commit bot

Pack repeated code in tex(Sub)Image2D and texSubImage3D into helper func

There are some repeated code in these functions and the only diff amongest
them is whether it gives "texImage2D" or "texSubImage2D" or "texSubImage3D".

This CL packs the repeated part into helper function. After this, when
we make changes to these functions in the future, we would only need to
change one place instead of 3 places. Also, this will reduce potential
bugs in the code. For example, at this moment, line 4131 in
WebGLRenderingContextBase.cpp (texImage2D) does this:
if (imageForRender && imageForRender->isSVGImage())

while line 1095 in WebGL2RenderingContextBase.cpp (texSubImage3D) does:
if (imageForRender->isSVGImage())
which doesn't do a null check on imageForRender.

This change can certainly prevent bugs like this.

For this change, we just need to make sure that all bots are green.

CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2025703002
Cr-Commit-Position: refs/heads/master@{#398286}
parent 22155739
......@@ -235,7 +235,6 @@ protected:
ScriptValue getInt64Parameter(ScriptState*, GLenum);
void texSubImage3DImpl(GLenum, GLint, GLint, GLint, GLint, GLenum, GLenum, Image*, WebGLImageConversion::ImageHtmlDomSource, bool, bool);
void samplerParameter(WebGLSampler*, GLenum, GLfloat, GLint, bool);
bool isBufferBoundToTransformFeedback(WebGLBuffer*);
......@@ -263,6 +262,7 @@ protected:
GLint getMaxTextureLevelForTarget(GLenum target) override;
void renderbufferStorageImpl(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, const char* functionName) override;
WebGLTexture* validateTexImageBinding(const char*, TexImageFunctionID, GLenum) override;
// Helper function to check texture 3D target and texture bound to the target.
// Generate GL errors and return 0 if target is invalid or texture bound is
// null. Otherwise, return the texture bound to the target.
......
......@@ -769,17 +769,18 @@ protected:
// Convert texture internal format.
GLenum convertTexInternalFormat(GLenum internalformat, GLenum type);
void texImage2DBase(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels);
void texImage2DImpl(GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type, Image*, WebGLImageConversion::ImageHtmlDomSource, bool flipY, bool premultiplyAlpha);
void texSubImage2DBase(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels);
void texSubImage2DImpl(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, Image*, WebGLImageConversion::ImageHtmlDomSource, bool flipY, bool premultiplyAlpha);
enum TexImageFunctionType {
TexImage,
TexSubImage,
CopyTexImage,
CompressedTexImage
};
enum TexImageFunctionID {
TexImage2D,
TexSubImage2D,
TexImage3D,
TexSubImage3D
};
enum TexImageByGPUType {
TexImage2DByGPU,
TexSubImage2DByGPU,
......@@ -789,6 +790,10 @@ protected:
Tex2D,
Tex3D
};
void texImage2DBase(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels);
void texImageImpl(TexImageFunctionID, GLenum target, GLint level, GLint internalformat, GLint xoffset, GLint yoffset, GLint zoffset,
GLenum format, GLenum type, Image*, WebGLImageConversion::ImageHtmlDomSource, bool flipY, bool premultiplyAlpha);
// Copy from the canvas element directly to the texture via the GPU, without a read-back to system memory.
void texImageCanvasByGPU(TexImageByGPUType, WebGLTexture*, GLenum target, GLint level,
GLint internalformat, GLenum type, GLint xoffset, GLint yoffset, GLint zoffset, HTMLCanvasElement*);
......@@ -819,6 +824,9 @@ protected:
// null. Otherwise, return the texture bound to the target.
WebGLTexture* validateTextureBinding(const char* functionName, GLenum target);
// Wrapper function for validateTexture2D(3D)Binding, used in texImageHelper functions.
virtual WebGLTexture* validateTexImageBinding(const char*, TexImageFunctionID, GLenum);
// Helper function to check texture 2D target and texture bound to the target.
// Generate GL errors and return 0 if target is invalid or texture bound is
// null. Otherwise, return the texture bound to the target.
......@@ -1088,6 +1096,16 @@ protected:
CrossThreadWeakPersistentThisPointer<WebGLRenderingContextBase> createWeakThisPointer() { return CrossThreadWeakPersistentThisPointer<WebGLRenderingContextBase>(this); }
ImageBitmap* transferToImageBitmapBase();
// Helper functions for tex(Sub)Image2D && texSubImage3D
void texImageHelperDOMArrayBufferView(TexImageFunctionID, GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, GLsizei, GLint, GLint, GLint, DOMArrayBufferView*);
void texImageHelperImageData(TexImageFunctionID, GLenum, GLint, GLint, GLint, GLenum, GLenum, GLsizei, GLint, GLint, GLint, ImageData*);
void texImageHelperHTMLImageElement(TexImageFunctionID, GLenum, GLint, GLint, GLenum, GLenum, GLint, GLint, GLint, HTMLImageElement*, ExceptionState&);
void texImageHelperHTMLCanvasElement(TexImageFunctionID, GLenum, GLint, GLint, GLenum, GLenum, GLint, GLint, GLint, HTMLCanvasElement*, ExceptionState&);
void texImageHelperHTMLVideoElement(TexImageFunctionID, GLenum, GLint, GLint, GLenum, GLenum, GLint, GLint, GLint, HTMLVideoElement*, ExceptionState&);
void texImageHelperImageBitmap(TexImageFunctionID, GLenum, GLint, GLint, GLenum, GLenum, GLint, GLint, GLint, ImageBitmap*, ExceptionState&);
static const char* getTexImageFunctionName(TexImageFunctionID);
private:
WebGLRenderingContextBase(HTMLCanvasElement*, OffscreenCanvas*, PassOwnPtr<WebGraphicsContext3DProvider>, const WebGLContextAttributes&);
static PassOwnPtr<WebGraphicsContext3DProvider> createContextProviderInternal(HTMLCanvasElement*, ScriptState*, WebGLContextAttributes, unsigned);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment