1589708bf7c706348b763e8277004cb160b202bdbrileya@google.com/* 2589708bf7c706348b763e8277004cb160b202bdbrileya@google.com * Copyright 2012 Google Inc. 3589708bf7c706348b763e8277004cb160b202bdbrileya@google.com * 4589708bf7c706348b763e8277004cb160b202bdbrileya@google.com * Use of this source code is governed by a BSD-style license that can be 5589708bf7c706348b763e8277004cb160b202bdbrileya@google.com * found in the LICENSE file. 6589708bf7c706348b763e8277004cb160b202bdbrileya@google.com */ 7589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 8589708bf7c706348b763e8277004cb160b202bdbrileya@google.com#ifndef SkLinearGradient_DEFINED 9589708bf7c706348b763e8277004cb160b202bdbrileya@google.com#define SkLinearGradient_DEFINED 10589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 11589708bf7c706348b763e8277004cb160b202bdbrileya@google.com#include "SkGradientShaderPriv.h" 12f3182ebc72db2bf2e24119d5cea05f270473a491reed#include "SkNx.h" 13f3182ebc72db2bf2e24119d5cea05f270473a491reed 14f3182ebc72db2bf2e24119d5cea05f270473a491reedstruct Sk4fStorage { 15f3182ebc72db2bf2e24119d5cea05f270473a491reed float fArray[4]; 16f3182ebc72db2bf2e24119d5cea05f270473a491reed 17f3182ebc72db2bf2e24119d5cea05f270473a491reed operator Sk4f() const { 18f3182ebc72db2bf2e24119d5cea05f270473a491reed return Sk4f::Load(fArray); 19f3182ebc72db2bf2e24119d5cea05f270473a491reed } 20f3182ebc72db2bf2e24119d5cea05f270473a491reed 21f3182ebc72db2bf2e24119d5cea05f270473a491reed Sk4fStorage& operator=(const Sk4f& src) { 22f3182ebc72db2bf2e24119d5cea05f270473a491reed src.store(fArray); 23f3182ebc72db2bf2e24119d5cea05f270473a491reed return *this; 24f3182ebc72db2bf2e24119d5cea05f270473a491reed } 25f3182ebc72db2bf2e24119d5cea05f270473a491reed}; 26589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 27589708bf7c706348b763e8277004cb160b202bdbrileya@google.comclass SkLinearGradient : public SkGradientShaderBase { 28589708bf7c706348b763e8277004cb160b202bdbrileya@google.compublic: 29bc590c01b00ef79e1e1f30058e7a70a29419f2a9fmalita enum { 30bc590c01b00ef79e1e1f30058e7a70a29419f2a9fmalita // Temp flag for testing the 4f impl. 31bc590c01b00ef79e1e1f30058e7a70a29419f2a9fmalita kForce4fContext_PrivateFlag = 1 << 7, 32bc590c01b00ef79e1e1f30058e7a70a29419f2a9fmalita }; 33bc590c01b00ef79e1e1f30058e7a70a29419f2a9fmalita 34addf2edf3da20f053daa3897cfe2c52d7369a7b1reed SkLinearGradient(const SkPoint pts[2], const Descriptor&); 35589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 3687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org class LinearGradientContext : public SkGradientShaderBase::GradientShaderBaseContext { 3787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org public: 38e901b6de3ef8dea842008a08fc81e92fb1478d61commit-bot@chromium.org LinearGradientContext(const SkLinearGradient&, const ContextRec&); 3987fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 4036352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; 4187fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 42f3182ebc72db2bf2e24119d5cea05f270473a491reed struct Rec { 43f3182ebc72db2bf2e24119d5cea05f270473a491reed Sk4fStorage fColor; 44f3182ebc72db2bf2e24119d5cea05f270473a491reed float fPos; 45f3182ebc72db2bf2e24119d5cea05f270473a491reed float fPosScale; 46f3182ebc72db2bf2e24119d5cea05f270473a491reed }; 4787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org private: 48f3182ebc72db2bf2e24119d5cea05f270473a491reed SkTDArray<Rec> fRecs; 49f3182ebc72db2bf2e24119d5cea05f270473a491reed bool fApplyAlphaAfterInterp; 50f3182ebc72db2bf2e24119d5cea05f270473a491reed 51f3182ebc72db2bf2e24119d5cea05f270473a491reed void shade4_clamp(int x, int y, SkPMColor dstC[], int count); 52f3182ebc72db2bf2e24119d5cea05f270473a491reed template <bool, bool> void shade4_dx_clamp(SkPMColor dstC[], int count, float fx, float dx, 53f3182ebc72db2bf2e24119d5cea05f270473a491reed float invDx, const float dither[2]); 54f3182ebc72db2bf2e24119d5cea05f270473a491reed 5587fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED; 5687fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org }; 5787fcd950198a16211b3988610beebb5ca5bcf323commit-bot@chromium.org 5836352bf5e38f45a70ee4f4fc132a38048d38206dmtklein GradientType asAGradient(GradientInfo* info) const override; 59c21b09eec91c9e263cb0b88467ea44e348ed4962bsalomon#if SK_SUPPORT_GPU 60839345d63466a4209a0985654ec033624821fd78brianosman sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override; 61c21b09eec91c9e263cb0b88467ea44e348ed4962bsalomon#endif 62589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 630f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org SK_TO_STRING_OVERRIDE() 64589708bf7c706348b763e8277004cb160b202bdbrileya@google.com SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient) 65589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 66589708bf7c706348b763e8277004cb160b202bdbrileya@google.comprotected: 678b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org SkLinearGradient(SkReadBuffer& buffer); 6836352bf5e38f45a70ee4f4fc132a38048d38206dmtklein void flatten(SkWriteBuffer& buffer) const override; 6983e939bcb79790f5ae3b28c398fbcf034675a6e5Herb Derby Context* onMakeContext(const ContextRec&, SkArenaAlloc*) const override; 70589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 71c86e470c190934a2f7680ed10cf9fad757e1ab75Florin Malita bool onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, 72882ccafee00a7d8d924258d59606fa878c0d9777Florin Malita const SkMatrix&, const SkPaint&, const SkMatrix*) const override; 73c86e470c190934a2f7680ed10cf9fad757e1ab75Florin Malita 74589708bf7c706348b763e8277004cb160b202bdbrileya@google.comprivate: 75bc590c01b00ef79e1e1f30058e7a70a29419f2a9fmalita class LinearGradient4fContext; 76bc590c01b00ef79e1e1f30058e7a70a29419f2a9fmalita 779fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed friend class SkGradientShader; 78589708bf7c706348b763e8277004cb160b202bdbrileya@google.com typedef SkGradientShaderBase INHERITED; 79589708bf7c706348b763e8277004cb160b202bdbrileya@google.com const SkPoint fStart; 80589708bf7c706348b763e8277004cb160b202bdbrileya@google.com const SkPoint fEnd; 81589708bf7c706348b763e8277004cb160b202bdbrileya@google.com}; 82589708bf7c706348b763e8277004cb160b202bdbrileya@google.com 83589708bf7c706348b763e8277004cb160b202bdbrileya@google.com#endif 84