Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.cpp

Issue 2125023002: Reland "webgl: use immutable texture for the default FBO." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add GL_BGRA8_EXT Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (m_preserveDrawingBuffer == Discard) { 277 if (m_preserveDrawingBuffer == Discard) {
278 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer); 278 std::swap(frontColorBufferMailbox->textureInfo, m_colorBuffer);
279 attachColorBufferToReadFramebuffer(); 279 attachColorBufferToReadFramebuffer();
280 280
281 if (m_discardFramebufferSupported) { 281 if (m_discardFramebufferSupported) {
282 // Explicitly discard framebuffer to save GPU memory bandwidth for t ile-based GPU arch. 282 // 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 }; 283 const GLenum attachments[3] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTAC HMENT, GL_STENCIL_ATTACHMENT };
284 m_gl->DiscardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments); 284 m_gl->DiscardFramebufferEXT(GL_FRAMEBUFFER, 3, attachments);
285 } 285 }
286 } else { 286 } 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); 287 m_gl->CopySubTextureCHROMIUM(m_colorBuffer.textureId, frontColorBufferMa ilbox->textureInfo.textureId,
288 0, 0, 0, 0, m_size.width(), m_size.height(), GL_FALSE, GL_FALSE, GL_ FALSE);
288 } 289 }
289 290
290 restoreFramebufferBindings(); 291 restoreFramebufferBindings();
291 m_contentsChanged = false; 292 m_contentsChanged = false;
292 293
293 m_gl->ProduceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo.text ureId, frontColorBufferMailbox->textureInfo.parameters.target, frontColorBufferM ailbox->mailbox.name); 294 m_gl->ProduceTextureDirectCHROMIUM(frontColorBufferMailbox->textureInfo.text ureId, frontColorBufferMailbox->textureInfo.parameters.target, frontColorBufferM ailbox->mailbox.name);
294 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM(); 295 const GLuint64 fenceSync = m_gl->InsertFenceSyncCHROMIUM();
295 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled()) 296 if (RuntimeEnabledFeatures::webGLImageChromiumEnabled())
296 m_gl->DescheduleUntilFinishedCHROMIUM(); 297 m_gl->DescheduleUntilFinishedCHROMIUM();
297 m_gl->Flush(); 298 m_gl->Flush();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 m_antiAliasingMode = None; 471 m_antiAliasingMode = None;
471 if (useMultisampling) { 472 if (useMultisampling) {
472 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount); 473 m_gl->GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount);
473 m_antiAliasingMode = MSAAExplicitResolve; 474 m_antiAliasingMode = MSAAExplicitResolve;
474 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) { 475 if (m_extensionsUtil->supportsExtension("GL_EXT_multisampled_render_to_t exture")) {
475 m_antiAliasingMode = MSAAImplicitResolve; 476 m_antiAliasingMode = MSAAImplicitResolve;
476 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) { 477 } else if (m_extensionsUtil->supportsExtension("GL_CHROMIUM_screen_space _antialiasing")) {
477 m_antiAliasingMode = ScreenSpaceAntialiasing; 478 m_antiAliasingMode = ScreenSpaceAntialiasing;
478 } 479 }
479 } 480 }
481 m_storageTextureSupported = m_extensionsUtil->supportsExtension("GL_EXT_text ure_storage");
Zhenyao Mo 2016/07/06 18:12:06 What about WebGL 2 / ES3 context? This extension
dshwang 2016/07/07 12:33:26 Done. Set m_storageTextureSupported to true on Web
480 m_sampleCount = std::min(4, maxSampleCount); 482 m_sampleCount = std::min(4, maxSampleCount);
481 483
482 m_gl->GenFramebuffers(1, &m_fbo); 484 m_gl->GenFramebuffers(1, &m_fbo);
483 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 485 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
484 if (wantExplicitResolve()) { 486 if (wantExplicitResolve()) {
485 m_gl->GenFramebuffers(1, &m_multisampleFBO); 487 m_gl->GenFramebuffers(1, &m_multisampleFBO);
486 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); 488 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
487 m_gl->GenRenderbuffers(1, &m_multisampleRenderbuffer); 489 m_gl->GenRenderbuffers(1, &m_multisampleRenderbuffer);
488 } 490 }
489 if (!reset(size)) 491 if (!reset(size))
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 unsigned count = height / 2; 936 unsigned count = height / 2;
935 for (unsigned i = 0; i < count; i++) { 937 for (unsigned i = 0; i < count; i++) {
936 uint8_t* rowA = framebuffer + i * rowBytes; 938 uint8_t* rowA = framebuffer + i * rowBytes;
937 uint8_t* rowB = framebuffer + (height - i - 1) * rowBytes; 939 uint8_t* rowB = framebuffer + (height - i - 1) * rowBytes;
938 memcpy(scanline, rowB, rowBytes); 940 memcpy(scanline, rowB, rowBytes);
939 memcpy(rowB, rowA, rowBytes); 941 memcpy(rowB, rowA, rowBytes);
940 memcpy(rowA, scanline, rowBytes); 942 memcpy(rowA, scanline, rowBytes);
941 } 943 }
942 } 944 }
943 945
944 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint unpackAlignment) 946 bool DrawingBuffer::createStorageTextureIfPossible(GLenum target, GLenum interna lformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type )
Zhenyao Mo 2016/07/06 18:12:06 To me this method should not return anything. It
Ken Russell (switch to Gerrit) 2016/07/06 23:53:49 Naming nit: could you please call this "allocate*"
dshwang 2016/07/07 12:33:26 Done.
945 { 947 {
946 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8); 948 if (m_storageTextureSupported) {
947 m_gl->TexImage2D(target, level, internalformat, width, height, border, forma t, type, 0); 949 GLenum internalStorageFormat = GL_NONE;
950 if (internalformat == GL_RGB) {
951 internalStorageFormat = GL_RGB8;
952 } else if (internalformat == GL_RGBA) {
953 internalStorageFormat = GL_RGBA8;
954 } else {
955 NOTREACHED();
956 }
957 m_gl->TexStorage2DEXT(GL_TEXTURE_2D, 1, internalStorageFormat, width, he ight);
958 return true;
959 }
960 m_gl->TexImage2D(target, 0, internalformat, width, height, border, format, t ype, 0);
961 return false;
948 } 962 }
949 963
950 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) 964 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info)
951 { 965 {
952 if (info->imageId) { 966 if (info->imageId) {
953 m_gl->BindTexture(info->parameters.target, info->textureId); 967 m_gl->BindTexture(info->parameters.target, info->textureId);
954 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId); 968 m_gl->ReleaseTexImage2DCHROMIUM(info->parameters.target, info->imageId);
955 m_gl->DestroyImageCHROMIUM(info->imageId); 969 m_gl->DestroyImageCHROMIUM(info->imageId);
956 info->imageId = 0; 970 info->imageId = 0;
957 info->gpuMemoryBufferId = -1; 971 info->gpuMemoryBufferId = -1;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 info.textureId = textureId; 1013 info.textureId = textureId;
1000 info.imageId = imageId; 1014 info.imageId = imageId;
1001 info.gpuMemoryBufferId = gpuMemoryBufferId; 1015 info.gpuMemoryBufferId = gpuMemoryBufferId;
1002 info.parameters = parameters; 1016 info.parameters = parameters;
1003 clearChromiumImageAlpha(info); 1017 clearChromiumImageAlpha(info);
1004 return info; 1018 return info;
1005 } 1019 }
1006 1020
1007 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size) 1021 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( const IntSize& size)
1008 { 1022 {
1023 DrawingBuffer::TextureInfo info;
1009 TextureParameters parameters = defaultTextureParameters(); 1024 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; 1025 info.parameters = parameters;
1026 info.textureId = createColorTexture(parameters);
1027 info.immutable = createStorageTextureIfPossible(parameters.target, parameter s.creationInternalColorFormat,
1028 size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE );
1016 return info; 1029 return info;
1017 } 1030 }
1018 1031
1019 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) 1032 void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size)
1020 { 1033 {
1021 ASSERT(info->textureId); 1034 ASSERT(info->textureId);
1022 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) { 1035 if (!RuntimeEnabledFeatures::webGLImageChromiumEnabled()) {
1036 if (info->immutable) {
1037 m_gl->DeleteTextures(1, &info->textureId);
1038 info->textureId = createColorTexture(info->parameters);
1039 }
1023 m_gl->BindTexture(info->parameters.target, info->textureId); 1040 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); 1041 info->immutable = createStorageTextureIfPossible(info->parameters.target , info->parameters.creationInternalColorFormat,
1042 size.width(), size.height(), 0, info->parameters.colorFormat, GL_UNS IGNED_BYTE);
1025 return; 1043 return;
1026 } 1044 }
1027 1045
1046 DCHECK(!info->immutable);
1028 deleteChromiumImageForTexture(info); 1047 deleteChromiumImageForTexture(info);
1029 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size. height(), info->parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM); 1048 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size. height(), info->parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM);
1030 if (info->imageId) { 1049 if (info->imageId) {
1031 m_gl->BindTexture(info->parameters.target, info->textureId); 1050 m_gl->BindTexture(info->parameters.target, info->textureId);
1032 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId); 1051 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId);
1033 1052
1034 GLint gpuMemoryBufferId = -1; 1053 GLint gpuMemoryBufferId = -1;
1035 m_gl->GetImageivCHROMIUM(info->imageId, GC3D_GPU_MEMORY_BUFFER_ID, &gpuM emoryBufferId); 1054 m_gl->GetImageivCHROMIUM(info->imageId, GC3D_GPU_MEMORY_BUFFER_ID, &gpuM emoryBufferId);
1036 DCHECK_NE(-1, gpuMemoryBufferId); 1055 DCHECK_NE(-1, gpuMemoryBufferId);
1037 info->gpuMemoryBufferId = gpuMemoryBufferId; 1056 info->gpuMemoryBufferId = gpuMemoryBufferId;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 1107
1089 void DrawingBuffer::restoreTextureBindings() 1108 void DrawingBuffer::restoreTextureBindings()
1090 { 1109 {
1091 // This class potentially modifies the bindings for GL_TEXTURE_2D and 1110 // This class potentially modifies the bindings for GL_TEXTURE_2D and
1092 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since 1111 // GL_TEXTURE_RECTANGLE. Only GL_TEXTURE_2D needs to be restored since
1093 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. 1112 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE.
1094 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); 1113 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding);
1095 } 1114 }
1096 1115
1097 } // namespace blink 1116 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698