15970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org/*
25970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org * Copyright 2014 Google Inc.
35970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org *
45970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
55970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org * found in the LICENSE file.
65970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org */
75970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org
85970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org#ifndef SkLocalMatrixShader_DEFINED
95970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org#define SkLocalMatrixShader_DEFINED
105970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org
115970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org#include "SkShader.h"
125970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org#include "SkReadBuffer.h"
135970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org#include "SkWriteBuffer.h"
145970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org
155970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.orgclass SkLocalMatrixShader : public SkShader {
165970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.orgpublic:
175970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix)
183e629e16548e45750fcad5e7a28bbf6dfc8571efLeon Scroggins III    : INHERITED(&localMatrix)
193e629e16548e45750fcad5e7a28bbf6dfc8571efLeon Scroggins III    , fProxyShader(SkRef(proxy))
205970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    {}
21e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
225970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    virtual size_t contextSize() const SK_OVERRIDE {
235970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        return fProxyShader->contextSize();
245970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    }
25e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
265970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix,
275970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org                                 TileMode* mode) const SK_OVERRIDE {
285970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        return fProxyShader->asABitmap(bitmap, matrix, mode);
295970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    }
30e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
315970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE {
325970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        return fProxyShader->asAGradient(info);
335970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    }
34e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
359de5b514d38c5b36066bcdc14fba2f7e5196d372dandov#if SK_SUPPORT_GPU
369de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
379de5b514d38c5b36066bcdc14fba2f7e5196d372dandov    virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix,
389de5b514d38c5b36066bcdc14fba2f7e5196d372dandov                             GrColor* grColor, GrEffectRef** grEffect) const SK_OVERRIDE {
393e629e16548e45750fcad5e7a28bbf6dfc8571efLeon Scroggins III        SkMatrix tmp = this->getLocalMatrix();
405970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        if (localMatrix) {
415970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org            tmp.preConcat(*localMatrix);
425970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        }
439de5b514d38c5b36066bcdc14fba2f7e5196d372dandov        return fProxyShader->asNewEffect(context, paint, &tmp, grColor, grEffect);
445970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    }
459de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
469de5b514d38c5b36066bcdc14fba2f7e5196d372dandov#else
479de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
489de5b514d38c5b36066bcdc14fba2f7e5196d372dandov    virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix,
499de5b514d38c5b36066bcdc14fba2f7e5196d372dandov                             GrColor* grColor, GrEffectRef** grEffect) const SK_OVERRIDE {
509de5b514d38c5b36066bcdc14fba2f7e5196d372dandov        SkDEBUGFAIL("Should not call in GPU-less build");
519de5b514d38c5b36066bcdc14fba2f7e5196d372dandov        return false;
529de5b514d38c5b36066bcdc14fba2f7e5196d372dandov    }
539de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
549de5b514d38c5b36066bcdc14fba2f7e5196d372dandov#endif
559de5b514d38c5b36066bcdc14fba2f7e5196d372dandov
565970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OVERRIDE {
575970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        if (localMatrix) {
583e629e16548e45750fcad5e7a28bbf6dfc8571efLeon Scroggins III            *localMatrix = this->getLocalMatrix();
595970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        }
605970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org        return SkRef(fProxyShader.get());
615970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    }
62e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
635970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    SK_TO_STRING_OVERRIDE()
645970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader)
65e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
665970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.orgprotected:
675970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    SkLocalMatrixShader(SkReadBuffer&);
685970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
695970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE;
70e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
715970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.orgprivate:
725970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    SkAutoTUnref<SkShader> fProxyShader;
73e92c68f7d7398e8a510b7157a38747b23cb883aeskia.committer@gmail.com
745970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org    typedef SkShader INHERITED;
755970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org};
765970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org
775970f625e96cdc007c563ae72f343ae0d71719a1commit-bot@chromium.org#endif
78