aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkNormalMapSource.h
diff options
context:
space:
mode:
authorGravatar dvonbeck <dvonbeck@google.com>2016-07-28 08:58:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-28 08:58:19 -0700
commitbba4cfebcabba3aca5c2452d7df1853258bd701c (patch)
treef3675119f7a7437c9fdfb5089f9f31f018095b08 /src/core/SkNormalMapSource.h
parent1c58696112a5d7bf1acbcc337099b0bf5eb80650 (diff)
Added API for Bevel NormalSource.
This CL adds an API for Bevel normal source and a dummy implementation that returns a normal (0, 0, 1) every time. This CL's base is the CL for accepting nullptrs: https://codereview.chromium.org/2132113002 BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2080993002 Review-Url: https://codereview.chromium.org/2080993002
Diffstat (limited to 'src/core/SkNormalMapSource.h')
-rw-r--r--src/core/SkNormalMapSource.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/core/SkNormalMapSource.h b/src/core/SkNormalMapSource.h
new file mode 100644
index 0000000000..5908369fc7
--- /dev/null
+++ b/src/core/SkNormalMapSource.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkNormalMapSource_DEFINED
+#define SkNormalMapSource_DEFINED
+
+#include "SkNormalSource.h"
+
+class SkNormalMapSourceImpl : public SkNormalSource {
+public:
+ SkNormalMapSourceImpl(sk_sp<SkShader> mapShader, const SkMatrix& invCTM)
+ : fMapShader(std::move(mapShader))
+ , fInvCTM(invCTM) {}
+
+#if SK_SUPPORT_GPU
+ sk_sp<GrFragmentProcessor> asFragmentProcessor(const SkShader::AsFPArgs&) const override;
+#endif
+
+ SkNormalSource::Provider* asProvider(const SkShader::ContextRec& rec,
+ void* storage) const override;
+ size_t providerSize(const SkShader::ContextRec& rec) const override;
+
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkNormalMapSourceImpl)
+
+protected:
+ void flatten(SkWriteBuffer& buf) const override;
+
+ bool computeNormTotalInverse(const SkShader::ContextRec& rec, SkMatrix* normTotalInverse) const;
+
+private:
+ class Provider : public SkNormalSource::Provider {
+ public:
+ Provider(const SkNormalMapSourceImpl& source, SkShader::Context* mapContext,
+ SkPaint* overridePaint);
+
+ virtual ~Provider() override;
+
+ void fillScanLine(int x, int y, SkPoint3 output[], int count) const override;
+
+ private:
+ const SkNormalMapSourceImpl& fSource;
+ SkShader::Context* fMapContext;
+
+ SkPaint* fOverridePaint;
+
+ typedef SkNormalSource::Provider INHERITED;
+ };
+
+ sk_sp<SkShader> fMapShader;
+ SkMatrix fInvCTM; // Inverse of the canvas total matrix, used for rotating normals.
+
+ friend class SkNormalSource;
+
+ typedef SkNormalSource INHERITED;
+};
+
+#endif
+