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, |
| 33 | sk_gpu_test::GrContextFactory::GLContextType type, |
| 34 | sk_gpu_test::GrContextFactory::GLContextOptions options, |
| 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); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 40 | return SkSurface::MakeRenderTarget(grFactory->get(type, options), SkBudgeted::kNo, |
| 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: |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 66 | GrContextFactory() {}; |
| 67 | explicit GrContextFactory(const GrContextOptions&) {} |
| 68 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 69 | typedef int GLContextType; |
| 70 | |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 71 | static const GLContextType kANGLE_GLContextType = 0, |
hendrikw | eddbefb | 2015-09-11 13:07:29 -0700 | [diff] [blame] | 72 | kANGLE_GL_GLContextType = 0, |
kkinnunen | f655e93 | 2016-03-03 07:39:48 -0800 | [diff] [blame] | 73 | kCommandBuffer_GLContextType = 0, |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 74 | kDebug_GLContextType = 0, |
| 75 | kMESA_GLContextType = 0, |
| 76 | kNVPR_GLContextType = 0, |
| 77 | kNative_GLContextType = 0, |
| 78 | kNull_GLContextType = 0; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 79 | static const int kGLContextTypeCnt = 1; |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 80 | enum GLContextOptions { |
| 81 | kNone_GLContextOptions = 0, |
| 82 | kEnableNVPR_GLContextOptions = 0x1, |
| 83 | }; |
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() {} |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 87 | }; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame^] | 88 | } // namespace sk_gpu_test |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 89 | |
| 90 | namespace DM { |
| 91 | |
| 92 | static const bool kGPUDisabled = true; |
| 93 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame^] | 94 | static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*, |
| 95 | sk_gpu_test::GrContextFactory::GLContextType, |
| 96 | sk_gpu_test::GrContextFactory::GLContextOptions, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 97 | SkImageInfo, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 98 | int, |
| 99 | bool) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 100 | return nullptr; |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | } // namespace DM |
| 104 | |
| 105 | #endif//SK_SUPPORT_GPU |
| 106 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 107 | #endif//DMGpuSupport_DEFINED |