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

Side by Side Diff: src/gpu/GrContext.cpp

Issue 2296193005: Add a makeDrawContextWithFallback that handles config fallback (Closed)
Patch Set: update Created 4 years, 3 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/GrClipStackClip.cpp ('k') | src/gpu/GrTextureParamsAdjuster.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 "GrContext.h" 8 #include "GrContext.h"
9 #include "GrContextPriv.h" 9 #include "GrContextPriv.h"
10 #include "GrContextOptions.h" 10 #include "GrContextOptions.h"
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsR enderTarget(desc)); 674 sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsR enderTarget(desc));
675 if (!surface) { 675 if (!surface) {
676 return nullptr; 676 return nullptr;
677 } 677 }
678 678
679 return this->drawingManager()->makeDrawContext(sk_ref_sp(surface->asRenderTa rget()), 679 return this->drawingManager()->makeDrawContext(sk_ref_sp(surface->asRenderTa rget()),
680 std::move(colorSpace), 680 std::move(colorSpace),
681 surfaceProps); 681 surfaceProps);
682 } 682 }
683 683
684 static inline GrPixelConfig GrPixelConfigFallback(GrPixelConfig config) {
685 static const GrPixelConfig kFallback[] = {
686 kUnknown_GrPixelConfig, // kUnknown_GrPixelConfig
687 kRGBA_8888_GrPixelConfig, // kAlpha_8_GrPixelConfig
688 kUnknown_GrPixelConfig, // kIndex_8_GrPixelConfig
689 kRGBA_8888_GrPixelConfig, // kRGB_565_GrPixelConfig
690 kRGBA_8888_GrPixelConfig, // kRGBA_4444_GrPixelConfig
691 kUnknown_GrPixelConfig, // kRGBA_8888_GrPixelConfig
692 kRGBA_8888_GrPixelConfig, // kBGRA_8888_GrPixelConfig
693 kUnknown_GrPixelConfig, // kSRGBA_8888_GrPixelConfig
694 kSRGBA_8888_GrPixelConfig, // kSBGRA_8888_GrPixelConfig
695 kUnknown_GrPixelConfig, // kETC1_GrPixelConfig
696 kUnknown_GrPixelConfig, // kLATC_GrPixelConfig
697 kUnknown_GrPixelConfig, // kR11_EAC_GrPixelConfig
698 kUnknown_GrPixelConfig, // kASTC_12x12_GrPixelConfig
699 kUnknown_GrPixelConfig, // kRGBA_float_GrPixelConfig
700 kRGBA_half_GrPixelConfig, // kAlpha_half_GrPixelConfig
701 kUnknown_GrPixelConfig, // kRGBA_half_GrPixelConfig
702 };
703 return kFallback[config];
704
705 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
706 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
707 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
708 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
709 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
710 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
711 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
712 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
713 GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig);
714 GR_STATIC_ASSERT(9 == kETC1_GrPixelConfig);
715 GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig);
716 GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig);
717 GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig);
718 GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig);
719 GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig);
720 GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig);
721 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFallback) == kGrPixelConfigCnt);
722 }
723
724 sk_sp<GrDrawContext> GrContext::makeDrawContextWithFallback(SkBackingFit fit,
725 int width, int heigh t,
726 GrPixelConfig config ,
727 sk_sp<SkColorSpace> colorSpace,
728 int sampleCnt,
729 GrSurfaceOrigin orig in,
730 const SkSurfaceProps * surfaceProps,
731 SkBudgeted budgeted) {
732 if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) {
733 config = GrPixelConfigFallback(config);
734 }
735
736 return this->makeDrawContext(fit, width, height, config, std::move(colorSpac e),
737 sampleCnt, origin, surfaceProps, budgeted);
738 }
739
684 sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit, 740 sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit,
685 int width, int height, 741 int width, int height,
686 GrPixelConfig config, 742 GrPixelConfig config,
687 sk_sp<SkColorSpace> colorSpace, 743 sk_sp<SkColorSpace> colorSpace,
688 int sampleCnt, 744 int sampleCnt,
689 GrSurfaceOrigin origin, 745 GrSurfaceOrigin origin,
690 const SkSurfaceProps* surfacePro ps, 746 const SkSurfaceProps* surfacePro ps,
691 SkBudgeted budgeted) { 747 SkBudgeted budgeted) {
748 if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) {
749 return nullptr;
750 }
751
692 GrSurfaceDesc desc; 752 GrSurfaceDesc desc;
693 desc.fFlags = kRenderTarget_GrSurfaceFlag; 753 desc.fFlags = kRenderTarget_GrSurfaceFlag;
694 desc.fOrigin = origin; 754 desc.fOrigin = origin;
695 desc.fWidth = width; 755 desc.fWidth = width;
696 desc.fHeight = height; 756 desc.fHeight = height;
697 desc.fConfig = config; 757 desc.fConfig = config;
698 desc.fSampleCnt = sampleCnt; 758 desc.fSampleCnt = sampleCnt;
699 759
700 sk_sp<GrTexture> tex; 760 sk_sp<GrTexture> tex;
701 if (SkBackingFit::kExact == fit) { 761 if (SkBackingFit::kExact == fit) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 ASSERT_SINGLE_OWNER 857 ASSERT_SINGLE_OWNER
798 fResourceCache->setLimits(maxTextures, maxTextureBytes); 858 fResourceCache->setLimits(maxTextures, maxTextureBytes);
799 } 859 }
800 860
801 ////////////////////////////////////////////////////////////////////////////// 861 //////////////////////////////////////////////////////////////////////////////
802 862
803 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { 863 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
804 ASSERT_SINGLE_OWNER 864 ASSERT_SINGLE_OWNER
805 fResourceCache->dumpMemoryStatistics(traceMemoryDump); 865 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
806 } 866 }
OLDNEW
« no previous file with comments | « src/gpu/GrClipStackClip.cpp ('k') | src/gpu/GrTextureParamsAdjuster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698