scroggo | 478652e | 2015-03-25 07:11:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 8 | #ifndef DMGpuSupport_DEFINED |
| 9 | #define DMGpuSupport_DEFINED |
| 10 | |
| 11 | // Provides Ganesh to DM, |
| 12 | // or if it's not available, fakes it enough so most code doesn't have to know that. |
| 13 | |
| 14 | #include "SkSurface.h" |
| 15 | |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 16 | // This should be safe to include even in no-gpu builds. Include by relative path so it |
| 17 | // can be found in non-gpu builds. |
| 18 | #include "../include/gpu/GrContextOptions.h" |
| 19 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 20 | #if SK_SUPPORT_GPU |
| 21 | |
| 22 | // Ganesh is available. Yippee! |
| 23 | |
| 24 | # include "GrContext.h" |
| 25 | # include "GrContextFactory.h" |
| 26 | |
| 27 | namespace DM { |
| 28 | |
| 29 | static const bool kGPUDisabled = false; |
| 30 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 31 | static inline sk_sp<SkSurface> NewGpuSurface( |
| 32 | sk_gpu_test::GrContextFactory* grFactory, |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 33 | sk_gpu_test::GrContextFactory::ContextType type, |
| 34 | sk_gpu_test::GrContextFactory::ContextOptions options, |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 35 | SkImageInfo info, |
| 36 | int samples, |
| 37 | bool useDIText) { |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 38 | uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 39 | if (SkImageInfoIsGammaCorrect(info)) { |
brianosman | b461d34 | 2016-04-13 13:10:14 -0700 | [diff] [blame] | 40 | flags |= SkSurfaceProps::kGammaCorrect_Flag; |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 41 | } |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 42 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 43 | return SkSurface::MakeRenderTarget(grFactory->get(type, options), SkBudgeted::kNo, |
| 44 | info, samples, &props); |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | } // namespace DM |
| 48 | |
| 49 | #else// !SK_SUPPORT_GPU |
| 50 | |
| 51 | // Ganesh is not available. Fake it. |
| 52 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 53 | enum GrGLStandard { |
| 54 | kNone_GrGLStandard, |
| 55 | kGL_GrGLStandard, |
| 56 | kGLES_GrGLStandard |
| 57 | }; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 58 | static const int kGrGLStandardCnt = 3; |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 59 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 60 | class GrContext { |
| 61 | public: |
| 62 | void dumpCacheStats(SkString*) const {} |
| 63 | void dumpGpuStats(SkString*) const {} |
| 64 | }; |
| 65 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 66 | namespace sk_gpu_test { |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 67 | class GrContextFactory { |
| 68 | public: |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 69 | GrContextFactory() {}; |
| 70 | explicit GrContextFactory(const GrContextOptions&) {} |
| 71 | |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 72 | typedef int ContextType; |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 73 | |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 74 | static const ContextType kANGLE_ContextType = 0, |
| 75 | kANGLE_GL_ContextType = 0, |
| 76 | kCommandBuffer_ContextType = 0, |
| 77 | kDebugGL_ContextType = 0, |
| 78 | kMESA_ContextType = 0, |
| 79 | kNVPR_ContextType = 0, |
| 80 | kNativeGL_ContextType = 0, |
| 81 | kGL_ContextType = 0, |
| 82 | kGLES_ContextType = 0, |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 83 | kNullGL_ContextType = 0, |
| 84 | kVulkan_ContextType = 0; |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 85 | static const int kContextTypeCnt = 1; |
| 86 | enum ContextOptions { |
| 87 | kNone_ContextOptions = 0, |
| 88 | kEnableNVPR_ContextOptions = 0x1, |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 89 | }; |
mtklein | 1e319f7 | 2014-07-15 08:27:06 -0700 | [diff] [blame] | 90 | void destroyContexts() {} |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 91 | |
| 92 | void abandonContexts() {} |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 93 | |
| 94 | void releaseResourcesAndAbandonContexts() {} |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 95 | }; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 96 | } // namespace sk_gpu_test |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 97 | |
| 98 | namespace DM { |
| 99 | |
| 100 | static const bool kGPUDisabled = true; |
| 101 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 102 | static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*, |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 103 | sk_gpu_test::GrContextFactory::ContextType, |
| 104 | sk_gpu_test::GrContextFactory::ContextOptions, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 105 | SkImageInfo, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 106 | int, |
| 107 | bool) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 108 | return nullptr; |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | } // namespace DM |
| 112 | |
| 113 | #endif//SK_SUPPORT_GPU |
| 114 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 115 | #endif//DMGpuSupport_DEFINED |