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

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1709163003: Add wrapBackendTextureAsRenderTarget API (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: fix test Created 4 years, 10 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 | « src/gpu/gl/GrGLGpu.h ('k') | src/image/SkSurface.cpp » ('j') | 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 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrGLGpu.h" 8 #include "GrGLGpu.h"
9 #include "GrGLGLSL.h" 9 #include "GrGLGLSL.h"
10 #include "GrGLStencilAttachment.h" 10 #include "GrGLStencilAttachment.h"
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if (!desc.fTextureHandle) { 540 if (!desc.fTextureHandle) {
541 return nullptr; 541 return nullptr;
542 } 542 }
543 #else 543 #else
544 const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc. fTextureHandle); 544 const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc. fTextureHandle);
545 if (!info || !info->fID) { 545 if (!info || !info->fID) {
546 return nullptr; 546 return nullptr;
547 } 547 }
548 #endif 548 #endif
549 549
550 int maxSize = this->caps()->maxTextureSize();
551 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
552 return nullptr;
553 }
554
555 // next line relies on GrBackendTextureDesc's flags matching GrTexture's 550 // next line relies on GrBackendTextureDesc's flags matching GrTexture's
556 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla g); 551 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla g);
557 552
558 GrGLTexture::IDDesc idDesc; 553 GrGLTexture::IDDesc idDesc;
559 GrSurfaceDesc surfDesc; 554 GrSurfaceDesc surfDesc;
560 555
561 #ifdef SK_IGNORE_GL_TEXTURE_TARGET 556 #ifdef SK_IGNORE_GL_TEXTURE_TARGET
562 idDesc.fInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); 557 idDesc.fInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle);
563 // We only support GL_TEXTURE_2D at the moment. 558 // We only support GL_TEXTURE_2D at the moment.
564 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; 559 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 desc.fConfig = wrapDesc.fConfig; 645 desc.fConfig = wrapDesc.fConfig;
651 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; 646 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag;
652 desc.fWidth = wrapDesc.fWidth; 647 desc.fWidth = wrapDesc.fWidth;
653 desc.fHeight = wrapDesc.fHeight; 648 desc.fHeight = wrapDesc.fHeight;
654 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() ); 649 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() );
655 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); 650 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
656 651
657 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil Bits); 652 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil Bits);
658 } 653 }
659 654
655 GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu reDesc& desc,
656 GrWrapOwnership owne rship) {
657 #ifdef SK_IGNORE_GL_TEXTURE_TARGET
658 if (!desc.fTextureHandle) {
659 return nullptr;
660 }
661 #else
662 const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc. fTextureHandle);
663 if (!info || !info->fID) {
664 return nullptr;
665 }
666 #endif
667
668 GrGLTexture::IDDesc idDesc;
669 GrSurfaceDesc surfDesc;
670
671 #ifdef SK_IGNORE_GL_TEXTURE_TARGET
672 idDesc.fInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle);
673 // We only support GL_TEXTURE_2D at the moment.
674 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D;
675 #else
676 idDesc.fInfo = *info;
677 #endif
678
679 if (GR_GL_TEXTURE_RECTANGLE != idDesc.fInfo.fTarget &&
680 GR_GL_TEXTURE_2D != idDesc.fInfo.fTarget) {
681 // Only texture rectangle and texture 2d are supported. We do not check whether texture
682 // rectangle is supported by Skia - if the caller provided us with a tex ture rectangle,
683 // we assume the necessary support exists.
684 return nullptr;
685 }
686
687 switch (ownership) {
688 case kAdopt_GrWrapOwnership:
689 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle;
690 break;
691 case kBorrow_GrWrapOwnership:
692 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle;
693 break;
694 }
695
696 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
697 surfDesc.fWidth = desc.fWidth;
698 surfDesc.fHeight = desc.fHeight;
699 surfDesc.fConfig = desc.fConfig;
700 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() );
701 // FIXME: this should be calling resolve_origin(), but Chrome code is curre ntly
702 // assuming the old behaviour, which is that backend textures are always
703 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to:
704 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget);
705 if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
706 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
707 } else {
708 surfDesc.fOrigin = desc.fOrigin;
709 }
710
711 GrGLRenderTarget::IDDesc rtIDDesc;
712 if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_Life Cycle,
713 idDesc.fInfo, &rtIDDesc)) {
714 return nullptr;
715 }
716 return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0);
717 }
718
660 //////////////////////////////////////////////////////////////////////////////// 719 ////////////////////////////////////////////////////////////////////////////////
720
661 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, 721 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
662 GrPixelConfig srcConfig, 722 GrPixelConfig srcConfig,
663 DrawPreference* drawPreference, 723 DrawPreference* drawPreference,
664 WritePixelTempDrawInfo* tempDrawInfo) { 724 WritePixelTempDrawInfo* tempDrawInfo) {
665 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) { 725 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf ace->config())) {
666 return false; 726 return false;
667 } 727 }
668 728
669 // This subclass only allows writes to textures. If the dst is not a texture we have to draw 729 // This subclass only allows writes to textures. If the dst is not a texture we have to draw
670 // into it. We could use glDrawPixels on GLs that have it, but we don't toda y. 730 // into it. We could use glDrawPixels on GLs that have it, but we don't toda y.
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 desc.fTextureStorageAllocator.fDeallocateTextureStorage( 1587 desc.fTextureStorageAllocator.fDeallocateTextureStorage(
1528 desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBackendOb ject>(info)); 1588 desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBackendOb ject>(info));
1529 return false; 1589 return false;
1530 } 1590 }
1531 return true; 1591 return true;
1532 } 1592 }
1533 1593
1534 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, 1594 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt,
1535 int width, 1595 int width,
1536 int height) { 1596 int height) {
1537 // All internally created RTs are also textures. We don't create
1538 // SBs for a client's standalone RT (that is a RT that isn't also a texture) .
1539 SkASSERT(rt->asTexture());
1540 SkASSERT(width >= rt->width()); 1597 SkASSERT(width >= rt->width());
1541 SkASSERT(height >= rt->height()); 1598 SkASSERT(height >= rt->height());
1542 1599
1543 int samples = rt->numStencilSamples(); 1600 int samples = rt->numStencilSamples();
1544 GrGLStencilAttachment::IDDesc sbDesc; 1601 GrGLStencilAttachment::IDDesc sbDesc;
1545 1602
1546 int sIdx = this->getCompatibleStencilIndex(rt->config()); 1603 int sIdx = this->getCompatibleStencilIndex(rt->config());
1547 if (sIdx < 0) { 1604 if (sIdx < 0) {
1548 return nullptr; 1605 return nullptr;
1549 } 1606 }
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3952 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 4009 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
3953 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 4010 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
3954 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 4011 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
3955 copyParams->fWidth = texture->width(); 4012 copyParams->fWidth = texture->width();
3956 copyParams->fHeight = texture->height(); 4013 copyParams->fHeight = texture->height();
3957 return true; 4014 return true;
3958 } 4015 }
3959 } 4016 }
3960 return false; 4017 return false;
3961 } 4018 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/image/SkSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698