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