Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/gpu/gl/GrGLProcessor.h

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: fix Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGLEffect_DEFINED 8 #ifndef GrGLProcessor_DEFINED
9 #define GrGLEffect_DEFINED 9 #define GrGLProcessor_DEFINED
10 10
11 #include "GrBackendEffectFactory.h" 11 #include "GrBackendProcessorFactory.h"
12 #include "GrGLProgramEffects.h" 12 #include "GrGLProgramEffects.h"
13 #include "GrGLShaderVar.h" 13 #include "GrGLShaderVar.h"
14 #include "GrGLSL.h" 14 #include "GrGLSL.h"
15 15
16 class GrGLShaderBuilder;
17
18 /** @file 16 /** @file
19 This file contains specializations for OpenGL of the shader stages declared in 17 This file contains specializations for OpenGL of the shader stages declared in
20 include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitt ing the 18 include/gpu/GrProcessor.h. Objects of type GrGLProcessor are responsible for emitting the
21 GLSL code that implements a GrEffect and for uploading uniforms at draw time . If they don't 19 GLSL code that implements a GrProcessor and for uploading uniforms at draw t ime. If they don't
22 always emit the same GLSL code, they must have a function: 20 always emit the same GLSL code, they must have a function:
23 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyB uilder*) 21 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcess orKeyBuilder*)
24 that is used to implement a program cache. When two GrEffects produce the sa me key this means 22 that is used to implement a program cache. When two GrProcessors produce the same key this means
25 that their GrGLEffects would emit the same GLSL code. 23 that their GrGLProcessors would emit the same GLSL code.
26 24
27 The GrGLEffect subclass must also have a constructor of the form: 25 The GrGLProcessor subclass must also have a constructor of the form:
28 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrEf fect&) 26 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrPr ocessor&)
29 27
30 These objects are created by the factory object returned by the GrEffect::ge tFactory(). 28 These objects are created by the factory object returned by the GrProcessor: :getFactory().
31 */ 29 */
32 30
33 class GrGLTexture; 31 class GrGLProcessor {
34 class GrGLGeometryProcessor; 32 public:
33 GrGLProcessor(const GrBackendProcessorFactory& factory)
34 : fFactory(factory) {
35 }
35 36
36 class GrGLEffect {
37 public:
38 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 37 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
39 38
40 /** 39 /**
41 * Passed to GrGLEffects so they can add transformed coordinates to their sh ader code. 40 * Passed to GrGLProcessors so they can add transformed coordinates to their shader code.
42 */ 41 */
43 typedef GrShaderVar TransformedCoords; 42 typedef GrShaderVar TransformedCoords;
44 typedef SkTArray<GrShaderVar> TransformedCoordsArray; 43 typedef SkTArray<GrShaderVar> TransformedCoordsArray;
45 44
46 /** 45 /**
47 * Passed to GrGLEffects so they can add texture reads to their shader code. 46 * Passed to GrGLProcessors so they can add texture reads to their shader co de.
48 */ 47 */
49 class TextureSampler { 48 class TextureSampler {
50 public: 49 public:
51 TextureSampler(UniformHandle uniform, const GrTextureAccess& access) 50 TextureSampler(UniformHandle uniform, const GrTextureAccess& access)
52 : fSamplerUniform(uniform) 51 : fSamplerUniform(uniform)
53 , fConfigComponentMask(GrPixelConfigComponentMask(access.getTexture( )->config())) { 52 , fConfigComponentMask(GrPixelConfigComponentMask(access.getTexture( )->config())) {
54 SkASSERT(0 != fConfigComponentMask); 53 SkASSERT(0 != fConfigComponentMask);
55 memcpy(fSwizzle, access.getSwizzle(), 5); 54 memcpy(fSwizzle, access.getSwizzle(), 5);
56 } 55 }
57 56
58 // bitfield of GrColorComponentFlags present in the texture's config. 57 // bitfield of GrColorComponentFlags present in the texture's config.
59 uint32_t configComponentMask() const { return fConfigComponentMask; } 58 uint32_t configComponentMask() const { return fConfigComponentMask; }
60 // this is .abcd 59 // this is .abcd
61 const char* swizzle() const { return fSwizzle; } 60 const char* swizzle() const { return fSwizzle; }
62 61
63 private: 62 private:
64 UniformHandle fSamplerUniform; 63 UniformHandle fSamplerUniform;
65 uint32_t fConfigComponentMask; 64 uint32_t fConfigComponentMask;
66 char fSwizzle[5]; 65 char fSwizzle[5];
67 66
68 friend class GrGLShaderBuilder; 67 friend class GrGLShaderBuilder;
69 }; 68 };
70 69
71 typedef SkTArray<TextureSampler> TextureSamplerArray; 70 typedef SkTArray<TextureSampler> TextureSamplerArray;
72 71
73 GrGLEffect(const GrBackendEffectFactory& factory) 72 virtual ~GrGLProcessor() {}
74 : fFactory(factory) 73
75 , fIsVertexEffect(false) { 74 /** A GrGLProcessor instance can be reused with any GrProcessor that produce s the same stage
75 key; this function reads data from a GrProcessor and uploads any uniform variables required
76 by the shaders created in emitCode(). The GrProcessor installed in the G rDrawEffect is
77 guaranteed to be of the same type that created this GrGLProcessor and to have an identical
78 effect key as the one that created this GrGLProcessor. Effects that use local coords have
79 to consider whether the GrProcessorStage's coord change matrix should be used. When explicit
80 local coordinates are used it can be ignored. */
81 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) {}
82
83 const char* name() const { return fFactory.name(); }
84
85 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilde r*) {}
86
87 protected:
88 const GrBackendProcessorFactory& fFactory;
89 };
90
91 class GrGLFragmentProcessor : public GrGLProcessor {
92 public:
93 GrGLFragmentProcessor(const GrBackendProcessorFactory& factory)
94 : INHERITED(factory) {
76 } 95 }
77 96
78 virtual ~GrGLEffect() {} 97 virtual ~GrGLFragmentProcessor() {}
79 98
80 /** Called when the program stage should insert its code into the shaders. T he code in each 99 /** Called when the program stage should insert its code into the shaders. T he code in each
81 shader will be in its own block ({}) and so locally scoped names will no t collide across 100 shader will be in its own block ({}) and so locally scoped names will no t collide across
82 stages. 101 stages.
83 102
84 @param builder Interface used to emit code in the shaders. 103 @param builder Interface used to emit code in the shaders.
85 @param effect The effect that generated this program stage. 104 @param effect The effect that generated this program stage.
86 @param key The key that was computed by GenKey() from the gener ating GrEffect. 105 @param key The key that was computed by GenKey() from the gener ating GrProcessor.
87 @param outputColor A predefined vec4 in the FS in which the stage shoul d place its output 106 @param outputColor A predefined vec4 in the FS in which the stage shoul d place its output
88 color (or coverage). 107 color (or coverage).
89 @param inputColor A vec4 that holds the input color to the stage in th e FS. This may be 108 @param inputColor A vec4 that holds the input color to the stage in th e FS. This may be
90 NULL in which case the implied input is solid white (all ones). 109 NULL in which case the implied input is solid white (all ones).
91 TODO: Better system for communicating optimization i nfo (e.g. input 110 TODO: Better system for communicating optimization i nfo (e.g. input
92 color is solid white, trans black, known to be opaqu e, etc.) that allows 111 color is solid white, trans black, known to be opaqu e, etc.) that allows
93 the effect to communicate back similar known info ab out its output. 112 the effect to communicate back similar known info ab out its output.
94 @param samplers One entry for each GrTextureAccess of the GrEffect t hat generated the 113 @param samplers One entry for each GrTextureAccess of the GrProcesso r that generated the
bsalomon 2014/09/22 15:35:23 This comment was already busted, but how about: C
95 GrGLEffect. These can be passed to the builder to em it texture 114 GrGLProcessor. These can be passed to the builder to emit texture
96 reads in the generated code. 115 reads in the generated code.
97 */ 116 */
98 virtual void emitCode(GrGLProgramBuilder* builder, 117 virtual void emitCode(GrGLProgramBuilder* builder,
99 const GrEffect& effect, 118 const GrFragmentProcessor& effect,
100 const GrEffectKey& key, 119 const GrProcessorKey& key,
101 const char* outputColor, 120 const char* outputColor,
102 const char* inputColor, 121 const char* inputColor,
103 const TransformedCoordsArray& coords, 122 const TransformedCoordsArray& coords,
104 const TextureSamplerArray& samplers) = 0; 123 const TextureSamplerArray& samplers) = 0;
105 124
106 /** A GrGLEffect instance can be reused with any GrEffect that produces the same stage
107 key; this function reads data from a GrEffect and uploads any uniform va riables required
108 by the shaders created in emitCode(). The GrEffect is
109 guaranteed to be of the same type that created this GrGLEffect and to ha ve an identical
110 effect key as the one that created this GrGLEffect. Effects that use loc al coords have
111 to consider whether the GrEffectStage's coord change matrix should be us ed. When explicit
112 local coordinates are used it can be ignored. */
113 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) {}
114
115 const char* name() const { return fFactory.name(); }
116
117 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder*) {}
118
119 /** Used by the system when generating shader code, to see if this effect ca n be downcasted to
120 the internal GrGLGeometryProcessor type */
121 bool isVertexEffect() const { return fIsVertexEffect; }
122
123 protected:
124 const GrBackendEffectFactory& fFactory;
125
126 private: 125 private:
127 friend class GrGLGeometryProcessor; // to set fIsVertexEffect 126 typedef GrGLProcessor INHERITED;
128
129 bool fIsVertexEffect;
130 }; 127 };
131 128
132 #endif 129 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698