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

Side by Side Diff: cc/tiles/software_image_decode_controller.h

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
10 #include <unordered_map> 11 #include <unordered_map>
11 #include <unordered_set> 12 #include <unordered_set>
12 13
13 #include "base/atomic_sequence_num.h" 14 #include "base/atomic_sequence_num.h"
14 #include "base/containers/mru_cache.h" 15 #include "base/containers/mru_cache.h"
15 #include "base/hash.h" 16 #include "base/hash.h"
16 #include "base/memory/discardable_memory_allocator.h" 17 #include "base/memory/discardable_memory_allocator.h"
17 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
18 #include "base/numerics/safe_math.h" 19 #include "base/numerics/safe_math.h"
19 #include "base/threading/thread_checker.h" 20 #include "base/threading/thread_checker.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // MemoryDumpProvider overrides. 126 // MemoryDumpProvider overrides.
126 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 127 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
127 base::trace_event::ProcessMemoryDump* pmd) override; 128 base::trace_event::ProcessMemoryDump* pmd) override;
128 129
129 private: 130 private:
130 // DecodedImage is a convenience storage for discardable memory. It can also 131 // DecodedImage is a convenience storage for discardable memory. It can also
131 // construct an image out of SkImageInfo and stored discardable memory. 132 // construct an image out of SkImageInfo and stored discardable memory.
132 class DecodedImage { 133 class DecodedImage {
133 public: 134 public:
134 DecodedImage(const SkImageInfo& info, 135 DecodedImage(const SkImageInfo& info,
135 scoped_ptr<base::DiscardableMemory> memory, 136 std::unique_ptr<base::DiscardableMemory> memory,
136 const SkSize& src_rect_offset, 137 const SkSize& src_rect_offset,
137 uint64_t tracing_id); 138 uint64_t tracing_id);
138 ~DecodedImage(); 139 ~DecodedImage();
139 140
140 SkImage* image() const { 141 SkImage* image() const {
141 DCHECK(locked_); 142 DCHECK(locked_);
142 return image_.get(); 143 return image_.get();
143 } 144 }
144 145
145 const SkSize& src_rect_offset() const { return src_rect_offset_; } 146 const SkSize& src_rect_offset() const { return src_rect_offset_; }
146 147
147 bool is_locked() const { return locked_; } 148 bool is_locked() const { return locked_; }
148 bool Lock(); 149 bool Lock();
149 void Unlock(); 150 void Unlock();
150 151
151 const base::DiscardableMemory* memory() const { return memory_.get(); } 152 const base::DiscardableMemory* memory() const { return memory_.get(); }
152 153
153 // An ID which uniquely identifies this DecodedImage within the image decode 154 // An ID which uniquely identifies this DecodedImage within the image decode
154 // controller. Used in memory tracing. 155 // controller. Used in memory tracing.
155 uint64_t tracing_id() const { return tracing_id_; } 156 uint64_t tracing_id() const { return tracing_id_; }
156 157
157 private: 158 private:
158 bool locked_; 159 bool locked_;
159 SkImageInfo image_info_; 160 SkImageInfo image_info_;
160 scoped_ptr<base::DiscardableMemory> memory_; 161 std::unique_ptr<base::DiscardableMemory> memory_;
161 skia::RefPtr<SkImage> image_; 162 skia::RefPtr<SkImage> image_;
162 SkSize src_rect_offset_; 163 SkSize src_rect_offset_;
163 uint64_t tracing_id_; 164 uint64_t tracing_id_;
164 }; 165 };
165 166
166 // MemoryBudget is a convenience class for memory bookkeeping and ensuring 167 // MemoryBudget is a convenience class for memory bookkeeping and ensuring
167 // that we don't go over the limit when pre-decoding. 168 // that we don't go over the limit when pre-decoding.
168 class MemoryBudget { 169 class MemoryBudget {
169 public: 170 public:
170 explicit MemoryBudget(size_t limit_bytes); 171 explicit MemoryBudget(size_t limit_bytes);
171 172
172 size_t AvailableMemoryBytes() const; 173 size_t AvailableMemoryBytes() const;
173 void AddUsage(size_t usage); 174 void AddUsage(size_t usage);
174 void SubtractUsage(size_t usage); 175 void SubtractUsage(size_t usage);
175 void ResetUsage(); 176 void ResetUsage();
176 177
177 private: 178 private:
178 size_t GetCurrentUsageSafe() const; 179 size_t GetCurrentUsageSafe() const;
179 180
180 size_t limit_bytes_; 181 size_t limit_bytes_;
181 base::CheckedNumeric<size_t> current_usage_bytes_; 182 base::CheckedNumeric<size_t> current_usage_bytes_;
182 }; 183 };
183 184
184 using ImageMRUCache = 185 using ImageMRUCache = base::HashingMRUCache<ImageKey,
185 base::HashingMRUCache<ImageKey, scoped_ptr<DecodedImage>, ImageKeyHash>; 186 std::unique_ptr<DecodedImage>,
187 ImageKeyHash>;
186 188
187 // Looks for the key in the cache and returns true if it was found and was 189 // Looks for the key in the cache and returns true if it was found and was
188 // successfully locked (or if it was already locked). Note that if this 190 // successfully locked (or if it was already locked). Note that if this
189 // function returns true, then a ref count is increased for the image. 191 // function returns true, then a ref count is increased for the image.
190 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); 192 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key);
191 193
192 // Actually decode the image. Note that this function can (and should) be 194 // Actually decode the image. Note that this function can (and should) be
193 // called with no lock acquired, since it can do a lot of work. Note that it 195 // called with no lock acquired, since it can do a lot of work. Note that it
194 // can also return nullptr to indicate the decode failed. 196 // can also return nullptr to indicate the decode failed.
195 scoped_ptr<DecodedImage> DecodeImageInternal(const ImageKey& key, 197 std::unique_ptr<DecodedImage> DecodeImageInternal(
196 const DrawImage& draw_image); 198 const ImageKey& key,
199 const DrawImage& draw_image);
197 200
198 // Get the decoded draw image for the given key and draw_image. Note that this 201 // Get the decoded draw image for the given key and draw_image. Note that this
199 // function has to be called with no lock acquired, since it will acquire its 202 // function has to be called with no lock acquired, since it will acquire its
200 // own locks and might call DecodeImageInternal above. Also note that this 203 // own locks and might call DecodeImageInternal above. Also note that this
201 // function will use the provided key, even if 204 // function will use the provided key, even if
202 // ImageKey::FromDrawImage(draw_image) would return a different key. 205 // ImageKey::FromDrawImage(draw_image) would return a different key.
203 // Note that when used internally, we still require that 206 // Note that when used internally, we still require that
204 // DrawWithImageFinished() is called afterwards. 207 // DrawWithImageFinished() is called afterwards.
205 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, 208 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key,
206 const DrawImage& draw_image); 209 const DrawImage& draw_image);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 250
248 ResourceFormat format_; 251 ResourceFormat format_;
249 252
250 // Used to uniquely identify DecodedImages for memory traces. 253 // Used to uniquely identify DecodedImages for memory traces.
251 base::AtomicSequenceNumber next_tracing_id_; 254 base::AtomicSequenceNumber next_tracing_id_;
252 }; 255 };
253 256
254 } // namespace cc 257 } // namespace cc
255 258
256 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 259 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « cc/tiles/raster_tile_priority_queue_required.cc ('k') | cc/tiles/software_image_decode_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698