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

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

Issue 1877483002: Add clone to Stage. Rename place to mix and PolymorphicUnion to Stage. Cleanup. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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
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
12 #include "SkColor.h" 11 #include "SkColor.h"
13 #include "SkImageInfo.h" 12 #include "SkImageInfo.h"
14 #include "SkMatrix.h" 13 #include "SkMatrix.h"
15 #include "SkNx.h"
16 #include "SkShader.h" 14 #include "SkShader.h"
17 15
18 class SkLinearBitmapPipeline { 16 class SkLinearBitmapPipeline {
19 public: 17 public:
20 SkLinearBitmapPipeline( 18 SkLinearBitmapPipeline(
21 const SkMatrix& inverse, 19 const SkMatrix& inverse,
22 SkFilterQuality filterQuality, 20 SkFilterQuality filterQuality,
23 SkShader::TileMode xTile, SkShader::TileMode yTile, 21 SkShader::TileMode xTile, SkShader::TileMode yTile,
24 float postAlpha, 22 float postAlpha,
25 const SkPixmap& srcPixmap); 23 const SkPixmap& srcPixmap);
26 ~SkLinearBitmapPipeline(); 24 ~SkLinearBitmapPipeline();
27 25
28 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); 26 void shadeSpan4f(int x, int y, SkPM4f* dst, int count);
29 27
30 template<typename Base, size_t kSize> 28 template<typename Base, size_t kSize, typename Next = void>
31 class PolymorphicUnion { 29 class Stage {
32 public: 30 public:
33 PolymorphicUnion() : fIsInitialized{false} {} 31 Stage() : fIsInitialized{false} {}
34 32 ~Stage();
35 ~PolymorphicUnion() {
36 if (fIsInitialized) {
37 this->get()->~Base();
38 }
39 }
40 33
41 template<typename Variant, typename... Args> 34 template<typename Variant, typename... Args>
42 void Initialize(Args&&... args) { 35 void initStage(Next* next, Args&& ... args);
43 SkASSERTF(sizeof(Variant) <= sizeof(fSpace),
44 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp ace));
45 36
46 new(&fSpace) Variant(std::forward<Args>(args)...); 37 template<typename Variant, typename... Args>
47 fIsInitialized = true; 38 void initSink(Args&& ... args);
48 }; 39
40 template <typename To, typename From>
41 To* getInterface();
42
43 // Note: There is no cloneSinkTo method because to code usually places t he top part of
mtklein 2016/04/08 19:30:29 to -> the ?
herb_g 2016/04/08 19:51:55 Done.
44 // the pipeline on a new sampler.
mtklein 2016/04/08 19:30:29 Copy this stage to `cloneToStage` with `next` as i
herb_g 2016/04/08 19:51:55 Done.
45 Base* cloneStageTo(Next* next, Stage* cloneToStage) const;
49 46
50 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } 47 Base* get() const { return reinterpret_cast<Base*>(&fSpace); }
51 Base* operator->() const { return this->get(); } 48 Base* operator->() const { return this->get(); }
52 Base& operator*() const { return *(this->get()); } 49 Base& operator*() const { return *(this->get()); }
53 50
54 private: 51 private:
52 std::function<void (Next*, void*)> fStageCloner;
55 struct SK_STRUCT_ALIGN(16) Space { 53 struct SK_STRUCT_ALIGN(16) Space {
56 char space[kSize]; 54 char space[kSize];
57 }; 55 };
58 bool fIsInitialized; 56 bool fIsInitialized;
59 mutable Space fSpace; 57 mutable Space fSpace;
60 }; 58 };
61 59
62 class PointProcessorInterface; 60 class PointProcessorInterface;
63 class SampleProcessorInterface; 61 class SampleProcessorInterface;
64 class PixelPlacerInterface; 62 class MixProcessorInterface;
65 class DestinationInterface; 63 class DestinationInterface;
66 64
67 // These values were generated by the assert above in PolymorphicUnion. 65 // These values were generated by the assert above in Stage::init{Sink|Stage }.
68 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 160>; 66 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorInterf ace>;
69 using TileStage = PolymorphicUnion<PointProcessorInterface, 160>; 67 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorInter face>;
70 using SampleStage = PolymorphicUnion<SampleProcessorInterface,100>; 68 using SampleStage = Stage<SampleProcessorInterface, 100, MixProcessorInterfa ce>;
71 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>; 69 using MixStage = Stage<MixProcessorInterface, 80>;
mtklein 2016/04/08 19:30:29 BlendStage or XferStage?
herb_g 2016/04/08 19:51:55 Done.
72 70
73 private: 71 private:
74 PointProcessorInterface* fFirstStage; 72 PointProcessorInterface* fFirstStage;
75 MatrixStage fMatrixStage; 73 MatrixStage fMatrixStage;
76 TileStage fTiler; 74 TileStage fTileStage;
77 SampleStage fSampleStage; 75 SampleStage fSampleStage;
78 PixelStage fPixelStage; 76 MixStage fMixStage;
79 DestinationInterface* fLastStage; 77 DestinationInterface* fLastStage;
80 }; 78 };
81 79
82 #endif // SkLinearBitmapPipeline_DEFINED 80 #endif // SkLinearBitmapPipeline_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698