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

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

Issue 1832573004: Gpu Image Decode Controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small fixes 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_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 <list>
vmpstr 2016/03/28 23:55:53 I don't see list usage... Or am I missing somethin
ericrk 2016/03/29 23:11:30 removed.
8 #include <unordered_map> 9 #include <unordered_map>
9 #include <unordered_set> 10 #include <unordered_set>
11 #include <vector>
10 12
13 #include "base/containers/mru_cache.h"
14 #include "base/memory/discardable_memory.h"
15 #include "base/memory/scoped_ptr.h"
11 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "base/trace_event/memory_dump_provider.h"
12 #include "cc/base/cc_export.h" 18 #include "cc/base/cc_export.h"
19 #include "cc/resources/resource_format.h"
13 #include "cc/tiles/image_decode_controller.h" 20 #include "cc/tiles/image_decode_controller.h"
21 #include "skia/ext/refptr.h"
22
23 class SkImageTextureData;
14 24
15 namespace cc { 25 namespace cc {
16 26
27 class ContextProvider;
28
29 // GpuImageDecodeController handles the decode and upload of images that will
30 // be used by Skia's GPU raster path. It also maintains a cache of these
31 // decoded/ uploaded images for later re-use.
vmpstr 2016/03/28 23:55:53 either "decoded / uploaded" or "decoded/uploaded"
ericrk 2016/03/29 23:11:30 Done.
32 //
33 // Generally, when an image is required for raster, GpuImageDecodeController
34 // creates two tasks, one to decode the image, and one to upload the image to
35 // the GPU. These tasks are completed before the raster task which depends on
36 // the image. We need to seperate decode and upload tasks, as decode can occur
37 // simultaneously on multiple threads, while upload requires the GL context
38 // lockmust happen on our non-concurrent raster thread.
vmpstr 2016/03/28 23:55:53 s/lockmust/lock and must/
ericrk 2016/03/29 23:11:30 Done.
39 //
40 // Decoded and Uploaded image data share a single cache entry. Depending on how
41 // far we've progressed, this cache entry may contain CPU-side decoded data,
42 // GPU-side uploaded data, or both. Because CPU-side decoded data is stored in
43 // discardable memory, and is only locked for short periods of time (until the
44 // upload completes), this memory is not counted against our sized cache
45 // limits. Uploaded GPU memory, being non- discardable, always counts against
vmpstr 2016/03/28 23:55:53 s/non- discardable/non-discardable/ :P
ericrk 2016/03/29 23:11:30 Done.
46 // our limits.
47 //
48 // In cases where the number of images needed exceeds our cache limits, we
49 // operate in an "at-raster" mode. In this mode, there are no decode/upload
50 // tasks, and images are decoded/uploaded as needed, immediately before being
51 // used in raster. Cache entries for at-raster tasks are marked as such, which
52 // prevents future tasks from taking a dependency on them and extending their
53 // lifetime longer than is necessary.
17 class CC_EXPORT GpuImageDecodeController : public ImageDecodeController { 54 class CC_EXPORT GpuImageDecodeController : public ImageDecodeController {
18 public: 55 public:
19 GpuImageDecodeController(); 56 explicit GpuImageDecodeController(ContextProvider* context,
57 ResourceFormat decode_format);
20 ~GpuImageDecodeController() override; 58 ~GpuImageDecodeController() override;
21 59
22 // ImageDecodeController overrides. 60 // ImageDecodeController overrides.
23 bool GetTaskForImageAndRef(const DrawImage& image, 61 bool GetTaskForImageAndRef(const DrawImage& image,
24 uint64_t prepare_tiles_id, 62 uint64_t prepare_tiles_id,
25 scoped_refptr<ImageDecodeTask>* task) override; 63 scoped_refptr<ImageDecodeTask>* task) override;
26 void UnrefImage(const DrawImage& image) override; 64 void UnrefImage(const DrawImage& image) override;
27 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; 65 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override;
28 void DrawWithImageFinished(const DrawImage& image, 66 void DrawWithImageFinished(const DrawImage& image,
29 const DecodedDrawImage& decoded_image) override; 67 const DecodedDrawImage& decoded_image) override;
30 void ReduceCacheUsage() override; 68 void ReduceCacheUsage() override;
31 69
70 // Called by Decode / Upload tasks.
32 void DecodeImage(const DrawImage& image); 71 void DecodeImage(const DrawImage& image);
72 void UploadImage(const DrawImage& image);
73 void DecodeTaskCompleted(const DrawImage& image);
74 void UploadTaskCompleted(const DrawImage& image);
33 75
34 void RemovePendingTaskForImage(const DrawImage& image); 76 // For testing only.
77 void SetCachedItemLimitForTesting(size_t limit) {
78 cached_items_limit_ = limit;
79 }
80 void SetCachedBytesLimitForTesting(size_t limit) {
81 cached_bytes_limit_ = limit;
82 }
83 size_t GetBytesUsedForTesting() const { return bytes_used_; }
35 84
36 private: 85 private:
86 class ScopedRefImageLocked;
87
88 enum class DecodedDataMode { GPU, CPU };
89
90 // Stores the CPU-side decoded bits of an image and supporting fields.
91 struct DecodedImageData {
92 DecodedImageData();
93 ~DecodedImageData();
94
95 // May be null if image not yet decoded.
96 scoped_ptr<base::DiscardableMemory> data;
97 uint32_t ref_count;
98 bool is_locked;
99 };
100
101 // Stores the GPU-side image and supporting fields.
102 struct UploadedImageData {
103 UploadedImageData();
104 ~UploadedImageData();
105
106 // May be null if image not yet uploaded / prepared.
107 skia::RefPtr<SkImage> image;
108 // True if the image is pending upload, in which case it counts against our
109 // memory budget even though the uploaded_image does not yet exist.
110 bool pending;
111 uint32_t ref_count;
112 };
113
114 struct ImageData {
115 ImageData(DecodedDataMode mode, size_t size);
116 ~ImageData();
117
118 const DecodedDataMode mode;
119 const size_t size;
120 bool is_at_raster;
121
122 DecodedImageData decode;
123 UploadedImageData upload;
124 };
125
126 // Similar to GetTaskForImageAndRef, but gets the dependent decode task
127 // rather than the upload task.
vmpstr 2016/03/28 23:55:53 Can you add a comment to the GetTaskForImageAndRef
ericrk 2016/03/29 23:11:30 Done.
128 scoped_refptr<ImageDecodeTask> GetImageDecodeTaskAndRefWithClassLock(
129 const DrawImage& image,
130 uint64_t prepare_tiles_id);
131
132 void RefImageDecodeWithClassLock(const DrawImage& draw_image);
vmpstr 2016/03/28 23:55:53 Are all private functions WithClassLock? :) I don'
ericrk 2016/03/29 23:11:30 Done.
133 void UnrefImageDecodeWithClassLock(const DrawImage& draw_image);
134 void RefImageWithClassLock(const DrawImage& draw_image);
135 void UnrefImageWithClassLock(const DrawImage& draw_image);
136
137 // Ensures that the cache can hold an element of |required_size|, freeing
138 // unreferenced cache entries if necessary to make room.
139 bool EnsureCapacityWithClassLock(size_t required_size);
140 bool CanFitSizeWithClassLock(size_t size) const;
141 bool CanFitCountWithClassLock(size_t num_elements) const;
142
143 void DecodeImageIfNecessaryWithClassLock(const DrawImage& draw_image,
144 ImageData* image_data);
145 void UploadImageIfNecessaryWithClassAndContextLock(
146 const DrawImage& draw_image,
147 ImageData* image_data);
148 void DeletePendingImagesWithClassAndContextLock();
149
150 scoped_ptr<GpuImageDecodeController::ImageData> CreateImageData(
151 const DrawImage& image);
152 SkImageInfo CreateImageInfoForDrawImage(const DrawImage& draw_image) const;
153
154 const ResourceFormat format_;
155 ContextProvider* context_;
156 GrContextThreadSafeProxy* context_threadsafe_proxy_;
157
158 // All members below this point must only be accessed while holding |lock_|.
37 base::Lock lock_; 159 base::Lock lock_;
38 160
39 std::unordered_set<uint32_t> prerolled_images_;
40 std::unordered_map<uint32_t, scoped_refptr<ImageDecodeTask>> 161 std::unordered_map<uint32_t, scoped_refptr<ImageDecodeTask>>
41 pending_image_tasks_; 162 pending_image_upload_tasks_;
163 std::unordered_map<uint32_t, scoped_refptr<ImageDecodeTask>>
164 pending_image_decode_tasks_;
165
166 using ImageDataMRUCache = base::MRUCache<uint32_t, scoped_ptr<ImageData>>;
167 ImageDataMRUCache image_data_;
168
169 size_t cached_items_limit_;
170 size_t cached_bytes_limit_;
171 size_t bytes_used_;
172
173 // We can't release GPU backed SkImages without holding the Skia context lock,
174 // so we add them to this list and defer deletion until the next time the lock
175 // is held.
176 std::vector<skia::RefPtr<SkImage>> images_pending_deletion_;
42 }; 177 };
43 178
44 } // namespace cc 179 } // namespace cc
45 180
46 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ 181 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698