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

Side by Side Diff: cc/resources/resource_provider.h

Issue 2081883002: Reland of cc: Add mailbox support to ResourceProvider write locks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@worker_context_sync_tokens_revert
Patch Set: rebase Created 4 years, 6 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
« no previous file with comments | « cc/raster/raster_buffer_provider_unittest.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_RESOURCES_RESOURCE_PROVIDER_H_ 5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_
6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 const ReturnedResourceArray& transferable_resources); 209 const ReturnedResourceArray& transferable_resources);
210 210
211 // The following lock classes are part of the ResourceProvider API and are 211 // The following lock classes are part of the ResourceProvider API and are
212 // needed to read and write the resource contents. The user must ensure 212 // needed to read and write the resource contents. The user must ensure
213 // that they only use GL locks on GL resources, etc, and this is enforced 213 // that they only use GL locks on GL resources, etc, and this is enforced
214 // by assertions. 214 // by assertions.
215 class CC_EXPORT ScopedReadLockGL { 215 class CC_EXPORT ScopedReadLockGL {
216 public: 216 public:
217 ScopedReadLockGL(ResourceProvider* resource_provider, 217 ScopedReadLockGL(ResourceProvider* resource_provider,
218 ResourceId resource_id); 218 ResourceId resource_id);
219 virtual ~ScopedReadLockGL(); 219 ~ScopedReadLockGL();
220 220
221 unsigned texture_id() const { return resource_->gl_id; } 221 unsigned texture_id() const { return texture_id_; }
222 GLenum target() const { return resource_->target; } 222 GLenum target() const { return target_; }
223 const gfx::Size& texture_size() const { return resource_->size; } 223 const gfx::Size& size() const { return size_; }
224 224
225 private: 225 private:
226 ResourceProvider* resource_provider_; 226 ResourceProvider* resource_provider_;
227 ResourceId resource_id_; 227 ResourceId resource_id_;
228 const ResourceProvider::Resource* resource_; 228 unsigned texture_id_;
229 GLenum target_;
230 gfx::Size size_;
229 231
230 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); 232 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
231 }; 233 };
232 234
233 class CC_EXPORT ScopedSamplerGL : public ScopedReadLockGL { 235 class CC_EXPORT ScopedSamplerGL {
234 public: 236 public:
235 ScopedSamplerGL(ResourceProvider* resource_provider, 237 ScopedSamplerGL(ResourceProvider* resource_provider,
236 ResourceId resource_id, 238 ResourceId resource_id,
237 GLenum filter); 239 GLenum filter);
238 ScopedSamplerGL(ResourceProvider* resource_provider, 240 ScopedSamplerGL(ResourceProvider* resource_provider,
239 ResourceId resource_id, 241 ResourceId resource_id,
240 GLenum unit, 242 GLenum unit,
241 GLenum filter); 243 GLenum filter);
242 ~ScopedSamplerGL() override; 244 ~ScopedSamplerGL();
243 245
246 unsigned texture_id() const { return resource_lock_.texture_id(); }
244 GLenum target() const { return target_; } 247 GLenum target() const { return target_; }
245 248
246 private: 249 private:
250 ScopedReadLockGL resource_lock_;
247 GLenum unit_; 251 GLenum unit_;
248 GLenum target_; 252 GLenum target_;
249 253
250 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); 254 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL);
251 }; 255 };
252 256
253 class CC_EXPORT ScopedWriteLockGL { 257 class CC_EXPORT ScopedWriteLockGL {
254 public: 258 public:
255 ScopedWriteLockGL(ResourceProvider* resource_provider, 259 ScopedWriteLockGL(ResourceProvider* resource_provider,
256 ResourceId resource_id); 260 ResourceId resource_id,
261 bool create_mailbox);
257 ~ScopedWriteLockGL(); 262 ~ScopedWriteLockGL();
258 263
259 unsigned texture_id() const { return texture_id_; } 264 unsigned texture_id() const { return texture_id_; }
265 GLenum target() const { return target_; }
266 ResourceFormat format() const { return format_; }
267 const gfx::Size& size() const { return size_; }
260 268
261 void UpdateResourceSyncToken(const gpu::SyncToken& sync_token) { 269 const TextureMailbox& mailbox() const { return mailbox_; }
262 set_sync_token_ = true; 270
271 void set_sync_token(const gpu::SyncToken& sync_token) {
263 sync_token_ = sync_token; 272 sync_token_ = sync_token;
264 } 273 }
265 274
275 void set_synchronized(bool synchronized) { synchronized_ = synchronized; }
276
266 private: 277 private:
267 ResourceProvider* resource_provider_; 278 ResourceProvider* resource_provider_;
268 ResourceProvider::Resource* resource_; 279 ResourceId resource_id_;
269 unsigned texture_id_; 280 unsigned texture_id_;
270 bool set_sync_token_; 281 GLenum target_;
282 ResourceFormat format_;
283 gfx::Size size_;
284 TextureMailbox mailbox_;
271 gpu::SyncToken sync_token_; 285 gpu::SyncToken sync_token_;
286 bool synchronized_;
287 base::ThreadChecker thread_checker_;
272 288
273 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); 289 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL);
274 }; 290 };
275 291
292 class CC_EXPORT ScopedTextureProvider {
293 public:
294 ScopedTextureProvider(gpu::gles2::GLES2Interface* gl,
295 ScopedWriteLockGL* resource_lock,
296 bool use_mailbox);
297 ~ScopedTextureProvider();
298
299 unsigned texture_id() const { return texture_id_; }
300
301 private:
302 gpu::gles2::GLES2Interface* gl_;
303 bool use_mailbox_;
304 unsigned texture_id_;
305
306 DISALLOW_COPY_AND_ASSIGN(ScopedTextureProvider);
307 };
308
309 class CC_EXPORT ScopedSkSurfaceProvider {
310 public:
311 ScopedSkSurfaceProvider(ContextProvider* context_provider,
312 ScopedWriteLockGL* resource_lock,
313 bool use_mailbox,
314 bool use_distance_field_text,
315 bool can_use_lcd_text,
316 int msaa_sample_count);
317 ~ScopedSkSurfaceProvider();
318
319 SkSurface* sk_surface() { return sk_surface_.get(); }
320
321 private:
322 ScopedTextureProvider texture_provider_;
323 sk_sp<SkSurface> sk_surface_;
324
325 DISALLOW_COPY_AND_ASSIGN(ScopedSkSurfaceProvider);
326 };
327
276 class CC_EXPORT ScopedReadLockSoftware { 328 class CC_EXPORT ScopedReadLockSoftware {
277 public: 329 public:
278 ScopedReadLockSoftware(ResourceProvider* resource_provider, 330 ScopedReadLockSoftware(ResourceProvider* resource_provider,
279 ResourceId resource_id); 331 ResourceId resource_id);
280 ~ScopedReadLockSoftware(); 332 ~ScopedReadLockSoftware();
281 333
282 const SkBitmap* sk_bitmap() const { 334 const SkBitmap* sk_bitmap() const {
283 DCHECK(valid()); 335 DCHECK(valid());
284 return &sk_bitmap_; 336 return &sk_bitmap_;
285 } 337 }
(...skipping 12 matching lines...) Expand all
298 public: 350 public:
299 ScopedWriteLockSoftware(ResourceProvider* resource_provider, 351 ScopedWriteLockSoftware(ResourceProvider* resource_provider,
300 ResourceId resource_id); 352 ResourceId resource_id);
301 ~ScopedWriteLockSoftware(); 353 ~ScopedWriteLockSoftware();
302 354
303 SkBitmap& sk_bitmap() { return sk_bitmap_; } 355 SkBitmap& sk_bitmap() { return sk_bitmap_; }
304 bool valid() const { return !!sk_bitmap_.getPixels(); } 356 bool valid() const { return !!sk_bitmap_.getPixels(); }
305 357
306 private: 358 private:
307 ResourceProvider* resource_provider_; 359 ResourceProvider* resource_provider_;
308 ResourceProvider::Resource* resource_; 360 ResourceId resource_id_;
309 SkBitmap sk_bitmap_; 361 SkBitmap sk_bitmap_;
310 base::ThreadChecker thread_checker_; 362 base::ThreadChecker thread_checker_;
311 363
312 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); 364 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware);
313 }; 365 };
314 366
315 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { 367 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer {
316 public: 368 public:
317 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, 369 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider,
318 ResourceId resource_id); 370 ResourceId resource_id);
319 ~ScopedWriteLockGpuMemoryBuffer(); 371 ~ScopedWriteLockGpuMemoryBuffer();
320 372
321 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); 373 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer();
322 374
323 private: 375 private:
324 ResourceProvider* resource_provider_; 376 ResourceProvider* resource_provider_;
325 ResourceProvider::Resource* resource_; 377 ResourceId resource_id_;
378 ResourceFormat format_;
379 gfx::Size size_;
326 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; 380 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
327 base::ThreadChecker thread_checker_; 381 base::ThreadChecker thread_checker_;
328 382
329 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); 383 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer);
330 }; 384 };
331 385
332 class CC_EXPORT ScopedWriteLockGr {
333 public:
334 ScopedWriteLockGr(ResourceProvider* resource_provider,
335 ResourceId resource_id);
336 ~ScopedWriteLockGr();
337
338 void InitSkSurface(GrContext* gr_context,
339 bool use_distance_field_text,
340 bool can_use_lcd_text,
341 int msaa_sample_count);
342 void ReleaseSkSurface();
343
344 SkSurface* sk_surface() { return sk_surface_.get(); }
345
346 gfx::Size GetResourceSize() const { return resource_->size; }
347
348 void UpdateResourceSyncToken(const gpu::SyncToken& sync_token) {
349 set_sync_token_ = true;
350 sync_token_ = sync_token;
351 }
352
353 private:
354 ResourceProvider* resource_provider_;
355 ResourceProvider::Resource* resource_;
356 base::ThreadChecker thread_checker_;
357 sk_sp<SkSurface> sk_surface_;
358 bool set_sync_token_;
359 gpu::SyncToken sync_token_;
360
361 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr);
362 };
363
364 class Fence : public base::RefCounted<Fence> { 386 class Fence : public base::RefCounted<Fence> {
365 public: 387 public:
366 Fence() {} 388 Fence() {}
367 389
368 virtual void Set() = 0; 390 virtual void Set() = 0;
369 virtual bool HasPassed() = 0; 391 virtual bool HasPassed() = 0;
370 virtual void Wait() = 0; 392 virtual void Wait() = 0;
371 393
372 protected: 394 protected:
373 friend class base::RefCounted<Fence>; 395 friend class base::RefCounted<Fence>;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 // A process-unique ID used for disambiguating memory dumps from different 681 // A process-unique ID used for disambiguating memory dumps from different
660 // resource providers. 682 // resource providers.
661 int tracing_id_; 683 int tracing_id_;
662 684
663 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); 685 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
664 }; 686 };
665 687
666 } // namespace cc 688 } // namespace cc
667 689
668 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 690 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/raster/raster_buffer_provider_unittest.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698