Chromium Code Reviews| Index: src/core/SkLinearBitmapPipeline.h |
| diff --git a/src/core/SkLinearBitmapPipeline.h b/src/core/SkLinearBitmapPipeline.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..161c3eb8d0f15b63df021be9266e1df2c46c49a4 |
| --- /dev/null |
| +++ b/src/core/SkLinearBitmapPipeline.h |
| @@ -0,0 +1,88 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SkLinearBitmapPipeline_DEFINED |
| +#define SkLinearBitmapPipeline_DEFINED |
| + |
| +#include <algorithm> |
| +#include <cmath> |
| +#include <limits> |
| +#include <cstdio> |
| +#include "SkColor.h" |
| +#include "SkImageInfo.h" |
| +#include "SkMatrix.h" |
| +#include "SkShader.h" |
| +#include "SkSize.h" |
| +#include "SkNx.h" |
| + |
| +class PointProcessorInterface { |
| +public: |
| + virtual ~PointProcessorInterface() { } |
| + virtual void pointListFew(int n, Sk4f x, Sk4f y) = 0; |
| + virtual void pointList4(Sk4f Xs, Sk4f Ys) = 0; |
| +}; |
| + |
| +class PixelPlacerInterface { |
| +public: |
| + virtual ~PixelPlacerInterface() { } |
| + virtual void setDestination(SkPM4f* dst) = 0; |
| + virtual void placePixel(Sk4f pixel0) = 0; |
| + virtual void place4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) = 0; |
| +}; |
| + |
| +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.
|
| +class PolymorphicUnion { |
| +public: |
| + PolymorphicUnion() {} |
| + |
| + ~PolymorphicUnion() { get()->~Base(); } |
| + |
| + template<typename Variant, typename... Args> |
| + void Initialize(Args&&... args) { |
| + SkASSERTF(sizeof(Variant) <= sizeof(fSpace), |
| + "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSpace)); |
| + #if defined(_MSC_VER) && _MSC_VER < 1900 |
| + #define alignof __alignof |
| + #endif |
| + SkASSERT(alignof(Variant) <= alignof(Space)); |
| + new(&fSpace) Variant(std::forward<Args>(args)...); |
| + }; |
| + |
| + Base* get() const { return reinterpret_cast<Base*>(&fSpace); } |
| + Base* operator->() const { return get(); } |
| + Base& operator*() const { return *get(); } |
| + |
| +private: |
| + using Space = typename std::aligned_union<kSize, Base, Sk4f>::type; |
| + mutable Space fSpace; |
| +}; |
| + |
| +using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>; |
|
mtklein
2016/02/16 21:13:10
Move inside SKLinearBitmapPipeline?
herb_g
2016/02/16 22:04:25
Done.
|
| +using TileStage = PolymorphicUnion<PointProcessorInterface, 96>; |
| +using SampleStage = PolymorphicUnion<PointProcessorInterface>; |
| +using PixelStage = PolymorphicUnion<PixelPlacerInterface>; |
| + |
| +class SkLinearBitmapPipeline { |
| +public: |
| + SkLinearBitmapPipeline( |
| + const SkMatrix& inverse, |
| + SkShader::TileMode xTile, SkShader::TileMode yTile, |
| + const SkImageInfo& srcImageInfo, |
| + const void* srcImageData); |
| + |
| + void shadeSpan4f(int x, int y, SkPM4f* dst, int count); |
| + |
| +private: |
| + PointProcessorInterface* fFirstStage; |
| + MatrixStage fMatrixStage; |
| + TileStage fTileXOrBothStage; |
| + TileStage fTileYStage; |
| + SampleStage fSampleStage; |
| + PixelStage fPixelStage; |
| +}; |
| + |
| +#endif // SkLinearBitmapPipeline_DEFINED |