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

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

Issue 2787053004: Respect colorSpace in DecodingImageGenerator::onGetPixels() (Closed)
Patch Set: AlphaOption 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& scaled_size, 80 const SkISize& scaled_size,
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. ImageDecoder::AlphaOption
101 typedef std::tuple<const ImageFrameGenerator*, SkISize, uint8_t>
102 DecoderCacheKey;
Nico 2017/04/11 15:41:05 Do you have an idea how much this will increase th
msarett1 2017/04/11 20:52:05 I imagine it's very small. I'm just adding a 8 by
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 kTypeDecoder, 112 kTypeDecoder,
(...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
151 size_t MemoryUsageInBytes() const override {
152 return size_.width() * size_.height() * 4;
153 }
154 CacheType GetType() const override { return kTypeDecoder; }
155
156 static DecoderCacheKey MakeCacheKey(
157 const ImageFrameGenerator* generator,
158 const SkISize& size,
159 ImageDecoder::AlphaOption alpha_option) {
160 return std::make_tuple(generator, size,
161 static_cast<uint8_t>(alpha_option));
162 }
163 static DecoderCacheKey MakeCacheKey(const ImageFrameGenerator* generator,
164 const ImageDecoder* decoder) {
165 return MakeCacheKey(generator,
166 SkISize::Make(decoder->DecodedSize().Width(),
167 decoder->DecodedSize().Height()),
168 decoder->GetAlphaOption());
169 }
170 DecoderCacheKey CacheKey() const {
171 return MakeCacheKey(generator_, size_, alpha_option_);
172 }
173 ImageDecoder* CachedDecoder() const { return cached_decoder_.get(); }
174
175 private:
148 DecoderCacheEntry(const ImageFrameGenerator* generator, 176 DecoderCacheEntry(const ImageFrameGenerator* generator,
149 int count, 177 int count,
150 std::unique_ptr<ImageDecoder> decoder) 178 std::unique_ptr<ImageDecoder> decoder)
151 : CacheEntry(generator, count), 179 : CacheEntry(generator, count),
152 cached_decoder_(std::move(decoder)), 180 cached_decoder_(std::move(decoder)),
153 size_(SkISize::Make(cached_decoder_->DecodedSize().Width(), 181 size_(SkISize::Make(cached_decoder_->DecodedSize().Width(),
154 cached_decoder_->DecodedSize().Height())) {} 182 cached_decoder_->DecodedSize().Height())),
183 alpha_option_(cached_decoder_->GetAlphaOption()) {}
155 184
156 size_t MemoryUsageInBytes() const override {
157 return size_.width() * size_.height() * 4;
158 }
159 CacheType GetType() const override { return kTypeDecoder; }
160
161 static DecoderCacheKey MakeCacheKey(const ImageFrameGenerator* generator,
162 const SkISize& size) {
163 return std::make_pair(generator, size);
164 }
165 static DecoderCacheKey MakeCacheKey(const ImageFrameGenerator* generator,
166 const ImageDecoder* decoder) {
167 return std::make_pair(generator,
168 SkISize::Make(decoder->DecodedSize().Width(),
169 decoder->DecodedSize().Height()));
170 }
171 DecoderCacheKey CacheKey() const { return MakeCacheKey(generator_, size_); }
172 ImageDecoder* CachedDecoder() const { return cached_decoder_.get(); }
173
174 private:
175 std::unique_ptr<ImageDecoder> cached_decoder_; 185 std::unique_ptr<ImageDecoder> cached_decoder_;
176 SkISize size_; 186 SkISize size_;
187 ImageDecoder::AlphaOption alpha_option_;
177 }; 188 };
178 189
179 ImageDecodingStore(); 190 ImageDecodingStore();
180 191
181 void Prune(); 192 void Prune();
182 193
183 // These helper methods are called while m_mutex is locked. 194 // These helper methods are called while m_mutex is locked.
184 template <class T, class U, class V> 195 template <class T, class U, class V>
185 void InsertCacheInternal(std::unique_ptr<T> cache_entry, 196 void InsertCacheInternal(std::unique_ptr<T> cache_entry,
186 U* cache_map, 197 U* cache_map,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // m_heapLimitInBytes 255 // m_heapLimitInBytes
245 // m_heapMemoryUsageInBytes 256 // m_heapMemoryUsageInBytes
246 // This mutex also protects calls to underlying skBitmap's 257 // This mutex also protects calls to underlying skBitmap's
247 // lockPixels()/unlockPixels() as they are not threadsafe. 258 // lockPixels()/unlockPixels() as they are not threadsafe.
248 Mutex mutex_; 259 Mutex mutex_;
249 }; 260 };
250 261
251 } // namespace blink 262 } // namespace blink
252 263
253 #endif 264 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698