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

Side by Side Diff: src/gpu/GrWindowRectangles.h

Issue 2312173002: Revert of Improve usage of window rectangles (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_drawsinreducedclip
Patch Set: Created 4 years, 3 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 | « src/gpu/GrScissorState.h ('k') | src/gpu/GrWindowRectsState.h » ('j') | no next file with comments »
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 GrWindowRectangles_DEFINED 8 #ifndef GrWindowRectangles_DEFINED
9 #define GrWindowRectangles_DEFINED 9 #define GrWindowRectangles_DEFINED
10 10
11 #include "GrNonAtomicRef.h" 11 #include "GrNonAtomicRef.h"
12 #include "SkRect.h" 12 #include "SkRect.h"
13 13
14 class GrWindowRectangles { 14 class GrWindowRectangles {
15 public: 15 public:
16 constexpr static int kMaxWindows = 8; 16 constexpr static int kMaxWindows = 8;
17 17
18 GrWindowRectangles() : fCount(0) {} 18 enum class Mode : bool {
19 kExclusive,
20 kInclusive
21 };
22
23 GrWindowRectangles(Mode mode = Mode::kExclusive) : fMode(mode), fCount(0) {}
19 GrWindowRectangles(const GrWindowRectangles& that) : fCount(0) { *this = tha t; } 24 GrWindowRectangles(const GrWindowRectangles& that) : fCount(0) { *this = tha t; }
20 ~GrWindowRectangles() { SkSafeUnref(this->rec()); } 25 ~GrWindowRectangles() { SkSafeUnref(this->rec()); }
21 26
22 bool empty() const { return !fCount; } 27 Mode mode() const { return fMode; }
23 int count() const { return fCount; } 28 int count() const { return fCount; }
29 bool disabled() const { return Mode::kExclusive == fMode && !fCount; }
24 const SkIRect* data() const; 30 const SkIRect* data() const;
25 31
26 void reset(); 32 void reset(Mode = Mode::kExclusive);
27 GrWindowRectangles& operator=(const GrWindowRectangles&); 33 GrWindowRectangles& operator=(const GrWindowRectangles&);
28 34
29 SkIRect& addWindow(const SkIRect& window) { return this->addWindow() = windo w; } 35 SkIRect& addWindow(const SkIRect& window) { return this->addWindow() = windo w; }
30 SkIRect& addWindow(); 36 SkIRect& addWindow();
31 37
32 bool operator!=(const GrWindowRectangles& that) const { return !(*this == th at); } 38 bool operator!=(const GrWindowRectangles& that) const { return !(*this == th at); }
33 bool operator==(const GrWindowRectangles&) const; 39 bool operator==(const GrWindowRectangles&) const;
34 40
35 private: 41 private:
36 constexpr static int kNumLocalWindows = 1; 42 constexpr static int kNumLocalWindows = 1;
37 struct Rec; 43 struct Rec;
38 44
39 const Rec* rec() const { return fCount <= kNumLocalWindows ? nullptr : fRec; } 45 const Rec* rec() const { return fCount <= kNumLocalWindows ? nullptr : fRec; }
40 46
41 int fCount; 47 Mode fMode;
48 uint8_t fCount;
42 union { 49 union {
43 SkIRect fLocalWindows[kNumLocalWindows]; // If fCount <= kNumLocalWind ows. 50 SkIRect fLocalWindows[kNumLocalWindows]; // If fCount <= kNumLocalWind ows.
44 Rec* fRec; // If fCount > kNumLocalWindo ws. 51 Rec* fRec; // If fCount > kNumLocalWindo ws.
45 }; 52 };
46 }; 53 };
47 54
48 struct GrWindowRectangles::Rec : public GrNonAtomicRef<Rec> { 55 struct GrWindowRectangles::Rec : public GrNonAtomicRef<Rec> {
49 Rec(const SkIRect* windows, int numWindows) { 56 Rec(const SkIRect* windows, int numWindows) {
50 SkASSERT(numWindows < kMaxWindows); 57 SkASSERT(numWindows < kMaxWindows);
51 memcpy(fData, windows, sizeof(SkIRect) * numWindows); 58 memcpy(fData, windows, sizeof(SkIRect) * numWindows);
52 } 59 }
53 60
54 SkIRect fData[kMaxWindows]; 61 SkIRect fData[kMaxWindows];
55 }; 62 };
56 63
57 inline const SkIRect* GrWindowRectangles::data() const { 64 inline const SkIRect* GrWindowRectangles::data() const {
58 return fCount <= kNumLocalWindows ? fLocalWindows : fRec->fData; 65 return fCount <= kNumLocalWindows ? fLocalWindows : fRec->fData;
59 } 66 }
60 67
61 inline void GrWindowRectangles::reset() { 68 inline void GrWindowRectangles::reset(Mode mode) {
62 SkSafeUnref(this->rec()); 69 SkSafeUnref(this->rec());
70 fMode = mode;
63 fCount = 0; 71 fCount = 0;
64 } 72 }
65 73
66 inline GrWindowRectangles& GrWindowRectangles::operator=(const GrWindowRectangle s& that) { 74 inline GrWindowRectangles& GrWindowRectangles::operator=(const GrWindowRectangle s& that) {
67 SkSafeUnref(this->rec()); 75 SkSafeUnref(this->rec());
76 fMode = that.fMode;
68 fCount = that.fCount; 77 fCount = that.fCount;
69 if (fCount <= kNumLocalWindows) { 78 if (fCount <= kNumLocalWindows) {
70 memcpy(fLocalWindows, that.fLocalWindows, fCount * sizeof(SkIRect)); 79 memcpy(fLocalWindows, that.fLocalWindows, fCount * sizeof(SkIRect));
71 } else { 80 } else {
72 fRec = SkRef(that.fRec); 81 fRec = SkRef(that.fRec);
73 } 82 }
74 return *this; 83 return *this;
75 } 84 }
76 85
77 inline SkIRect& GrWindowRectangles::addWindow() { 86 inline SkIRect& GrWindowRectangles::addWindow() {
78 SkASSERT(fCount < kMaxWindows); 87 SkASSERT(fCount < kMaxWindows);
79 if (fCount < kNumLocalWindows) { 88 if (fCount < kNumLocalWindows) {
80 return fLocalWindows[fCount++]; 89 return fLocalWindows[fCount++];
81 } 90 }
82 if (fCount == kNumLocalWindows) { 91 if (fCount == kNumLocalWindows) {
83 fRec = new Rec(fLocalWindows, kNumLocalWindows); 92 fRec = new Rec(fLocalWindows, kNumLocalWindows);
84 } else if (!fRec->unique()) { // Simple copy-on-write. 93 } else if (!fRec->unique()) { // Simple copy-on-write.
85 fRec->unref(); 94 fRec->unref();
86 fRec = new Rec(fRec->fData, fCount); 95 fRec = new Rec(fRec->fData, fCount);
87 } 96 }
88 return fRec->fData[fCount++]; 97 return fRec->fData[fCount++];
89 } 98 }
90 99
91 inline bool GrWindowRectangles::operator==(const GrWindowRectangles& that) const { 100 inline bool GrWindowRectangles::operator==(const GrWindowRectangles& that) const {
92 if (fCount != that.fCount) { 101 if (fMode != that.fMode || fCount != that.fCount) {
93 return false; 102 return false;
94 } 103 }
95 if (fCount > kNumLocalWindows && fRec == that.fRec) { 104 if (fCount > kNumLocalWindows && fRec == that.fRec) {
96 return true; 105 return true;
97 } 106 }
98 return !fCount || !memcmp(this->data(), that.data(), sizeof(SkIRect) * fCoun t); 107 return !fCount || !memcmp(this->data(), that.data(), sizeof(SkIRect) * fCoun t);
99 } 108 }
100 109
101 #endif 110 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrScissorState.h ('k') | src/gpu/GrWindowRectsState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698