OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrXferProcessor_DEFINED | 8 #ifndef GrXferProcessor_DEFINED |
9 #define GrXferProcessor_DEFINED | 9 #define GrXferProcessor_DEFINED |
10 | 10 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 * its state to reflected the given blend optimizations. If the XP needs to
see a specific input | 160 * its state to reflected the given blend optimizations. If the XP needs to
see a specific input |
161 * color to blend correctly, it will set the OverrideColor flag and the outp
ut parameter | 161 * color to blend correctly, it will set the OverrideColor flag and the outp
ut parameter |
162 * overrideColor will be the required value that should be passed into the X
P. | 162 * overrideColor will be the required value that should be passed into the X
P. |
163 * A caller who calls this function on a XP is required to honor the returne
d OptFlags | 163 * A caller who calls this function on a XP is required to honor the returne
d OptFlags |
164 * and color values for its draw. | 164 * and color values for its draw. |
165 */ | 165 */ |
166 OptFlags getOptimizations(const GrProcOptInfo& colorPOI, | 166 OptFlags getOptimizations(const GrProcOptInfo& colorPOI, |
167 const GrProcOptInfo& coveragePOI, | 167 const GrProcOptInfo& coveragePOI, |
168 bool doesStencilWrite, | 168 bool doesStencilWrite, |
169 GrColor* overrideColor, | 169 GrColor* overrideColor, |
170 const GrDrawTargetCaps& caps); | 170 const GrCaps& caps); |
171 | 171 |
172 /** | 172 /** |
173 * Returns whether this XP will require an Xfer barrier on the given rt. If
true, outBarrierType | 173 * Returns whether this XP will require an Xfer barrier on the given rt. If
true, outBarrierType |
174 * is updated to contain the type of barrier needed. | 174 * is updated to contain the type of barrier needed. |
175 */ | 175 */ |
176 bool willNeedXferBarrier(const GrRenderTarget* rt, | 176 bool willNeedXferBarrier(const GrRenderTarget* rt, |
177 const GrDrawTargetCaps& caps, | 177 const GrCaps& caps, |
178 GrXferBarrierType* outBarrierType) const; | 178 GrXferBarrierType* outBarrierType) const; |
179 | 179 |
180 struct BlendInfo { | 180 struct BlendInfo { |
181 void reset() { | 181 void reset() { |
182 fEquation = kAdd_GrBlendEquation; | 182 fEquation = kAdd_GrBlendEquation; |
183 fSrcBlend = kOne_GrBlendCoeff; | 183 fSrcBlend = kOne_GrBlendCoeff; |
184 fDstBlend = kZero_GrBlendCoeff; | 184 fDstBlend = kZero_GrBlendCoeff; |
185 fBlendConstant = 0; | 185 fBlendConstant = 0; |
186 fWriteColor = true; | 186 fWriteColor = true; |
187 } | 187 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 protected: | 258 protected: |
259 GrXferProcessor(); | 259 GrXferProcessor(); |
260 GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); | 260 GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); |
261 | 261 |
262 private: | 262 private: |
263 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 263 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
264 const GrProcOptInfo& coveragePOI, | 264 const GrProcOptInfo& coveragePOI, |
265 bool doesStencilWrite, | 265 bool doesStencilWrite, |
266 GrColor* overrideColor, | 266 GrColor* overrideColor, |
267 const GrDrawTargetCaps& caps) = 0; | 267 const GrCaps& caps) = 0; |
268 | 268 |
269 /** | 269 /** |
270 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer | 270 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer |
271 * processor's GL backend implementation. | 271 * processor's GL backend implementation. |
272 */ | 272 */ |
273 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 273 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
274 GrProcessorKeyBuilder* b) const = 0; | 274 GrProcessorKeyBuilder* b) const = 0; |
275 | 275 |
276 /** | 276 /** |
277 * If not using a texture barrier, retrieves whether the subclass will requi
re a different type | 277 * If not using a texture barrier, retrieves whether the subclass will requi
re a different type |
278 * of barrier. | 278 * of barrier. |
279 */ | 279 */ |
280 virtual bool onWillNeedXferBarrier(const GrRenderTarget*, | 280 virtual bool onWillNeedXferBarrier(const GrRenderTarget*, |
281 const GrDrawTargetCaps&, | 281 const GrCaps&, |
282 GrXferBarrierType* outBarrierType SK_UNUS
ED) const { | 282 GrXferBarrierType* outBarrierType SK_UNUS
ED) const { |
283 return false; | 283 return false; |
284 } | 284 } |
285 | 285 |
286 /** | 286 /** |
287 * Retrieves the hardware blend state required by this Xfer processor. The B
lendInfo struct | 287 * Retrieves the hardware blend state required by this Xfer processor. The B
lendInfo struct |
288 * comes initialized to default values, so the Xfer processor only needs to
set the state it | 288 * comes initialized to default values, so the Xfer processor only needs to
set the state it |
289 * needs. It may not even need to override this method at all. | 289 * needs. It may not even need to override this method at all. |
290 */ | 290 */ |
291 virtual void onGetBlendInfo(BlendInfo*) const {} | 291 virtual void onGetBlendInfo(BlendInfo*) const {} |
(...skipping 21 matching lines...) Expand all Loading... |
313 * | 313 * |
314 * Before the XP is created, the XPF is able to answer queries about what functi
onality the XPs it | 314 * Before the XP is created, the XPF is able to answer queries about what functi
onality the XPs it |
315 * creates will have. For example, can it create an XP that supports RGB coverag
e or will the XP | 315 * creates will have. For example, can it create an XP that supports RGB coverag
e or will the XP |
316 * blend with the destination color. | 316 * blend with the destination color. |
317 */ | 317 */ |
318 class GrXPFactory : public SkRefCnt { | 318 class GrXPFactory : public SkRefCnt { |
319 public: | 319 public: |
320 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, | 320 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, |
321 const GrProcOptInfo& coveragePOI, | 321 const GrProcOptInfo& coveragePOI, |
322 const GrDeviceCoordTexture* dstCopy, | 322 const GrDeviceCoordTexture* dstCopy, |
323 const GrDrawTargetCaps& caps) const; | 323 const GrCaps& caps) const; |
324 | 324 |
325 /** | 325 /** |
326 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to | 326 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to |
327 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the | 327 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the |
328 * final computed color from the color stages. | 328 * final computed color from the color stages. |
329 */ | 329 */ |
330 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; | 330 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; |
331 | 331 |
332 struct InvariantOutput { | 332 struct InvariantOutput { |
333 bool fWillBlendWithDst; | 333 bool fWillBlendWithDst; |
334 GrColor fBlendedColor; | 334 GrColor fBlendedColor; |
335 uint32_t fBlendedColorFlags; | 335 uint32_t fBlendedColorFlags; |
336 }; | 336 }; |
337 | 337 |
338 /** | 338 /** |
339 * This function returns known information about the output of the xfer proc
essor produced by | 339 * This function returns known information about the output of the xfer proc
essor produced by |
340 * this xp factory. The invariant color information returned by this functio
n refers to the | 340 * this xp factory. The invariant color information returned by this functio
n refers to the |
341 * final color produced after all blending. | 341 * final color produced after all blending. |
342 */ | 342 */ |
343 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO
ptInfo& coveragePOI, | 343 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO
ptInfo& coveragePOI, |
344 InvariantOutput*) const = 0; | 344 InvariantOutput*) const = 0; |
345 | 345 |
346 bool willNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colo
rPOI, | 346 bool willNeedDstCopy(const GrCaps& caps, const GrProcOptInfo& colorPOI, |
347 const GrProcOptInfo& coveragePOI) const; | 347 const GrProcOptInfo& coveragePOI) const; |
348 | 348 |
349 bool isEqual(const GrXPFactory& that) const { | 349 bool isEqual(const GrXPFactory& that) const { |
350 if (this->classID() != that.classID()) { | 350 if (this->classID() != that.classID()) { |
351 return false; | 351 return false; |
352 } | 352 } |
353 return this->onIsEqual(that); | 353 return this->onIsEqual(that); |
354 } | 354 } |
355 | 355 |
356 /** | 356 /** |
357 * Helper for down-casting to a GrXPFactory subclass | 357 * Helper for down-casting to a GrXPFactory subclass |
358 */ | 358 */ |
359 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } | 359 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } |
360 | 360 |
361 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return
fClassID; } | 361 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return
fClassID; } |
362 | 362 |
363 protected: | 363 protected: |
364 GrXPFactory() : fClassID(kIllegalXPFClassID) {} | 364 GrXPFactory() : fClassID(kIllegalXPFClassID) {} |
365 | 365 |
366 template <typename XPF_SUBCLASS> void initClassID() { | 366 template <typename XPF_SUBCLASS> void initClassID() { |
367 static uint32_t kClassID = GenClassID(); | 367 static uint32_t kClassID = GenClassID(); |
368 fClassID = kClassID; | 368 fClassID = kClassID; |
369 } | 369 } |
370 | 370 |
371 uint32_t fClassID; | 371 uint32_t fClassID; |
372 | 372 |
373 private: | 373 private: |
374 virtual GrXferProcessor* onCreateXferProcessor(const GrDrawTargetCaps& caps, | 374 virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, |
375 const GrProcOptInfo& colorPOI
, | 375 const GrProcOptInfo& colorPOI
, |
376 const GrProcOptInfo& coverage
POI, | 376 const GrProcOptInfo& coverage
POI, |
377 const GrDeviceCoordTexture* d
stCopy) const = 0; | 377 const GrDeviceCoordTexture* d
stCopy) const = 0; |
378 /** | 378 /** |
379 * Returns true if the XP generated by this factory will explicitly read ds
t in the fragment | 379 * Returns true if the XP generated by this factory will explicitly read ds
t in the fragment |
380 * shader. | 380 * shader. |
381 */ | 381 */ |
382 virtual bool willReadDstColor(const GrDrawTargetCaps& caps, | 382 virtual bool willReadDstColor(const GrCaps& caps, |
383 const GrProcOptInfo& colorPOI, | 383 const GrProcOptInfo& colorPOI, |
384 const GrProcOptInfo& coveragePOI) const = 0; | 384 const GrProcOptInfo& coveragePOI) const = 0; |
385 | 385 |
386 virtual bool onIsEqual(const GrXPFactory&) const = 0; | 386 virtual bool onIsEqual(const GrXPFactory&) const = 0; |
387 | 387 |
388 static uint32_t GenClassID() { | 388 static uint32_t GenClassID() { |
389 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The | 389 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The |
390 // atomic inc returns the old value not the incremented value. So we add | 390 // atomic inc returns the old value not the incremented value. So we add |
391 // 1 to the returned value. | 391 // 1 to the returned value. |
392 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1
; | 392 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1
; |
393 if (!id) { | 393 if (!id) { |
394 SkFAIL("This should never wrap as it should only be called once for
each GrXPFactory " | 394 SkFAIL("This should never wrap as it should only be called once for
each GrXPFactory " |
395 "subclass."); | 395 "subclass."); |
396 } | 396 } |
397 return id; | 397 return id; |
398 } | 398 } |
399 | 399 |
400 enum { | 400 enum { |
401 kIllegalXPFClassID = 0, | 401 kIllegalXPFClassID = 0, |
402 }; | 402 }; |
403 static int32_t gCurrXPFClassID; | 403 static int32_t gCurrXPFClassID; |
404 | 404 |
405 typedef GrProgramElement INHERITED; | 405 typedef GrProgramElement INHERITED; |
406 }; | 406 }; |
407 | 407 |
408 #endif | 408 #endif |
409 | 409 |
OLD | NEW |