| OLD | NEW | 
|     1 /* |     1 /* | 
|     2  * Copyright (c) 2010, Google Inc. All rights reserved. |     2  * Copyright (c) 2010, Google 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 are |     5  * modification, are permitted provided that the following conditions are | 
|     6  * met: |     6  * met: | 
|     7  * |     7  * | 
|     8  *     * Redistributions of source code must retain the above copyright |     8  *     * Redistributions of source code must retain the above copyright | 
|     9  * notice, this list of conditions and the following disclaimer. |     9  * notice, this list of conditions and the following disclaimer. | 
|    10  *     * Redistributions in binary form must reproduce the above |    10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   628         GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |   628         GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 
|   629 } |   629 } | 
|   630  |   630  | 
|   631 WebGLId DrawingBuffer::createColorTexture(const TextureParameters& parameters) |   631 WebGLId DrawingBuffer::createColorTexture(const TextureParameters& parameters) | 
|   632 { |   632 { | 
|   633     WebGLId offscreenColorTexture = m_context->createTexture(); |   633     WebGLId offscreenColorTexture = m_context->createTexture(); | 
|   634     if (!offscreenColorTexture) |   634     if (!offscreenColorTexture) | 
|   635         return 0; |   635         return 0; | 
|   636  |   636  | 
|   637     m_gl->BindTexture(parameters.target, offscreenColorTexture); |   637     m_gl->BindTexture(parameters.target, offscreenColorTexture); | 
|   638     m_context->texParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR
      ); |   638     m_gl->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 
|   639     m_context->texParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR
      ); |   639     m_gl->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 
|   640     m_context->texParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_E
      DGE); |   640     m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 
|   641     m_context->texParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_E
      DGE); |   641     m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 
|   642  |   642  | 
|   643     return offscreenColorTexture; |   643     return offscreenColorTexture; | 
|   644 } |   644 } | 
|   645  |   645  | 
|   646 void DrawingBuffer::createSecondaryBuffers() |   646 void DrawingBuffer::createSecondaryBuffers() | 
|   647 { |   647 { | 
|   648     // create a multisample FBO |   648     // create a multisample FBO | 
|   649     if (m_antiAliasingMode == MSAAExplicitResolve) { |   649     if (m_antiAliasingMode == MSAAExplicitResolve) { | 
|   650         m_multisampleFBO = m_context->createFramebuffer(); |   650         m_multisampleFBO = m_context->createFramebuffer(); | 
|   651         m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |   651         m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   686  |   686  | 
|   687 void DrawingBuffer::resizeDepthStencil(const IntSize& size) |   687 void DrawingBuffer::resizeDepthStencil(const IntSize& size) | 
|   688 { |   688 { | 
|   689     if (!m_requestedAttributes.depth && !m_requestedAttributes.stencil) |   689     if (!m_requestedAttributes.depth && !m_requestedAttributes.stencil) | 
|   690         return; |   690         return; | 
|   691  |   691  | 
|   692     if (!m_depthStencilBuffer) |   692     if (!m_depthStencilBuffer) | 
|   693         m_depthStencilBuffer = m_context->createRenderbuffer(); |   693         m_depthStencilBuffer = m_context->createRenderbuffer(); | 
|   694     m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); |   694     m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer); | 
|   695     if (m_antiAliasingMode == MSAAImplicitResolve) |   695     if (m_antiAliasingMode == MSAAImplicitResolve) | 
|   696         m_context->renderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCo
      unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |   696         m_gl->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCount, 
      GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 
|   697     else if (m_antiAliasingMode == MSAAExplicitResolve) |   697     else if (m_antiAliasingMode == MSAAExplicitResolve) | 
|   698         m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo
      unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); |   698         m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCo
      unt, GL_DEPTH24_STENCIL8_OES, size.width(), size.height()); | 
|   699     else |   699     else | 
|   700         m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, size
      .width(), size.height()); |   700         m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, size
      .width(), size.height()); | 
|   701     m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, G
      L_RENDERBUFFER, m_depthStencilBuffer); |   701     m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, G
      L_RENDERBUFFER, m_depthStencilBuffer); | 
|   702     m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0); |   702     m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0); | 
|   703 } |   703 } | 
|   704  |   704  | 
|   705  |   705  | 
|   706  |   706  | 
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   941         uint8_t* rowB = framebuffer + (height - i - 1) * rowBytes; |   941         uint8_t* rowB = framebuffer + (height - i - 1) * rowBytes; | 
|   942         memcpy(scanline, rowB, rowBytes); |   942         memcpy(scanline, rowB, rowBytes); | 
|   943         memcpy(rowB, rowA, rowBytes); |   943         memcpy(rowB, rowA, rowBytes); | 
|   944         memcpy(rowA, scanline, rowBytes); |   944         memcpy(rowA, scanline, rowBytes); | 
|   945     } |   945     } | 
|   946 } |   946 } | 
|   947  |   947  | 
|   948 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
      ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
       type, GLint unpackAlignment) |   948 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
      ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
       type, GLint unpackAlignment) | 
|   949 { |   949 { | 
|   950     ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 
      || unpackAlignment == 8); |   950     ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 
      || unpackAlignment == 8); | 
|   951     m_context->texImage2D(target, level, internalformat, width, height, border, 
      format, type, 0); |   951     m_gl->TexImage2D(target, level, internalformat, width, height, border, forma
      t, type, 0); | 
|   952 } |   952 } | 
|   953  |   953  | 
|   954 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |   954 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 
|   955 { |   955 { | 
|   956     if (info->imageId) { |   956     if (info->imageId) { | 
|   957         m_gl->BindTexture(info->parameters.target, info->textureId); |   957         m_gl->BindTexture(info->parameters.target, info->textureId); | 
|   958         m_context->releaseTexImage2DCHROMIUM(info->parameters.target, info->imag
      eId); |   958         m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); | 
|   959         m_context->destroyImageCHROMIUM(info->imageId); |   959         m_gl->DestroyImageCHROMIUM(info->imageId); | 
|   960         info->imageId = 0; |   960         info->imageId = 0; | 
|   961     } |   961     } | 
|   962 } |   962 } | 
|   963  |   963  | 
|   964 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
      ntSize& size) |   964 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
      ntSize& size) | 
|   965 { |   965 { | 
|   966     // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose |   966     // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose | 
|   967     // behavior mimics a texture with internal format GL_RGB. |   967     // behavior mimics a texture with internal format GL_RGB. | 
|   968     // https://crbug.com/581777. |   968     // https://crbug.com/581777. | 
|   969     if (!m_requestedAttributes.alpha) |   969     if (!m_requestedAttributes.alpha) | 
|   970         return createDefaultTextureAndAllocateMemory(size); |   970         return createDefaultTextureAndAllocateMemory(size); | 
|   971  |   971  | 
|   972     if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |   972     if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | 
|   973         return createDefaultTextureAndAllocateMemory(size); |   973         return createDefaultTextureAndAllocateMemory(size); | 
|   974  |   974  | 
|   975     // First, try to allocate a CHROMIUM_image. This always has the potential to |   975     // First, try to allocate a CHROMIUM_image. This always has the potential to | 
|   976     // fail. |   976     // fail. | 
|   977     TextureParameters parameters = chromiumImageTextureParameters(); |   977     TextureParameters parameters = chromiumImageTextureParameters(); | 
|   978     WGC3Duint imageId = m_context->createGpuMemoryBufferImageCHROMIUM(size.width
      (), size.height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |   978     WGC3Duint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s
      ize.height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 
|   979     if (!imageId) |   979     if (!imageId) | 
|   980         return createDefaultTextureAndAllocateMemory(size); |   980         return createDefaultTextureAndAllocateMemory(size); | 
|   981  |   981  | 
|   982     WebGLId textureId = createColorTexture(parameters); |   982     WebGLId textureId = createColorTexture(parameters); | 
|   983     if (!textureId) { |   983     if (!textureId) { | 
|   984         m_context->destroyImageCHROMIUM(imageId); |   984         m_gl->DestroyImageCHROMIUM(imageId); | 
|   985         return createDefaultTextureAndAllocateMemory(size); |   985         return createDefaultTextureAndAllocateMemory(size); | 
|   986     } |   986     } | 
|   987  |   987  | 
|   988     m_context->bindTexImage2DCHROMIUM(parameters.target, imageId); |   988     m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); | 
|   989  |   989  | 
|   990     TextureInfo info; |   990     TextureInfo info; | 
|   991     info.textureId = textureId; |   991     info.textureId = textureId; | 
|   992     info.imageId = imageId; |   992     info.imageId = imageId; | 
|   993     info.parameters = parameters; |   993     info.parameters = parameters; | 
|   994     return info; |   994     return info; | 
|   995 } |   995 } | 
|   996  |   996  | 
|   997 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory(
      const IntSize& size) |   997 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory(
      const IntSize& size) | 
|   998 { |   998 { | 
|   999     TextureParameters parameters = defaultTextureParameters(); |   999     TextureParameters parameters = defaultTextureParameters(); | 
|  1000     WebGLId textureId = createColorTexture(parameters); |  1000     WebGLId textureId = createColorTexture(parameters); | 
|  1001     texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat,
       size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); |  1001     texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat,
       size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); | 
|  1002  |  1002  | 
|  1003     DrawingBuffer::TextureInfo info; |  1003     DrawingBuffer::TextureInfo info; | 
|  1004     info.textureId = textureId; |  1004     info.textureId = textureId; | 
|  1005     info.parameters = parameters; |  1005     info.parameters = parameters; | 
|  1006     return info; |  1006     return info; | 
|  1007 } |  1007 } | 
|  1008  |  1008  | 
|  1009 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) |  1009 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) | 
|  1010 { |  1010 { | 
|  1011     ASSERT(info->textureId); |  1011     ASSERT(info->textureId); | 
|  1012     if (info->imageId) { |  1012     if (info->imageId) { | 
|  1013         deleteChromiumImageForTexture(info); |  1013         deleteChromiumImageForTexture(info); | 
|  1014         info->imageId = m_context->createGpuMemoryBufferImageCHROMIUM(size.width
      (), size.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |  1014         info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s
      ize.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 
|  1015         if (info->imageId) { |  1015         if (info->imageId) { | 
|  1016             m_gl->BindTexture(info->parameters.target, info->textureId); |  1016             m_gl->BindTexture(info->parameters.target, info->textureId); | 
|  1017             m_context->bindTexImage2DCHROMIUM(info->parameters.target, info->ima
      geId); |  1017             m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId)
      ; | 
|  1018             return; |  1018             return; | 
|  1019         } |  1019         } | 
|  1020  |  1020  | 
|  1021         // If the desired texture target is different, there's no way to fall ba
      ck |  1021         // If the desired texture target is different, there's no way to fall ba
      ck | 
|  1022         // to a non CHROMIUM_image texture. |  1022         // to a non CHROMIUM_image texture. | 
|  1023         if (chromiumImageTextureParameters().target != defaultTextureParameters(
      ).target) |  1023         if (chromiumImageTextureParameters().target != defaultTextureParameters(
      ).target) | 
|  1024             return; |  1024             return; | 
|  1025     } |  1025     } | 
|  1026  |  1026  | 
|  1027     m_gl->BindTexture(info->parameters.target, info->textureId); |  1027     m_gl->BindTexture(info->parameters.target, info->textureId); | 
|  1028     texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal
      ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN
      SIGNED_BYTE); |  1028     texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal
      ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN
      SIGNED_BYTE); | 
|  1029 } |  1029 } | 
|  1030  |  1030  | 
|  1031 void DrawingBuffer::attachColorBufferToCurrentFBO() |  1031 void DrawingBuffer::attachColorBufferToCurrentFBO() | 
|  1032 { |  1032 { | 
|  1033     WGC3Denum target = m_colorBuffer.parameters.target; |  1033     WGC3Denum target = m_colorBuffer.parameters.target; | 
|  1034  |  1034  | 
|  1035     m_gl->BindTexture(target, m_colorBuffer.textureId); |  1035     m_gl->BindTexture(target, m_colorBuffer.textureId); | 
|  1036  |  1036  | 
|  1037     if (m_antiAliasingMode == MSAAImplicitResolve) |  1037     if (m_antiAliasingMode == MSAAImplicitResolve) | 
|  1038         m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
      TTACHMENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); |  1038         m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH
      MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); | 
|  1039     else |  1039     else | 
|  1040         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
       m_colorBuffer.textureId, 0); |  1040         m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
       m_colorBuffer.textureId, 0); | 
|  1041  |  1041  | 
|  1042     m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |  1042     m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 
|  1043 } |  1043 } | 
|  1044  |  1044  | 
|  1045 } // namespace blink |  1045 } // namespace blink | 
| OLD | NEW |