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 | |
| 16 | #if SK_SUPPORT_GPU |
| 17 | |
| 18 | // Ganesh is available. Yippee! |
| 19 | |
| 20 | # include "GrContext.h" |
| 21 | # include "GrContextFactory.h" |
| 22 | |
| 23 | namespace DM { |
| 24 | |
| 25 | static const bool kGPUDisabled = false; |
| 26 | |
| 27 | static inline SkSurface* NewGpuSurface(GrContextFactory* grFactory, |
| 28 | GrContextFactory::GLContextType type, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 29 | GrGLStandard gpuAPI, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 30 | SkImageInfo info, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 31 | int samples, |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 32 | bool useDIText) { |
| 33 | uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 34 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 35 | return SkSurface::NewRenderTarget(grFactory->get(type, gpuAPI), SkSurface::kNo_Budgeted, |
| 36 | info, samples, &props); |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | } // namespace DM |
| 40 | |
| 41 | #else// !SK_SUPPORT_GPU |
| 42 | |
| 43 | // Ganesh is not available. Fake it. |
| 44 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 45 | enum GrGLStandard { |
| 46 | kNone_GrGLStandard, |
| 47 | kGL_GrGLStandard, |
| 48 | kGLES_GrGLStandard |
| 49 | }; |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 50 | static const int kGrGLStandardCnt = 3; |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 51 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 52 | class GrContext { |
| 53 | public: |
| 54 | void dumpCacheStats(SkString*) const {} |
| 55 | void dumpGpuStats(SkString*) const {} |
| 56 | }; |
| 57 | |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 58 | struct GrContextOptions { |
| 59 | bool fImmediateMode; |
| 60 | }; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 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; |
mtklein | 1e319f7 | 2014-07-15 08:27:06 -0700 | [diff] [blame] | 78 | void destroyContexts() {} |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 79 | |
| 80 | void abandonContexts() {} |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | namespace DM { |
| 84 | |
| 85 | static const bool kGPUDisabled = true; |
| 86 | |
| 87 | static inline SkSurface* NewGpuSurface(GrContextFactory*, |
| 88 | GrContextFactory::GLContextType, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 89 | GrGLStandard, |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 90 | SkImageInfo, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 91 | int, |
| 92 | bool) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 93 | return nullptr; |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | } // namespace DM |
| 97 | |
| 98 | #endif//SK_SUPPORT_GPU |
| 99 | |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 100 | #endif//DMGpuSupport_DEFINED |