| 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
| 9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
| 10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| 11 #include "gl/GrGLVertexEffect.h" | 11 #include "gl/GrGLVertexEffect.h" |
| 12 #include "GrTBackendEffectFactory.h" | 12 #include "GrTBackendEffectFactory.h" |
| 13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 14 #include "effects/GrVertexEffect.h" | 14 #include "effects/GrVertexEffect.h" |
| 15 | 15 |
| 16 /////////////////////////////////////////////////////////////////////////////// | 16 /////////////////////////////////////////////////////////////////////////////// |
| 17 class GrGLAlignedRectEffect; | 17 class GrGLAlignedRectEffect; |
| 18 | 18 |
| 19 // Axis Aligned special case | 19 // Axis Aligned special case |
| 20 class GrAlignedRectEffect : public GrVertexEffect { | 20 class GrAlignedRectEffect : public GrVertexEffect { |
| 21 public: | 21 public: |
| 22 static GrEffectRef* Create() { | 22 static GrEffect* Create() { |
| 23 GR_CREATE_STATIC_EFFECT(gAlignedRectEffect, GrAlignedRectEffect, ()); | 23 GR_CREATE_STATIC_EFFECT(gAlignedRectEffect, GrAlignedRectEffect, ()); |
| 24 gAlignedRectEffect->ref(); | 24 gAlignedRectEffect->ref(); |
| 25 return gAlignedRectEffect; | 25 return gAlignedRectEffect; |
| 26 } | 26 } |
| 27 | 27 |
| 28 virtual ~GrAlignedRectEffect() {} | 28 virtual ~GrAlignedRectEffect() {} |
| 29 | 29 |
| 30 static const char* Name() { return "AlignedRectEdge"; } | 30 static const char* Name() { return "AlignedRectEdge"; } |
| 31 | 31 |
| 32 virtual void getConstantColorComponents(GrColor* color, | 32 virtual void getConstantColorComponents(GrColor* color, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } | 106 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } |
| 107 | 107 |
| 108 GR_DECLARE_EFFECT_TEST; | 108 GR_DECLARE_EFFECT_TEST; |
| 109 | 109 |
| 110 typedef GrVertexEffect INHERITED; | 110 typedef GrVertexEffect INHERITED; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 | 113 |
| 114 GR_DEFINE_EFFECT_TEST(GrAlignedRectEffect); | 114 GR_DEFINE_EFFECT_TEST(GrAlignedRectEffect); |
| 115 | 115 |
| 116 GrEffectRef* GrAlignedRectEffect::TestCreate(SkRandom* random, | 116 GrEffect* GrAlignedRectEffect::TestCreate(SkRandom* random, |
| 117 GrContext* context, | 117 GrContext* context, |
| 118 const GrDrawTargetCaps&, | 118 const GrDrawTargetCaps&, |
| 119 GrTexture* textures[]) { | 119 GrTexture* textures[]) { |
| 120 return GrAlignedRectEffect::Create(); | 120 return GrAlignedRectEffect::Create(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 /////////////////////////////////////////////////////////////////////////////// | 123 /////////////////////////////////////////////////////////////////////////////// |
| 124 class GrGLRectEffect; | 124 class GrGLRectEffect; |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * The output of this effect is a modulation of the input color and coverage | 127 * The output of this effect is a modulation of the input color and coverage |
| 128 * for an arbitrarily oriented rect. The rect is specified as: | 128 * for an arbitrarily oriented rect. The rect is specified as: |
| 129 * Center of the rect | 129 * Center of the rect |
| 130 * Unit vector point down the height of the rect | 130 * Unit vector point down the height of the rect |
| 131 * Half width + 0.5 | 131 * Half width + 0.5 |
| 132 * Half height + 0.5 | 132 * Half height + 0.5 |
| 133 * The center and vector are stored in a vec4 varying ("RectEdge") with the | 133 * The center and vector are stored in a vec4 varying ("RectEdge") with the |
| 134 * center in the xy components and the vector in the zw components. | 134 * center in the xy components and the vector in the zw components. |
| 135 * The munged width and height are stored in a vec2 varying ("WidthHeight") | 135 * The munged width and height are stored in a vec2 varying ("WidthHeight") |
| 136 * with the width in x and the height in y. | 136 * with the width in x and the height in y. |
| 137 */ | 137 */ |
| 138 class GrRectEffect : public GrVertexEffect { | 138 class GrRectEffect : public GrVertexEffect { |
| 139 public: | 139 public: |
| 140 static GrEffectRef* Create() { | 140 static GrEffect* Create() { |
| 141 GR_CREATE_STATIC_EFFECT(gRectEffect, GrRectEffect, ()); | 141 GR_CREATE_STATIC_EFFECT(gRectEffect, GrRectEffect, ()); |
| 142 gRectEffect->ref(); | 142 gRectEffect->ref(); |
| 143 return gRectEffect; | 143 return gRectEffect; |
| 144 } | 144 } |
| 145 | 145 |
| 146 virtual ~GrRectEffect() {} | 146 virtual ~GrRectEffect() {} |
| 147 | 147 |
| 148 static const char* Name() { return "RectEdge"; } | 148 static const char* Name() { return "RectEdge"; } |
| 149 | 149 |
| 150 virtual void getConstantColorComponents(GrColor* color, | 150 virtual void getConstantColorComponents(GrColor* color, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } | 241 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } |
| 242 | 242 |
| 243 GR_DECLARE_EFFECT_TEST; | 243 GR_DECLARE_EFFECT_TEST; |
| 244 | 244 |
| 245 typedef GrVertexEffect INHERITED; | 245 typedef GrVertexEffect INHERITED; |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 | 248 |
| 249 GR_DEFINE_EFFECT_TEST(GrRectEffect); | 249 GR_DEFINE_EFFECT_TEST(GrRectEffect); |
| 250 | 250 |
| 251 GrEffectRef* GrRectEffect::TestCreate(SkRandom* random, | 251 GrEffect* GrRectEffect::TestCreate(SkRandom* random, |
| 252 GrContext* context, | 252 GrContext* context, |
| 253 const GrDrawTargetCaps&, | 253 const GrDrawTargetCaps&, |
| 254 GrTexture* textures[]) { | 254 GrTexture* textures[]) { |
| 255 return GrRectEffect::Create(); | 255 return GrRectEffect::Create(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 /////////////////////////////////////////////////////////////////////////////// | 258 /////////////////////////////////////////////////////////////////////////////// |
| 259 | 259 |
| 260 namespace { | 260 namespace { |
| 261 | 261 |
| 262 extern const GrVertexAttrib gAARectCoverageAttribs[] = { | 262 extern const GrVertexAttrib gAARectCoverageAttribs[] = { |
| 263 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | 263 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
| 264 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBindin
g}, | 264 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBindin
g}, |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 SkASSERT(sizeof(RectVertex) == drawState->getVertexSize()); | 624 SkASSERT(sizeof(RectVertex) == drawState->getVertexSize()); |
| 625 | 625 |
| 626 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 626 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 627 if (!geo.succeeded()) { | 627 if (!geo.succeeded()) { |
| 628 GrPrintf("Failed to get space for vertices!\n"); | 628 GrPrintf("Failed to get space for vertices!\n"); |
| 629 return; | 629 return; |
| 630 } | 630 } |
| 631 | 631 |
| 632 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices()); | 632 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices()); |
| 633 | 633 |
| 634 GrEffectRef* effect = GrRectEffect::Create(); | 634 GrEffect* effect = GrRectEffect::Create(); |
| 635 static const int kRectAttrIndex = 1; | 635 static const int kRectAttrIndex = 1; |
| 636 static const int kWidthIndex = 2; | 636 static const int kWidthIndex = 2; |
| 637 drawState->addCoverageEffect(effect, kRectAttrIndex, kWidthIndex)->unref(); | 637 drawState->addCoverageEffect(effect, kRectAttrIndex, kWidthIndex)->unref(); |
| 638 | 638 |
| 639 for (int i = 0; i < 4; ++i) { | 639 for (int i = 0; i < 4; ++i) { |
| 640 verts[i].fCenter = center; | 640 verts[i].fCenter = center; |
| 641 verts[i].fDir = dir; | 641 verts[i].fDir = dir; |
| 642 verts[i].fWidthHeight.fX = newWidth; | 642 verts[i].fWidthHeight.fX = newWidth; |
| 643 verts[i].fWidthHeight.fY = newHeight; | 643 verts[i].fWidthHeight.fY = newHeight; |
| 644 } | 644 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 674 SkASSERT(sizeof(AARectVertex) == drawState->getVertexSize()); | 674 SkASSERT(sizeof(AARectVertex) == drawState->getVertexSize()); |
| 675 | 675 |
| 676 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); | 676 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); |
| 677 if (!geo.succeeded()) { | 677 if (!geo.succeeded()) { |
| 678 GrPrintf("Failed to get space for vertices!\n"); | 678 GrPrintf("Failed to get space for vertices!\n"); |
| 679 return; | 679 return; |
| 680 } | 680 } |
| 681 | 681 |
| 682 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices()); | 682 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices()); |
| 683 | 683 |
| 684 GrEffectRef* effect = GrAlignedRectEffect::Create(); | 684 GrEffect* effect = GrAlignedRectEffect::Create(); |
| 685 static const int kOffsetIndex = 1; | 685 static const int kOffsetIndex = 1; |
| 686 drawState->addCoverageEffect(effect, kOffsetIndex)->unref(); | 686 drawState->addCoverageEffect(effect, kOffsetIndex)->unref(); |
| 687 | 687 |
| 688 SkRect devRect; | 688 SkRect devRect; |
| 689 combinedMatrix.mapRect(&devRect, rect); | 689 combinedMatrix.mapRect(&devRect, rect); |
| 690 | 690 |
| 691 SkRect devBounds = { | 691 SkRect devBounds = { |
| 692 devRect.fLeft - SK_ScalarHalf, | 692 devRect.fLeft - SK_ScalarHalf, |
| 693 devRect.fTop - SK_ScalarHalf, | 693 devRect.fTop - SK_ScalarHalf, |
| 694 devRect.fRight + SK_ScalarHalf, | 694 devRect.fRight + SK_ScalarHalf, |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 923 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 924 | 924 |
| 925 if (devInside.isEmpty()) { | 925 if (devInside.isEmpty()) { |
| 926 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); | 926 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); |
| 927 return; | 927 return; |
| 928 } | 928 } |
| 929 | 929 |
| 930 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, | 930 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, |
| 931 devInside, useVertexCoverage, true); | 931 devInside, useVertexCoverage, true); |
| 932 } | 932 } |
| OLD | NEW |