shader_transfer_cache_entry.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CC_PAINT_SHADER_TRANSFER_CACHE_ENTRY_H_
  5. #define CC_PAINT_SHADER_TRANSFER_CACHE_ENTRY_H_
  6. #include "base/containers/span.h"
  7. #include "cc/paint/paint_export.h"
  8. #include "cc/paint/paint_shader.h"
  9. #include "cc/paint/transfer_cache_entry.h"
  10. namespace cc {
  11. // There is only a service transfer cache entry here. The reason shaders
  12. // are cached at all are to reuse internal Skia caches for SkPictureShaders.
  13. // However, the major reason not to transfer from the client is that it
  14. // avoids the design change to make it possible for transfer cache entries
  15. // to depend on transfer cache entries. This adds a number of wrinkles
  16. // (during serialization, deserialization, scheduling). The assumption
  17. // is that most picture shaders are small (e.g. a few ops to draw a tiled
  18. // image) and that the design complication for this edge case isn't worth
  19. // it.
  20. class CC_PAINT_EXPORT ServiceShaderTransferCacheEntry final
  21. : public ServiceTransferCacheEntryBase<TransferCacheEntryType::kShader> {
  22. public:
  23. explicit ServiceShaderTransferCacheEntry(sk_sp<PaintShader> shader,
  24. size_t size);
  25. ~ServiceShaderTransferCacheEntry() final;
  26. size_t CachedSize() const final;
  27. bool Deserialize(GrDirectContext* context,
  28. base::span<const uint8_t> data) final;
  29. sk_sp<PaintShader> shader() const { return shader_; }
  30. private:
  31. sk_sp<PaintShader> shader_;
  32. size_t size_ = 0;
  33. };
  34. } // namespace cc
  35. #endif // CC_PAINT_SHADER_TRANSFER_CACHE_ENTRY_H_