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

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

Issue 769533004: Fuse GrReplacements and GrLayerCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clang Created 6 years 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/GrLayerHoister.cpp ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('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 2014 Google Inc. 2 * Copyright 2014 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 GrRecordReplaceDraw_DEFINED 8 #ifndef GrRecordReplaceDraw_DEFINED
9 #define GrRecordReplaceDraw_DEFINED 9 #define GrRecordReplaceDraw_DEFINED
10 10
11 #include "SkChecksum.h"
12 #include "SkDrawPictureCallback.h" 11 #include "SkDrawPictureCallback.h"
13 #include "SkImage.h"
14 #include "SkRect.h"
15 #include "SkTDynamicHash.h"
16 12
17 class SkBBoxHierarchy; 13 class GrLayerCache;
18 class SkBitmap;
19 class SkCanvas; 14 class SkCanvas;
20 class SkImage;
21 class SkMatrix; 15 class SkMatrix;
22 class SkPaint;
23 class SkPicture; 16 class SkPicture;
24 class SkRecord;
25
26 // GrReplacements collects op ranges that can be replaced with
27 // a single drawBitmap call (using a precomputed bitmap).
28 class GrReplacements {
29 public:
30 // All the operations between fStart and fStop (inclusive) will be replaced with
31 // a single drawBitmap call using fPos, fImage and fPaint.
32 class ReplacementInfo {
33 public:
34 struct Key {
35 Key(uint32_t pictureID, const SkMatrix& initialMat,
36 const int* key, int keySize, bool copyKey = false)
37 : fKeySize(keySize)
38 , fFreeKey(copyKey) {
39 fIDMatrix.fPictureID = pictureID;
40 fIDMatrix.fInitialMat = initialMat;
41 fIDMatrix.fInitialMat.getType(); // force initialization of type so hashes match
42
43 if (copyKey) {
44 int* tempKey = SkNEW_ARRAY(int, keySize);
45 memcpy(tempKey, key, keySize * sizeof(int));
46 fKey = tempKey;
47 } else {
48 fKey = key;
49 }
50
51 // The pictureID/matrix portion needs to be tightly packed.
52 GR_STATIC_ASSERT(sizeof(IDMatrix) == sizeof(uint32_t)+ // pictureID
53 9 * sizeof(SkScalar)+sizeof(uint32 _t)); // matrix
54 }
55
56 ~Key() {
57 if (fFreeKey) {
58 SkDELETE_ARRAY(fKey);
59 }
60 }
61 bool operator==(const Key& other) const {
62 if (fKeySize != other.fKeySize) {
63 return false;
64 }
65 return fIDMatrix.fPictureID == other.fIDMatrix.fPictureID &&
66 fIDMatrix.fInitialMat.cheapEqualTo(other.fIDMatrix.fIniti alMat) &&
67 !memcmp(fKey, other.fKey, fKeySize * sizeof(int));
68 }
69
70 uint32_t hash() const {
71 uint32_t hash = SkChecksum::Murmur3(reinterpret_cast<const uint3 2_t*>(fKey),
72 fKeySize * sizeof(int));
73 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&fI DMatrix),
74 sizeof(IDMatrix), hash);
75 }
76
77 private:
78 struct IDMatrix {
79 uint32_t fPictureID;
80 SkMatrix fInitialMat;
81 } fIDMatrix;
82
83 const int* fKey;
84 const int fKeySize;
85 const bool fFreeKey;
86 };
87
88 static const Key& GetKey(const ReplacementInfo& layer) { return layer.fK ey; }
89 static uint32_t Hash(const Key& key) { return key.hash(); }
90
91 ReplacementInfo(uint32_t pictureID, const SkMatrix& initialMat,
92 const int* key, int keySize)
93 : fKey(pictureID, initialMat, key, keySize, true)
94 , fImage(NULL)
95 , fPaint(NULL) {
96 }
97 ~ReplacementInfo() { fImage->unref(); SkDELETE(fPaint); }
98
99 const Key fKey;
100 unsigned fStop;
101 SkIPoint fPos;
102 SkImage* fImage; // Owns a ref
103 const SkPaint* fPaint; // Owned by this object
104
105 SkIRect fSrcRect;
106 };
107
108 ~GrReplacements() { this->freeAll(); }
109
110 // Add a new replacement range.
111 ReplacementInfo* newReplacement(uint32_t pictureID, const SkMatrix& initialM at,
112 const int* key, int keySize);
113
114 const ReplacementInfo* lookup(uint32_t pictureID, const SkMatrix& initalMat,
115 const int* key, int keySize) const;
116
117 private:
118 SkTDynamicHash<ReplacementInfo, ReplacementInfo::Key> fReplacementHash;
119
120 void freeAll();
121 };
122 17
123 // Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with 18 // Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with
124 // drawBitmap calls. A convenience wrapper around SkRecords::Draw. 19 // drawBitmap calls. A convenience wrapper around SkRecords::Draw.
125 // It returns the number of saveLayer/restore blocks replaced with drawBitmap ca lls. 20 // It returns the number of saveLayer/restore blocks replaced with drawBitmap ca lls.
126 int GrRecordReplaceDraw(const SkPicture*, 21 int GrRecordReplaceDraw(const SkPicture*,
127 SkCanvas*, 22 SkCanvas*,
128 const GrReplacements*, 23 GrLayerCache* layerCache,
129 const SkMatrix& initialMatrix, 24 const SkMatrix& initialMatrix,
130 SkDrawPictureCallback*); 25 SkDrawPictureCallback*);
131 26
132 #endif // GrRecordReplaceDraw_DEFINED 27 #endif // GrRecordReplaceDraw_DEFINED
OLDNEW
« no previous file with comments | « src/gpu/GrLayerHoister.cpp ('k') | src/gpu/GrRecordReplaceDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698