| OLD | NEW |
| 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 Loading... |
| 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 ~ScopedReadLockGL(); | 219 virtual ~ScopedReadLockGL(); |
| 220 | 220 |
| 221 unsigned texture_id() const { return texture_id_; } | 221 unsigned texture_id() const { return resource_->gl_id; } |
| 222 GLenum target() const { return target_; } | 222 GLenum target() const { return resource_->target; } |
| 223 const gfx::Size& size() const { return size_; } | 223 const gfx::Size& texture_size() const { return resource_->size; } |
| 224 | 224 |
| 225 private: | 225 private: |
| 226 ResourceProvider* resource_provider_; | 226 ResourceProvider* resource_provider_; |
| 227 ResourceId resource_id_; | 227 ResourceId resource_id_; |
| 228 unsigned texture_id_; | 228 const ResourceProvider::Resource* resource_; |
| 229 GLenum target_; | |
| 230 gfx::Size size_; | |
| 231 | 229 |
| 232 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); | 230 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); |
| 233 }; | 231 }; |
| 234 | 232 |
| 235 class CC_EXPORT ScopedSamplerGL { | 233 class CC_EXPORT ScopedSamplerGL : public ScopedReadLockGL { |
| 236 public: | 234 public: |
| 237 ScopedSamplerGL(ResourceProvider* resource_provider, | 235 ScopedSamplerGL(ResourceProvider* resource_provider, |
| 238 ResourceId resource_id, | 236 ResourceId resource_id, |
| 239 GLenum filter); | 237 GLenum filter); |
| 240 ScopedSamplerGL(ResourceProvider* resource_provider, | 238 ScopedSamplerGL(ResourceProvider* resource_provider, |
| 241 ResourceId resource_id, | 239 ResourceId resource_id, |
| 242 GLenum unit, | 240 GLenum unit, |
| 243 GLenum filter); | 241 GLenum filter); |
| 244 ~ScopedSamplerGL(); | 242 ~ScopedSamplerGL() override; |
| 245 | 243 |
| 246 unsigned texture_id() const { return resource_lock_.texture_id(); } | |
| 247 GLenum target() const { return target_; } | 244 GLenum target() const { return target_; } |
| 248 | 245 |
| 249 private: | 246 private: |
| 250 ScopedReadLockGL resource_lock_; | |
| 251 GLenum unit_; | 247 GLenum unit_; |
| 252 GLenum target_; | 248 GLenum target_; |
| 253 | 249 |
| 254 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); | 250 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); |
| 255 }; | 251 }; |
| 256 | 252 |
| 257 class CC_EXPORT ScopedWriteLockGL { | 253 class CC_EXPORT ScopedWriteLockGL { |
| 258 public: | 254 public: |
| 259 ScopedWriteLockGL(ResourceProvider* resource_provider, | 255 ScopedWriteLockGL(ResourceProvider* resource_provider, |
| 260 ResourceId resource_id, | 256 ResourceId resource_id); |
| 261 bool create_mailbox); | |
| 262 ~ScopedWriteLockGL(); | 257 ~ScopedWriteLockGL(); |
| 263 | 258 |
| 264 unsigned texture_id() const { return texture_id_; } | 259 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_; } | |
| 268 | 260 |
| 269 const TextureMailbox& mailbox() const { return mailbox_; } | 261 void UpdateResourceSyncToken(const gpu::SyncToken& sync_token) { |
| 270 | 262 set_sync_token_ = true; |
| 271 void set_sync_token(const gpu::SyncToken& sync_token) { | |
| 272 sync_token_ = sync_token; | 263 sync_token_ = sync_token; |
| 273 } | 264 } |
| 274 | 265 |
| 275 void set_synchronized(bool synchronized) { synchronized_ = synchronized; } | |
| 276 | |
| 277 private: | 266 private: |
| 278 ResourceProvider* resource_provider_; | 267 ResourceProvider* resource_provider_; |
| 279 ResourceId resource_id_; | 268 ResourceProvider::Resource* resource_; |
| 280 unsigned texture_id_; | 269 unsigned texture_id_; |
| 281 GLenum target_; | 270 bool set_sync_token_; |
| 282 ResourceFormat format_; | |
| 283 gfx::Size size_; | |
| 284 TextureMailbox mailbox_; | |
| 285 gpu::SyncToken sync_token_; | 271 gpu::SyncToken sync_token_; |
| 286 bool synchronized_; | |
| 287 base::ThreadChecker thread_checker_; | |
| 288 | 272 |
| 289 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); | 273 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); |
| 290 }; | 274 }; |
| 291 | 275 |
| 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 | |
| 328 class CC_EXPORT ScopedReadLockSoftware { | 276 class CC_EXPORT ScopedReadLockSoftware { |
| 329 public: | 277 public: |
| 330 ScopedReadLockSoftware(ResourceProvider* resource_provider, | 278 ScopedReadLockSoftware(ResourceProvider* resource_provider, |
| 331 ResourceId resource_id); | 279 ResourceId resource_id); |
| 332 ~ScopedReadLockSoftware(); | 280 ~ScopedReadLockSoftware(); |
| 333 | 281 |
| 334 const SkBitmap* sk_bitmap() const { | 282 const SkBitmap* sk_bitmap() const { |
| 335 DCHECK(valid()); | 283 DCHECK(valid()); |
| 336 return &sk_bitmap_; | 284 return &sk_bitmap_; |
| 337 } | 285 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 350 public: | 298 public: |
| 351 ScopedWriteLockSoftware(ResourceProvider* resource_provider, | 299 ScopedWriteLockSoftware(ResourceProvider* resource_provider, |
| 352 ResourceId resource_id); | 300 ResourceId resource_id); |
| 353 ~ScopedWriteLockSoftware(); | 301 ~ScopedWriteLockSoftware(); |
| 354 | 302 |
| 355 SkBitmap& sk_bitmap() { return sk_bitmap_; } | 303 SkBitmap& sk_bitmap() { return sk_bitmap_; } |
| 356 bool valid() const { return !!sk_bitmap_.getPixels(); } | 304 bool valid() const { return !!sk_bitmap_.getPixels(); } |
| 357 | 305 |
| 358 private: | 306 private: |
| 359 ResourceProvider* resource_provider_; | 307 ResourceProvider* resource_provider_; |
| 360 ResourceId resource_id_; | 308 ResourceProvider::Resource* resource_; |
| 361 SkBitmap sk_bitmap_; | 309 SkBitmap sk_bitmap_; |
| 362 base::ThreadChecker thread_checker_; | 310 base::ThreadChecker thread_checker_; |
| 363 | 311 |
| 364 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 312 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
| 365 }; | 313 }; |
| 366 | 314 |
| 367 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { | 315 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { |
| 368 public: | 316 public: |
| 369 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 317 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
| 370 ResourceId resource_id); | 318 ResourceId resource_id); |
| 371 ~ScopedWriteLockGpuMemoryBuffer(); | 319 ~ScopedWriteLockGpuMemoryBuffer(); |
| 372 | 320 |
| 373 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); | 321 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer(); |
| 374 | 322 |
| 375 private: | 323 private: |
| 376 ResourceProvider* resource_provider_; | 324 ResourceProvider* resource_provider_; |
| 377 ResourceId resource_id_; | 325 ResourceProvider::Resource* resource_; |
| 378 ResourceFormat format_; | |
| 379 gfx::Size size_; | |
| 380 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; | 326 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; |
| 381 base::ThreadChecker thread_checker_; | 327 base::ThreadChecker thread_checker_; |
| 382 | 328 |
| 383 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); | 329 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); |
| 384 }; | 330 }; |
| 385 | 331 |
| 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 |
| 386 class Fence : public base::RefCounted<Fence> { | 364 class Fence : public base::RefCounted<Fence> { |
| 387 public: | 365 public: |
| 388 Fence() {} | 366 Fence() {} |
| 389 | 367 |
| 390 virtual void Set() = 0; | 368 virtual void Set() = 0; |
| 391 virtual bool HasPassed() = 0; | 369 virtual bool HasPassed() = 0; |
| 392 virtual void Wait() = 0; | 370 virtual void Wait() = 0; |
| 393 | 371 |
| 394 protected: | 372 protected: |
| 395 friend class base::RefCounted<Fence>; | 373 friend class base::RefCounted<Fence>; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 // A process-unique ID used for disambiguating memory dumps from different | 659 // A process-unique ID used for disambiguating memory dumps from different |
| 682 // resource providers. | 660 // resource providers. |
| 683 int tracing_id_; | 661 int tracing_id_; |
| 684 | 662 |
| 685 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 663 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 686 }; | 664 }; |
| 687 | 665 |
| 688 } // namespace cc | 666 } // namespace cc |
| 689 | 667 |
| 690 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 668 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |