1 | /* |
---|---|
2 | * Copyright 2017 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #include "include/core/SkPromiseImageTexture.h" |
9 | #include "src/core/SkMessageBus.h" |
10 | |
11 | #if SK_SUPPORT_GPU |
12 | |
13 | std::atomic<uint32_t> SkPromiseImageTexture::gUniqueID{1}; |
14 | |
15 | SkPromiseImageTexture::SkPromiseImageTexture(const GrBackendTexture& backendTexture) { |
16 | SkASSERT(backendTexture.isValid()); |
17 | fBackendTexture = backendTexture; |
18 | fUniqueID = gUniqueID++; |
19 | } |
20 | |
21 | SkPromiseImageTexture::~SkPromiseImageTexture() { |
22 | for (const auto& msg : fMessages) { |
23 | SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(msg); |
24 | } |
25 | } |
26 | |
27 | void SkPromiseImageTexture::addKeyToInvalidate(uint32_t contextID, const GrUniqueKey& key) { |
28 | SkASSERT(contextID != SK_InvalidUniqueID); |
29 | SkASSERT(key.isValid()); |
30 | for (const auto& msg : fMessages) { |
31 | if (msg.contextID() == contextID && msg.key() == key) { |
32 | return; |
33 | } |
34 | } |
35 | fMessages.emplace_back(key, contextID); |
36 | } |
37 | |
38 | #if GR_TEST_UTILS |
39 | SkTArray<GrUniqueKey> SkPromiseImageTexture::testingOnly_uniqueKeysToInvalidate() const { |
40 | SkTArray<GrUniqueKey> results; |
41 | for (const auto& msg : fMessages) { |
42 | results.push_back(msg.key()); |
43 | } |
44 | return results; |
45 | } |
46 | #endif |
47 | |
48 | #endif |
49 |