1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkNormalFlatSource.h"
#include "SkArenaAlloc.h"
#include "SkNormalSource.h"
#include "SkNormalSourcePriv.h"
#include "SkPoint3.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
class NormalFlatFP : public GrFragmentProcessor {
public:
NormalFlatFP() : INHERITED(kConstantOutputForConstantInput_OptimizationFlag) {
this->initClassID<NormalFlatFP>();
}
class GLSLNormalFlatFP : public GLSLNormalFP {
public:
GLSLNormalFlatFP() {}
void onEmitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor);
}
static void GenKey(const GrProcessor& proc, const GrShaderCaps&, GrProcessorKeyBuilder* b) {
b->add32(0x0);
}
protected:
void setNormalData(const GrGLSLProgramDataManager& pdman,
const GrProcessor& proc) override {}
};
const char* name() const override { return "NormalFlatFP"; }
private:
void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
GLSLNormalFlatFP::GenKey(*this, caps, b);
}
GrColor4f constantOutputForConstantInput(GrColor4f) const override {
return GrColor4f(0, 0, 1, 0);
}
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLNormalFlatFP; }
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
typedef GrFragmentProcessor INHERITED;
};
sk_sp<GrFragmentProcessor> SkNormalFlatSourceImpl::asFragmentProcessor(
const SkShader::AsFPArgs&) const {
return sk_make_sp<NormalFlatFP>();
}
#endif // SK_SUPPORT_GPU
////////////////////////////////////////////////////////////////////////////
SkNormalFlatSourceImpl::Provider::Provider() {}
SkNormalFlatSourceImpl::Provider::~Provider() {}
SkNormalSource::Provider* SkNormalFlatSourceImpl::asProvider(const SkShader::ContextRec &rec,
SkArenaAlloc *alloc) const {
return alloc->make<Provider>();
}
void SkNormalFlatSourceImpl::Provider::fillScanLine(int x, int y, SkPoint3 output[],
int count) const {
for (int i = 0; i < count; i++) {
output[i] = {0.0f, 0.0f, 1.0f};
}
}
////////////////////////////////////////////////////////////////////////////////
sk_sp<SkFlattenable> SkNormalFlatSourceImpl::CreateProc(SkReadBuffer& buf) {
return sk_make_sp<SkNormalFlatSourceImpl>();
}
void SkNormalFlatSourceImpl::flatten(SkWriteBuffer& buf) const {
this->INHERITED::flatten(buf);
}
////////////////////////////////////////////////////////////////////////////
sk_sp<SkNormalSource> SkNormalSource::MakeFlat() {
return sk_make_sp<SkNormalFlatSourceImpl>();
}
|