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

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

Issue 1951193002: cc: Add mailbox support to ResourceProvider write locks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@worker_context_stream
Patch Set: vmpstr's review 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/zero_copy_raster_buffer_provider.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 protected: 225 private:
226 ResourceProvider* resource_provider_; 226 ResourceProvider* resource_provider_;
227 ResourceId resource_id_; 227 ResourceId resource_id_;
228 228 unsigned texture_id_;
229 private: 229 GLenum target_;
230 const ResourceProvider::Resource* resource_; 230 gfx::Size size_;
231 231
232 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); 232 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
233 }; 233 };
234 234
235 class CC_EXPORT ScopedSamplerGL : public ScopedReadLockGL { 235 class CC_EXPORT ScopedSamplerGL {
236 public: 236 public:
237 ScopedSamplerGL(ResourceProvider* resource_provider, 237 ScopedSamplerGL(ResourceProvider* resource_provider,
238 ResourceId resource_id, 238 ResourceId resource_id,
239 GLenum filter); 239 GLenum filter);
240 ScopedSamplerGL(ResourceProvider* resource_provider, 240 ScopedSamplerGL(ResourceProvider* resource_provider,
241 ResourceId resource_id, 241 ResourceId resource_id,
242 GLenum unit, 242 GLenum unit,
243 GLenum filter); 243 GLenum filter);
244 ~ScopedSamplerGL() override; 244 ~ScopedSamplerGL();
245 245
246 unsigned texture_id() const { return resource_lock_.texture_id(); }
246 GLenum target() const { return target_; } 247 GLenum target() const { return target_; }
247 248
248 private: 249 private:
250 ScopedReadLockGL resource_lock_;
249 GLenum unit_; 251 GLenum unit_;
250 GLenum target_; 252 GLenum target_;
251 253
252 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); 254 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL);
253 }; 255 };
254 256
255 class CC_EXPORT ScopedWriteLockGL { 257 class CC_EXPORT ScopedWriteLockGL {
256 public: 258 public:
257 ScopedWriteLockGL(ResourceProvider* resource_provider, 259 ScopedWriteLockGL(ResourceProvider* resource_provider,
258 ResourceId resource_id); 260 ResourceId resource_id,
261 bool create_mailbox);
259 ~ScopedWriteLockGL(); 262 ~ScopedWriteLockGL();
260 263
261 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_; }
262 268
263 void UpdateResourceSyncToken(const gpu::SyncToken& sync_token) { 269 const TextureMailbox& mailbox() const { return mailbox_; }
264 set_sync_token_ = true; 270
271 void set_sync_token(const gpu::SyncToken& sync_token) {
265 sync_token_ = sync_token; 272 sync_token_ = sync_token;
266 } 273 }
267 274
275 void set_synchronized(bool synchronized) { synchronized_ = synchronized; }
276
268 private: 277 private:
269 ResourceProvider* resource_provider_; 278 ResourceProvider* resource_provider_;
270 ResourceProvider::Resource* resource_; 279 ResourceId resource_id_;
271 unsigned texture_id_; 280 unsigned texture_id_;
272 bool set_sync_token_; 281 GLenum target_;
282 ResourceFormat format_;
283 gfx::Size size_;
284 TextureMailbox mailbox_;
273 gpu::SyncToken sync_token_; 285 gpu::SyncToken sync_token_;
286 bool synchronized_;
287 base::ThreadChecker thread_checker_;
274 288
275 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); 289 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL);
276 }; 290 };
277 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
278 class CC_EXPORT ScopedReadLockSoftware { 328 class CC_EXPORT ScopedReadLockSoftware {
279 public: 329 public:
280 ScopedReadLockSoftware(ResourceProvider* resource_provider, 330 ScopedReadLockSoftware(ResourceProvider* resource_provider,
281 ResourceId resource_id); 331 ResourceId resource_id);
282 ~ScopedReadLockSoftware(); 332 ~ScopedReadLockSoftware();
283 333
284 const SkBitmap* sk_bitmap() const { 334 const SkBitmap* sk_bitmap() const {
285 DCHECK(valid()); 335 DCHECK(valid());
286 return &sk_bitmap_; 336 return &sk_bitmap_;
287 } 337 }
(...skipping 12 matching lines...) Expand all
300 public: 350 public:
301 ScopedWriteLockSoftware(ResourceProvider* resource_provider, 351 ScopedWriteLockSoftware(ResourceProvider* resource_provider,
302 ResourceId resource_id); 352 ResourceId resource_id);
303 ~ScopedWriteLockSoftware(); 353 ~ScopedWriteLockSoftware();
304 354
305 SkBitmap& sk_bitmap() { return sk_bitmap_; } 355 SkBitmap& sk_bitmap() { return sk_bitmap_; }
306 bool valid() const { return !!sk_bitmap_.getPixels(); } 356 bool valid() const { return !!sk_bitmap_.getPixels(); }
307 357
308 private: 358 private:
309 ResourceProvider* resource_provider_; 359 ResourceProvider* resource_provider_;
310 ResourceProvider::Resource* resource_; 360 ResourceId resource_id_;
311 SkBitmap sk_bitmap_; 361 SkBitmap sk_bitmap_;
312 base::ThreadChecker thread_checker_; 362 base::ThreadChecker thread_checker_;
313 363
314 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); 364 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware);
315 }; 365 };
316 366
317 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { 367 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer {
318 public: 368 public:
319 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, 369 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider,
320 ResourceId resource_id); 370 ResourceId resource_id);
321 ~ScopedWriteLockGpuMemoryBuffer(); 371 ~ScopedWriteLockGpuMemoryBuffer();
322 372
323 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); 373 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer();
324 374
325 private: 375 private:
326 ResourceProvider* resource_provider_; 376 ResourceProvider* resource_provider_;
327 ResourceProvider::Resource* resource_; 377 ResourceId resource_id_;
378 ResourceFormat format_;
379 gfx::Size size_;
328 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; 380 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
329 base::ThreadChecker thread_checker_; 381 base::ThreadChecker thread_checker_;
330 382
331 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); 383 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer);
332 }; 384 };
333 385
334 class CC_EXPORT ScopedReadLockGpuMemoryBuffer { 386 class CC_EXPORT ScopedReadLockGpuMemoryBuffer {
335 public: 387 public:
336 ScopedReadLockGpuMemoryBuffer(ResourceProvider* resource_provider, 388 ScopedReadLockGpuMemoryBuffer(ResourceProvider* resource_provider,
337 ResourceId resource_id); 389 ResourceId resource_id);
338 ~ScopedReadLockGpuMemoryBuffer(); 390 ~ScopedReadLockGpuMemoryBuffer();
339 391
392 ResourceId resource_id() const { return resource_id_; }
393
340 // This may return nullptr. 394 // This may return nullptr.
341 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer() const; 395 gfx::GpuMemoryBuffer* gpu_memory_buffer() const {
396 return gpu_memory_buffer_;
397 }
342 398
343 // This returns the GL texture that is backed by a GL image bound to the 399 // This returns the GL texture that is backed by a GL image bound to the
344 // resource's GpuMemoryBuffer. 400 // resource's GpuMemoryBuffer.
345 unsigned GetTextureId() const; 401 unsigned texture_id() const { return texture_id_; }
346
347 ResourceId GetResourceId() const;
348 402
349 private: 403 private:
350 ResourceProvider* resource_provider_; 404 ResourceProvider* resource_provider_;
351 ResourceId resource_id_; 405 ResourceId resource_id_;
352 const ResourceProvider::Resource* resource_; 406 gfx::GpuMemoryBuffer* gpu_memory_buffer_;
407 unsigned texture_id_;
353 base::ThreadChecker thread_checker_; 408 base::ThreadChecker thread_checker_;
354 409
355 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGpuMemoryBuffer); 410 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGpuMemoryBuffer);
356 }; 411 };
357 412
358 class CC_EXPORT ScopedWriteLockGr {
359 public:
360 ScopedWriteLockGr(ResourceProvider* resource_provider,
361 ResourceId resource_id);
362 ~ScopedWriteLockGr();
363
364 void InitSkSurface(GrContext* gr_context,
365 bool use_distance_field_text,
366 bool can_use_lcd_text,
367 int msaa_sample_count);
368 void ReleaseSkSurface();
369
370 SkSurface* sk_surface() { return sk_surface_.get(); }
371
372 gfx::Size GetResourceSize() const { return resource_->size; }
373
374 void UpdateResourceSyncToken(const gpu::SyncToken& sync_token) {
375 set_sync_token_ = true;
376 sync_token_ = sync_token;
377 }
378
379 private:
380 ResourceProvider* resource_provider_;
381 ResourceProvider::Resource* resource_;
382 base::ThreadChecker thread_checker_;
383 sk_sp<SkSurface> sk_surface_;
384 bool set_sync_token_;
385 gpu::SyncToken sync_token_;
386
387 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr);
388 };
389
390 class Fence : public base::RefCounted<Fence> { 413 class Fence : public base::RefCounted<Fence> {
391 public: 414 public:
392 Fence() {} 415 Fence() {}
393 416
394 virtual void Set() = 0; 417 virtual void Set() = 0;
395 virtual bool HasPassed() = 0; 418 virtual bool HasPassed() = 0;
396 virtual void Wait() = 0; 419 virtual void Wait() = 0;
397 420
398 protected: 421 protected:
399 friend class base::RefCounted<Fence>; 422 friend class base::RefCounted<Fence>;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // A process-unique ID used for disambiguating memory dumps from different 709 // A process-unique ID used for disambiguating memory dumps from different
687 // resource providers. 710 // resource providers.
688 int tracing_id_; 711 int tracing_id_;
689 712
690 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); 713 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
691 }; 714 };
692 715
693 } // namespace cc 716 } // namespace cc
694 717
695 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 718 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/raster/zero_copy_raster_buffer_provider.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698