blob: 7038c10966588e211b9e15caee506446c1abe129 [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
118 bool onReadPixels(GrRenderTarget* target,
119 int left, int top, int width, int height,
120 GrPixelConfig,
121 void* buffer,
122 size_t rowBytes) SK_OVERRIDE {
123 return false;
bsalomon33435572014-11-05 14:47:41 -0800124 }
125
bsalomonf90a02b2014-11-26 12:28:00 -0800126 bool onWriteTexturePixels(GrTexture* texture,
bsalomon33435572014-11-05 14:47:41 -0800127 int left, int top, int width, int height,
bsalomonf90a02b2014-11-26 12:28:00 -0800128 GrPixelConfig config, const void* buffer,
129 size_t rowBytes) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800130 return false;
131 }
132
bsalomonf90a02b2014-11-26 12:28:00 -0800133 void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE { return; }
134
135 bool createStencilBufferForRenderTarget(GrRenderTarget*, int width, int height) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800136 return false;
137 }
138
bsalomonf90a02b2014-11-26 12:28:00 -0800139 bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTarget*) SK_OVERRIDE {
bsalomon33435572014-11-05 14:47:41 -0800140 return false;
141 }
142
joshualittdafa4d02014-12-04 08:59:10 -0800143 bool flushGraphicsState(const GrOptDrawState&) SK_OVERRIDE { return false; }
bsalomon33435572014-11-05 14:47:41 -0800144
bsalomonf90a02b2014-11-26 12:28:00 -0800145 void clearStencil(GrRenderTarget* target) SK_OVERRIDE {}
bsalomon33435572014-11-05 14:47:41 -0800146
bsalomonf90a02b2014-11-26 12:28:00 -0800147 void didAddGpuTraceMarker() SK_OVERRIDE { }
bsalomon33435572014-11-05 14:47:41 -0800148
bsalomonf90a02b2014-11-26 12:28:00 -0800149 void didRemoveGpuTraceMarker() SK_OVERRIDE { }
bsalomon33435572014-11-05 14:47:41 -0800150
151 typedef GrGpu INHERITED;
152};
153
154GrContext* GrContext::CreateMockContext() {
155 GrContext* context = SkNEW_ARGS(GrContext, (Options()));
156
157 context->initMockContext();
158 return context;
159}
160
161void GrContext::initMockContext() {
162 SkASSERT(NULL == fGpu);
163 fGpu = SkNEW_ARGS(MockGpu, (this));
164 SkASSERT(fGpu);
165 this->initCommon();
166
167 // We delete these because we want to test the cache starting with zero resources. Also, none of
168 // these objects are required for any of tests that use this context. TODO: make stop allocating
169 // resources in the buffer pools.
170 SkDELETE(fDrawBuffer);
171 SkDELETE(fDrawBufferVBAllocPool);
172 SkDELETE(fDrawBufferIBAllocPool);
173
174 fDrawBuffer = NULL;
175 fDrawBufferVBAllocPool = NULL;
176 fDrawBufferIBAllocPool = NULL;
177}