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 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 // the top left corner of the resulting rect to the top left of the texture. | 920 // the top left corner of the resulting rect to the top left of the texture. |
921 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); | 921 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); |
922 | 922 |
923 GrSWMaskHelper helper(context); | 923 GrSWMaskHelper helper(context); |
924 | 924 |
925 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip | 925 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip |
926 // space. | 926 // space. |
927 SkMatrix translate; | 927 SkMatrix translate; |
928 translate.setTranslate(clipToMaskOffset); | 928 translate.setTranslate(clipToMaskOffset); |
929 | 929 |
930 helper.init(maskSpaceIBounds, &translate, false); | 930 helper.init(maskSpaceIBounds, &translate); |
931 helper.clear(GrReducedClip::kAllIn_InitialState == initialState ? 0xFF : 0x0
0); | 931 helper.clear(GrReducedClip::kAllIn_InitialState == initialState ? 0xFF : 0x0
0); |
932 | 932 |
933 for (GrReducedClip::ElementList::Iter iter(elements.headIter()) ; iter.get()
; iter.next()) { | 933 for (GrReducedClip::ElementList::Iter iter(elements.headIter()) ; iter.get()
; iter.next()) { |
934 const Element* element = iter.get(); | 934 const Element* element = iter.get(); |
935 SkRegion::Op op = element->getOp(); | 935 SkRegion::Op op = element->getOp(); |
936 | 936 |
937 if (SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op ==
op) { | 937 if (SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op ==
op) { |
938 // Intersect and reverse difference require modifying pixels outside
of the geometry | 938 // Intersect and reverse difference require modifying pixels outside
of the geometry |
939 // that is being "drawn". In both cases we erase all the pixels outs
ide of the geometry | 939 // that is being "drawn". In both cases we erase all the pixels outs
ide of the geometry |
940 // but leave the pixels inside the geometry alone. For reverse diffe
rence we invert all | 940 // but leave the pixels inside the geometry alone. For reverse diffe
rence we invert all |
941 // the pixels before clearing the ones outside the geometry. | 941 // the pixels before clearing the ones outside the geometry. |
942 if (SkRegion::kReverseDifference_Op == op) { | 942 if (SkRegion::kReverseDifference_Op == op) { |
943 SkRect temp = SkRect::Make(clipSpaceIBounds); | 943 SkRect temp = SkRect::Make(clipSpaceIBounds); |
944 // invert the entire scene | 944 // invert the entire scene |
945 helper.draw(temp, SkRegion::kXOR_Op, false, 0xFF); | 945 helper.drawRect(temp, SkRegion::kXOR_Op, false, 0xFF); |
946 } | 946 } |
947 SkPath clipPath; | 947 SkPath clipPath; |
948 element->asPath(&clipPath); | 948 element->asPath(&clipPath); |
949 clipPath.toggleInverseFillType(); | 949 clipPath.toggleInverseFillType(); |
950 helper.draw(clipPath, GrStyle::SimpleFill(), SkRegion::kReplace_Op,
element->isAA(), | 950 helper.drawPath(clipPath, GrStyle::SimpleFill(), SkRegion::kReplace_
Op, |
951 0x00); | 951 element->isAA(), 0x00); |
952 continue; | 952 continue; |
953 } | 953 } |
954 | 954 |
955 // The other ops (union, xor, diff) only affect pixels inside | 955 // The other ops (union, xor, diff) only affect pixels inside |
956 // the geometry so they can just be drawn normally | 956 // the geometry so they can just be drawn normally |
957 if (Element::kRect_Type == element->getType()) { | 957 if (Element::kRect_Type == element->getType()) { |
958 helper.draw(element->getRect(), op, element->isAA(), 0xFF); | 958 helper.drawRect(element->getRect(), op, element->isAA(), 0xFF); |
959 } else { | 959 } else { |
960 SkPath path; | 960 SkPath path; |
961 element->asPath(&path); | 961 element->asPath(&path); |
962 helper.draw(path, GrStyle::SimpleFill(), op, element->isAA(), 0xFF); | 962 helper.drawPath(path, GrStyle::SimpleFill(), op, element->isAA(), 0x
FF); |
963 } | 963 } |
964 } | 964 } |
965 | 965 |
966 // Allocate clip mask texture | 966 // Allocate clip mask texture |
967 GrSurfaceDesc desc; | 967 GrSurfaceDesc desc; |
968 desc.fWidth = clipSpaceIBounds.width(); | 968 desc.fWidth = clipSpaceIBounds.width(); |
969 desc.fHeight = clipSpaceIBounds.height(); | 969 desc.fHeight = clipSpaceIBounds.height(); |
970 desc.fConfig = kAlpha_8_GrPixelConfig; | 970 desc.fConfig = kAlpha_8_GrPixelConfig; |
971 | 971 |
972 GrTexture* result = context->resourceProvider()->createApproxTexture(desc, 0
); | 972 GrTexture* result = context->resourceProvider()->createApproxTexture(desc, 0
); |
973 if (!result) { | 973 if (!result) { |
974 return nullptr; | 974 return nullptr; |
975 } | 975 } |
976 result->resourcePriv().setUniqueKey(key); | 976 result->resourcePriv().setUniqueKey(key); |
977 | 977 |
978 helper.toTexture(result); | 978 helper.toTexture(result); |
979 | 979 |
980 return result; | 980 return result; |
981 } | 981 } |
OLD | NEW |