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

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

Issue 597293002: Fix sub-picture layer rendering bugs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 6 years, 2 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/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"
11 #include "SkDrawPictureCallback.h" 12 #include "SkDrawPictureCallback.h"
13 #include "SkImage.h"
12 #include "SkRect.h" 14 #include "SkRect.h"
13 #include "SkTDArray.h" 15 #include "SkTDynamicHash.h"
14 16
15 class SkBBoxHierarchy; 17 class SkBBoxHierarchy;
16 class SkBitmap; 18 class SkBitmap;
17 class SkCanvas; 19 class SkCanvas;
18 class SkImage; 20 class SkImage;
19 class SkMatrix; 21 class SkMatrix;
20 class SkPaint; 22 class SkPaint;
21 class SkPicture; 23 class SkPicture;
22 class SkRecord; 24 class SkRecord;
23 25
24 // GrReplacements collects op ranges that can be replaced with 26 // GrReplacements collects op ranges that can be replaced with
25 // a single drawBitmap call (using a precomputed bitmap). 27 // a single drawBitmap call (using a precomputed bitmap).
26 class GrReplacements { 28 class GrReplacements {
27 public: 29 public:
28 // All the operations between fStart and fStop (inclusive) will be replaced with 30 // All the operations between fStart and fStop (inclusive) will be replaced with
29 // a single drawBitmap call using fPos, fBM and fPaint. 31 // a single drawBitmap call using fPos, fBM and fPaint.
30 struct ReplacementInfo { 32 class ReplacementInfo {
31 unsigned fStart; 33 public:
34 struct Key {
35 Key(uint32_t pictureID, unsigned int start, const SkMatrix& ctm, boo l foo)
36 : fPictureID(pictureID)
37 , fStart(start)
38 , fCTM(ctm) {
39 fCTM.getType(); // force initialization of type so hashes match
40
41 // Key needs to be tightly packed.
42 GR_STATIC_ASSERT(sizeof(Key) == sizeof(uint32_t) + // pictu re ID
43 sizeof(int) + // start
44 9 * sizeof(SkScalar) // 3x3 f rom CTM
45 +sizeof(uint32_t)); // matri x's type
46 }
47
48 bool operator==(const Key& other) const {
49 return fPictureID == other.fPictureID &&
50 fStart == other.fStart &&
51 fCTM.cheapEqualTo(other.fCTM); // TODO: should be fuzzy
52 }
53
54 uint32_t pictureID() const { return fPictureID; }
55 unsigned int start() const { return fStart; }
56
57 private:
58 uint32_t fPictureID;
59 unsigned int fStart;
60 const SkMatrix fCTM;
61 };
62
63 static const Key& GetKey(const ReplacementInfo& layer) { return layer.fK ey; }
64 static uint32_t Hash(const Key& key) {
65 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
66 }
67
68 ReplacementInfo(uint32_t pictureID, unsigned int start, const SkMatrix& ctm, bool foo)
69 : fKey(pictureID, start, ctm, foo)
70 , fImage(NULL)
71 , fPaint(NULL) {
72 }
73 ~ReplacementInfo() { fImage->unref(); SkDELETE(fPaint); }
74
75 unsigned int start() const { return fKey.start(); }
76
77 const Key fKey;
32 unsigned fStop; 78 unsigned fStop;
33 SkIPoint fPos; 79 SkIPoint fPos;
34 SkImage* fImage; // Owns a ref 80 SkImage* fImage; // Owns a ref
35 const SkPaint* fPaint; // Owned by this object 81 const SkPaint* fPaint; // Owned by this object
36 82
37 SkIRect fSrcRect; 83 SkIRect fSrcRect;
38 }; 84 };
39 85
40 ~GrReplacements() { this->freeAll(); } 86 ~GrReplacements() { this->freeAll(); }
41 87
42 // Add a new replacement range. The replacement ranges should be 88 // Add a new replacement range.
43 // sorted in increasing order and non-overlapping (esp. no nested 89 ReplacementInfo* newReplacement(uint32_t pictureID, unsigned int start, cons t SkMatrix& ctm);
44 // saveLayers).
45 ReplacementInfo* push();
46 90
47 // look up a replacement range by its start offset. 91 // look up a replacement range by its start offset.
48 // lastLookedUp is an in/out parameter that is used to speed up the search. 92 // TODO: also need to add clip to lookup
49 // It should be initialized to 0 on the first call and then passed back in 93 const ReplacementInfo* lookupByStart(uint32_t pictureID, size_t start, const SkMatrix& ctm) const;
50 // unmodified on subsequent calls.
51 const ReplacementInfo* lookupByStart(size_t start, int* lastLookedUp) const;
52 94
53 private: 95 private:
54 SkTDArray<ReplacementInfo> fReplacements; 96 SkTDynamicHash<ReplacementInfo, ReplacementInfo::Key> fReplacementHash;
55 97
56 void freeAll(); 98 void freeAll();
57
58 #ifdef SK_DEBUG
59 void validate() const;
60 #endif
61 }; 99 };
62 100
63 // Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with 101 // Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with
64 // drawBitmap calls. A convenience wrapper around SkRecords::Draw. 102 // drawBitmap calls. A convenience wrapper around SkRecords::Draw.
65 void GrRecordReplaceDraw(const SkPicture*, 103 void GrRecordReplaceDraw(const SkPicture*,
66 SkCanvas*, 104 SkCanvas*,
67 const GrReplacements*, 105 const GrReplacements*,
68 const SkMatrix&, 106 const SkMatrix& initialMatrix,
69 SkDrawPictureCallback*); 107 SkDrawPictureCallback*);
70 108
71 #endif // GrRecordReplaceDraw_DEFINED 109 #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