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 | |
| 31 | static inline SkSurface* NewGpuSurface(GrContextFactory* grFactory, |
| 32 | GrContextFactory::GLContextType type, |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 33 | GrContextFactory::GLContextOptions options, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 34 | SkImageInfo info, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 35 | int samples, |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 36 | bool useDIText) { |
| 37 | uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 38 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 39 | return SkSurface::NewRenderTarget(grFactory->get(type, options), SkSurface::kNo_Budgeted, |
| 40 | info, samples, &props); |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | } // namespace DM |
| 44 | |
| 45 | #else// !SK_SUPPORT_GPU |
| 46 | |
| 47 | // Ganesh is not available. Fake it. |
| 48 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 49 | enum GrGLStandard { |
| 50 | kNone_GrGLStandard, |
| 51 | kGL_GrGLStandard, |
| 52 | kGLES_GrGLStandard |
| 53 | }; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 54 | static const int kGrGLStandardCnt = 3; |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 55 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 56 | class GrContext { |
| 57 | public: |
| 58 | void dumpCacheStats(SkString*) const {} |
| 59 | void dumpGpuStats(SkString*) const {} |
| 60 | }; |
| 61 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 62 | class GrContextFactory { |
| 63 | public: |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 64 | GrContextFactory() {}; |
| 65 | explicit GrContextFactory(const GrContextOptions&) {} |
| 66 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 67 | typedef int GLContextType; |
| 68 | |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 69 | static const GLContextType kANGLE_GLContextType = 0, |
hendrikw | eddbefb | 2015-09-11 13:07:29 -0700 | [diff] [blame] | 70 | kANGLE_GL_GLContextType = 0, |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 71 | kCommandBuffer_GLContextType = 0, |
| 72 | kDebug_GLContextType = 0, |
| 73 | kMESA_GLContextType = 0, |
| 74 | kNVPR_GLContextType = 0, |
| 75 | kNative_GLContextType = 0, |
| 76 | kNull_GLContextType = 0; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 77 | static const int kGLContextTypeCnt = 1; |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 78 | enum GLContextOptions { |
| 79 | kNone_GLContextOptions = 0, |
| 80 | kEnableNVPR_GLContextOptions = 0x1, |
| 81 | }; |
mtklein | 1e319f7 | 2014-07-15 08:27:06 -0700 | [diff] [blame] | 82 | void destroyContexts() {} |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 83 | |
| 84 | void abandonContexts() {} |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | namespace DM { |
| 88 | |
| 89 | static const bool kGPUDisabled = true; |
| 90 | |
| 91 | static inline SkSurface* NewGpuSurface(GrContextFactory*, |
| 92 | GrContextFactory::GLContextType, |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 93 | GrContextFactory::GLContextOptions, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 94 | SkImageInfo, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 95 | int, |
| 96 | bool) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 97 | return nullptr; |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | } // namespace DM |
| 101 | |
| 102 | #endif//SK_SUPPORT_GPU |
| 103 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 104 | #endif//DMGpuSupport_DEFINED |