| 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 #include "GrClipMaskManager.h" | 8 #include "GrClipMaskManager.h" |
| 9 #include "GrCaps.h" | 9 #include "GrCaps.h" |
| 10 #include "GrDrawingManager.h" | 10 #include "GrDrawingManager.h" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 377 |
| 378 // The top-left of the mask corresponds to the top-left corner of the bo
unds. | 378 // The top-left of the mask corresponds to the top-left corner of the bo
unds. |
| 379 SkVector clipToMaskOffset = { | 379 SkVector clipToMaskOffset = { |
| 380 SkIntToScalar(-clipSpaceIBounds.fLeft), | 380 SkIntToScalar(-clipSpaceIBounds.fLeft), |
| 381 SkIntToScalar(-clipSpaceIBounds.fTop) | 381 SkIntToScalar(-clipSpaceIBounds.fTop) |
| 382 }; | 382 }; |
| 383 | 383 |
| 384 if (UseSWOnlyPath(this->getContext(), pipelineBuilder, rt, clipToMaskOff
set, elements)) { | 384 if (UseSWOnlyPath(this->getContext(), pipelineBuilder, rt, clipToMaskOff
set, elements)) { |
| 385 // The clip geometry is complex enough that it will be more efficien
t to create it | 385 // The clip geometry is complex enough that it will be more efficien
t to create it |
| 386 // entirely in software | 386 // entirely in software |
| 387 result = CreateSoftwareClipMask(this->getContext(), | 387 result = CreateSoftwareClipMask(this->getContext()->textureProvider(
), |
| 388 genID, | 388 genID, |
| 389 initialState, | 389 initialState, |
| 390 elements, | 390 elements, |
| 391 clipToMaskOffset, | 391 clipToMaskOffset, |
| 392 clipSpaceIBounds); | 392 clipSpaceIBounds); |
| 393 } else { | 393 } else { |
| 394 result = CreateAlphaClipMask(this->getContext(), | 394 result = CreateAlphaClipMask(this->getContext(), |
| 395 genID, | 395 genID, |
| 396 initialState, | 396 initialState, |
| 397 elements, | 397 elements, |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 SkRect::Make(clipSpaceIBounds)); | 784 SkRect::Make(clipSpaceIBounds)); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 } | 788 } |
| 789 return true; | 789 return true; |
| 790 } | 790 } |
| 791 | 791 |
| 792 //////////////////////////////////////////////////////////////////////////////// | 792 //////////////////////////////////////////////////////////////////////////////// |
| 793 sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask( | 793 sk_sp<GrTexture> GrClipMaskManager::CreateSoftwareClipMask( |
| 794 GrContext* context, | 794 GrTextureProvider* texProvid
er, |
| 795 int32_t elementsGenID, | 795 int32_t elementsGenID, |
| 796 GrReducedClip::InitialState
initialState, | 796 GrReducedClip::InitialState
initialState, |
| 797 const GrReducedClip::Element
List& elements, | 797 const GrReducedClip::Element
List& elements, |
| 798 const SkVector& clipToMaskOf
fset, | 798 const SkVector& clipToMaskOf
fset, |
| 799 const SkIRect& clipSpaceIBou
nds) { | 799 const SkIRect& clipSpaceIBou
nds) { |
| 800 GrUniqueKey key; | 800 GrUniqueKey key; |
| 801 GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); | 801 GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); |
| 802 GrResourceProvider* resourceProvider = context->resourceProvider(); | 802 if (GrTexture* texture = texProvider->findAndRefTextureByUniqueKey(key)) { |
| 803 if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)
) { | |
| 804 return sk_sp<GrTexture>(texture); | 803 return sk_sp<GrTexture>(texture); |
| 805 } | 804 } |
| 806 | 805 |
| 807 // The mask texture may be larger than necessary. We round out the clip spac
e bounds and pin | 806 // The mask texture may be larger than necessary. We round out the clip spac
e bounds and pin |
| 808 // the top left corner of the resulting rect to the top left of the texture. | 807 // the top left corner of the resulting rect to the top left of the texture. |
| 809 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); | 808 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); |
| 810 | 809 |
| 811 GrSWMaskHelper helper(context); | 810 GrSWMaskHelper helper(texProvider); |
| 812 | 811 |
| 813 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip | 812 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip |
| 814 // space. | 813 // space. |
| 815 SkMatrix translate; | 814 SkMatrix translate; |
| 816 translate.setTranslate(clipToMaskOffset); | 815 translate.setTranslate(clipToMaskOffset); |
| 817 | 816 |
| 818 helper.init(maskSpaceIBounds, &translate); | 817 helper.init(maskSpaceIBounds, &translate); |
| 819 helper.clear(GrReducedClip::kAllIn_InitialState == initialState ? 0xFF : 0x0
0); | 818 helper.clear(GrReducedClip::kAllIn_InitialState == initialState ? 0xFF : 0x0
0); |
| 820 | 819 |
| 821 for (GrReducedClip::ElementList::Iter iter(elements.headIter()) ; iter.get()
; iter.next()) { | 820 for (GrReducedClip::ElementList::Iter iter(elements.headIter()) ; iter.get()
; iter.next()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 850 helper.drawPath(path, GrStyle::SimpleFill(), op, element->isAA(), 0x
FF); | 849 helper.drawPath(path, GrStyle::SimpleFill(), op, element->isAA(), 0x
FF); |
| 851 } | 850 } |
| 852 } | 851 } |
| 853 | 852 |
| 854 // Allocate clip mask texture | 853 // Allocate clip mask texture |
| 855 GrSurfaceDesc desc; | 854 GrSurfaceDesc desc; |
| 856 desc.fWidth = clipSpaceIBounds.width(); | 855 desc.fWidth = clipSpaceIBounds.width(); |
| 857 desc.fHeight = clipSpaceIBounds.height(); | 856 desc.fHeight = clipSpaceIBounds.height(); |
| 858 desc.fConfig = kAlpha_8_GrPixelConfig; | 857 desc.fConfig = kAlpha_8_GrPixelConfig; |
| 859 | 858 |
| 860 sk_sp<GrTexture> result(context->resourceProvider()->createApproxTexture(des
c, 0)); | 859 sk_sp<GrTexture> result(texProvider->createApproxTexture(desc)); |
| 861 if (!result) { | 860 if (!result) { |
| 862 return nullptr; | 861 return nullptr; |
| 863 } | 862 } |
| 864 result->resourcePriv().setUniqueKey(key); | 863 result->resourcePriv().setUniqueKey(key); |
| 865 | 864 |
| 866 helper.toTexture(result.get()); | 865 helper.toTexture(result.get()); |
| 867 | 866 |
| 868 return result; | 867 return result; |
| 869 } | 868 } |
| OLD | NEW |