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, |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 34 | sk_gpu_test::GrContextFactory::ContextOverrides overrides, |
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; |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 39 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 40 | return SkSurface::MakeRenderTarget(grFactory->get(type, overrides), SkBudgeted::kNo, |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 41 | info, samples, &props); |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | } // namespace DM |
| 45 | |
| 46 | #else// !SK_SUPPORT_GPU |
| 47 | |
| 48 | // Ganesh is not available. Fake it. |
| 49 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 50 | enum GrGLStandard { |
| 51 | kNone_GrGLStandard, |
| 52 | kGL_GrGLStandard, |
| 53 | kGLES_GrGLStandard |
| 54 | }; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 55 | static const int kGrGLStandardCnt = 3; |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 56 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 57 | class GrContext { |
| 58 | public: |
| 59 | void dumpCacheStats(SkString*) const {} |
| 60 | void dumpGpuStats(SkString*) const {} |
| 61 | }; |
| 62 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 63 | namespace sk_gpu_test { |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 64 | class GrContextFactory { |
| 65 | public: |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 66 | GrContextFactory() {} |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 67 | explicit GrContextFactory(const GrContextOptions&) {} |
| 68 | |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 69 | typedef int ContextType; |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 70 | |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 71 | static const ContextType kANGLE_ContextType = 0, |
| 72 | kANGLE_GL_ContextType = 0, |
| 73 | kCommandBuffer_ContextType = 0, |
| 74 | kDebugGL_ContextType = 0, |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 75 | kNVPR_ContextType = 0, |
| 76 | kNativeGL_ContextType = 0, |
| 77 | kGL_ContextType = 0, |
| 78 | kGLES_ContextType = 0, |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 79 | kNullGL_ContextType = 0, |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 80 | kVulkan_ContextType = 0, |
| 81 | kMetal_ContextType = 0; |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 82 | static const int kContextTypeCnt = 1; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 83 | enum class ContextOverrides {}; |
mtklein | 1e319f7 | 2014-07-15 08:27:06 -0700 | [diff] [blame] | 84 | void destroyContexts() {} |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 85 | |
| 86 | void abandonContexts() {} |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 87 | |
| 88 | void releaseResourcesAndAbandonContexts() {} |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 89 | }; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 90 | } // namespace sk_gpu_test |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 91 | |
| 92 | namespace DM { |
| 93 | |
| 94 | static const bool kGPUDisabled = true; |
| 95 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 96 | static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*, |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 97 | sk_gpu_test::GrContextFactory::ContextType, |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 98 | sk_gpu_test::GrContextFactory::ContextOverrides, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 99 | SkImageInfo, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 100 | int, |
| 101 | bool) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 102 | return nullptr; |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | } // namespace DM |
| 106 | |
| 107 | #endif//SK_SUPPORT_GPU |
| 108 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 109 | #endif//DMGpuSupport_DEFINED |