Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: src/core/SkLinearBitmapPipeline.h

Issue 1704583003: Simplified linear pipeline. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix unaligned size problem. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
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 #ifndef SkLinearBitmapPipeline_DEFINED
9 #define SkLinearBitmapPipeline_DEFINED
10
11 #include <algorithm>
12 #include <cmath>
13 #include <limits>
14 #include <cstdio>
15 #include "SkColor.h"
16 #include "SkImageInfo.h"
17 #include "SkMatrix.h"
18 #include "SkShader.h"
19 #include "SkSize.h"
20 #include "SkNx.h"
21
22 using Sk4fArg = const Sk4f&;
23
24 class PointProcessorInterface {
25 public:
26 virtual ~PointProcessorInterface() { }
27 virtual void pointListFew(int n, Sk4fArg xs, Sk4fArg ys) = 0;
28 virtual void pointList4(Sk4fArg xs, Sk4fArg ys) = 0;
29 };
30
31 class PixelPlacerInterface {
32 public:
33 virtual ~PixelPlacerInterface() { }
34 virtual void setDestination(SkPM4f* dst) = 0;
35 virtual void placePixel(Sk4fArg pixel0) = 0;
36 virtual void place4Pixels(Sk4fArg p0, Sk4fArg p1, Sk4fArg p2, Sk4fArg p3) = 0;
37 };
38
39 class SkLinearBitmapPipeline {
40 public:
41 SkLinearBitmapPipeline(
42 const SkMatrix& inverse,
43 SkShader::TileMode xTile, SkShader::TileMode yTile,
44 const SkImageInfo& srcImageInfo,
45 const void* srcImageData);
46
47 void shadeSpan4f(int x, int y, SkPM4f* dst, int count);
48
49 template<typename Base, size_t kSize>
50 class PolymorphicUnion {
51 public:
52 PolymorphicUnion() {}
53
54 ~PolymorphicUnion() { get()->~Base(); }
55
56 template<typename Variant, typename... Args>
57 void Initialize(Args&&... args) {
58 SkASSERTF(sizeof(Variant) <= sizeof(fSpace),
59 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp ace));
60
61 new(&fSpace) Variant(std::forward<Args>(args)...);
62 };
63
64 Base* get() const { return reinterpret_cast<Base*>(&fSpace); }
65 Base* operator->() const { return get(); }
66 Base& operator*() const { return *get(); }
67
68 private:
69 struct SK_STRUCT_ALIGN(16) Space {
70 char space[kSize];
71 };
72 mutable Space fSpace;
73 };
74
75 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>;
76 using TileStage = PolymorphicUnion<PointProcessorInterface, 96>;
77 using SampleStage = PolymorphicUnion<PointProcessorInterface, 80>;
78 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>;
79
80 private:
81 PointProcessorInterface* fFirstStage;
82 MatrixStage fMatrixStage;
83 TileStage fTileXOrBothStage;
84 TileStage fTileYStage;
85 SampleStage fSampleStage;
86 PixelStage fPixelStage;
87 };
88
89 #endif // SkLinearBitmapPipeline_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698