| OLD | NEW |
| 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 4054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4065 bool possibleDirectCopy = false; | 4065 bool possibleDirectCopy = false; |
| 4066 if (functionType == TexImage2DByGPU) { | 4066 if (functionType == TexImage2DByGPU) { |
| 4067 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target,
internalformat, type, level); | 4067 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target,
internalformat, type, level); |
| 4068 } | 4068 } |
| 4069 | 4069 |
| 4070 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. | 4070 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. |
| 4071 if (!possibleDirectCopy) { | 4071 if (!possibleDirectCopy) { |
| 4072 targetLevel = 0; | 4072 targetLevel = 0; |
| 4073 targetInternalformat = GL_RGBA; | 4073 targetInternalformat = GL_RGBA; |
| 4074 targetType = GL_UNSIGNED_BYTE; | 4074 targetType = GL_UNSIGNED_BYTE; |
| 4075 targetTexture = webContext()->createTexture(); | 4075 contextGL()->GenTextures(1, &targetTexture); |
| 4076 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); | 4076 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); |
| 4077 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); | 4077 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); |
| 4078 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAR
EST); | 4078 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAR
EST); |
| 4079 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO
_EDGE); | 4079 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO
_EDGE); |
| 4080 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO
_EDGE); | 4080 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO
_EDGE); |
| 4081 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas->
width(), | 4081 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas->
width(), |
| 4082 canvas->height(), 0, GL_RGBA, targetType, 0); | 4082 canvas->height(), 0, GL_RGBA, targetType, 0); |
| 4083 } | 4083 } |
| 4084 | 4084 |
| 4085 if (!canvas->is3D()) { | 4085 if (!canvas->is3D()) { |
| 4086 ImageBuffer* buffer = canvas->buffer(); | 4086 ImageBuffer* buffer = canvas->buffer(); |
| 4087 if (!buffer->copyToPlatformTexture(webContext(), contextGL(), targetText
ure, targetInternalformat, targetType, | 4087 if (!buffer->copyToPlatformTexture(webContext(), contextGL(), targetText
ure, targetInternalformat, targetType, |
| 4088 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4088 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4089 ASSERT_NOT_REACHED(); | 4089 ASSERT_NOT_REACHED(); |
| 4090 } | 4090 } |
| 4091 } else { | 4091 } else { |
| 4092 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); | 4092 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); |
| 4093 ScopedTexture2DRestorer restorer(gl); | 4093 ScopedTexture2DRestorer restorer(gl); |
| 4094 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), contextGL(
), targetTexture, targetInternalformat, targetType, | 4094 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), contextGL(
), targetTexture, targetInternalformat, targetType, |
| 4095 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ | 4095 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ |
| 4096 ASSERT_NOT_REACHED(); | 4096 ASSERT_NOT_REACHED(); |
| 4097 } | 4097 } |
| 4098 } | 4098 } |
| 4099 | 4099 |
| 4100 if (!possibleDirectCopy) { | 4100 if (!possibleDirectCopy) { |
| 4101 WebGLId tmpFBO = webContext()->createFramebuffer(); | 4101 GLuint tmpFBO; |
| 4102 contextGL()->GenFramebuffers(1, &tmpFBO); |
| 4102 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); | 4103 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); |
| 4103 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, targetTexture, 0); | 4104 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, targetTexture, 0); |
| 4104 contextGL()->BindTexture(texture->getTarget(), texture->object()); | 4105 contextGL()->BindTexture(texture->getTarget(), texture->object()); |
| 4105 if (functionType == TexImage2DByGPU) { | 4106 if (functionType == TexImage2DByGPU) { |
| 4106 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, canvas->wi
dth(), canvas->height()); | 4107 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, canvas->wi
dth(), canvas->height()); |
| 4107 } else if (functionType == TexSubImage2DByGPU) { | 4108 } else if (functionType == TexSubImage2DByGPU) { |
| 4108 contextGL()->CopyTexSubImage2D(target, level, xoffset, yoffset, 0, 0
, canvas->width(), canvas->height()); | 4109 contextGL()->CopyTexSubImage2D(target, level, xoffset, yoffset, 0, 0
, canvas->width(), canvas->height()); |
| 4109 } else if (functionType == TexSubImage3DByGPU) { | 4110 } else if (functionType == TexSubImage3DByGPU) { |
| 4110 webContext()->copyTexSubImage3D(target, level, xoffset, yoffset, zof
fset, 0, 0, canvas->width(), canvas->height()); | 4111 webContext()->copyTexSubImage3D(target, level, xoffset, yoffset, zof
fset, 0, 0, canvas->width(), canvas->height()); |
| 4111 } | 4112 } |
| 4112 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, 0, 0); | 4113 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, 0, 0); |
| 4113 restoreCurrentFramebuffer(); | 4114 restoreCurrentFramebuffer(); |
| 4114 webContext()->deleteFramebuffer(tmpFBO); | 4115 contextGL()->DeleteFramebuffers(1, &tmpFBO); |
| 4115 webContext()->deleteTexture(targetTexture); | 4116 contextGL()->DeleteTextures(1, &targetTexture); |
| 4116 } | 4117 } |
| 4117 } | 4118 } |
| 4118 | 4119 |
| 4119 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4120 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
| 4120 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 4121 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
| 4121 { | 4122 { |
| 4122 if (isContextLost()) | 4123 if (isContextLost()) |
| 4123 return; | 4124 return; |
| 4124 if (!validateHTMLCanvasElement("texImage2D", canvas, exceptionState)) | 4125 if (!validateHTMLCanvasElement("texImage2D", canvas, exceptionState)) |
| 4125 return; | 4126 return; |
| (...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6299 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6300 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6300 } | 6301 } |
| 6301 | 6302 |
| 6302 void WebGLRenderingContextBase::restoreUnpackParameters() | 6303 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6303 { | 6304 { |
| 6304 if (m_unpackAlignment != 1) | 6305 if (m_unpackAlignment != 1) |
| 6305 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6306 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6306 } | 6307 } |
| 6307 | 6308 |
| 6308 } // namespace blink | 6309 } // namespace blink |
| OLD | NEW |