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

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

Issue 2787053004: Respect colorSpace in DecodingImageGenerator::onGetPixels() (Closed)
Patch Set: Moving xform back to image generator 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
scroggo_chromium 2017/04/10 17:31:24 nit: Maybe be explicit that this is AlphaOption?
msarett1 2017/04/10 21:34:26 Done.
101 typedef std::pair<const ImageFrameGenerator*, std::pair<SkISize, uint8_t>>
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 28 matching lines...) Expand all
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) {
144 return WTF::wrapUnique( 147 return WTF::wrapUnique(
145 new DecoderCacheEntry(generator, 0, std::move(decoder))); 148 new DecoderCacheEntry(generator, 0, std::move(decoder)));
146 } 149 }
147 150
148 DecoderCacheEntry(const ImageFrameGenerator* generator,
149 int count,
150 std::unique_ptr<ImageDecoder> decoder)
151 : CacheEntry(generator, count),
152 m_cachedDecoder(std::move(decoder)),
153 m_size(SkISize::Make(m_cachedDecoder->decodedSize().width(),
154 m_cachedDecoder->decodedSize().height())) {}
155
156 size_t memoryUsageInBytes() const override { 151 size_t memoryUsageInBytes() const override {
157 return m_size.width() * m_size.height() * 4; 152 return m_size.width() * m_size.height() * 4;
158 } 153 }
159 CacheType type() const override { return TypeDecoder; } 154 CacheType type() const override { return TypeDecoder; }
160 155
161 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator, 156 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator,
162 const SkISize& size) { 157 const SkISize& size,
163 return std::make_pair(generator, size); 158 ImageDecoder::AlphaOption alphaOption) {
159 return std::make_pair(generator,
160 std::make_pair(size, (uint8_t)alphaOption));
scroggo_chromium 2017/04/10 17:31:24 nit: C++ style cast
msarett1 2017/04/10 21:34:26 Done.
164 } 161 }
165 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator, 162 static DecoderCacheKey makeCacheKey(const ImageFrameGenerator* generator,
166 const ImageDecoder* decoder) { 163 const ImageDecoder* decoder) {
167 return std::make_pair(generator, 164 return makeCacheKey(generator,
168 SkISize::Make(decoder->decodedSize().width(), 165 SkISize::Make(decoder->decodedSize().width(),
169 decoder->decodedSize().height())); 166 decoder->decodedSize().height()),
167 decoder->alphaOption());
170 } 168 }
171 DecoderCacheKey cacheKey() const { 169 DecoderCacheKey cacheKey() const {
172 return makeCacheKey(m_generator, m_size); 170 return makeCacheKey(m_generator, m_size, m_alphaOption);
173 } 171 }
174 ImageDecoder* cachedDecoder() const { return m_cachedDecoder.get(); } 172 ImageDecoder* cachedDecoder() const { return m_cachedDecoder.get(); }
175 173
176 private: 174 private:
175 DecoderCacheEntry(const ImageFrameGenerator* generator,
176 int count,
177 std::unique_ptr<ImageDecoder> decoder)
178 : CacheEntry(generator, count),
179 m_cachedDecoder(std::move(decoder)),
180 m_size(SkISize::Make(m_cachedDecoder->decodedSize().width(),
181 m_cachedDecoder->decodedSize().height())) {
182 m_alphaOption = m_cachedDecoder->alphaOption();
scroggo_chromium 2017/04/10 17:31:24 nit: This could go in the initializer list. (See
msarett1 2017/04/10 21:34:26 Yes of course, you're right. Thanks.
183 }
184
177 std::unique_ptr<ImageDecoder> m_cachedDecoder; 185 std::unique_ptr<ImageDecoder> m_cachedDecoder;
178 SkISize m_size; 186 SkISize m_size;
187 ImageDecoder::AlphaOption m_alphaOption;
179 }; 188 };
180 189
181 ImageDecodingStore(); 190 ImageDecodingStore();
182 191
183 void prune(); 192 void prune();
184 193
185 // These helper methods are called while m_mutex is locked. 194 // These helper methods are called while m_mutex is locked.
186 template <class T, class U, class V> 195 template <class T, class U, class V>
187 void insertCacheInternal(std::unique_ptr<T> cacheEntry, 196 void insertCacheInternal(std::unique_ptr<T> cacheEntry,
188 U* cacheMap, 197 U* cacheMap,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // m_heapLimitInBytes 255 // m_heapLimitInBytes
247 // m_heapMemoryUsageInBytes 256 // m_heapMemoryUsageInBytes
248 // This mutex also protects calls to underlying skBitmap's 257 // This mutex also protects calls to underlying skBitmap's
249 // lockPixels()/unlockPixels() as they are not threadsafe. 258 // lockPixels()/unlockPixels() as they are not threadsafe.
250 Mutex m_mutex; 259 Mutex m_mutex;
251 }; 260 };
252 261
253 } // namespace blink 262 } // namespace blink
254 263
255 #endif 264 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698