blob: e4c7a8351398ded88c5ee06f458d565824210eed [file] [log] [blame]
commit-bot@chromium.org78a10782013-08-21 19:27:48 +00001
2/*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "GrTest.h"
10
joshualitt50408ad2014-11-03 12:31:14 -080011#include "GrInOrderDrawBuffer.h"
bsalomon71cb0c22014-11-14 12:10:14 -080012#include "GrResourceCache2.h"
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000013
14void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target) {
15 SkASSERT(!fContext);
16
17 fContext.reset(SkRef(ctx));
18 fDrawTarget.reset(SkRef(target));
19
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000020 SkNEW_IN_TLAZY(&fACR, GrDrawTarget::AutoClipRestore, (target));
21 SkNEW_IN_TLAZY(&fAGP, GrDrawTarget::AutoGeometryPush, (target));
22}
23
24void GrContext::getTestTarget(GrTestTarget* tar) {
25 this->flush();
26 // We could create a proxy GrDrawTarget that passes through to fGpu until ~GrTextTarget() and
27 // then disconnects. This would help prevent test writers from mixing using the returned
28 // GrDrawTarget and regular drawing. We could also assert or fail in GrContext drawing methods
29 // until ~GrTestTarget().
joshualitt50408ad2014-11-03 12:31:14 -080030 tar->init(this, fDrawBuffer);
commit-bot@chromium.org78a10782013-08-21 19:27:48 +000031}
32
33///////////////////////////////////////////////////////////////////////////////
34
35void GrContext::setMaxTextureSizeOverride(int maxTextureSizeOverride) {
36 fMaxTextureSizeOverride = maxTextureSizeOverride;
37}
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000038
39void GrContext::purgeAllUnlockedResources() {
bsalomon71cb0c22014-11-14 12:10:14 -080040 fResourceCache2->purgeAllUnlocked();
robertphillips@google.com94d8f1e2013-12-18 17:25:33 +000041}
bsalomon33435572014-11-05 14:47:41 -080042
43///////////////////////////////////////////////////////////////////////////////
44// Code for the mock context. It's built on a mock GrGpu class that does nothing.
45////
46
47#include "GrBufferAllocPool.h"
48#include "GrInOrderDrawBuffer.h"
49#include "GrGpu.h"
50
egdaniel8dd688b2015-01-22 10:16:09 -080051class GrPipeline;
joshualittd53a8272014-11-10 16:03:14 -080052
bsalomon33435572014-11-05 14:47:41 -080053class MockGpu : public GrGpu {
54public:
55 MockGpu(GrContext* context) : INHERITED(context) { fCaps.reset(SkNEW(GrDrawTargetCaps)); }
bsalomonf90a02b2014-11-26 12:28:00 -080056 ~MockGpu() SK_OVERRIDE {}
57 bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -080058 return true;
59 }
60
bsalomonf90a02b2014-11-26 12:28:00 -080061 bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget,
62 int left, int top,
63 int width, int height,
64 GrPixelConfig config,
65 size_t rowBytes) const SK_OVERRIDE { return false; }
joshualitt873ad0e2015-01-20 09:08:51 -080066 void buildProgramDesc(GrProgramDesc*,const GrPrimitiveProcessor&,
egdaniel8dd688b2015-01-22 10:16:09 -080067 const GrPipeline&,
bsalomonf90a02b2014-11-26 12:28:00 -080068 const GrProgramDesc::DescInfo&,
joshualitt873ad0e2015-01-20 09:08:51 -080069 const GrBatchTracker&) const SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -080070
bsalomonf90a02b2014-11-26 12:28:00 -080071 void discard(GrRenderTarget*) SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -080072
bsalomonf90a02b2014-11-26 12:28:00 -080073 bool canCopySurface(const GrSurface* dst,
74 const GrSurface* src,
75 const SkIRect& srcRect,
76 const SkIPoint& dstPoint) SK_OVERRIDE { return false; };
joshualitt3322fa42014-11-07 08:48:51 -080077
bsalomonf90a02b2014-11-26 12:28:00 -080078 bool copySurface(GrSurface* dst,
79 GrSurface* src,
80 const SkIRect& srcRect,
81 const SkIPoint& dstPoint) SK_OVERRIDE { return false; };
82
83 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_OVERRIDE {
84 return false;
85 }
joshualitt3322fa42014-11-07 08:48:51 -080086
bsalomon33435572014-11-05 14:47:41 -080087private:
bsalomonf90a02b2014-11-26 12:28:00 -080088 void onResetContext(uint32_t resetBits) SK_OVERRIDE {}
89
bsalomon5236cf42015-01-14 10:42:08 -080090 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
bsalomonf90a02b2014-11-26 12:28:00 -080091 size_t rowBytes) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -080092 return NULL;
93 }
94
bsalomon5236cf42015-01-14 10:42:08 -080095 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted,
bsalomonf90a02b2014-11-26 12:28:00 -080096 const void* srcData) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -080097 return NULL;
98 }
99
bsalomonf90a02b2014-11-26 12:28:00 -0800100 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE { return NULL; }
101
102 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800103 return NULL;
104 }
105
bsalomonf90a02b2014-11-26 12:28:00 -0800106 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_OVERRIDE { return NULL; }
107
108 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVERRIDE { return NULL; }
109
110 void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
111 bool canIgnoreRect) SK_OVERRIDE {}
112
113 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) SK_OVERRIDE {}
114
joshualitt873ad0e2015-01-20 09:08:51 -0800115 void onDraw(const DrawArgs&, const GrDrawTarget::DrawInfo&) SK_OVERRIDE {}
bsalomonf90a02b2014-11-26 12:28:00 -0800116
bsalomon3e791242014-12-17 13:43:13 -0800117 void onStencilPath(const GrPath* path, const StencilPathState& state) SK_OVERRIDE {}
bsalomond95263c2014-12-16 13:05:12 -0800118
joshualitt873ad0e2015-01-20 09:08:51 -0800119 void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&) SK_OVERRIDE {}
bsalomond95263c2014-12-16 13:05:12 -0800120
joshualitt873ad0e2015-01-20 09:08:51 -0800121 void onDrawPaths(const DrawArgs&,
bsalomond95263c2014-12-16 13:05:12 -0800122 const GrPathRange*,
123 const void* indices,
124 GrDrawTarget::PathIndexType,
125 const float transformValues[],
126 GrDrawTarget::PathTransformType,
127 int count,
128 const GrStencilSettings&) SK_OVERRIDE {}
129
bsalomonf90a02b2014-11-26 12:28:00 -0800130 bool onReadPixels(GrRenderTarget* target,
131 int left, int top, int width, int height,
132 GrPixelConfig,
133 void* buffer,
134 size_t rowBytes) SK_OVERRIDE {
135 return false;
bsalomon33435572014-11-05 14:47:41 -0800136 }
137
bsalomonf90a02b2014-11-26 12:28:00 -0800138 bool onWriteTexturePixels(GrTexture* texture,
bsalomon33435572014-11-05 14:47:41 -0800139 int left, int top, int width, int height,
bsalomonf90a02b2014-11-26 12:28:00 -0800140 GrPixelConfig config, const void* buffer,
141 size_t rowBytes) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800142 return false;
143 }
144
bsalomonf90a02b2014-11-26 12:28:00 -0800145 void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE { return; }
146
kkinnunen36c57df2015-01-27 00:30:18 -0800147 bool createStencilBufferForRenderTarget(GrRenderTarget*, bool budgeted,
148 int width, int height) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800149 return false;
150 }
151
bsalomonf90a02b2014-11-26 12:28:00 -0800152 bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTarget*) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800153 return false;
154 }
155
bsalomonf90a02b2014-11-26 12:28:00 -0800156 void clearStencil(GrRenderTarget* target) SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -0800157
bsalomond95263c2014-12-16 13:05:12 -0800158 void didAddGpuTraceMarker() SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -0800159
bsalomond95263c2014-12-16 13:05:12 -0800160 void didRemoveGpuTraceMarker() SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -0800161
162 typedef GrGpu INHERITED;
163};
164
165GrContext* GrContext::CreateMockContext() {
166 GrContext* context = SkNEW_ARGS(GrContext, (Options()));
167
168 context->initMockContext();
169 return context;
170}
171
172void GrContext::initMockContext() {
173 SkASSERT(NULL == fGpu);
174 fGpu = SkNEW_ARGS(MockGpu, (this));
175 SkASSERT(fGpu);
176 this->initCommon();
177
178 // We delete these because we want to test the cache starting with zero resources. Also, none of
179 // these objects are required for any of tests that use this context. TODO: make stop allocating
180 // resources in the buffer pools.
181 SkDELETE(fDrawBuffer);
182 SkDELETE(fDrawBufferVBAllocPool);
183 SkDELETE(fDrawBufferIBAllocPool);
184
185 fDrawBuffer = NULL;
186 fDrawBufferVBAllocPool = NULL;
187 fDrawBufferIBAllocPool = NULL;
188}