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

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

Issue 1723683002: Better encapsulation and vector calling convention. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make inlines VECTORCALL. 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
« no previous file with comments | « no previous file | src/core/SkLinearBitmapPipeline.cpp » ('j') | src/core/SkLinearBitmapPipeline.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkLinearBitmapPipeline_DEFINED 8 #ifndef SkLinearBitmapPipeline_DEFINED
9 #define SkLinearBitmapPipeline_DEFINED 9 #define SkLinearBitmapPipeline_DEFINED
10 10
11 11
12 #include "SkColor.h" 12 #include "SkColor.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 #include "SkMatrix.h" 14 #include "SkMatrix.h"
15 #include "SkNx.h" 15 #include "SkNx.h"
16 #include "SkShader.h" 16 #include "SkShader.h"
17 17
18 using Sk4fArg = const Sk4f&;
19
20 class PointProcessorInterface {
21 public:
22 virtual ~PointProcessorInterface() { }
23 virtual void pointListFew(int n, Sk4fArg xs, Sk4fArg ys) = 0;
24 virtual void pointList4(Sk4fArg xs, Sk4fArg ys) = 0;
25
26 // The pointSpan method efficiently process horizontal spans of pixels.
27 // * start - the point where to start the span.
28 // * length - the number of pixels to traverse in source space.
29 // * count - the number of pixels to produce in destination space.
30 // Both start and length are mapped through the inversion matrix to produce values in source
31 // space. After the matrix operation, the tilers may break the spans up into smaller spans.
32 // The tilers can produce spans that seem nonsensical.
33 // * The clamp tiler can create spans with length of 0. This indicates to co py an edge pixel out
34 // to the edge of the destination scan.
35 // * The mirror tiler can produce spans with negative length. This indicates that the source
36 // should be traversed in the opposite direction to the destination pixels .
37 virtual void pointSpan(SkPoint start, SkScalar length, int count) = 0;
38 };
39
40 class BilerpProcessorInterface : public PointProcessorInterface {
41 public:
42 // The x's and y's are setup in the following order:
43 // +--------+--------+
44 // | | |
45 // | px00 | px10 |
46 // | 0 | 1 |
47 // +--------+--------+
48 // | | |
49 // | px01 | px11 |
50 // | 2 | 3 |
51 // +--------+--------+
52 // These pixels coordinates are arranged in the following order in xs and ys :
53 // px00 px10 px01 px11
54 virtual void bilerpList(Sk4fArg xs, Sk4fArg ys) = 0;
55 };
56
57 class PixelPlacerInterface {
58 public:
59 virtual ~PixelPlacerInterface() { }
60 virtual void setDestination(SkPM4f* dst) = 0;
61 virtual void placePixel(Sk4fArg pixel0) = 0;
62 virtual void place4Pixels(Sk4fArg p0, Sk4fArg p1, Sk4fArg p2, Sk4fArg p3) = 0;
63 };
64
65 class SkLinearBitmapPipeline { 18 class SkLinearBitmapPipeline {
66 public: 19 public:
67 SkLinearBitmapPipeline( 20 SkLinearBitmapPipeline(
68 const SkMatrix& inverse, 21 const SkMatrix& inverse,
69 SkFilterQuality filterQuality, 22 SkFilterQuality filterQuality,
70 SkShader::TileMode xTile, SkShader::TileMode yTile, 23 SkShader::TileMode xTile, SkShader::TileMode yTile,
71 const SkPixmap& srcPixmap); 24 const SkPixmap& srcPixmap);
25 ~SkLinearBitmapPipeline();
72 26
73 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); 27 void shadeSpan4f(int x, int y, SkPM4f* dst, int count);
74 28
75 template<typename Base, size_t kSize> 29 template<typename Base, size_t kSize>
76 class PolymorphicUnion { 30 class PolymorphicUnion {
77 public: 31 public:
78 PolymorphicUnion() {} 32 PolymorphicUnion() {}
79 33
80 ~PolymorphicUnion() { get()->~Base(); } 34 ~PolymorphicUnion() { get()->~Base(); }
81 35
82 template<typename Variant, typename... Args> 36 template<typename Variant, typename... Args>
83 void Initialize(Args&&... args) { 37 void Initialize(Args&&... args) {
84 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), 38 SkASSERTF(sizeof(Variant) <= sizeof(fSpace),
85 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp ace)); 39 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp ace));
86 40
87 new(&fSpace) Variant(std::forward<Args>(args)...); 41 new(&fSpace) Variant(std::forward<Args>(args)...);
88 }; 42 };
89 43
90 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } 44 Base* get() const { return reinterpret_cast<Base*>(&fSpace); }
91 Base* operator->() const { return get(); } 45 Base* operator->() const { return get(); }
92 Base& operator*() const { return *get(); } 46 Base& operator*() const { return *get(); }
93 47
94 private: 48 private:
95 struct SK_STRUCT_ALIGN(16) Space { 49 struct SK_STRUCT_ALIGN(16) Space {
96 char space[kSize]; 50 char space[kSize];
97 }; 51 };
98 mutable Space fSpace; 52 mutable Space fSpace;
99 }; 53 };
100 54
55 class PointProcessorInterface;
56 class BilerpProcessorInterface;
57 class PixelPlacerInterface;
58
101 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>; 59 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>;
102 using FilterStage = PolymorphicUnion<PointProcessorInterface, 8>; 60 using FilterStage = PolymorphicUnion<PointProcessorInterface, 8>;
103 using TileStage = PolymorphicUnion<BilerpProcessorInterface, 96>; 61 using TileStage = PolymorphicUnion<BilerpProcessorInterface, 96>;
104 using SampleStage = PolymorphicUnion<BilerpProcessorInterface, 80>; 62 using SampleStage = PolymorphicUnion<BilerpProcessorInterface, 80>;
105 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>; 63 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>;
106 64
107 private: 65 private:
108 PointProcessorInterface* fFirstStage; 66 PointProcessorInterface* fFirstStage;
109 MatrixStage fMatrixStage; 67 MatrixStage fMatrixStage;
110 FilterStage fFilterStage; 68 FilterStage fFilterStage;
111 TileStage fTileXOrBothStage; 69 TileStage fTileXOrBothStage;
112 TileStage fTileYStage; 70 TileStage fTileYStage;
113 SampleStage fSampleStage; 71 SampleStage fSampleStage;
114 PixelStage fPixelStage; 72 PixelStage fPixelStage;
115 }; 73 };
116 74
117 #endif // SkLinearBitmapPipeline_DEFINED 75 #endif // SkLinearBitmapPipeline_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkLinearBitmapPipeline.cpp » ('j') | src/core/SkLinearBitmapPipeline.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698