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

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

Issue 385713005: Allow GrGLEffects to produce variable length keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@key
Patch Set: rebase Created 6 years, 5 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
« no previous file with comments | « src/gpu/effects/GrYUVtoRGBEffect.cpp ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 GrGLEffect_DEFINED
9 #define GrGLEffect_DEFINED 9 #define GrGLEffect_DEFINED
10 10
11 #include "GrBackendEffectFactory.h" 11 #include "GrBackendEffectFactory.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; 16 class GrGLShaderBuilder;
17 17
18 /** @file 18 /** @file
19 This file contains specializations for OpenGL of the shader stages declared in 19 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 20 include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitt ing the
21 GLSL code that implements a GrEffect and for uploading uniforms at draw time . If they don't 21 GLSL code that implements a GrEffect and for uploading uniforms at draw time . If they don't
22 always emit the same GLSL code, they must have a function: 22 always emit the same GLSL code, they must have a function:
23 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) 23 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffect KeyBuilder*)
24 that is used to implement a program cache. When two GrEffects produce the sa me key this means 24 that is used to implement a program cache. When two GrEffects produce the sa me key this means
25 that their GrGLEffects would emit the same GLSL code. 25 that their GrGLEffects would emit the same GLSL code.
26 26
27 The GrGLEffect subclass must also have a constructor of the form: 27 The GrGLEffect subclass must also have a constructor of the form:
28 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDr awEffect&) 28 EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDr awEffect&)
29 The effect held by the GrDrawEffect is guaranteed to be of the type that gen erated the 29 The effect held by the GrDrawEffect is guaranteed to be of the type that gen erated the
30 GrGLEffect subclass instance. 30 GrGLEffect subclass instance.
31 31
32 These objects are created by the factory object returned by the GrEffect::ge tFactory(). 32 These objects are created by the factory object returned by the GrEffect::ge tFactory().
33 */ 33 */
34 34
35 class GrDrawEffect; 35 class GrDrawEffect;
36 class GrGLTexture; 36 class GrGLTexture;
37 class GrGLVertexEffect; 37 class GrGLVertexEffect;
38 38
39 class GrGLEffect { 39 class GrGLEffect {
40 40
41 public: 41 public:
42 typedef GrBackendEffectFactory::EffectKey EffectKey;
43 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; 42 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
44 typedef GrGLProgramEffects::TextureSampler TextureSampler; 43 typedef GrGLProgramEffects::TextureSampler TextureSampler;
45 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray; 44 typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray;
46 45
47 GrGLEffect(const GrBackendEffectFactory& factory) 46 GrGLEffect(const GrBackendEffectFactory& factory)
48 : fFactory(factory) 47 : fFactory(factory)
49 , fIsVertexEffect(false) { 48 , fIsVertexEffect(false) {
50 } 49 }
51 50
52 virtual ~GrGLEffect() {} 51 virtual ~GrGLEffect() {}
53 52
54 /** Called when the program stage should insert its code into the shaders. T he code in each 53 /** Called when the program stage should insert its code into the shaders. T he code in each
55 shader will be in its own block ({}) and so locally scoped names will no t collide across 54 shader will be in its own block ({}) and so locally scoped names will no t collide across
56 stages. 55 stages.
57 56
58 @param builder Interface used to emit code in the shaders. 57 @param builder Interface used to emit code in the shaders.
59 @param drawEffect A wrapper on the effect that generated this program stage. 58 @param drawEffect A wrapper on the effect that generated this program stage.
60 @param key The key that was computed by GenKey() from the gener ating GrEffect. 59 @param key The key that was computed by GenKey() from the gener ating GrEffect.
61 Only the bits indicated by GrBackendEffectFactory::k EffectKeyBits are
62 guaranteed to match the value produced by GenKey();
63 @param outputColor A predefined vec4 in the FS in which the stage shoul d place its output 60 @param outputColor A predefined vec4 in the FS in which the stage shoul d place its output
64 color (or coverage). 61 color (or coverage).
65 @param inputColor A vec4 that holds the input color to the stage in th e FS. This may be 62 @param inputColor A vec4 that holds the input color to the stage in th e FS. This may be
66 NULL in which case the implied input is solid white (all ones). 63 NULL in which case the implied input is solid white (all ones).
67 TODO: Better system for communicating optimization i nfo (e.g. input 64 TODO: Better system for communicating optimization i nfo (e.g. input
68 color is solid white, trans black, known to be opaqu e, etc.) that allows 65 color is solid white, trans black, known to be opaqu e, etc.) that allows
69 the effect to communicate back similar known info ab out its output. 66 the effect to communicate back similar known info ab out its output.
70 @param samplers One entry for each GrTextureAccess of the GrEffect t hat generated the 67 @param samplers One entry for each GrTextureAccess of the GrEffect t hat generated the
71 GrGLEffect. These can be passed to the builder to em it texture 68 GrGLEffect. These can be passed to the builder to em it texture
72 reads in the generated code. 69 reads in the generated code.
73 */ 70 */
74 virtual void emitCode(GrGLShaderBuilder* builder, 71 virtual void emitCode(GrGLShaderBuilder* builder,
75 const GrDrawEffect& drawEffect, 72 const GrDrawEffect& drawEffect,
76 EffectKey key, 73 const GrEffectKey& key,
77 const char* outputColor, 74 const char* outputColor,
78 const char* inputColor, 75 const char* inputColor,
79 const TransformedCoordsArray& coords, 76 const TransformedCoordsArray& coords,
80 const TextureSamplerArray& samplers) = 0; 77 const TextureSamplerArray& samplers) = 0;
81 78
82 /** A GrGLEffect instance can be reused with any GrEffect that produces the same stage 79 /** A GrGLEffect instance can be reused with any GrEffect that produces the same stage
83 key; this function reads data from a stage and uploads any uniform varia bles required 80 key; this function reads data from a GrEffect and uploads any uniform va riables required
84 by the shaders created in emitCode(). The GrEffect installed in the GrEf fectStage is 81 by the shaders created in emitCode(). The GrEffect installed in the GrDr awEffect is
85 guaranteed to be of the same type that created this GrGLEffect and to ha ve an identical 82 guaranteed to be of the same type that created this GrGLEffect and to ha ve an identical
86 EffectKey as the one that created this GrGLEffect. Effects that use loca l coords have 83 effect key as the one that created this GrGLEffect. Effects that use loc al coords have
87 to consider whether the GrEffectStage's coord change matrix should be us ed. When explicit 84 to consider whether the GrEffectStage's coord change matrix should be us ed. When explicit
88 local coordinates are used it can be ignored. */ 85 local coordinates are used it can be ignored. */
89 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) {} 86 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) {}
90 87
91 const char* name() const { return fFactory.name(); } 88 const char* name() const { return fFactory.name(); }
92 89
93 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { retur n 0; } 90 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder* ) {}
94 91
95 /** Used by the system when generating shader code, to see if this effect ca n be downcasted to 92 /** Used by the system when generating shader code, to see if this effect ca n be downcasted to
96 the internal GrGLVertexEffect type */ 93 the internal GrGLVertexEffect type */
97 bool isVertexEffect() const { return fIsVertexEffect; } 94 bool isVertexEffect() const { return fIsVertexEffect; }
98 95
99 protected: 96 protected:
100 const GrBackendEffectFactory& fFactory; 97 const GrBackendEffectFactory& fFactory;
101 98
102 private: 99 private:
103 friend class GrGLVertexEffect; // to set fIsVertexEffect 100 friend class GrGLVertexEffect; // to set fIsVertexEffect
104 101
105 bool fIsVertexEffect; 102 bool fIsVertexEffect;
106 }; 103 };
107 104
108 #endif 105 #endif
OLDNEW
« no previous file with comments | « src/gpu/effects/GrYUVtoRGBEffect.cpp ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698