blob: 742ec189a554dd23a053b5c53374da71b1e3d85c [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,
34 sk_gpu_test::GrContextFactory::ContextOptions options,
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;
brianosman898235c2016-04-06 07:38:23 -070039 if (SkImageInfoIsGammaCorrect(info)) {
brianosmanb461d342016-04-13 13:10:14 -070040 flags |= SkSurfaceProps::kGammaCorrect_Flag;
brianosman898235c2016-04-06 07:38:23 -070041 }
jvanverth4736e142014-11-07 07:12:46 -080042 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
reede8f30622016-03-23 18:59:25 -070043 return SkSurface::MakeRenderTarget(grFactory->get(type, options), SkBudgeted::kNo,
44 info, samples, &props);
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000045}
46
47} // namespace DM
48
49#else// !SK_SUPPORT_GPU
50
51// Ganesh is not available. Fake it.
52
kkinnunen80549fc2014-06-30 06:36:31 -070053enum GrGLStandard {
54 kNone_GrGLStandard,
55 kGL_GrGLStandard,
56 kGLES_GrGLStandard
57};
mtklein2ecf86e2014-11-06 08:06:39 -080058static const int kGrGLStandardCnt = 3;
kkinnunen80549fc2014-06-30 06:36:31 -070059
mtkleinb9eb4ac2015-02-02 18:26:03 -080060class GrContext {
61public:
62 void dumpCacheStats(SkString*) const {}
63 void dumpGpuStats(SkString*) const {}
64};
65
bsalomon3724e572016-03-30 18:56:19 -070066namespace sk_gpu_test {
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000067class GrContextFactory {
68public:
bsalomon4ee6bd82015-05-27 13:23:23 -070069 GrContextFactory() {};
70 explicit GrContextFactory(const GrContextOptions&) {}
71
bsalomon85b4b532016-04-05 11:06:27 -070072 typedef int ContextType;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000073
bsalomon85b4b532016-04-05 11:06:27 -070074 static const ContextType kANGLE_ContextType = 0,
75 kANGLE_GL_ContextType = 0,
76 kCommandBuffer_ContextType = 0,
77 kDebugGL_ContextType = 0,
78 kMESA_ContextType = 0,
79 kNVPR_ContextType = 0,
80 kNativeGL_ContextType = 0,
81 kGL_ContextType = 0,
82 kGLES_ContextType = 0,
bsalomondc0fcd42016-04-11 14:21:33 -070083 kNullGL_ContextType = 0,
84 kVulkan_ContextType = 0;
bsalomon85b4b532016-04-05 11:06:27 -070085 static const int kContextTypeCnt = 1;
86 enum ContextOptions {
87 kNone_ContextOptions = 0,
88 kEnableNVPR_ContextOptions = 0x1,
kkinnunen5219fd92015-12-10 06:28:13 -080089 };
mtklein1e319f72014-07-15 08:27:06 -070090 void destroyContexts() {}
bsalomon2354f842014-07-28 13:48:36 -070091
92 void abandonContexts() {}
bsalomon6e2aad42016-04-01 11:54:31 -070093
94 void releaseResourcesAndAbandonContexts() {}
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000095};
bsalomon3724e572016-03-30 18:56:19 -070096} // namespace sk_gpu_test
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000097
98namespace DM {
99
100static const bool kGPUDisabled = true;
101
bsalomon3724e572016-03-30 18:56:19 -0700102static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
bsalomon85b4b532016-04-05 11:06:27 -0700103 sk_gpu_test::GrContextFactory::ContextType,
104 sk_gpu_test::GrContextFactory::ContextOptions,
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000105 SkImageInfo,
jvanverth4736e142014-11-07 07:12:46 -0800106 int,
107 bool) {
halcanary96fcdcc2015-08-27 07:41:13 -0700108 return nullptr;
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000109}
110
111} // namespace DM
112
113#endif//SK_SUPPORT_GPU
114
commit-bot@chromium.org787227d2014-03-26 21:26:15 +0000115#endif//DMGpuSupport_DEFINED