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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageDecodingStore.h

Issue 2787053004: Respect colorSpace in DecodingImageGenerator::onGetPixels() (Closed)
Patch Set: Response to comments Created 3 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 (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 ~ImageDecodingStore(); 72 ~ImageDecodingStore();
73 73
74 static ImageDecodingStore& instance(); 74 static ImageDecodingStore& instance();
75 75
76 // Accesses a cached decoder object. A decoder is indexed by origin 76 // Accesses a cached decoder object. A decoder is indexed by origin
77 // (ImageFrameGenerator) and scaled size. Returns true if the cached object is 77 // (ImageFrameGenerator) and scaled size. Returns true if the cached object is
78 // found. 78 // found.
79 bool lockDecoder(const ImageFrameGenerator*, 79 bool lockDecoder(const ImageFrameGenerator*,
80 const SkISize& scaledSize, 80 const SkISize& scaledSize,
81 ImageDecoder::AlphaOption,
81 ImageDecoder**); 82 ImageDecoder**);
82 void unlockDecoder(const ImageFrameGenerator*, const ImageDecoder*); 83 void unlockDecoder(const ImageFrameGenerator*, const ImageDecoder*);
83 void insertDecoder(const ImageFrameGenerator*, std::unique_ptr<ImageDecoder>); 84 void insertDecoder(const ImageFrameGenerator*, std::unique_ptr<ImageDecoder>);
84 void removeDecoder(const ImageFrameGenerator*, const ImageDecoder*); 85 void removeDecoder(const ImageFrameGenerator*, const ImageDecoder*);
85 86
86 // Remove all cache entries indexed by ImageFrameGenerator. 87 // Remove all cache entries indexed by ImageFrameGenerator.
87 void removeCacheIndexedByGenerator(const ImageFrameGenerator*); 88 void removeCacheIndexedByGenerator(const ImageFrameGenerator*);
88 89
89 void clear(); 90 void clear();
90 void setCacheLimitInBytes(size_t); 91 void setCacheLimitInBytes(size_t);
91 size_t memoryUsageInBytes(); 92 size_t memoryUsageInBytes();
92 int cacheEntries(); 93 int cacheEntries();
93 int decoderCacheEntries(); 94 int decoderCacheEntries();
94 95
95 private: 96 private:
96 // Decoder cache entry is identified by: 97 // Decoder cache entry is identified by:
97 // 1. Pointer to ImageFrameGenerator. 98 // 1. Pointer to ImageFrameGenerator.
98 // 2. Size of the image. 99 // 2. Size of the image.
99 typedef std::pair<const ImageFrameGenerator*, SkISize> DecoderCacheKey; 100 // 3. Decoder alpha option
101 typedef std::pair<const ImageFrameGenerator*, std::pair<SkISize, uint32_t>>
scroggo_chromium 2017/04/07 18:06:06 Why not make this a tuple? (And why do you convert
msarett1 2017/04/10 14:42:45 I'm trying to make use of the existing hash functi
scroggo_chromium 2017/04/10 17:31:23 sgtm
102 DecoderCacheKey;
100 103
101 // Base class for all cache entries. 104 // Base class for all cache entries.
102 class CacheEntry : public DoublyLinkedListNode<CacheEntry> { 105 class CacheEntry : public DoublyLinkedListNode<CacheEntry> {
103 USING_FAST_MALLOC(CacheEntry); 106 USING_FAST_MALLOC(CacheEntry);
104 WTF_MAKE_NONCOPYABLE(CacheEntry); 107 WTF_MAKE_NONCOPYABLE(CacheEntry);
105 friend class WTF::DoublyLinkedListNode<CacheEntry>; 108 friend class WTF::DoublyLinkedListNode<CacheEntry>;
106 109
107 public: 110 public:
108 enum CacheType { 111 enum CacheType {
109 TypeDecoder, 112 TypeDecoder,
(...skipping 24 matching lines...) Expand all
134 private: 137 private:
135 CacheEntry* m_prev; 138 CacheEntry* m_prev;
136 CacheEntry* m_next; 139 CacheEntry* m_next;
137 }; 140 };
138 141
139 class DecoderCacheEntry final : public CacheEntry { 142 class DecoderCacheEntry final : public CacheEntry {
140 public: 143 public:
141 static std::unique_ptr<DecoderCacheEntry> create( 144 static std::unique_ptr<DecoderCacheEntry> create(
142 const ImageFrameGenerator* generator, 145 const ImageFrameGenerator* generator,
143 std::unique_ptr<ImageDecoder> decoder) { 146 std::unique_ptr<ImageDecoder> decoder) {
147 ImageDecoder::AlphaOption alphaOption = decoder->alphaOption();
144 return WTF::wrapUnique( 148 return WTF::wrapUnique(
145 new DecoderCacheEntry(generator, 0, std::move(decoder))); 149 new DecoderCacheEntry(generator, 0, std::move(decoder), alphaOption));
146 } 150 }
147 151
148 DecoderCacheEntry(const ImageFrameGenerator* generator, 152 DecoderCacheEntry(const ImageFrameGenerator* generator,
149 int count, 153 int count,
150 std::unique_ptr<ImageDecoder> decoder) 154 std::unique_ptr<ImageDecoder> decoder,
155 ImageDecoder::AlphaOption alphaOption)
151 : CacheEntry(generator, count), 156 : CacheEntry(generator, count),
152 m_cachedDecoder(std::move(decoder)), 157 m_cachedDecoder(std::move(decoder)),
153 m_size(SkISize::Make(m_cachedDecoder->decodedSize().width(), 158 m_size(SkISize::Make(m_cachedDecoder->decodedSize().width(),
154 m_cachedDecoder->decodedSize().height())) {} 159 m_cachedDecoder->decodedSize().height())),
160 m_alphaOption(alphaOption) {}
scroggo_chromium 2017/04/07 18:06:06 Can you move the call to decoder->alphaOption() he
msarett1 2017/04/10 14:42:45 |decoder| is deleted by std::move(), so we would e
scroggo_chromium 2017/04/10 17:31:23 We already call m_cachedDecoder->decodedSize() - d
155 161
156 size_t memoryUsageInBytes() const override { 162 size_t memoryUsageInBytes() const override {
157 return m_size.width() * m_size.height() * 4; 163 return m_size.width() * m_size.height() * 4;
158 } 164 }
159 CacheType type() const override { return TypeDecoder; } 165 CacheType type() const override { return TypeDecoder; }
160 166
161 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator, 167 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator,
162 const SkISize& size) { 168 const SkISize& size,
163 return std::make_pair(generator, size); 169 ImageDecoder::AlphaOption alphaOption) {
170 return std::make_pair(generator,
171 std::make_pair(size, (uint32_t)alphaOption));
164 } 172 }
165 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator, 173 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator,
166 const ImageDecoder* decoder) { 174 const ImageDecoder* decoder) {
167 return std::make_pair(generator, 175 return makeCacheKey(generator,
168 SkISize::Make(decoder->decodedSize().width(), 176 SkISize::Make(decoder->decodedSize().width(),
169 decoder->decodedSize().height())); 177 decoder->decodedSize().height()),
178 decoder->alphaOption());
170 } 179 }
171 DecoderCacheKey cacheKey() const { 180 DecoderCacheKey cacheKey() const {
172 return makeCacheKey(m_generator, m_size); 181 return makeCacheKey(m_generator, m_size, m_alphaOption);
173 } 182 }
174 ImageDecoder* cachedDecoder() const { return m_cachedDecoder.get(); } 183 ImageDecoder* cachedDecoder() const { return m_cachedDecoder.get(); }
175 184
176 private: 185 private:
177 std::unique_ptr<ImageDecoder> m_cachedDecoder; 186 std::unique_ptr<ImageDecoder> m_cachedDecoder;
178 SkISize m_size; 187 SkISize m_size;
188 ImageDecoder::AlphaOption m_alphaOption;
179 }; 189 };
180 190
181 ImageDecodingStore(); 191 ImageDecodingStore();
182 192
183 void prune(); 193 void prune();
184 194
185 // These helper methods are called while m_mutex is locked. 195 // These helper methods are called while m_mutex is locked.
186 template <class T, class U, class V> 196 template <class T, class U, class V>
187 void insertCacheInternal(std::unique_ptr<T> cacheEntry, 197 void insertCacheInternal(std::unique_ptr<T> cacheEntry,
188 U* cacheMap, 198 U* cacheMap,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // m_heapLimitInBytes 256 // m_heapLimitInBytes
247 // m_heapMemoryUsageInBytes 257 // m_heapMemoryUsageInBytes
248 // This mutex also protects calls to underlying skBitmap's 258 // This mutex also protects calls to underlying skBitmap's
249 // lockPixels()/unlockPixels() as they are not threadsafe. 259 // lockPixels()/unlockPixels() as they are not threadsafe.
250 Mutex m_mutex; 260 Mutex m_mutex;
251 }; 261 };
252 262
253 } // namespace blink 263 } // namespace blink
254 264
255 #endif 265 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698