| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality) | 236 void DrawingBuffer::setFilterQuality(SkFilterQuality filterQuality) |
| 237 { | 237 { |
| 238 if (m_filterQuality != filterQuality) { | 238 if (m_filterQuality != filterQuality) { |
| 239 m_filterQuality = filterQuality; | 239 m_filterQuality = filterQuality; |
| 240 if (m_layer) | 240 if (m_layer) |
| 241 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality); | 241 m_layer->setNearestNeighbor(filterQuality == kNone_SkFilterQuality); |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 bool DrawingBuffer::requiresRGBEmulation() |
| 246 { |
| 247 #if OS(MACOSX) |
| 248 return !m_drawFramebufferBinding && !m_wantAlphaChannel && m_colorBuffer.ima
geId; |
| 249 #else |
| 250 return false; |
| 251 #endif |
| 252 } |
| 253 |
| 245 void DrawingBuffer::freeRecycledMailboxes() | 254 void DrawingBuffer::freeRecycledMailboxes() |
| 246 { | 255 { |
| 247 if (m_recycledMailboxQueue.isEmpty()) | 256 if (m_recycledMailboxQueue.isEmpty()) |
| 248 return; | 257 return; |
| 249 while (!m_recycledMailboxQueue.isEmpty()) | 258 while (!m_recycledMailboxQueue.isEmpty()) |
| 250 deleteMailbox(m_recycledMailboxQueue.takeLast()); | 259 deleteMailbox(m_recycledMailboxQueue.takeLast()); |
| 251 } | 260 } |
| 252 | 261 |
| 253 bool DrawingBuffer::prepareMailbox(WebExternalTextureMailbox* outMailbox, WebExt
ernalBitmap* bitmap) | 262 bool DrawingBuffer::prepareMailbox(WebExternalTextureMailbox* outMailbox, WebExt
ernalBitmap* bitmap) |
| 254 { | 263 { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 ASSERT_NOT_REACHED(); | 362 ASSERT_NOT_REACHED(); |
| 354 } | 363 } |
| 355 | 364 |
| 356 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters() | 365 DrawingBuffer::TextureParameters DrawingBuffer::chromiumImageTextureParameters() |
| 357 { | 366 { |
| 358 #if OS(MACOSX) | 367 #if OS(MACOSX) |
| 359 // A CHROMIUM_image backed texture requires a specialized set of parameters | 368 // A CHROMIUM_image backed texture requires a specialized set of parameters |
| 360 // on OSX. | 369 // on OSX. |
| 361 TextureParameters parameters; | 370 TextureParameters parameters; |
| 362 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; | 371 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; |
| 363 parameters.internalColorFormat = GL_BGRA_EXT; | 372 parameters.internalColorFormat = GL_RGBA; |
| 364 parameters.internalRenderbufferFormat = GL_RGBA8_OES; | 373 parameters.internalRenderbufferFormat = GL_RGBA8_OES; |
| 365 parameters.colorFormat = GL_RGBA; | 374 |
| 375 // Unused. |
| 376 parameters.colorFormat = 0; |
| 366 return parameters; | 377 return parameters; |
| 367 #else | 378 #else |
| 368 return defaultTextureParameters(); | 379 return defaultTextureParameters(); |
| 369 #endif | 380 #endif |
| 370 } | 381 } |
| 371 | 382 |
| 372 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() | 383 DrawingBuffer::TextureParameters DrawingBuffer::defaultTextureParameters() |
| 373 { | 384 { |
| 374 TextureParameters parameters; | 385 TextureParameters parameters; |
| 375 parameters.target = GL_TEXTURE_2D; | 386 parameters.target = GL_TEXTURE_2D; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 } while (!adjustedSize.isEmpty()); | 768 } while (!adjustedSize.isEmpty()); |
| 758 | 769 |
| 759 setSize(adjustedSize); | 770 setSize(adjustedSize); |
| 760 | 771 |
| 761 if (adjustedSize.isEmpty()) | 772 if (adjustedSize.isEmpty()) |
| 762 return false; | 773 return false; |
| 763 } | 774 } |
| 764 | 775 |
| 765 m_gl->Disable(GL_SCISSOR_TEST); | 776 m_gl->Disable(GL_SCISSOR_TEST); |
| 766 m_gl->ClearColor(0, 0, 0, 0); | 777 m_gl->ClearColor(0, 0, 0, 0); |
| 767 m_gl->ColorMask(true, true, true, true); | 778 m_gl->ColorMask(true, true, true, !requiresRGBEmulation()); |
| 768 | 779 |
| 769 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 780 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |
| 770 if (!!m_depthStencilBuffer) { | 781 if (!!m_depthStencilBuffer) { |
| 771 m_gl->ClearDepthf(1.0f); | 782 m_gl->ClearDepthf(1.0f); |
| 772 clearMask |= GL_DEPTH_BUFFER_BIT; | 783 clearMask |= GL_DEPTH_BUFFER_BIT; |
| 773 m_gl->DepthMask(true); | 784 m_gl->DepthMask(true); |
| 774 } | 785 } |
| 775 if (!!m_depthStencilBuffer) { | 786 if (!!m_depthStencilBuffer) { |
| 776 m_gl->ClearStencil(0); | 787 m_gl->ClearStencil(0); |
| 777 clearMask |= GL_STENCIL_BUFFER_BIT; | 788 clearMask |= GL_STENCIL_BUFFER_BIT; |
| 778 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 789 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); |
| 779 } | 790 } |
| 780 | 791 |
| 781 clearFramebuffers(clearMask); | 792 clearFramebuffers(clearMask); |
| 793 m_gl->ColorMask(true, true, true, true); |
| 782 return true; | 794 return true; |
| 783 } | 795 } |
| 784 | 796 |
| 785 void DrawingBuffer::commit() | 797 void DrawingBuffer::commit() |
| 786 { | 798 { |
| 787 if (m_multisampleFBO && !m_contentsChangeCommitted) { | 799 if (m_multisampleFBO && !m_contentsChangeCommitted) { |
| 788 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 800 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); |
| 789 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 801 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); |
| 790 | 802 |
| 791 if (m_scissorEnabled) | 803 if (m_scissorEnabled) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 953 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
| 942 { | 954 { |
| 943 if (info->imageId) { | 955 if (info->imageId) { |
| 944 m_gl->BindTexture(info->parameters.target, info->textureId); | 956 m_gl->BindTexture(info->parameters.target, info->textureId); |
| 945 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); | 957 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); |
| 946 m_gl->DestroyImageCHROMIUM(info->imageId); | 958 m_gl->DestroyImageCHROMIUM(info->imageId); |
| 947 info->imageId = 0; | 959 info->imageId = 0; |
| 948 } | 960 } |
| 949 } | 961 } |
| 950 | 962 |
| 963 void DrawingBuffer::clearChromiumImageIfNecessary(const TextureInfo& info) |
| 964 { |
| 965 if (m_wantAlphaChannel) |
| 966 return; |
| 967 |
| 968 GLuint fbo = 0; |
| 969 m_gl->GenFramebuffers(1, &fbo); |
| 970 m_gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 971 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame
ters.target, info.textureId, 0); |
| 972 m_gl->ClearColor(0, 0, 0, 1); |
| 973 m_gl->ColorMask(false, false, false, true); |
| 974 m_gl->Clear(GL_COLOR_BUFFER_BIT); |
| 975 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, info.parame
ters.target, 0, 0); |
| 976 m_gl->DeleteFramebuffers(1, &fbo); |
| 977 restoreFramebufferBindings(); |
| 978 } |
| 979 |
| 951 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
ntSize& size) | 980 DrawingBuffer::TextureInfo DrawingBuffer::createTextureAndAllocateMemory(const I
ntSize& size) |
| 952 { | 981 { |
| 953 // TODO(erikchen): Add support for a CHROMIUM_image back buffer whose | |
| 954 // behavior mimics a texture with internal format GL_RGB. | |
| 955 // https://crbug.com/581777. | |
| 956 if (!m_wantAlphaChannel) | |
| 957 return createDefaultTextureAndAllocateMemory(size); | |
| 958 | |
| 959 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | 982 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |
| 960 return createDefaultTextureAndAllocateMemory(size); | 983 return createDefaultTextureAndAllocateMemory(size); |
| 961 | 984 |
| 962 // First, try to allocate a CHROMIUM_image. This always has the potential to | 985 // First, try to allocate a CHROMIUM_image. This always has the potential to |
| 963 // fail. | 986 // fail. |
| 964 TextureParameters parameters = chromiumImageTextureParameters(); | 987 TextureParameters parameters = chromiumImageTextureParameters(); |
| 965 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size
.height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 988 GLuint imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size
.height(), parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |
| 966 if (!imageId) | 989 if (!imageId) |
| 967 return createDefaultTextureAndAllocateMemory(size); | 990 return createDefaultTextureAndAllocateMemory(size); |
| 968 | 991 |
| 969 GLuint textureId = createColorTexture(parameters); | 992 GLuint textureId = createColorTexture(parameters); |
| 970 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); | 993 m_gl->BindTexImage2DCHROMIUM(parameters.target, imageId); |
| 971 | 994 |
| 972 TextureInfo info; | 995 TextureInfo info; |
| 973 info.textureId = textureId; | 996 info.textureId = textureId; |
| 974 info.imageId = imageId; | 997 info.imageId = imageId; |
| 975 info.parameters = parameters; | 998 info.parameters = parameters; |
| 999 clearChromiumImageIfNecessary(info); |
| 976 return info; | 1000 return info; |
| 977 } | 1001 } |
| 978 | 1002 |
| 979 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory(
const IntSize& size) | 1003 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory(
const IntSize& size) |
| 980 { | 1004 { |
| 981 TextureParameters parameters = defaultTextureParameters(); | 1005 TextureParameters parameters = defaultTextureParameters(); |
| 982 GLuint textureId = createColorTexture(parameters); | 1006 GLuint textureId = createColorTexture(parameters); |
| 983 texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat,
size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); | 1007 texImage2DResourceSafe(parameters.target, 0, parameters.internalColorFormat,
size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); |
| 984 | 1008 |
| 985 DrawingBuffer::TextureInfo info; | 1009 DrawingBuffer::TextureInfo info; |
| 986 info.textureId = textureId; | 1010 info.textureId = textureId; |
| 987 info.parameters = parameters; | 1011 info.parameters = parameters; |
| 988 return info; | 1012 return info; |
| 989 } | 1013 } |
| 990 | 1014 |
| 991 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) | 1015 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) |
| 992 { | 1016 { |
| 993 ASSERT(info->textureId); | 1017 ASSERT(info->textureId); |
| 994 if (info->imageId) { | 1018 if (info->imageId) { |
| 995 deleteChromiumImageForTexture(info); | 1019 deleteChromiumImageForTexture(info); |
| 996 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s
ize.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); | 1020 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), s
ize.height(), info->parameters.internalColorFormat, GC3D_SCANOUT_CHROMIUM); |
| 997 if (info->imageId) { | 1021 if (info->imageId) { |
| 998 m_gl->BindTexture(info->parameters.target, info->textureId); | 1022 m_gl->BindTexture(info->parameters.target, info->textureId); |
| 999 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId)
; | 1023 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId)
; |
| 1024 clearChromiumImageIfNecessary(*info); |
| 1000 return; | 1025 return; |
| 1001 } | 1026 } |
| 1002 | 1027 |
| 1003 // If the desired texture target is different, there's no way to fall ba
ck | 1028 // If the desired texture target is different, there's no way to fall ba
ck |
| 1004 // to a non CHROMIUM_image texture. | 1029 // to a non CHROMIUM_image texture. |
| 1005 if (chromiumImageTextureParameters().target != defaultTextureParameters(
).target) | 1030 if (chromiumImageTextureParameters().target != defaultTextureParameters(
).target) |
| 1006 return; | 1031 return; |
| 1007 } | 1032 } |
| 1008 | 1033 |
| 1009 m_gl->BindTexture(info->parameters.target, info->textureId); | 1034 m_gl->BindTexture(info->parameters.target, info->textureId); |
| 1010 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal
ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN
SIGNED_BYTE); | 1035 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.internal
ColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UN
SIGNED_BYTE); |
| 1011 } | 1036 } |
| 1012 | 1037 |
| 1013 void DrawingBuffer::attachColorBufferToCurrentFBO() | 1038 void DrawingBuffer::attachColorBufferToCurrentFBO() |
| 1014 { | 1039 { |
| 1015 GLenum target = m_colorBuffer.parameters.target; | 1040 GLenum target = m_colorBuffer.parameters.target; |
| 1016 | 1041 |
| 1017 m_gl->BindTexture(target, m_colorBuffer.textureId); | 1042 m_gl->BindTexture(target, m_colorBuffer.textureId); |
| 1018 | 1043 |
| 1019 if (m_antiAliasingMode == MSAAImplicitResolve) | 1044 if (m_antiAliasingMode == MSAAImplicitResolve) |
| 1020 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH
MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); | 1045 m_gl->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACH
MENT0, target, m_colorBuffer.textureId, 0, m_sampleCount); |
| 1021 else | 1046 else |
| 1022 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
m_colorBuffer.textureId, 0); | 1047 m_gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
m_colorBuffer.textureId, 0); |
| 1023 | 1048 |
| 1024 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1049 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
| 1025 } | 1050 } |
| 1026 | 1051 |
| 1027 } // namespace blink | 1052 } // namespace blink |
| OLD | NEW |