blob: 37aa81332b30075c0cf439e6e22ee2ef1b9e1abd [file] [log] [blame]
Matt Sarett030cbd52016-11-22 15:48:50 -05001/*
2 * Copyright 2016 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 "SkColorFilter.h"
Florin Malitab391f122017-05-30 13:28:06 -04009#include "SkFlattenable.h"
Matt Sarett030cbd52016-11-22 15:48:50 -050010
11#ifndef SkOverdrawColorFilter_DEFINED
12#define SkOverdrawColorFilter_DEFINED
13
14/**
15 * Uses the value in the src alpha channel to set the dst pixel.
16 * 0 -> fColors[0]
17 * 1 -> fColors[1]
18 * ...
19 * 5 (or larger) -> fColors[5]
20 *
21 */
Sadrul Habib Chowdhury4189d1b2017-08-18 10:20:02 -040022class SK_API SkOverdrawColorFilter : public SkColorFilter {
Matt Sarett030cbd52016-11-22 15:48:50 -050023public:
24 static constexpr int kNumColors = 6;
25
26 static sk_sp<SkOverdrawColorFilter> Make(const SkPMColor colors[kNumColors]) {
27 return sk_sp<SkOverdrawColorFilter>(new SkOverdrawColorFilter(colors));
28 }
29
30#if SK_SUPPORT_GPU
Brian Salomon4cbb6e62017-10-25 15:12:19 -040031 std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(
32 GrContext*, const GrColorSpaceInfo&) const override;
Matt Sarett030cbd52016-11-22 15:48:50 -050033#endif
34
Matt Sarett030cbd52016-11-22 15:48:50 -050035 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer& buffer);
36 Factory getFactory() const override { return CreateProc; }
Cary Clark4dc5a452018-05-21 11:56:57 -040037 static void InitializeFlattenables();
Matt Sarett030cbd52016-11-22 15:48:50 -050038
39protected:
40 void flatten(SkWriteBuffer& buffer) const override;
41
42private:
43 SkOverdrawColorFilter(const SkPMColor colors[kNumColors]) {
44 memcpy(fColors, colors, kNumColors * sizeof(SkPMColor));
45 }
46
Mike Kleinc6912f72017-05-31 16:27:14 -040047 void onAppendStages(SkRasterPipeline*, SkColorSpace*, SkArenaAlloc*, bool) const override;
Mike Reed25f38052017-05-31 15:03:02 -040048
Matt Sarett030cbd52016-11-22 15:48:50 -050049 SkPMColor fColors[kNumColors];
50
51 typedef SkColorFilter INHERITED;
52};
53
54#endif // SkOverdrawColorFilter_DEFINED