Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 class PointProcessorInterface { | |
| 23 public: | |
| 24 virtual ~PointProcessorInterface() { } | |
| 25 virtual void pointListFew(int n, Sk4f x, Sk4f y) = 0; | |
| 26 virtual void pointList4(Sk4f Xs, Sk4f Ys) = 0; | |
| 27 }; | |
| 28 | |
| 29 class PixelPlacerInterface { | |
| 30 public: | |
| 31 virtual ~PixelPlacerInterface() { } | |
| 32 virtual void setDestination(SkPM4f* dst) = 0; | |
| 33 virtual void placePixel(Sk4f pixel0) = 0; | |
| 34 virtual void place4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) = 0; | |
| 35 }; | |
| 36 | |
| 37 template<typename Base, size_t kSize = 80> | |
|
mtklein
2016/02/16 21:13:10
Seems clearer without a default.
herb_g
2016/02/16 22:04:25
Done.
| |
| 38 class PolymorphicUnion { | |
| 39 public: | |
| 40 PolymorphicUnion() {} | |
| 41 | |
| 42 ~PolymorphicUnion() { get()->~Base(); } | |
| 43 | |
| 44 template<typename Variant, typename... Args> | |
| 45 void Initialize(Args&&... args) { | |
| 46 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), | |
| 47 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSpace) ); | |
| 48 #if defined(_MSC_VER) && _MSC_VER < 1900 | |
| 49 #define alignof __alignof | |
| 50 #endif | |
| 51 SkASSERT(alignof(Variant) <= alignof(Space)); | |
| 52 new(&fSpace) Variant(std::forward<Args>(args)...); | |
| 53 }; | |
| 54 | |
| 55 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } | |
| 56 Base* operator->() const { return get(); } | |
| 57 Base& operator*() const { return *get(); } | |
| 58 | |
| 59 private: | |
| 60 using Space = typename std::aligned_union<kSize, Base, Sk4f>::type; | |
| 61 mutable Space fSpace; | |
| 62 }; | |
| 63 | |
| 64 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>; | |
|
mtklein
2016/02/16 21:13:10
Move inside SKLinearBitmapPipeline?
herb_g
2016/02/16 22:04:25
Done.
| |
| 65 using TileStage = PolymorphicUnion<PointProcessorInterface, 96>; | |
| 66 using SampleStage = PolymorphicUnion<PointProcessorInterface>; | |
| 67 using PixelStage = PolymorphicUnion<PixelPlacerInterface>; | |
| 68 | |
| 69 class SkLinearBitmapPipeline { | |
| 70 public: | |
| 71 SkLinearBitmapPipeline( | |
| 72 const SkMatrix& inverse, | |
| 73 SkShader::TileMode xTile, SkShader::TileMode yTile, | |
| 74 const SkImageInfo& srcImageInfo, | |
| 75 const void* srcImageData); | |
| 76 | |
| 77 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); | |
| 78 | |
| 79 private: | |
| 80 PointProcessorInterface* fFirstStage; | |
| 81 MatrixStage fMatrixStage; | |
| 82 TileStage fTileXOrBothStage; | |
| 83 TileStage fTileYStage; | |
| 84 SampleStage fSampleStage; | |
| 85 PixelStage fPixelStage; | |
| 86 }; | |
| 87 | |
| 88 #endif // SkLinearBitmapPipeline_DEFINED | |
| OLD | NEW |