OLD | NEW |
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 GrEffect_DEFINED | 8 #ifndef GrEffect_DEFINED |
9 #define GrEffect_DEFINED | 9 #define GrEffect_DEFINED |
10 | 10 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrEffectUnitTest.h" | 12 #include "GrEffectUnitTest.h" |
13 #include "GrNoncopyable.h" | 13 #include "GrNoncopyable.h" |
14 #include "GrRefCnt.h" | |
15 #include "GrTexture.h" | 14 #include "GrTexture.h" |
16 #include "GrTextureAccess.h" | 15 #include "GrTextureAccess.h" |
17 #include "GrTypesPriv.h" | 16 #include "GrTypesPriv.h" |
18 | 17 |
19 class GrBackendEffectFactory; | 18 class GrBackendEffectFactory; |
20 class GrContext; | 19 class GrContext; |
21 class GrEffect; | 20 class GrEffect; |
22 class SkString; | 21 class SkString; |
23 | 22 |
24 /** | 23 /** |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 Ganesh shading pipeline. | 66 Ganesh shading pipeline. |
68 Subclasses must have a function that produces a human-readable name: | 67 Subclasses must have a function that produces a human-readable name: |
69 static const char* Name(); | 68 static const char* Name(); |
70 GrEffect objects *must* be immutable: after being constructed, their fields
may not change. | 69 GrEffect objects *must* be immutable: after being constructed, their fields
may not change. |
71 | 70 |
72 GrEffect subclass objects should be created by factory functions that return
GrEffectRef. | 71 GrEffect subclass objects should be created by factory functions that return
GrEffectRef. |
73 There is no public way to wrap a GrEffect in a GrEffectRef. Thus, a factory
should be a static | 72 There is no public way to wrap a GrEffect in a GrEffectRef. Thus, a factory
should be a static |
74 member function of a GrEffect subclass. | 73 member function of a GrEffect subclass. |
75 | 74 |
76 Because almost no code should ever handle a GrEffect directly outside of a G
rEffectRef, we | 75 Because almost no code should ever handle a GrEffect directly outside of a G
rEffectRef, we |
77 privately inherit from GrRefCnt to help prevent accidental direct ref'ing/un
ref'ing of effects. | 76 privately inherit from SkRefCnt to help prevent accidental direct ref'ing/un
ref'ing of effects. |
78 | 77 |
79 Dynamically allocated GrEffects and their corresponding GrEffectRefs are man
aged by a per-thread | 78 Dynamically allocated GrEffects and their corresponding GrEffectRefs are man
aged by a per-thread |
80 memory pool. The ref count of an effect must reach 0 before the thread termi
nates and the pool | 79 memory pool. The ref count of an effect must reach 0 before the thread termi
nates and the pool |
81 is destroyed. To create a static effect use the macro GR_CREATE_STATIC_EFFEC
T declared below. | 80 is destroyed. To create a static effect use the macro GR_CREATE_STATIC_EFFEC
T declared below. |
82 */ | 81 */ |
83 class GrEffect : private GrRefCnt { | 82 class GrEffect : private SkRefCnt { |
84 public: | 83 public: |
85 SK_DECLARE_INST_COUNT(GrEffect) | 84 SK_DECLARE_INST_COUNT(GrEffect) |
86 | 85 |
87 /** | 86 /** |
88 * The types of vertex coordinates available to an effect in the vertex shad
er. Effects can | 87 * The types of vertex coordinates available to an effect in the vertex shad
er. Effects can |
89 * require their own vertex attribute but these coordinates are made availab
le by the framework | 88 * require their own vertex attribute but these coordinates are made availab
le by the framework |
90 * in all programs. kCustom_CoordsType is provided to signify that an altern
ative set of coords | 89 * in all programs. kCustom_CoordsType is provided to signify that an altern
ative set of coords |
91 * is used (usually an explicit vertex attribute) but its meaning is determi
ned by the effect | 90 * is used (usually an explicit vertex attribute) but its meaning is determi
ned by the effect |
92 * subclass. | 91 * subclass. |
93 */ | 92 */ |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor
ing an effect-stage | 309 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor
ing an effect-stage |
311 // from deferred state, to call isEqual on naked
GrEffects, and | 310 // from deferred state, to call isEqual on naked
GrEffects, and |
312 // to inc/dec deferred ref counts. | 311 // to inc/dec deferred ref counts. |
313 | 312 |
314 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 313 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
315 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; | 314 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; |
316 bool fWillReadDstColor; | 315 bool fWillReadDstColor; |
317 bool fWillReadFragmentPosition; | 316 bool fWillReadFragmentPosition; |
318 GrEffectRef* fEffectRef; | 317 GrEffectRef* fEffectRef; |
319 | 318 |
320 typedef GrRefCnt INHERITED; | 319 typedef SkRefCnt INHERITED; |
321 }; | 320 }; |
322 | 321 |
323 inline GrEffectRef::GrEffectRef(GrEffect* effect) { | 322 inline GrEffectRef::GrEffectRef(GrEffect* effect) { |
324 SkASSERT(NULL != effect); | 323 SkASSERT(NULL != effect); |
325 effect->ref(); | 324 effect->ref(); |
326 fEffect = effect; | 325 fEffect = effect; |
327 } | 326 } |
328 | 327 |
329 /** | 328 /** |
330 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 329 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
331 * at global destruction time. NAME will be the name of the created GrEffectRef. | 330 * at global destruction time. NAME will be the name of the created GrEffectRef. |
332 */ | 331 */ |
333 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ | 332 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ |
334 enum {
\ | 333 enum {
\ |
335 k_##NAME##_EffectRefOffset = GR_CT_ALIGN_UP(sizeof(EFFECT_CLASS), 8),
\ | 334 k_##NAME##_EffectRefOffset = GR_CT_ALIGN_UP(sizeof(EFFECT_CLASS), 8),
\ |
336 k_##NAME##_StorageSize = k_##NAME##_EffectRefOffset + sizeof(GrEffectRef)
\ | 335 k_##NAME##_StorageSize = k_##NAME##_EffectRefOffset + sizeof(GrEffectRef)
\ |
337 };
\ | 336 };
\ |
338 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage;
\ | 337 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage;
\ |
339 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E
ffectRefOffset; \ | 338 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E
ffectRefOffset; \ |
340 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF
FECT_CLASS, ARGS);\ | 339 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF
FECT_CLASS, ARGS);\ |
341 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect);
\ | 340 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect);
\ |
342 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM
E##_Effect)); \ | 341 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM
E##_Effect)); \ |
343 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME) | 342 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME) |
344 | 343 |
345 | 344 |
346 #endif | 345 #endif |
OLD | NEW |