blob: c5f8eb8bb4930bfb1de09df324978d4feda5e2c1 [file] [log] [blame]
jvanverthfa38a302014-10-06 05:59:05 -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
Jim Van Verth83010462017-03-16 08:45:39 -04008#ifndef GrSmallPathRenderer_DEFINED
9#define GrSmallPathRenderer_DEFINED
jvanverthfa38a302014-10-06 05:59:05 -070010
Brian Salomon903da792016-12-16 14:24:46 -050011#include "GrDrawOpAtlas.h"
Jim Van Verth106b5c42017-09-26 12:45:29 -040012#include "GrOnFlushResourceProvider.h"
jvanverthfa38a302014-10-06 05:59:05 -070013#include "GrPathRenderer.h"
14#include "GrRect.h"
bsalomonee432412016-06-27 07:18:18 -070015#include "GrShape.h"
jvanverthfa38a302014-10-06 05:59:05 -070016
mtklein4e976072016-08-08 09:06:27 -070017#include "SkOpts.h"
bsalomon71cb0c22014-11-14 12:10:14 -080018#include "SkTDynamicHash.h"
jvanverthfa38a302014-10-06 05:59:05 -070019
20class GrContext;
jvanverthfa38a302014-10-06 05:59:05 -070021
Robert Phillipsd2e9f762018-03-07 11:54:37 -050022class ShapeData;
23class ShapeDataKey;
24
Jim Van Verth106b5c42017-09-26 12:45:29 -040025class GrSmallPathRenderer : public GrPathRenderer, public GrOnFlushCallbackObject {
jvanverthfa38a302014-10-06 05:59:05 -070026public:
Jim Van Verth83010462017-03-16 08:45:39 -040027 GrSmallPathRenderer();
Brian Salomond3b65972017-03-22 12:05:03 -040028 ~GrSmallPathRenderer() override;
jvanverthfa38a302014-10-06 05:59:05 -070029
Jim Van Verth106b5c42017-09-26 12:45:29 -040030 // GrOnFlushCallbackObject overrides
31 //
32 // Note: because this class is associated with a path renderer we want it to be removed from
33 // the list of active OnFlushBackkbackObjects in an freeGpuResources call (i.e., we accept the
34 // default retainOnFreeGpuResources implementation).
35
Robert Phillipscd5099c2018-02-09 09:56:56 -050036 void preFlush(GrOnFlushResourceProvider* onFlushResourceProvider, const uint32_t*, int,
37 SkTArray<sk_sp<GrRenderTargetContext>>*) override {
38 if (fAtlas) {
39 fAtlas->instantiate(onFlushResourceProvider);
40 }
41 }
Jim Van Verth106b5c42017-09-26 12:45:29 -040042
Chris Dalton3968ff92017-11-27 12:26:31 -070043 void postFlush(GrDeferredUploadToken startTokenForNextFlush,
Robert Phillipsd2e9f762018-03-07 11:54:37 -050044 const uint32_t* /*opListIDs*/, int /*numOpListIDs*/) override {
Jim Van Verth106b5c42017-09-26 12:45:29 -040045 if (fAtlas) {
46 fAtlas->compact(startTokenForNextFlush);
47 }
48 }
49
Robert Phillipsd2e9f762018-03-07 11:54:37 -050050 using ShapeCache = SkTDynamicHash<ShapeData, ShapeDataKey>;
51 typedef SkTInternalLList<ShapeData> ShapeDataList;
52
Robert Phillips7c525e62018-06-12 10:11:12 -040053 static std::unique_ptr<GrDrawOp> createOp_TestingOnly(GrContext*,
54 GrPaint&&,
55 const GrShape&,
Robert Phillipsd2e9f762018-03-07 11:54:37 -050056 const SkMatrix& viewMatrix,
57 GrDrawOpAtlas* atlas,
Robert Phillips7c525e62018-06-12 10:11:12 -040058 ShapeCache*,
59 ShapeDataList*,
Robert Phillipsd2e9f762018-03-07 11:54:37 -050060 bool gammaCorrect,
61 const GrUserStencilSettings*);
62 struct PathTestStruct;
63
jvanverthfa38a302014-10-06 05:59:05 -070064private:
Robert Phillipsd2e9f762018-03-07 11:54:37 -050065 class SmallPathOp;
66
bsalomon8acedde2016-06-24 10:42:16 -070067 StencilSupport onGetStencilSupport(const GrShape&) const override {
robertphillipse7d4b2f2015-08-13 07:57:10 -070068 return GrPathRenderer::kNoSupport_StencilSupport;
69 }
bsalomon0aff2fa2015-07-31 06:48:27 -070070
Chris Dalton5ed44232017-09-07 13:22:46 -060071 CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
bsalomon0aff2fa2015-07-31 06:48:27 -070072
73 bool onDrawPath(const DrawPathArgs&) override;
74
Brian Salomon2ee084e2016-12-16 18:59:19 -050075 static void HandleEviction(GrDrawOpAtlas::AtlasID, void*);
joshualitt5bf99f12015-03-13 11:47:42 -070076
Brian Salomon2ee084e2016-12-16 18:59:19 -050077 std::unique_ptr<GrDrawOpAtlas> fAtlas;
Ben Wagner594f9ed2016-11-08 14:13:39 -050078 ShapeCache fShapeCache;
79 ShapeDataList fShapeList;
halcanary9d524f22016-03-29 09:03:52 -070080
jvanverthfa38a302014-10-06 05:59:05 -070081 typedef GrPathRenderer INHERITED;
jvanverthfa38a302014-10-06 05:59:05 -070082};
83
84#endif