OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrClipMaskManager.h" | 9 #include "GrClipMaskManager.h" |
10 #include "GrAAConvexPathRenderer.h" | 10 #include "GrAAConvexPathRenderer.h" |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 385 |
386 temp->set(this->getContext(), desc); | 386 temp->set(this->getContext(), desc); |
387 } | 387 } |
388 | 388 |
389 //////////////////////////////////////////////////////////////////////////////// | 389 //////////////////////////////////////////////////////////////////////////////// |
390 // Handles caching & allocation (if needed) of a clip alpha-mask texture for bot
h the sw-upload | 390 // Handles caching & allocation (if needed) of a clip alpha-mask texture for bot
h the sw-upload |
391 // or gpu-rendered cases. Returns true if there is no more work to be done (i.e.
, we got a cache | 391 // or gpu-rendered cases. Returns true if there is no more work to be done (i.e.
, we got a cache |
392 // hit) | 392 // hit) |
393 bool GrClipMaskManager::getMaskTexture(int32_t clipStackGenID, | 393 bool GrClipMaskManager::getMaskTexture(int32_t clipStackGenID, |
394 const SkIRect& clipSpaceIBounds, | 394 const SkIRect& clipSpaceIBounds, |
395 GrTexture** result) { | 395 GrTexture** result, |
| 396 bool willUpload) { |
396 bool cached = fAACache.canReuse(clipStackGenID, clipSpaceIBounds); | 397 bool cached = fAACache.canReuse(clipStackGenID, clipSpaceIBounds); |
397 if (!cached) { | 398 if (!cached) { |
398 | 399 |
399 // There isn't a suitable entry in the cache so we create a new texture
to store the mask. | 400 // There isn't a suitable entry in the cache so we create a new texture
to store the mask. |
400 // Since we are setting up the cache we know the last lookup was a miss.
Free up the | 401 // Since we are setting up the cache we know the last lookup was a miss.
Free up the |
401 // currently cached mask so it can be reused. | 402 // currently cached mask so it can be reused. |
402 fAACache.reset(); | 403 fAACache.reset(); |
403 | 404 |
404 GrTextureDesc desc; | 405 GrTextureDesc desc; |
405 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 406 desc.fFlags = willUpload ? kNone_GrTextureFlags : kRenderTarget_GrTextur
eFlagBit; |
406 desc.fWidth = clipSpaceIBounds.width(); | 407 desc.fWidth = clipSpaceIBounds.width(); |
407 desc.fHeight = clipSpaceIBounds.height(); | 408 desc.fHeight = clipSpaceIBounds.height(); |
408 desc.fConfig = kRGBA_8888_GrPixelConfig; | 409 desc.fConfig = kRGBA_8888_GrPixelConfig; |
409 if (this->getContext()->isConfigRenderable(kAlpha_8_GrPixelConfig, false
)) { | 410 if (this->getContext()->isConfigRenderable(kAlpha_8_GrPixelConfig, false
)) { |
410 // We would always like A8 but it isn't supported on all platforms | 411 // We would always like A8 but it isn't supported on all platforms |
411 desc.fConfig = kAlpha_8_GrPixelConfig; | 412 desc.fConfig = kAlpha_8_GrPixelConfig; |
412 } | 413 } |
413 | 414 |
414 fAACache.acquireMask(clipStackGenID, desc, clipSpaceIBounds); | 415 fAACache.acquireMask(clipStackGenID, desc, clipSpaceIBounds); |
415 } | 416 } |
416 | 417 |
417 *result = fAACache.getLastMask(); | 418 *result = fAACache.getLastMask(); |
418 return cached; | 419 return cached; |
419 } | 420 } |
420 | 421 |
421 //////////////////////////////////////////////////////////////////////////////// | 422 //////////////////////////////////////////////////////////////////////////////// |
422 // Create a 8-bit clip mask in alpha | 423 // Create a 8-bit clip mask in alpha |
423 GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t clipStackGenID, | 424 GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t clipStackGenID, |
424 InitialState initialState, | 425 InitialState initialState, |
425 const ElementList& elements, | 426 const ElementList& elements, |
426 const SkIRect& clipSpaceIBound
s) { | 427 const SkIRect& clipSpaceIBound
s) { |
427 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); | 428 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); |
428 | 429 |
429 GrTexture* result; | 430 GrTexture* result; |
430 if (this->getMaskTexture(clipStackGenID, clipSpaceIBounds, &result)) { | 431 if (this->getMaskTexture(clipStackGenID, clipSpaceIBounds, &result, false))
{ |
431 fCurrClipMaskType = kAlpha_ClipMaskType; | 432 fCurrClipMaskType = kAlpha_ClipMaskType; |
432 return result; | 433 return result; |
433 } | 434 } |
434 | 435 |
435 if (NULL == result) { | 436 if (NULL == result) { |
436 fAACache.reset(); | 437 fAACache.reset(); |
437 return NULL; | 438 return NULL; |
438 } | 439 } |
439 | 440 |
440 // The top-left of the mask corresponds to the top-left corner of the bounds
. | 441 // The top-left of the mask corresponds to the top-left corner of the bounds
. |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 } | 919 } |
919 | 920 |
920 //////////////////////////////////////////////////////////////////////////////// | 921 //////////////////////////////////////////////////////////////////////////////// |
921 GrTexture* GrClipMaskManager::createSoftwareClipMask(int32_t clipStackGenID, | 922 GrTexture* GrClipMaskManager::createSoftwareClipMask(int32_t clipStackGenID, |
922 GrReducedClip::InitialState
initialState, | 923 GrReducedClip::InitialState
initialState, |
923 const GrReducedClip::Elemen
tList& elements, | 924 const GrReducedClip::Elemen
tList& elements, |
924 const SkIRect& clipSpaceIBo
unds) { | 925 const SkIRect& clipSpaceIBo
unds) { |
925 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); | 926 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); |
926 | 927 |
927 GrTexture* result; | 928 GrTexture* result; |
928 if (this->getMaskTexture(clipStackGenID, clipSpaceIBounds, &result)) { | 929 if (this->getMaskTexture(clipStackGenID, clipSpaceIBounds, &result, true)) { |
929 return result; | 930 return result; |
930 } | 931 } |
931 | 932 |
932 if (NULL == result) { | 933 if (NULL == result) { |
933 fAACache.reset(); | 934 fAACache.reset(); |
934 return NULL; | 935 return NULL; |
935 } | 936 } |
936 | 937 |
937 // The mask texture may be larger than necessary. We round out the clip spac
e bounds and pin | 938 // The mask texture may be larger than necessary. We round out the clip spac
e bounds and pin |
938 // the top left corner of the resulting rect to the top left of the texture. | 939 // the top left corner of the resulting rect to the top left of the texture. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 | 1031 |
1031 // TODO: dynamically attach a stencil buffer | 1032 // TODO: dynamically attach a stencil buffer |
1032 int stencilBits = 0; | 1033 int stencilBits = 0; |
1033 GrStencilBuffer* stencilBuffer = | 1034 GrStencilBuffer* stencilBuffer = |
1034 drawState.getRenderTarget()->getStencilBuffer(); | 1035 drawState.getRenderTarget()->getStencilBuffer(); |
1035 if (NULL != stencilBuffer) { | 1036 if (NULL != stencilBuffer) { |
1036 stencilBits = stencilBuffer->bits(); | 1037 stencilBits = stencilBuffer->bits(); |
1037 this->adjustStencilParams(settings, clipMode, stencilBits); | 1038 this->adjustStencilParams(settings, clipMode, stencilBits); |
1038 } | 1039 } |
1039 } | 1040 } |
OLD | NEW |