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

Side by Side Diff: cc/resource_provider.h

Issue 12197004: cc: Enforce correct recycling in resource pool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use fence interface. Created 7 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_RESOURCE_PROVIDER_H_ 5 #ifndef CC_RESOURCE_PROVIDER_H_
6 #define CC_RESOURCE_PROVIDER_H_ 6 #define CC_RESOURCE_PROVIDER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 private: 215 private:
216 ResourceProvider* m_resourceProvider; 216 ResourceProvider* m_resourceProvider;
217 ResourceProvider::ResourceId m_resourceId; 217 ResourceProvider::ResourceId m_resourceId;
218 SkBitmap m_skBitmap; 218 SkBitmap m_skBitmap;
219 scoped_ptr<SkCanvas> m_skCanvas; 219 scoped_ptr<SkCanvas> m_skCanvas;
220 220
221 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); 221 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware);
222 }; 222 };
223 223
224 class Fence : public base::RefCounted<Fence> {
225 public:
226 virtual bool hasPassed() = 0;
227 };
228
224 // Acquire pixel buffer for resource. The pixel buffer can be used to 229 // Acquire pixel buffer for resource. The pixel buffer can be used to
225 // set resource pixels without performing unnecessary copying. 230 // set resource pixels without performing unnecessary copying.
226 void acquirePixelBuffer(ResourceId id); 231 void acquirePixelBuffer(ResourceId id);
227 void releasePixelBuffer(ResourceId id); 232 void releasePixelBuffer(ResourceId id);
228 233
229 // Map/unmap the acquired pixel buffer. 234 // Map/unmap the acquired pixel buffer.
230 uint8_t* mapPixelBuffer(ResourceId id); 235 uint8_t* mapPixelBuffer(ResourceId id);
231 void unmapPixelBuffer(ResourceId id); 236 void unmapPixelBuffer(ResourceId id);
232 237
233 // Update pixels from acquired pixel buffer. 238 // Update pixels from acquired pixel buffer.
234 void setPixelsFromBuffer(ResourceId id); 239 void setPixelsFromBuffer(ResourceId id);
235 240
236 // Asynchronously update pixels from acquired pixel buffer. 241 // Asynchronously update pixels from acquired pixel buffer.
237 void beginSetPixels(ResourceId id); 242 void beginSetPixels(ResourceId id);
238 bool didSetPixelsComplete(ResourceId id); 243 bool didSetPixelsComplete(ResourceId id);
239 244
240 // For tests only! This prevents detecting uninitialized reads. 245 // For tests only! This prevents detecting uninitialized reads.
241 // Use setPixels or lockForWrite to allocate implicitly. 246 // Use setPixels or lockForWrite to allocate implicitly.
242 void allocateForTesting(ResourceId id); 247 void allocateForTesting(ResourceId id);
243 248
249 // Sets the current read fence. If a resource is locked for read
250 // and has read fences enabled, the resource will not allow writes
251 // until this fence has passed.
252 void setReadLockFence(Fence* fence) { m_currentReadLockFence = fence; }
253 Fence* getReadLockFence() { return m_currentReadLockFence; }
254
255 // Enable read lock fences for a specific resource.
256 void enableReadLockFences(ResourceProvider::ResourceId, bool enable);
257
258 // Indicates if we can currently lock this resource for write.
259 bool canLockForWrite(ResourceId);
260
244 private: 261 private:
245 struct Resource { 262 struct Resource {
246 Resource(); 263 Resource();
247 ~Resource(); 264 ~Resource();
248 Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenu m filter); 265 Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenu m filter);
249 Resource(uint8_t* pixels, const gfx::Size& size, GLenum format, GLenum f ilter); 266 Resource(uint8_t* pixels, const gfx::Size& size, GLenum format, GLenum f ilter);
250 267
251 unsigned glId; 268 unsigned glId;
252 // Pixel buffer used for set pixels without unnecessary copying. 269 // Pixel buffer used for set pixels without unnecessary copying.
253 unsigned glPixelBufferId; 270 unsigned glPixelBufferId;
254 // Query used to determine when asynchronous set pixels complete. 271 // Query used to determine when asynchronous set pixels complete.
255 unsigned glUploadQueryId; 272 unsigned glUploadQueryId;
256 TextureMailbox mailbox; 273 TextureMailbox mailbox;
257 uint8_t* pixels; 274 uint8_t* pixels;
258 uint8_t* pixelBuffer; 275 uint8_t* pixelBuffer;
259 int lockForReadCount; 276 int lockForReadCount;
260 bool lockedForWrite; 277 bool lockedForWrite;
261 bool external; 278 bool external;
262 bool exported; 279 bool exported;
263 bool markedForDeletion; 280 bool markedForDeletion;
264 bool pendingSetPixels; 281 bool pendingSetPixels;
265 bool allocated; 282 bool allocated;
283 bool enableReadLockFences;
284 scoped_refptr<Fence> readLockFence;
266 gfx::Size size; 285 gfx::Size size;
267 GLenum format; 286 GLenum format;
268 // TODO(skyostil): Use a separate sampler object for filter state. 287 // TODO(skyostil): Use a separate sampler object for filter state.
269 GLenum filter; 288 GLenum filter;
270 ResourceType type; 289 ResourceType type;
271 }; 290 };
272 typedef base::hash_map<ResourceId, Resource> ResourceMap; 291 typedef base::hash_map<ResourceId, Resource> ResourceMap;
273 struct Child { 292 struct Child {
274 Child(); 293 Child();
275 ~Child(); 294 ~Child();
276 295
277 ResourceIdMap childToParentMap; 296 ResourceIdMap childToParentMap;
278 ResourceIdMap parentToChildMap; 297 ResourceIdMap parentToChildMap;
279 }; 298 };
280 typedef base::hash_map<int, Child> ChildMap; 299 typedef base::hash_map<int, Child> ChildMap;
281 300
301 bool readLockFenceHasPassed(Resource* resource) { return !resource->readLock Fence ||
nduca 2013/02/05 22:39:05 does ? operator clean this? blah ? blah->hasPassed
302 resource->readLock Fence->hasPassed(); }
303
282 explicit ResourceProvider(OutputSurface*); 304 explicit ResourceProvider(OutputSurface*);
283 bool initialize(); 305 bool initialize();
284 306
285 const Resource* lockForRead(ResourceId); 307 const Resource* lockForRead(ResourceId);
286 void unlockForRead(ResourceId); 308 void unlockForRead(ResourceId);
287 const Resource* lockForWrite(ResourceId); 309 const Resource* lockForWrite(ResourceId);
288 void unlockForWrite(ResourceId); 310 void unlockForWrite(ResourceId);
289 static void populateSkBitmapWithResource(SkBitmap*, const Resource*); 311 static void populateSkBitmapWithResource(SkBitmap*, const Resource*);
290 312
291 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl eResource*); 313 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl eResource*);
(...skipping 10 matching lines...) Expand all
302 bool m_useTextureStorageExt; 324 bool m_useTextureStorageExt;
303 bool m_useTextureUsageHint; 325 bool m_useTextureUsageHint;
304 bool m_useShallowFlush; 326 bool m_useShallowFlush;
305 scoped_ptr<TextureUploader> m_textureUploader; 327 scoped_ptr<TextureUploader> m_textureUploader;
306 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; 328 scoped_ptr<AcceleratedTextureCopier> m_textureCopier;
307 int m_maxTextureSize; 329 int m_maxTextureSize;
308 GLenum m_bestTextureFormat; 330 GLenum m_bestTextureFormat;
309 331
310 base::ThreadChecker m_threadChecker; 332 base::ThreadChecker m_threadChecker;
311 333
334 scoped_refptr<Fence> m_currentReadLockFence;
335
312 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); 336 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
313 }; 337 };
314 338
315 } 339 }
316 340
317 #endif // CC_RESOURCE_PROVIDER_H_ 341 #endif // CC_RESOURCE_PROVIDER_H_
OLDNEW
« cc/resource_pool.cc ('K') | « cc/resource_pool.cc ('k') | cc/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698