| 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 4085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4096 bool possibleDirectCopy = false; | 4096 bool possibleDirectCopy = false; |
| 4097 if (functionType == TexImage2DByGPU) { | 4097 if (functionType == TexImage2DByGPU) { |
| 4098 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target,
internalformat, type, level); | 4098 possibleDirectCopy = Extensions3DUtil::canUseCopyTextureCHROMIUM(target,
internalformat, type, level); |
| 4099 } | 4099 } |
| 4100 | 4100 |
| 4101 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. | 4101 // if direct copy is not possible, create a temporary texture and then copy
from canvas to temporary texture to target texture. |
| 4102 if (!possibleDirectCopy) { | 4102 if (!possibleDirectCopy) { |
| 4103 targetLevel = 0; | 4103 targetLevel = 0; |
| 4104 targetInternalformat = GL_RGBA; | 4104 targetInternalformat = GL_RGBA; |
| 4105 targetType = GL_UNSIGNED_BYTE; | 4105 targetType = GL_UNSIGNED_BYTE; |
| 4106 targetTexture = webContext()->createTexture(); | 4106 contextGL()->GenTextures(1, &targetTexture); |
| 4107 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); | 4107 contextGL()->BindTexture(GL_TEXTURE_2D, targetTexture); |
| 4108 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); | 4108 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAR
EST); |
| 4109 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAR
EST); | 4109 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAR
EST); |
| 4110 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO
_EDGE); | 4110 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO
_EDGE); |
| 4111 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO
_EDGE); | 4111 contextGL()->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO
_EDGE); |
| 4112 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas->
width(), | 4112 contextGL()->TexImage2D(GL_TEXTURE_2D, 0, targetInternalformat, canvas->
width(), |
| 4113 canvas->height(), 0, GL_RGBA, targetType, 0); | 4113 canvas->height(), 0, GL_RGBA, targetType, 0); |
| 4114 } | 4114 } |
| 4115 | 4115 |
| 4116 if (!canvas->is3D()) { | 4116 if (!canvas->is3D()) { |
| 4117 ImageBuffer* buffer = canvas->buffer(); | 4117 ImageBuffer* buffer = canvas->buffer(); |
| 4118 if (!buffer->copyToPlatformTexture(webContext(), contextGL(), targetText
ure, targetInternalformat, targetType, | 4118 if (!buffer->copyToPlatformTexture(webContext(), contextGL(), targetText
ure, targetInternalformat, targetType, |
| 4119 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4119 targetLevel, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
| 4120 ASSERT_NOT_REACHED(); | 4120 ASSERT_NOT_REACHED(); |
| 4121 } | 4121 } |
| 4122 } else { | 4122 } else { |
| 4123 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); | 4123 WebGLRenderingContextBase* gl = toWebGLRenderingContextBase(canvas->rend
eringContext()); |
| 4124 ScopedTexture2DRestorer restorer(gl); | 4124 ScopedTexture2DRestorer restorer(gl); |
| 4125 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), contextGL(
), targetTexture, targetInternalformat, targetType, | 4125 if (!gl->drawingBuffer()->copyToPlatformTexture(webContext(), contextGL(
), targetTexture, targetInternalformat, targetType, |
| 4126 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ | 4126 targetLevel, m_unpackPremultiplyAlpha, !m_unpackFlipY, BackBuffer))
{ |
| 4127 ASSERT_NOT_REACHED(); | 4127 ASSERT_NOT_REACHED(); |
| 4128 } | 4128 } |
| 4129 } | 4129 } |
| 4130 | 4130 |
| 4131 if (!possibleDirectCopy) { | 4131 if (!possibleDirectCopy) { |
| 4132 WebGLId tmpFBO = webContext()->createFramebuffer(); | 4132 GLuint tmpFBO; |
| 4133 contextGL()->GenFramebuffers(1, &tmpFBO); |
| 4133 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); | 4134 contextGL()->BindFramebuffer(GL_FRAMEBUFFER, tmpFBO); |
| 4134 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, targetTexture, 0); | 4135 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, targetTexture, 0); |
| 4135 contextGL()->BindTexture(texture->getTarget(), texture->object()); | 4136 contextGL()->BindTexture(texture->getTarget(), texture->object()); |
| 4136 if (functionType == TexImage2DByGPU) { | 4137 if (functionType == TexImage2DByGPU) { |
| 4137 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, canvas->wi
dth(), canvas->height()); | 4138 contextGL()->CopyTexSubImage2D(target, level, 0, 0, 0, 0, canvas->wi
dth(), canvas->height()); |
| 4138 } else if (functionType == TexSubImage2DByGPU) { | 4139 } else if (functionType == TexSubImage2DByGPU) { |
| 4139 contextGL()->CopyTexSubImage2D(target, level, xoffset, yoffset, 0, 0
, canvas->width(), canvas->height()); | 4140 contextGL()->CopyTexSubImage2D(target, level, xoffset, yoffset, 0, 0
, canvas->width(), canvas->height()); |
| 4140 } else if (functionType == TexSubImage3DByGPU) { | 4141 } else if (functionType == TexSubImage3DByGPU) { |
| 4141 webContext()->copyTexSubImage3D(target, level, xoffset, yoffset, zof
fset, 0, 0, canvas->width(), canvas->height()); | 4142 webContext()->copyTexSubImage3D(target, level, xoffset, yoffset, zof
fset, 0, 0, canvas->width(), canvas->height()); |
| 4142 } | 4143 } |
| 4143 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, 0, 0); | 4144 contextGL()->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, 0, 0); |
| 4144 restoreCurrentFramebuffer(); | 4145 restoreCurrentFramebuffer(); |
| 4145 webContext()->deleteFramebuffer(tmpFBO); | 4146 contextGL()->DeleteFramebuffers(1, &tmpFBO); |
| 4146 webContext()->deleteTexture(targetTexture); | 4147 contextGL()->DeleteTextures(1, &targetTexture); |
| 4147 } | 4148 } |
| 4148 } | 4149 } |
| 4149 | 4150 |
| 4150 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4151 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
| 4151 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) | 4152 GLenum format, GLenum type, HTMLCanvasElement* canvas, ExceptionState& excep
tionState) |
| 4152 { | 4153 { |
| 4153 if (isContextLost()) | 4154 if (isContextLost()) |
| 4154 return; | 4155 return; |
| 4155 if (!validateHTMLCanvasElement("texImage2D", canvas, exceptionState)) | 4156 if (!validateHTMLCanvasElement("texImage2D", canvas, exceptionState)) |
| 4156 return; | 4157 return; |
| (...skipping 2175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6332 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6333 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 6333 } | 6334 } |
| 6334 | 6335 |
| 6335 void WebGLRenderingContextBase::restoreUnpackParameters() | 6336 void WebGLRenderingContextBase::restoreUnpackParameters() |
| 6336 { | 6337 { |
| 6337 if (m_unpackAlignment != 1) | 6338 if (m_unpackAlignment != 1) |
| 6338 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6339 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
| 6339 } | 6340 } |
| 6340 | 6341 |
| 6341 } // namespace blink | 6342 } // namespace blink |
| OLD | NEW |