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

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

Issue 2399733002: DrawingBuffer cleanup: Part 1 of many (Closed)
Patch Set: Fix unittests Created 4 years, 2 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
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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 void DrawingBuffer::gpuMailboxReleased(const gpu::Mailbox& mailbox, 408 void DrawingBuffer::gpuMailboxReleased(const gpu::Mailbox& mailbox,
409 const gpu::SyncToken& syncToken, 409 const gpu::SyncToken& syncToken,
410 bool lostResource) { 410 bool lostResource) {
411 if (m_destructionInProgress || 411 if (m_destructionInProgress ||
412 m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR || lostResource || 412 m_gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR || lostResource ||
413 m_isHidden) { 413 m_isHidden) {
414 deleteMailbox(mailbox, syncToken); 414 deleteMailbox(mailbox, syncToken);
415 return; 415 return;
416 } 416 }
417 417
418 // Creation of image backed mailboxes is very expensive, so be less
419 // aggressive about pruning them. Pruning is done in FIFO order.
420 size_t cacheLimit = 1;
421 if (shouldUseChromiumImage())
422 cacheLimit = 4;
423 while (m_recycledMailboxQueue.size() >= cacheLimit) {
424 RefPtr<RecycledMailbox> recycled = m_recycledMailboxQueue.takeLast();
425 deleteMailbox(recycled->mailbox, recycled->syncToken);
426 }
427
428 RefPtr<MailboxInfo> mailboxInfo;
418 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { 429 for (size_t i = 0; i < m_textureMailboxes.size(); i++) {
419 RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[i]; 430 if (m_textureMailboxes[i]->mailbox == mailbox) {
420 if (mailboxInfo->mailbox == mailbox) { 431 mailboxInfo = m_textureMailboxes[i];
421 m_recycledMailboxQueue.prepend( 432 break;
422 adoptRef(new RecycledMailbox(mailbox, syncToken)));
423 return;
424 } 433 }
425 } 434 }
426 ASSERT_NOT_REACHED(); 435 DCHECK(mailboxInfo);
436 if (mailboxInfo->size != m_size) {
437 deleteMailbox(mailbox, syncToken);
438 return;
439 }
440
441 m_recycledMailboxQueue.prepend(
442 adoptRef(new RecycledMailbox(mailbox, syncToken)));
427 } 443 }
428 444
429 void DrawingBuffer::softwareMailboxReleased( 445 void DrawingBuffer::softwareMailboxReleased(
430 std::unique_ptr<cc::SharedBitmap> bitmap, 446 std::unique_ptr<cc::SharedBitmap> bitmap,
431 const IntSize& size, 447 const IntSize& size,
432 const gpu::SyncToken& syncToken, 448 const gpu::SyncToken& syncToken,
433 bool lostResource) { 449 bool lostResource) {
434 DCHECK(!syncToken.HasData()); // No sync tokens for software resources. 450 DCHECK(!syncToken.HasData()); // No sync tokens for software resources.
435 if (m_destructionInProgress || lostResource || m_isHidden || size != m_size) 451 if (m_destructionInProgress || lostResource || m_isHidden || size != m_size)
436 return; // Just delete the bitmap. 452 return; // Just delete the bitmap.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 parameters.internalColorFormat = format; 579 parameters.internalColorFormat = format;
564 parameters.colorFormat = format; 580 parameters.colorFormat = format;
565 } 581 }
566 return parameters; 582 return parameters;
567 } 583 }
568 584
569 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::takeRecycledMailbox() { 585 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::takeRecycledMailbox() {
570 if (m_recycledMailboxQueue.isEmpty()) 586 if (m_recycledMailboxQueue.isEmpty())
571 return nullptr; 587 return nullptr;
572 588
573 // Creation of image backed mailboxes is very expensive, so be less 589 RefPtr<RecycledMailbox> recycled = m_recycledMailboxQueue.takeLast();
574 // aggressive about pruning them.
575 size_t cacheLimit = 1;
576 if (shouldUseChromiumImage())
577 cacheLimit = 4;
578
579 RefPtr<RecycledMailbox> recycled;
580 while (m_recycledMailboxQueue.size() > cacheLimit) {
581 recycled = m_recycledMailboxQueue.takeLast();
582 deleteMailbox(recycled->mailbox, recycled->syncToken);
583 }
584 recycled = m_recycledMailboxQueue.takeLast();
585
586 if (recycled->syncToken.HasData()) 590 if (recycled->syncToken.HasData())
587 m_gl->WaitSyncTokenCHROMIUM(recycled->syncToken.GetData()); 591 m_gl->WaitSyncTokenCHROMIUM(recycled->syncToken.GetData());
588 592
589 RefPtr<MailboxInfo> mailboxInfo; 593 RefPtr<MailboxInfo> mailboxInfo;
590 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { 594 for (size_t i = 0; i < m_textureMailboxes.size(); i++) {
591 if (m_textureMailboxes[i]->mailbox == recycled->mailbox) { 595 if (m_textureMailboxes[i]->mailbox == recycled->mailbox) {
592 mailboxInfo = m_textureMailboxes[i]; 596 mailboxInfo = m_textureMailboxes[i];
593 break; 597 break;
594 } 598 }
595 } 599 }
596 ASSERT(mailboxInfo); 600 DCHECK(mailboxInfo);
597 601 DCHECK(mailboxInfo->size == m_size);
598 if (mailboxInfo->size != m_size) {
599 resizeTextureMemory(&mailboxInfo->textureInfo, m_size);
600 mailboxInfo->size = m_size;
601 }
602
603 return mailboxInfo.release(); 602 return mailboxInfo.release();
604 } 603 }
605 604
606 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox( 605 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(
607 const TextureInfo& info) { 606 const TextureInfo& info) {
608 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo); 607 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo);
609 m_gl->GenMailboxCHROMIUM(returnMailbox->mailbox.name); 608 m_gl->GenMailboxCHROMIUM(returnMailbox->mailbox.name);
610 returnMailbox->textureInfo = info; 609 returnMailbox->textureInfo = info;
611 returnMailbox->size = m_size; 610 returnMailbox->size = m_size;
612 m_textureMailboxes.append(returnMailbox); 611 m_textureMailboxes.append(returnMailbox);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 m_gl->DeleteRenderbuffers(1, &m_multisampleRenderbuffer); 797 m_gl->DeleteRenderbuffers(1, &m_multisampleRenderbuffer);
799 798
800 if (m_depthStencilBuffer) 799 if (m_depthStencilBuffer)
801 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer); 800 m_gl->DeleteRenderbuffers(1, &m_depthStencilBuffer);
802 801
803 if (m_colorBuffer.textureId) { 802 if (m_colorBuffer.textureId) {
804 deleteChromiumImageForTexture(&m_colorBuffer); 803 deleteChromiumImageForTexture(&m_colorBuffer);
805 m_gl->DeleteTextures(1, &m_colorBuffer.textureId); 804 m_gl->DeleteTextures(1, &m_colorBuffer.textureId);
806 } 805 }
807 806
808 setSize(IntSize()); 807 m_size = IntSize();
809 808
810 m_colorBuffer = TextureInfo(); 809 m_colorBuffer = TextureInfo();
811 m_frontColorBuffer = FrontBufferInfo(); 810 m_frontColorBuffer = FrontBufferInfo();
812 m_multisampleRenderbuffer = 0; 811 m_multisampleRenderbuffer = 0;
813 m_depthStencilBuffer = 0; 812 m_depthStencilBuffer = 0;
814 m_multisampleFBO = 0; 813 m_multisampleFBO = 0;
815 m_fbo = 0; 814 m_fbo = 0;
816 815
817 if (m_layer) 816 if (m_layer)
818 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); 817 GraphicsLayer::unregisterContentsLayer(m_layer->layer());
819 } 818 }
820 819
821 GLuint DrawingBuffer::createColorTexture(const TextureParameters& parameters) { 820 GLuint DrawingBuffer::createColorTexture(const TextureParameters& parameters) {
822 GLuint offscreenColorTexture; 821 GLuint offscreenColorTexture;
823 m_gl->GenTextures(1, &offscreenColorTexture); 822 m_gl->GenTextures(1, &offscreenColorTexture);
824 m_gl->BindTexture(parameters.target, offscreenColorTexture); 823 m_gl->BindTexture(parameters.target, offscreenColorTexture);
825 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 824 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
826 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 825 m_gl->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
827 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 826 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
828 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 827 m_gl->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
829 return offscreenColorTexture; 828 return offscreenColorTexture;
830 } 829 }
831 830
832 bool DrawingBuffer::resizeMultisampleFramebuffer(const IntSize& size) {
833 DCHECK(wantExplicitResolve());
834 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
835 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleRenderbuffer);
836 m_gl->RenderbufferStorageMultisampleCHROMIUM(
837 GL_RENDERBUFFER, m_sampleCount, getMultisampledRenderbufferFormat(),
838 size.width(), size.height());
839
840 if (m_gl->GetError() == GL_OUT_OF_MEMORY)
841 return false;
842
843 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
844 GL_RENDERBUFFER, m_multisampleRenderbuffer);
845
846 return true;
847 }
848
849 void DrawingBuffer::resizeDepthStencil(const IntSize& size) {
850 m_gl->BindFramebuffer(GL_FRAMEBUFFER,
851 m_multisampleFBO ? m_multisampleFBO : m_fbo);
852 if (!m_depthStencilBuffer)
853 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer);
854 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
855 if (m_antiAliasingMode == MSAAImplicitResolve)
856 m_gl->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCount,
857 GL_DEPTH24_STENCIL8_OES,
858 size.width(), size.height());
859 else if (m_antiAliasingMode == MSAAExplicitResolve)
860 m_gl->RenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER, m_sampleCount,
861 GL_DEPTH24_STENCIL8_OES,
862 size.width(), size.height());
863 else
864 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES,
865 size.width(), size.height());
866 // For ES 2.0 contexts DEPTH_STENCIL is not available natively, so we emulate
867 // it at the command buffer level for WebGL contexts.
868 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
869 GL_RENDERBUFFER, m_depthStencilBuffer);
870 m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0);
871 }
872
873 bool DrawingBuffer::resizeDefaultFramebuffer(const IntSize& size) { 831 bool DrawingBuffer::resizeDefaultFramebuffer(const IntSize& size) {
874 // Resize or create m_colorBuffer. 832 // Resize or create m_colorBuffer.
875 if (m_colorBuffer.textureId) { 833 if (m_colorBuffer.textureId) {
876 resizeTextureMemory(&m_colorBuffer, size); 834 deleteChromiumImageForTexture(&m_colorBuffer);
877 } else { 835 m_gl->DeleteTextures(1, &m_colorBuffer.textureId);
878 m_colorBuffer = createTextureAndAllocateMemory(size);
879 } 836 }
837 m_colorBuffer = createTextureAndAllocateMemory(size);
880 838
881 attachColorBufferToReadFramebuffer(); 839 attachColorBufferToReadFramebuffer();
882 840
883 if (wantExplicitResolve()) { 841 if (wantExplicitResolve()) {
884 if (!resizeMultisampleFramebuffer(size)) 842 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
843 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_multisampleRenderbuffer);
844 m_gl->RenderbufferStorageMultisampleCHROMIUM(
845 GL_RENDERBUFFER, m_sampleCount, getMultisampledRenderbufferFormat(),
846 size.width(), size.height());
847
848 if (m_gl->GetError() == GL_OUT_OF_MEMORY)
885 return false; 849 return false;
850
851 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
852 GL_RENDERBUFFER, m_multisampleRenderbuffer);
886 } 853 }
887 854
888 if (wantDepthOrStencil()) 855 if (wantDepthOrStencil()) {
889 resizeDepthStencil(size); 856 m_gl->BindFramebuffer(GL_FRAMEBUFFER,
857 m_multisampleFBO ? m_multisampleFBO : m_fbo);
858 if (!m_depthStencilBuffer)
859 m_gl->GenRenderbuffers(1, &m_depthStencilBuffer);
860 m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
861 if (m_antiAliasingMode == MSAAImplicitResolve) {
862 m_gl->RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, m_sampleCount,
863 GL_DEPTH24_STENCIL8_OES,
864 size.width(), size.height());
865 } else if (m_antiAliasingMode == MSAAExplicitResolve) {
866 m_gl->RenderbufferStorageMultisampleCHROMIUM(
867 GL_RENDERBUFFER, m_sampleCount, GL_DEPTH24_STENCIL8_OES, size.width(),
868 size.height());
869 } else {
870 m_gl->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES,
871 size.width(), size.height());
872 }
873 // For ES 2.0 contexts DEPTH_STENCIL is not available natively, so we
874 // emulate
875 // it at the command buffer level for WebGL contexts.
876 m_gl->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
877 GL_RENDERBUFFER, m_depthStencilBuffer);
878 m_gl->BindRenderbuffer(GL_RENDERBUFFER, 0);
879 }
890 880
891 if (wantExplicitResolve()) { 881 if (wantExplicitResolve()) {
892 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); 882 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
893 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 883 if (m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
894 return false; 884 return false;
895 } 885 }
896 886
897 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 887 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
898 return m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) == 888 return m_gl->CheckFramebufferStatus(GL_FRAMEBUFFER) ==
899 GL_FRAMEBUFFER_COMPLETE; 889 GL_FRAMEBUFFER_COMPLETE;
900 } 890 }
901 891
902 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) { 892 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) {
903 // We will clear the multisample FBO, but we also need to clear the 893 // We will clear the multisample FBO, but we also need to clear the
904 // non-multisampled buffer. 894 // non-multisampled buffer.
905 if (m_multisampleFBO) { 895 if (m_multisampleFBO) {
906 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 896 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
907 m_gl->Clear(GL_COLOR_BUFFER_BIT); 897 m_gl->Clear(GL_COLOR_BUFFER_BIT);
908 } 898 }
909 899
910 m_gl->BindFramebuffer(GL_FRAMEBUFFER, 900 m_gl->BindFramebuffer(GL_FRAMEBUFFER,
911 m_multisampleFBO ? m_multisampleFBO : m_fbo); 901 m_multisampleFBO ? m_multisampleFBO : m_fbo);
912 m_gl->Clear(clearMask); 902 m_gl->Clear(clearMask);
913 } 903 }
914 904
915 void DrawingBuffer::setSize(const IntSize& size) {
916 if (m_size == size)
917 return;
918
919 m_size = size;
920 }
921
922 IntSize DrawingBuffer::adjustSize(const IntSize& desiredSize, 905 IntSize DrawingBuffer::adjustSize(const IntSize& desiredSize,
923 const IntSize& curSize, 906 const IntSize& curSize,
924 int maxTextureSize) { 907 int maxTextureSize) {
925 IntSize adjustedSize = desiredSize; 908 IntSize adjustedSize = desiredSize;
926 909
927 // Clamp if the desired size is greater than the maximum texture size for the 910 // Clamp if the desired size is greater than the maximum texture size for the
928 // device. 911 // device.
929 if (adjustedSize.height() > maxTextureSize) 912 if (adjustedSize.height() > maxTextureSize)
930 adjustedSize.setHeight(maxTextureSize); 913 adjustedSize.setHeight(maxTextureSize);
931 914
(...skipping 11 matching lines...) Expand all
943 926
944 if (adjustedSize != m_size) { 927 if (adjustedSize != m_size) {
945 do { 928 do {
946 if (!resizeDefaultFramebuffer(adjustedSize)) { 929 if (!resizeDefaultFramebuffer(adjustedSize)) {
947 adjustedSize.scale(s_resourceAdjustedRatio); 930 adjustedSize.scale(s_resourceAdjustedRatio);
948 continue; 931 continue;
949 } 932 }
950 break; 933 break;
951 } while (!adjustedSize.isEmpty()); 934 } while (!adjustedSize.isEmpty());
952 935
953 setSize(adjustedSize); 936 m_size = adjustedSize;
erikchen 2016/10/06 17:08:25 if adjustedSize is empty, then recycled mailboxes
ccameron 2016/10/06 17:48:01 Oops! Moved the "free" to be right next to the m_s
954 937
955 if (adjustedSize.isEmpty()) 938 if (adjustedSize.isEmpty())
956 return false; 939 return false;
957 } 940 }
958 941
959 m_gl->Disable(GL_SCISSOR_TEST); 942 m_gl->Disable(GL_SCISSOR_TEST);
960 m_gl->ClearColor(0, 0, 0, 943 m_gl->ClearColor(0, 0, 0,
961 defaultBufferRequiresAlphaChannelToBePreserved() ? 1 : 0); 944 defaultBufferRequiresAlphaChannelToBePreserved() ? 1 : 0);
962 m_gl->ColorMask(true, true, true, true); 945 m_gl->ColorMask(true, true, true, true);
963 946
964 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; 947 GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
965 if (!!m_depthStencilBuffer) { 948 if (!!m_depthStencilBuffer) {
966 m_gl->ClearDepthf(1.0f); 949 m_gl->ClearDepthf(1.0f);
967 clearMask |= GL_DEPTH_BUFFER_BIT; 950 clearMask |= GL_DEPTH_BUFFER_BIT;
968 m_gl->DepthMask(true); 951 m_gl->DepthMask(true);
969 } 952 }
970 if (!!m_depthStencilBuffer) { 953 if (!!m_depthStencilBuffer) {
971 m_gl->ClearStencil(0); 954 m_gl->ClearStencil(0);
972 clearMask |= GL_STENCIL_BUFFER_BIT; 955 clearMask |= GL_STENCIL_BUFFER_BIT;
973 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); 956 m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF);
974 } 957 }
975 958
976 clearFramebuffers(clearMask); 959 clearFramebuffers(clearMask);
960 freeRecycledMailboxes();
977 return true; 961 return true;
978 } 962 }
979 963
980 void DrawingBuffer::commit() { 964 void DrawingBuffer::commit() {
981 if (wantExplicitResolve() && !m_contentsChangeCommitted) { 965 if (wantExplicitResolve() && !m_contentsChangeCommitted) {
982 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); 966 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO);
983 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); 967 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
984 968
985 if (m_scissorEnabled) 969 if (m_scissorEnabled)
986 m_gl->Disable(GL_SCISSOR_TEST); 970 m_gl->Disable(GL_SCISSOR_TEST);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 1225
1242 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory( 1226 DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory(
1243 const IntSize& size) { 1227 const IntSize& size) {
1244 DrawingBuffer::TextureInfo info; 1228 DrawingBuffer::TextureInfo info;
1245 TextureParameters parameters = defaultTextureParameters(); 1229 TextureParameters parameters = defaultTextureParameters();
1246 info.parameters = parameters; 1230 info.parameters = parameters;
1247 info.textureId = createColorTexture(parameters); 1231 info.textureId = createColorTexture(parameters);
1248 allocateConditionallyImmutableTexture( 1232 allocateConditionallyImmutableTexture(
1249 parameters.target, parameters.creationInternalColorFormat, size.width(), 1233 parameters.target, parameters.creationInternalColorFormat, size.width(),
1250 size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); 1234 size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE);
1251 info.immutable = m_storageTextureSupported;
1252 return info; 1235 return info;
1253 } 1236 }
1254 1237
1255 void DrawingBuffer::resizeTextureMemory(TextureInfo* info,
1256 const IntSize& size) {
1257 ASSERT(info->textureId);
1258 if (!shouldUseChromiumImage()) {
1259 if (info->immutable) {
1260 DCHECK(m_storageTextureSupported);
1261 m_gl->DeleteTextures(1, &info->textureId);
1262 info->textureId = createColorTexture(info->parameters);
1263 }
1264 m_gl->BindTexture(info->parameters.target, info->textureId);
1265 allocateConditionallyImmutableTexture(
1266 info->parameters.target, info->parameters.creationInternalColorFormat,
1267 size.width(), size.height(), 0, info->parameters.colorFormat,
1268 GL_UNSIGNED_BYTE);
1269 info->immutable = m_storageTextureSupported;
1270 return;
1271 }
1272
1273 DCHECK(!info->immutable);
1274 deleteChromiumImageForTexture(info);
1275 info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(
1276 size.width(), size.height(), info->parameters.creationInternalColorFormat,
1277 GC3D_SCANOUT_CHROMIUM);
1278 if (info->imageId) {
1279 m_gl->BindTexture(info->parameters.target, info->textureId);
1280 m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId);
1281 clearChromiumImageAlpha(*info);
1282 } else {
1283 // At this point, the texture still exists, but has no allocated
1284 // storage. This is intentional, and mimics the behavior of a texImage2D
1285 // failure.
1286 }
1287 }
1288
1289 void DrawingBuffer::attachColorBufferToReadFramebuffer() { 1238 void DrawingBuffer::attachColorBufferToReadFramebuffer() {
1290 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo); 1239 m_gl->BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
1291 1240
1292 GLenum target = m_colorBuffer.parameters.target; 1241 GLenum target = m_colorBuffer.parameters.target;
1293 GLenum id = m_colorBuffer.textureId; 1242 GLenum id = m_colorBuffer.textureId;
1294 1243
1295 m_gl->BindTexture(target, id); 1244 m_gl->BindTexture(target, id);
1296 1245
1297 if (m_antiAliasingMode == MSAAImplicitResolve) 1246 if (m_antiAliasingMode == MSAAImplicitResolve)
1298 m_gl->FramebufferTexture2DMultisampleEXT( 1247 m_gl->FramebufferTexture2DMultisampleEXT(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE. 1282 // the public interface for WebGL does not support GL_TEXTURE_RECTANGLE.
1334 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding); 1283 m_gl->BindTexture(GL_TEXTURE_2D, m_texture2DBinding);
1335 } 1284 }
1336 1285
1337 bool DrawingBuffer::shouldUseChromiumImage() { 1286 bool DrawingBuffer::shouldUseChromiumImage() {
1338 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && 1287 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() &&
1339 m_chromiumImageUsage == AllowChromiumImage; 1288 m_chromiumImageUsage == AllowChromiumImage;
1340 } 1289 }
1341 1290
1342 } // namespace blink 1291 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698