blob: 3acf27ec2a14a1c726ff89689a0b8c20bfd530dc [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
joshualittd53a8272014-11-10 16:03:14 -080051class GrOptDrawState;
52
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&,
67 const GrOptDrawState&,
bsalomonf90a02b2014-11-26 12:28:00 -080068 const GrProgramDesc::DescInfo&,
69 GrGpu::DrawType,
joshualitt873ad0e2015-01-20 09:08:51 -080070 const GrBatchTracker&) const SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -080071
bsalomonf90a02b2014-11-26 12:28:00 -080072 void discard(GrRenderTarget*) SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -080073
bsalomonf90a02b2014-11-26 12:28:00 -080074 bool canCopySurface(const GrSurface* dst,
75 const GrSurface* src,
76 const SkIRect& srcRect,
77 const SkIPoint& dstPoint) SK_OVERRIDE { return false; };
joshualitt3322fa42014-11-07 08:48:51 -080078
bsalomonf90a02b2014-11-26 12:28:00 -080079 bool copySurface(GrSurface* dst,
80 GrSurface* src,
81 const SkIRect& srcRect,
82 const SkIPoint& dstPoint) SK_OVERRIDE { return false; };
83
84 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_OVERRIDE {
85 return false;
86 }
joshualitt3322fa42014-11-07 08:48:51 -080087
bsalomon33435572014-11-05 14:47:41 -080088private:
bsalomonf90a02b2014-11-26 12:28:00 -080089 void onResetContext(uint32_t resetBits) SK_OVERRIDE {}
90
bsalomon5236cf42015-01-14 10:42:08 -080091 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
bsalomonf90a02b2014-11-26 12:28:00 -080092 size_t rowBytes) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -080093 return NULL;
94 }
95
bsalomon5236cf42015-01-14 10:42:08 -080096 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted,
bsalomonf90a02b2014-11-26 12:28:00 -080097 const void* srcData) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -080098 return NULL;
99 }
100
bsalomonf90a02b2014-11-26 12:28:00 -0800101 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE { return NULL; }
102
103 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800104 return NULL;
105 }
106
bsalomonf90a02b2014-11-26 12:28:00 -0800107 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_OVERRIDE { return NULL; }
108
109 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVERRIDE { return NULL; }
110
111 void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
112 bool canIgnoreRect) SK_OVERRIDE {}
113
114 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) SK_OVERRIDE {}
115
joshualitt873ad0e2015-01-20 09:08:51 -0800116 void onDraw(const DrawArgs&, const GrDrawTarget::DrawInfo&) SK_OVERRIDE {}
bsalomonf90a02b2014-11-26 12:28:00 -0800117
bsalomon3e791242014-12-17 13:43:13 -0800118 void onStencilPath(const GrPath* path, const StencilPathState& state) SK_OVERRIDE {}
bsalomond95263c2014-12-16 13:05:12 -0800119
joshualitt873ad0e2015-01-20 09:08:51 -0800120 void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&) SK_OVERRIDE {}
bsalomond95263c2014-12-16 13:05:12 -0800121
joshualitt873ad0e2015-01-20 09:08:51 -0800122 void onDrawPaths(const DrawArgs&,
bsalomond95263c2014-12-16 13:05:12 -0800123 const GrPathRange*,
124 const void* indices,
125 GrDrawTarget::PathIndexType,
126 const float transformValues[],
127 GrDrawTarget::PathTransformType,
128 int count,
129 const GrStencilSettings&) SK_OVERRIDE {}
130
bsalomonf90a02b2014-11-26 12:28:00 -0800131 bool onReadPixels(GrRenderTarget* target,
132 int left, int top, int width, int height,
133 GrPixelConfig,
134 void* buffer,
135 size_t rowBytes) SK_OVERRIDE {
136 return false;
bsalomon33435572014-11-05 14:47:41 -0800137 }
138
bsalomonf90a02b2014-11-26 12:28:00 -0800139 bool onWriteTexturePixels(GrTexture* texture,
bsalomon33435572014-11-05 14:47:41 -0800140 int left, int top, int width, int height,
bsalomonf90a02b2014-11-26 12:28:00 -0800141 GrPixelConfig config, const void* buffer,
142 size_t rowBytes) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800143 return false;
144 }
145
bsalomonf90a02b2014-11-26 12:28:00 -0800146 void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE { return; }
147
148 bool createStencilBufferForRenderTarget(GrRenderTarget*, 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}