transfer_cache_entry.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "cc/paint/transfer_cache_entry.h"
  5. #include <memory>
  6. #include "base/notreached.h"
  7. #include "cc/paint/image_transfer_cache_entry.h"
  8. #include "cc/paint/raw_memory_transfer_cache_entry.h"
  9. #include "cc/paint/shader_transfer_cache_entry.h"
  10. #include "cc/paint/skottie_transfer_cache_entry.h"
  11. namespace cc {
  12. std::unique_ptr<ServiceTransferCacheEntry> ServiceTransferCacheEntry::Create(
  13. TransferCacheEntryType type) {
  14. switch (type) {
  15. case TransferCacheEntryType::kRawMemory:
  16. return std::make_unique<ServiceRawMemoryTransferCacheEntry>();
  17. case TransferCacheEntryType::kImage:
  18. return std::make_unique<ServiceImageTransferCacheEntry>();
  19. case TransferCacheEntryType::kShader:
  20. // ServiceShader/TextBlobTransferCache is only created via
  21. // CreateLocalEntry and is never serialized/deserialized.
  22. return nullptr;
  23. case TransferCacheEntryType::kSkottie:
  24. return std::make_unique<ServiceSkottieTransferCacheEntry>();
  25. }
  26. return nullptr;
  27. }
  28. bool ServiceTransferCacheEntry::SafeConvertToType(
  29. uint32_t raw_type,
  30. TransferCacheEntryType* type) {
  31. if (raw_type > static_cast<uint32_t>(TransferCacheEntryType::kLast))
  32. return false;
  33. *type = static_cast<TransferCacheEntryType>(raw_type);
  34. return true;
  35. }
  36. // static
  37. bool ServiceTransferCacheEntry::UsesGrContext(TransferCacheEntryType type) {
  38. switch (type) {
  39. case TransferCacheEntryType::kRawMemory:
  40. case TransferCacheEntryType::kShader:
  41. case TransferCacheEntryType::kSkottie:
  42. return false;
  43. case TransferCacheEntryType::kImage:
  44. return true;
  45. }
  46. NOTREACHED();
  47. return true;
  48. }
  49. } // namespace cc