1 | /* |
2 | * Copyright 2013 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #include "include/core/SkString.h" |
9 | #include "include/effects/SkLumaColorFilter.h" |
10 | #include "include/private/SkColorData.h" |
11 | #include "src/core/SkEffectPriv.h" |
12 | #include "src/core/SkRasterPipeline.h" |
13 | #include "src/core/SkVM.h" |
14 | |
15 | #if SK_SUPPORT_GPU |
16 | #include "include/gpu/GrContext.h" |
17 | #include "src/gpu/effects/generated/GrLumaColorFilterEffect.h" |
18 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
19 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
20 | #endif |
21 | |
22 | bool SkLumaColorFilter::onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const { |
23 | rec.fPipeline->append(SkRasterPipeline::bt709_luminance_or_luma_to_alpha); |
24 | rec.fPipeline->append(SkRasterPipeline::clamp_0); |
25 | rec.fPipeline->append(SkRasterPipeline::clamp_1); |
26 | return true; |
27 | } |
28 | |
29 | skvm::Color SkLumaColorFilter::onProgram(skvm::Builder* p, skvm::Color c, |
30 | SkColorSpace* dstCS, |
31 | skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const { |
32 | return { |
33 | p->splat(0.0f), |
34 | p->splat(0.0f), |
35 | p->splat(0.0f), |
36 | clamp01(c.r * 0.2126f + c.g * 0.7152f + c.b * 0.0722f), |
37 | }; |
38 | } |
39 | |
40 | sk_sp<SkColorFilter> SkLumaColorFilter::Make() { |
41 | return sk_sp<SkColorFilter>(new SkLumaColorFilter); |
42 | } |
43 | |
44 | SkLumaColorFilter::SkLumaColorFilter() : INHERITED() {} |
45 | |
46 | sk_sp<SkFlattenable> SkLumaColorFilter::CreateProc(SkReadBuffer&) { |
47 | return Make(); |
48 | } |
49 | |
50 | void SkLumaColorFilter::flatten(SkWriteBuffer&) const {} |
51 | |
52 | #if SK_SUPPORT_GPU |
53 | std::unique_ptr<GrFragmentProcessor> SkLumaColorFilter::asFragmentProcessor( |
54 | GrRecordingContext*, const GrColorInfo&) const { |
55 | return GrLumaColorFilterEffect::Make(); |
56 | } |
57 | #endif |
58 | |