| OLD | NEW |
| 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_GPU_IMAGE_DECODE_CONTROLLER_H_ | 5 #ifndef CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ |
| 6 #define CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ | 6 #define CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 explicit GpuImageDecodeController(ContextProvider* context, | 54 explicit GpuImageDecodeController(ContextProvider* context, |
| 55 ResourceFormat decode_format); | 55 ResourceFormat decode_format); |
| 56 ~GpuImageDecodeController() override; | 56 ~GpuImageDecodeController() override; |
| 57 | 57 |
| 58 // ImageDecodeController overrides. | 58 // ImageDecodeController overrides. |
| 59 | 59 |
| 60 // Finds the existing uploaded image for the provided DrawImage. Creates an | 60 // Finds the existing uploaded image for the provided DrawImage. Creates an |
| 61 // upload task to upload the image if an exsiting image does not exist. | 61 // upload task to upload the image if an exsiting image does not exist. |
| 62 bool GetTaskForImageAndRef(const DrawImage& image, | 62 bool GetTaskForImageAndRef(const DrawImage& image, |
| 63 uint64_t prepare_tiles_id, | 63 uint64_t prepare_tiles_id, |
| 64 scoped_refptr<ImageDecodeTask>* task) override; | 64 scoped_refptr<TileTask>* task) override; |
| 65 void UnrefImage(const DrawImage& image) override; | 65 void UnrefImage(const DrawImage& image) override; |
| 66 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; | 66 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; |
| 67 void DrawWithImageFinished(const DrawImage& image, | 67 void DrawWithImageFinished(const DrawImage& image, |
| 68 const DecodedDrawImage& decoded_image) override; | 68 const DecodedDrawImage& decoded_image) override; |
| 69 void ReduceCacheUsage() override; | 69 void ReduceCacheUsage() override; |
| 70 void SetShouldAggressivelyFreeResources( | 70 void SetShouldAggressivelyFreeResources( |
| 71 bool aggressively_free_resources) override; | 71 bool aggressively_free_resources) override; |
| 72 | 72 |
| 73 // Called by Decode / Upload tasks. | 73 // Called by Decode / Upload tasks. |
| 74 void DecodeImage(const DrawImage& image); | 74 void DecodeImage(const DrawImage& image); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 using ImageDataMRUCache = | 129 using ImageDataMRUCache = |
| 130 base::MRUCache<uint32_t, std::unique_ptr<ImageData>>; | 130 base::MRUCache<uint32_t, std::unique_ptr<ImageData>>; |
| 131 | 131 |
| 132 // All private functions should only be called while holding |lock_|. Some | 132 // All private functions should only be called while holding |lock_|. Some |
| 133 // functions also require the |context_| lock. These are indicated by | 133 // functions also require the |context_| lock. These are indicated by |
| 134 // additional comments. | 134 // additional comments. |
| 135 | 135 |
| 136 // Similar to GetTaskForImageAndRef, but gets the dependent decode task | 136 // Similar to GetTaskForImageAndRef, but gets the dependent decode task |
| 137 // rather than the upload task, if necessary. | 137 // rather than the upload task, if necessary. |
| 138 scoped_refptr<ImageDecodeTask> GetImageDecodeTaskAndRef( | 138 scoped_refptr<TileTask> GetImageDecodeTaskAndRef(const DrawImage& image, |
| 139 const DrawImage& image, | 139 uint64_t prepare_tiles_id); |
| 140 uint64_t prepare_tiles_id); | |
| 141 | 140 |
| 142 void RefImageDecode(const DrawImage& draw_image); | 141 void RefImageDecode(const DrawImage& draw_image); |
| 143 void UnrefImageDecode(const DrawImage& draw_image); | 142 void UnrefImageDecode(const DrawImage& draw_image); |
| 144 void RefImage(const DrawImage& draw_image); | 143 void RefImage(const DrawImage& draw_image); |
| 145 void UnrefImageInternal(const DrawImage& draw_image); | 144 void UnrefImageInternal(const DrawImage& draw_image); |
| 146 void RefCountChanged(ImageData* image_data); | 145 void RefCountChanged(ImageData* image_data); |
| 147 | 146 |
| 148 // Ensures that the cache can hold an element of |required_size|, freeing | 147 // Ensures that the cache can hold an element of |required_size|, freeing |
| 149 // unreferenced cache entries if necessary to make room. | 148 // unreferenced cache entries if necessary to make room. |
| 150 bool EnsureCapacity(size_t required_size); | 149 bool EnsureCapacity(size_t required_size); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 163 ImageData* image_data); | 162 ImageData* image_data); |
| 164 void DeletePendingImages(); | 163 void DeletePendingImages(); |
| 165 | 164 |
| 166 const ResourceFormat format_; | 165 const ResourceFormat format_; |
| 167 ContextProvider* context_; | 166 ContextProvider* context_; |
| 168 skia::RefPtr<GrContextThreadSafeProxy> context_threadsafe_proxy_; | 167 skia::RefPtr<GrContextThreadSafeProxy> context_threadsafe_proxy_; |
| 169 | 168 |
| 170 // All members below this point must only be accessed while holding |lock_|. | 169 // All members below this point must only be accessed while holding |lock_|. |
| 171 base::Lock lock_; | 170 base::Lock lock_; |
| 172 | 171 |
| 173 std::unordered_map<uint32_t, scoped_refptr<ImageDecodeTask>> | 172 std::unordered_map<uint32_t, scoped_refptr<TileTask>> |
| 174 pending_image_upload_tasks_; | 173 pending_image_upload_tasks_; |
| 175 std::unordered_map<uint32_t, scoped_refptr<ImageDecodeTask>> | 174 std::unordered_map<uint32_t, scoped_refptr<TileTask>> |
| 176 pending_image_decode_tasks_; | 175 pending_image_decode_tasks_; |
| 177 | 176 |
| 178 ImageDataMRUCache image_data_; | 177 ImageDataMRUCache image_data_; |
| 179 | 178 |
| 180 size_t cached_items_limit_; | 179 size_t cached_items_limit_; |
| 181 size_t cached_bytes_limit_; | 180 size_t cached_bytes_limit_; |
| 182 size_t bytes_used_; | 181 size_t bytes_used_; |
| 183 | 182 |
| 184 // We can't release GPU backed SkImages without holding the context lock, | 183 // We can't release GPU backed SkImages without holding the context lock, |
| 185 // so we add them to this list and defer deletion until the next time the lock | 184 // so we add them to this list and defer deletion until the next time the lock |
| 186 // is held. | 185 // is held. |
| 187 std::vector<skia::RefPtr<SkImage>> images_pending_deletion_; | 186 std::vector<skia::RefPtr<SkImage>> images_pending_deletion_; |
| 188 }; | 187 }; |
| 189 | 188 |
| 190 } // namespace cc | 189 } // namespace cc |
| 191 | 190 |
| 192 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ | 191 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ |
| OLD | NEW |