blob: 7f2848faecfb401338e36508758ef0755bb9a159 [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; }
66 void buildProgramDesc(const GrOptDrawState&,
67 const GrProgramDesc::DescInfo&,
68 GrGpu::DrawType,
69 GrProgramDesc* desc) 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
90 GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
91 const void* srcData,
92 size_t rowBytes) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -080093 return NULL;
94 }
95
bsalomonf90a02b2014-11-26 12:28:00 -080096 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
97 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
116 void onDraw(const GrOptDrawState&, const GrDrawTarget::DrawInfo&) SK_OVERRIDE {}
117
bsalomond95263c2014-12-16 13:05:12 -0800118 void onStencilPath(const GrOptDrawState&, const GrPath*, const GrStencilSettings&) SK_OVERRIDE {
119 }
120
121 void onDrawPath(const GrOptDrawState&, const GrPath*, const GrStencilSettings&) SK_OVERRIDE {}
122
123 void onDrawPaths(const GrOptDrawState&,
124 const GrPathRange*,
125 const void* indices,
126 GrDrawTarget::PathIndexType,
127 const float transformValues[],
128 GrDrawTarget::PathTransformType,
129 int count,
130 const GrStencilSettings&) SK_OVERRIDE {}
131
bsalomonf90a02b2014-11-26 12:28:00 -0800132 bool onReadPixels(GrRenderTarget* target,
133 int left, int top, int width, int height,
134 GrPixelConfig,
135 void* buffer,
136 size_t rowBytes) SK_OVERRIDE {
137 return false;
bsalomon33435572014-11-05 14:47:41 -0800138 }
139
bsalomonf90a02b2014-11-26 12:28:00 -0800140 bool onWriteTexturePixels(GrTexture* texture,
bsalomon33435572014-11-05 14:47:41 -0800141 int left, int top, int width, int height,
bsalomonf90a02b2014-11-26 12:28:00 -0800142 GrPixelConfig config, const void* buffer,
143 size_t rowBytes) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800144 return false;
145 }
146
bsalomonf90a02b2014-11-26 12:28:00 -0800147 void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE { return; }
148
149 bool createStencilBufferForRenderTarget(GrRenderTarget*, int width, int height) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800150 return false;
151 }
152
bsalomonf90a02b2014-11-26 12:28:00 -0800153 bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTarget*) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800154 return false;
155 }
156
bsalomonf90a02b2014-11-26 12:28:00 -0800157 void clearStencil(GrRenderTarget* target) SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -0800158
bsalomond95263c2014-12-16 13:05:12 -0800159 void didAddGpuTraceMarker() SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -0800160
bsalomond95263c2014-12-16 13:05:12 -0800161 void didRemoveGpuTraceMarker() SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -0800162
163 typedef GrGpu INHERITED;
164};
165
166GrContext* GrContext::CreateMockContext() {
167 GrContext* context = SkNEW_ARGS(GrContext, (Options()));
168
169 context->initMockContext();
170 return context;
171}
172
173void GrContext::initMockContext() {
174 SkASSERT(NULL == fGpu);
175 fGpu = SkNEW_ARGS(MockGpu, (this));
176 SkASSERT(fGpu);
177 this->initCommon();
178
179 // We delete these because we want to test the cache starting with zero resources. Also, none of
180 // these objects are required for any of tests that use this context. TODO: make stop allocating
181 // resources in the buffer pools.
182 SkDELETE(fDrawBuffer);
183 SkDELETE(fDrawBufferVBAllocPool);
184 SkDELETE(fDrawBufferIBAllocPool);
185
186 fDrawBuffer = NULL;
187 fDrawBufferVBAllocPool = NULL;
188 fDrawBufferIBAllocPool = NULL;
189}