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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 private: | 74 private: |
75 gpu::gles2::GLES2Interface* m_gl; | 75 gpu::gles2::GLES2Interface* m_gl; |
76 GLenum m_oldActiveTextureUnit; | 76 GLenum m_oldActiveTextureUnit; |
77 GLuint m_oldTextureUnitZeroId; | 77 GLuint m_oldTextureUnitZeroId; |
78 }; | 78 }; |
79 | 79 |
80 static bool shouldFailDrawingBufferCreationForTesting = false; | 80 static bool shouldFailDrawingBufferCreationForTesting = false; |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 PassRefPtr<DrawingBuffer> DrawingBuffer::create(std::unique_ptr<WebGraphicsConte xt3DProvider> contextProvider, const IntSize& size, bool premultipliedAlpha, boo l wantAlphaChannel, bool wantDepthBuffer, bool wantStencilBuffer, bool wantAntia liasing, PreserveDrawingBuffer preserve) | 84 PassRefPtr<DrawingBuffer> DrawingBuffer::create(std::unique_ptr<WebGraphicsConte xt3DProvider> contextProvider, |
85 const IntSize& size, bool premultipliedAlpha, bool wantAlphaChannel, | |
86 bool wantDepthBuffer, bool wantStencilBuffer, bool wantAntialiasing, | |
87 PreserveDrawingBuffer preserve, WebGLVersion webGLVersion) | |
85 { | 88 { |
86 ASSERT(contextProvider); | 89 ASSERT(contextProvider); |
87 | 90 |
88 if (shouldFailDrawingBufferCreationForTesting) { | 91 if (shouldFailDrawingBufferCreationForTesting) { |
89 shouldFailDrawingBufferCreationForTesting = false; | 92 shouldFailDrawingBufferCreationForTesting = false; |
90 return nullptr; | 93 return nullptr; |
91 } | 94 } |
92 | 95 |
93 std::unique_ptr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create( contextProvider->contextGL()); | 96 std::unique_ptr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create( contextProvider->contextGL()); |
94 if (!extensionsUtil->isValid()) { | 97 if (!extensionsUtil->isValid()) { |
(...skipping 10 matching lines...) Expand all Loading... | |
105 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 108 extensionsUtil->ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
106 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp le")) | 109 if (extensionsUtil->supportsExtension("GL_CHROMIUM_framebuffer_multisamp le")) |
107 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult isample"); | 110 extensionsUtil->ensureExtensionEnabled("GL_CHROMIUM_framebuffer_mult isample"); |
108 else | 111 else |
109 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t o_texture"); | 112 extensionsUtil->ensureExtensionEnabled("GL_EXT_multisampled_render_t o_texture"); |
110 } | 113 } |
111 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT _discard_framebuffer"); | 114 bool discardFramebufferSupported = extensionsUtil->supportsExtension("GL_EXT _discard_framebuffer"); |
112 if (discardFramebufferSupported) | 115 if (discardFramebufferSupported) |
113 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); | 116 extensionsUtil->ensureExtensionEnabled("GL_EXT_discard_framebuffer"); |
114 | 117 |
115 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c ontextProvider), std::move(extensionsUtil), discardFramebufferSupported, wantAlp haChannel, premultipliedAlpha, preserve, wantDepthBuffer, wantStencilBuffer)); | 118 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(std::move(c ontextProvider), std::move(extensionsUtil), |
119 discardFramebufferSupported, wantAlphaChannel, premultipliedAlpha, | |
120 preserve, webGLVersion, wantDepthBuffer, wantStencilBuffer)); | |
116 if (!drawingBuffer->initialize(size, multisampleSupported)) { | 121 if (!drawingBuffer->initialize(size, multisampleSupported)) { |
117 drawingBuffer->beginDestruction(); | 122 drawingBuffer->beginDestruction(); |
118 return PassRefPtr<DrawingBuffer>(); | 123 return PassRefPtr<DrawingBuffer>(); |
119 } | 124 } |
120 return drawingBuffer.release(); | 125 return drawingBuffer.release(); |
121 } | 126 } |
122 | 127 |
123 void DrawingBuffer::forceNextDrawingBufferCreationToFail() | 128 void DrawingBuffer::forceNextDrawingBufferCreationToFail() |
124 { | 129 { |
125 shouldFailDrawingBufferCreationForTesting = true; | 130 shouldFailDrawingBufferCreationForTesting = true; |
126 } | 131 } |
127 | 132 |
128 DrawingBuffer::DrawingBuffer( | 133 DrawingBuffer::DrawingBuffer( |
129 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, | 134 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, |
130 std::unique_ptr<Extensions3DUtil> extensionsUtil, | 135 std::unique_ptr<Extensions3DUtil> extensionsUtil, |
131 bool discardFramebufferSupported, | 136 bool discardFramebufferSupported, |
132 bool wantAlphaChannel, | 137 bool wantAlphaChannel, |
133 bool premultipliedAlpha, | 138 bool premultipliedAlpha, |
134 PreserveDrawingBuffer preserve, | 139 PreserveDrawingBuffer preserve, |
140 WebGLVersion webGLVersion, | |
135 bool wantDepth, | 141 bool wantDepth, |
136 bool wantStencil) | 142 bool wantStencil) |
137 : m_preserveDrawingBuffer(preserve) | 143 : m_preserveDrawingBuffer(preserve) |
144 , m_webGLVersion(webGLVersion) | |
138 , m_contextProvider(std::move(contextProvider)) | 145 , m_contextProvider(std::move(contextProvider)) |
139 , m_gl(m_contextProvider->contextGL()) | 146 , m_gl(m_contextProvider->contextGL()) |
140 , m_extensionsUtil(std::move(extensionsUtil)) | 147 , m_extensionsUtil(std::move(extensionsUtil)) |
141 , m_discardFramebufferSupported(discardFramebufferSupported) | 148 , m_discardFramebufferSupported(discardFramebufferSupported) |
142 , m_wantAlphaChannel(wantAlphaChannel) | 149 , m_wantAlphaChannel(wantAlphaChannel) |
143 , m_premultipliedAlpha(premultipliedAlpha) | 150 , m_premultipliedAlpha(premultipliedAlpha) |
144 , m_wantDepth(wantDepth) | 151 , m_wantDepth(wantDepth) |
145 , m_wantStencil(wantStencil) | 152 , m_wantStencil(wantStencil) |
146 { | 153 { |
147 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); | 154 memset(m_colorMask, 0, 4 * sizeof(GLboolean)); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 if (m_preserveDrawingBuffer == Discard) { | 284 if (m_preserveDrawingBuffer == Discard) { |
278 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); | 285 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); |
279 attachColorBufferToReadFramebuffer(); | 286 attachColorBufferToReadFramebuffer(); |
280 | 287 |
281 if (m_discardFramebufferSupported) { | 288 if (m_discardFramebufferSupported) { |
282 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch. | 289 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch. |
283 const GLenum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTAC HMENT, GL_STENCIL_ATTACHMENT }; | 290 const GLenum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTAC HMENT, GL_STENCIL_ATTACHMENT }; |
284 m_gl->DiscardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); | 291 m_gl->DiscardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); |
285 } | 292 } |
286 } else { | 293 } else { |
287 m_gl->CopyTextureCHROMIUM(m_colorBuffer.textureId, frontColorBufferMailb ox->textureInfo.textureId, frontColorBufferMailbox->textureInfo.parameters.inter nalColorFormat, GL_UNSIGNED_BYTE, GL_FALSE, GL_FALSE, GL_FALSE); | 294 m_gl->CopySubTextureCHROMIUM(m_colorBuffer.textureId, frontColorBufferMa ilbox->textureInfo.textureId, |
295 0, 0, 0, 0, m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_ FALSE); | |
288 } | 296 } |
289 | 297 |
290 restoreFramebufferBindings(); | 298 restoreFramebufferBindings(); |
291 m_contentsChanged = false; | 299 m_contentsChanged = false; |
292 | 300 |
293 m_gl->ProduceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo.text ureId, frontColorBufferMailbox->textureInfo.parameters.target, frontColorBufferM ailbox->mailbox.name); | 301 m_gl->ProduceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo.text ureId, frontColorBufferMailbox->textureInfo.parameters.target, frontColorBufferM ailbox->mailbox.name); |
294 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); | 302 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); |
295 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) | 303 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) |
296 m_gl->DescheduleUntilFinishedCHROMIUM(); | 304 m_gl->DescheduleUntilFinishedCHROMIUM(); |
297 m_gl->Flush(); | 305 m_gl->Flush(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 m_antiAliasingMode = None; | 478 m_antiAliasingMode = None; |
471 if (useMultisampling) { | 479 if (useMultisampling) { |
472 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); | 480 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); |
473 m_antiAliasingMode = MSAAExplicitResolve; | 481 m_antiAliasingMode = MSAAExplicitResolve; |
474 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) { | 482 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) { |
475 m_antiAliasingMode = MSAAImplicitResolve; | 483 m_antiAliasingMode = MSAAImplicitResolve; |
476 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) { | 484 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) { |
477 m_antiAliasingMode = ScreenSpaceAntialiasing; | 485 m_antiAliasingMode = ScreenSpaceAntialiasing; |
478 } | 486 } |
479 } | 487 } |
488 m_storageTextureSupported = m_webGLVersion == WebGL2 || m_extensionsUtil->su pportsExtension("GL_EXT_texture_storage"); | |
Zhenyao Mo
2016/07/07 16:33:37
nit: m_webGLVersion > WebGL1 (for future versions)
dshwang
2016/07/07 16:47:36
Done.
| |
480 m_sampleCount = std::min(4, maxSampleCount); | 489 m_sampleCount = std::min(4, maxSampleCount); |
481 | 490 |
482 m_gl->GenFramebuffers(1, &m_fbo); | 491 m_gl->GenFramebuffers(1, &m_fbo); |
483 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 492 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
484 if (wantExplicitResolve()) { | 493 if (wantExplicitResolve()) { |
485 m_gl->GenFramebuffers(1, &m_multisampleFBO); | 494 m_gl->GenFramebuffers(1, &m_multisampleFBO); |
486 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); | 495 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); |
487 m_gl->GenRenderbuffers(1, &m_multisampleRenderbuffer); | 496 m_gl->GenRenderbuffers(1, &m_multisampleRenderbuffer); |
488 } | 497 } |
489 if (!reset(size)) | 498 if (!reset(size)) |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 unsigned count = height / 2; | 943 unsigned count = height / 2; |
935 for (unsigned i = 0; i < count; i++) { | 944 for (unsigned i = 0; i < count; i++) { |
936 uint8_t* rowA = framebuffer + i * rowBytes; | 945 uint8_t* rowA = framebuffer + i * rowBytes; |
937 uint8_t* rowB = framebuffer + (height - i - 1) * rowBytes; | 946 uint8_t* rowB = framebuffer + (height - i - 1) * rowBytes; |
938 memcpy(scanline, rowB, rowBytes); | 947 memcpy(scanline, rowB, rowBytes); |
939 memcpy(rowB, rowA, rowBytes); | 948 memcpy(rowB, rowA, rowBytes); |
940 memcpy(rowA, scanline, rowBytes); | 949 memcpy(rowA, scanline, rowBytes); |
941 } | 950 } |
942 } | 951 } |
943 | 952 |
944 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint unpackAlignment) | 953 void DrawingBuffer::allocateConditionallyImmutableTexture(GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLen um type) |
945 { | 954 { |
946 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8); | 955 if (m_storageTextureSupported) { |
947 m_gl->TexImage2D(target, level, internalformat, width, height, border, forma t, type, 0); | 956 GLenum internalStorageFormat = GL_NONE; |
957 if (internalformat == GL_RGB) { | |
958 internalStorageFormat = GL_RGB8; | |
959 } else if (internalformat == GL_RGBA) { | |
960 internalStorageFormat = GL_RGBA8; | |
961 } else { | |
962 NOTREACHED(); | |
963 } | |
964 m_gl->TexStorage2DEXT(GL_TEXTURE_2D, 1, internalStorageFormat, width, he ight); | |
965 return; | |
966 } | |
967 m_gl->TexImage2D(target, 0, internalformat, width, height, border, format, t ype, 0); | |
948 } | 968 } |
949 | 969 |
950 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 970 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
951 { | 971 { |
952 if (info->imageId) { | 972 if (info->imageId) { |
953 m_gl->BindTexture(info->parameters.target, info->textureId); | 973 m_gl->BindTexture(info->parameters.target, info->textureId); |
954 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); | 974 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); |
955 m_gl->DestroyImageCHROMIUM(info->imageId); | 975 m_gl->DestroyImageCHROMIUM(info->imageId); |
956 info->imageId = 0; | 976 info->imageId = 0; |
957 info->gpuMemoryBufferId = -1; | 977 info->gpuMemoryBufferId = -1; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 info.textureId = textureId; | 1019 info.textureId = textureId; |
1000 info.imageId = imageId; | 1020 info.imageId = imageId; |
1001 info.gpuMemoryBufferId = gpuMemoryBufferId; | 1021 info.gpuMemoryBufferId = gpuMemoryBufferId; |
1002 info.parameters = parameters; | 1022 info.parameters = parameters; |
1003 clearChromiumImageAlpha(info); | 1023 clearChromiumImageAlpha(info); |
1004 return info; | 1024 return info; |
1005 } | 1025 } |
1006 | 1026 |
1007 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size) | 1027 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size) |
1008 { | 1028 { |
1029 DrawingBuffer::TextureInfo info; | |
1009 TextureParameters parameters = defaultTextureParameters(); | 1030 TextureParameters parameters = defaultTextureParameters(); |
1010 GLuint textureId = createColorTexture(parameters); | |
1011 texImage2DResourceSafe(parameters.target, 0, parameters.creationInternalColo rFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYT E); | |
1012 | |
1013 DrawingBuffer::TextureInfo info; | |
1014 info.textureId = textureId; | |
1015 info.parameters = parameters; | 1031 info.parameters = parameters; |
1032 info.textureId = createColorTexture(parameters); | |
1033 allocateConditionallyImmutableTexture(parameters.target, parameters.creation InternalColorFormat, | |
1034 size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE ); | |
1035 info.immutable = m_storageTextureSupported; | |
1016 return info; | 1036 return info; |
1017 } | 1037 } |
1018 | 1038 |
1019 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) | 1039 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) |
1020 { | 1040 { |
1021 ASSERT(info->textureId); | 1041 ASSERT(info->textureId); |
1022 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { | 1042 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { |
1043 if (info->immutable) { | |
1044 DCHECK(m_storageTextureSupported); | |
1045 m_gl->DeleteTextures(1, &info->textureId); | |
1046 info->textureId = createColorTexture(info->parameters); | |
1047 } | |
1023 m_gl->BindTexture(info->parameters.target, info->textureId); | 1048 m_gl->BindTexture(info->parameters.target, info->textureId); |
1024 texImage2DResourceSafe(info->parameters.target, 0, info->parameters.crea tionInternalColorFormat, size.width(), size.height(), 0, info->parameters.colorF ormat, GL_UNSIGNED_BYTE); | 1049 allocateConditionallyImmutableTexture(info->parameters.target, info->par ameters.creationInternalColorFormat, |
1050 size.width(), size.height(), 0, info->parameters.colorFormat, GL_UNS IGNED_BYTE); | |
1051 info->immutable = m_storageTextureSupported; | |
1025 return; | 1052 return; |
1026 } | 1053 } |
1027 | 1054 |
1055 DCHECK(!info->immutable); | |
1028 deleteChromiumImageForTexture(info); | 1056 deleteChromiumImageForTexture(info); |
1029 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size. height(), info->parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM); | 1057 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size. height(), info->parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM); |
1030 if (info->imageId) { | 1058 if (info->imageId) { |
1031 m_gl->BindTexture(info->parameters.target, info->textureId); | 1059 m_gl->BindTexture(info->parameters.target, info->textureId); |
1032 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId); | 1060 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId); |
1033 | 1061 |
1034 GLint gpuMemoryBufferId = -1; | 1062 GLint gpuMemoryBufferId = -1; |
1035 m_gl->GetImageivCHROMIUM(info->imageId, GC3D_GPU_MEMORY_BUFFER_ID, &gpuM emoryBufferId); | 1063 m_gl->GetImageivCHROMIUM(info->imageId, GC3D_GPU_MEMORY_BUFFER_ID, &gpuM emoryBufferId); |
1036 DCHECK_NE(-1, gpuMemoryBufferId); | 1064 DCHECK_NE(-1, gpuMemoryBufferId); |
1037 info->gpuMemoryBufferId = gpuMemoryBufferId; | 1065 info->gpuMemoryBufferId = gpuMemoryBufferId; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 | 1116 |
1089 void DrawingBuffer::restoreTextureBindings() | 1117 void DrawingBuffer::restoreTextureBindings() |
1090 { | 1118 { |
1091 // This class potentially modifies the bindings for GL_TEXTURE_2D and | 1119 // This class potentially modifies the bindings for GL_TEXTURE_2D and |
1092 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since | 1120 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since |
1093 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. | 1121 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. |
1094 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); | 1122 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); |
1095 } | 1123 } |
1096 | 1124 |
1097 } // namespace blink | 1125 } // namespace blink |
OLD | NEW |