blob: 75bfc3b23e8a271cd546be6fd861ba97ea7cee94 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
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.org787227d2014-03-26 21:26:15 +00008#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
bsalomon6dea83f2015-12-03 12:58:06 -080016// 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.org787227d2014-03-26 21:26:15 +000020#if SK_SUPPORT_GPU
21
22// Ganesh is available. Yippee!
23
24# include "GrContext.h"
25# include "GrContextFactory.h"
26
27namespace DM {
28
29static const bool kGPUDisabled = false;
30
bsalomon3724e572016-03-30 18:56:19 -070031static inline sk_sp<SkSurface> NewGpuSurface(
32 sk_gpu_test::GrContextFactory* grFactory,
bsalomon85b4b532016-04-05 11:06:27 -070033 sk_gpu_test::GrContextFactory::ContextType type,
csmartdaltone812d492017-02-21 12:36:05 -070034 sk_gpu_test::GrContextFactory::ContextOverrides overrides,
bsalomon3724e572016-03-30 18:56:19 -070035 SkImageInfo info,
36 int samples,
37 bool useDIText) {
bsalomonafcd7cd2015-08-31 12:39:41 -070038 uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
jvanverth4736e142014-11-07 07:12:46 -080039 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
csmartdaltone812d492017-02-21 12:36:05 -070040 return SkSurface::MakeRenderTarget(grFactory->get(type, overrides), SkBudgeted::kNo,
reede8f30622016-03-23 18:59:25 -070041 info, samples, &props);
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000042}
43
44} // namespace DM
45
46#else// !SK_SUPPORT_GPU
47
48// Ganesh is not available. Fake it.
49
kkinnunen80549fc2014-06-30 06:36:31 -070050enum GrGLStandard {
51 kNone_GrGLStandard,
52 kGL_GrGLStandard,
53 kGLES_GrGLStandard
54};
mtklein2ecf86e2014-11-06 08:06:39 -080055static const int kGrGLStandardCnt = 3;
kkinnunen80549fc2014-06-30 06:36:31 -070056
mtkleinb9eb4ac2015-02-02 18:26:03 -080057class GrContext {
58public:
59 void dumpCacheStats(SkString*) const {}
60 void dumpGpuStats(SkString*) const {}
61};
62
bsalomon3724e572016-03-30 18:56:19 -070063namespace sk_gpu_test {
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000064class GrContextFactory {
65public:
csmartdaltone812d492017-02-21 12:36:05 -070066 GrContextFactory() {}
bsalomon4ee6bd82015-05-27 13:23:23 -070067 explicit GrContextFactory(const GrContextOptions&) {}
68
bsalomon85b4b532016-04-05 11:06:27 -070069 typedef int ContextType;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000070
bsalomon85b4b532016-04-05 11:06:27 -070071 static const ContextType kANGLE_ContextType = 0,
72 kANGLE_GL_ContextType = 0,
73 kCommandBuffer_ContextType = 0,
74 kDebugGL_ContextType = 0,
75 kMESA_ContextType = 0,
76 kNVPR_ContextType = 0,
77 kNativeGL_ContextType = 0,
78 kGL_ContextType = 0,
79 kGLES_ContextType = 0,
bsalomondc0fcd42016-04-11 14:21:33 -070080 kNullGL_ContextType = 0,
81 kVulkan_ContextType = 0;
bsalomon85b4b532016-04-05 11:06:27 -070082 static const int kContextTypeCnt = 1;
csmartdaltone812d492017-02-21 12:36:05 -070083 enum class ContextOverrides {};
mtklein1e319f72014-07-15 08:27:06 -070084 void destroyContexts() {}
bsalomon2354f842014-07-28 13:48:36 -070085
86 void abandonContexts() {}
bsalomon6e2aad42016-04-01 11:54:31 -070087
88 void releaseResourcesAndAbandonContexts() {}
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000089};
bsalomon3724e572016-03-30 18:56:19 -070090} // namespace sk_gpu_test
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000091
92namespace DM {
93
94static const bool kGPUDisabled = true;
95
bsalomon3724e572016-03-30 18:56:19 -070096static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
bsalomon85b4b532016-04-05 11:06:27 -070097 sk_gpu_test::GrContextFactory::ContextType,
csmartdaltone812d492017-02-21 12:36:05 -070098 sk_gpu_test::GrContextFactory::ContextOverrides,
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000099 SkImageInfo,
jvanverth4736e142014-11-07 07:12:46 -0800100 int,
101 bool) {
halcanary96fcdcc2015-08-27 07:41:13 -0700102 return nullptr;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000103}
104
105} // namespace DM
106
107#endif//SK_SUPPORT_GPU
108
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000109#endif//DMGpuSupport_DEFINED