transfer_cache_deserialize_helper.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2017 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_TRANSFER_CACHE_DESERIALIZE_HELPER_H_
  5. #define CC_PAINT_TRANSFER_CACHE_DESERIALIZE_HELPER_H_
  6. #include <cstdint>
  7. #include <memory>
  8. #include "cc/paint/paint_export.h"
  9. #include "cc/paint/transfer_cache_entry.h"
  10. namespace cc {
  11. // Helper interface consumed by cc/paint during OOP raster deserialization.
  12. // Provides access to the transfer cache.
  13. // TODO(ericrk): We should use TransferCacheEntryId, not uint64_t here, but
  14. // we need to figure out layering. crbug.com/777622
  15. class CC_PAINT_EXPORT TransferCacheDeserializeHelper {
  16. public:
  17. virtual ~TransferCacheDeserializeHelper() = default;
  18. // Type safe access to an entry in the transfer cache. Returns null if the
  19. // entry is missing or of the wrong type.
  20. template <typename T>
  21. T* GetEntryAs(uint32_t id) {
  22. // There is a bit of a weirdness if we use T::kType directly in the DCHECK
  23. // below. Specifically, the linker can't seem to find that symbol ¯\_(ツ)_/¯
  24. // so instead save off the type into a local variable and use that.
  25. auto entry_type = T::kType;
  26. ServiceTransferCacheEntry* entry = GetEntryInternal(entry_type, id);
  27. if (entry == nullptr) {
  28. return nullptr;
  29. }
  30. total_size_ += entry->CachedSize();
  31. // The service side entry is created using T::kType, so the class created is
  32. // guaranteed to make the entry type.
  33. DCHECK_EQ(entry->Type(), entry_type);
  34. return static_cast<T*>(entry);
  35. }
  36. // Creates an entry directly. If an entry exists, it will be clobbered.
  37. virtual void CreateLocalEntry(
  38. uint32_t id,
  39. std::unique_ptr<ServiceTransferCacheEntry> entry) = 0;
  40. size_t GetTotalEntrySizes() const { return total_size_; }
  41. private:
  42. virtual ServiceTransferCacheEntry* GetEntryInternal(
  43. TransferCacheEntryType entry_type,
  44. uint32_t entry_id) = 0;
  45. size_t total_size_ = 0;
  46. };
  47. } // namespace cc
  48. #endif // CC_PAINT_TRANSFER_CACHE_DESERIALIZE_HELPER_H_