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

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

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