1 /*
2  * Copyright 2016 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 
8 #ifndef gr_instanced_InstanceProcessor_DEFINED
9 #define gr_instanced_InstanceProcessor_DEFINED
10 
11 #include "GrCaps.h"
12 #include "GrGeometryProcessor.h"
13 #include "instanced/InstancedRenderingTypes.h"
14 
15 namespace gr_instanced {
16 
17 /**
18  * This class provides a GP implementation that uses instanced rendering. Is sends geometry in as
19  * basic, pre-baked canonical shapes, and uses instanced vertex attribs to control how these shapes
20  * are transformed and drawn. MSAA is accomplished with the sample mask rather than finely
21  * tesselated geometry.
22  */
23 class InstanceProcessor : public GrGeometryProcessor {
24 public:
25     InstanceProcessor(OpInfo, GrBuffer* paramsBuffer);
26 
name()27     const char* name() const override { return "Instance Processor"; }
opInfo()28     OpInfo opInfo() const { return fOpInfo; }
29 
getGLSLProcessorKey(const GrShaderCaps &,GrProcessorKeyBuilder * b)30     void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
31         b->add32(fOpInfo.fData);
32     }
33     GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
34 
35     /**
36      * Returns a buffer of ShapeVertex that defines the canonical instanced geometry.
37      */
38     static const GrBuffer* SK_WARN_UNUSED_RESULT FindOrCreateVertexBuffer(GrGpu*);
39 
40     /**
41      * Returns a buffer of 8-bit indices for the canonical instanced geometry. The client can call
42      * GetIndexRangeForXXX to know which indices to use for a specific shape.
43      */
44     static const GrBuffer* SK_WARN_UNUSED_RESULT FindOrCreateIndex8Buffer(GrGpu*);
45 
46     static IndexRange GetIndexRangeForRect(GrAAType);
47     static IndexRange GetIndexRangeForOval(GrAAType, const SkRect& devBounds);
48     static IndexRange GetIndexRangeForRRect(GrAAType);
49 
50     static const char* GetNameOfIndexRange(IndexRange);
51 
52 private:
53     /**
54      * Called by the platform-specific instanced rendering implementation to determine the level of
55      * support this class can offer on the given GLSL platform.
56      */
57     static GrCaps::InstancedSupport CheckSupport(const GrShaderCaps&, const GrCaps&);
58 
59     OpInfo fOpInfo;
60     BufferAccess fParamsAccess;
61 
62     friend class GLInstancedRendering; // For CheckSupport.
63 
64     typedef GrGeometryProcessor INHERITED;
65 };
66 
67 }
68 
69 #endif
70