Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 "src/gpu/GrAttachment.h" |
| 9 | |
| 10 | #include "include/private/GrResourceKey.h" |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame^] | 11 | #include "src/gpu/GrCaps.h" |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 12 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame^] | 13 | void GrAttachment::ComputeSharedAttachmentUniqueKey(const GrCaps& caps, |
| 14 | const GrBackendFormat& format, |
| 15 | SkISize dimensions, |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 16 | UsageFlags requiredUsage, |
| 17 | int sampleCnt, |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame^] | 18 | GrProtected isProtected, |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 19 | GrUniqueKey* key) { |
| 20 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 21 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame^] | 22 | SkASSERT(!dimensions.isEmpty()); |
| 23 | |
| 24 | SkASSERT(static_cast<uint32_t>(isProtected) <= 1); |
| 25 | SkASSERT(static_cast<uint32_t>(requiredUsage) < (1u << 8)); |
| 26 | SkASSERT(static_cast<uint32_t>(sampleCnt) < (1u << (32 - 9))); |
| 27 | |
| 28 | uint64_t formatKey = caps.computeFormatKey(format); |
| 29 | |
| 30 | GrUniqueKey::Builder builder(key, kDomain, 5); |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 31 | builder[0] = dimensions.width(); |
| 32 | builder[1] = dimensions.height(); |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame^] | 33 | builder[2] = formatKey & 0xFFFFFFFF; |
| 34 | builder[3] = (formatKey >> 32) & 0xFFFFFFFF; |
| 35 | builder[4] = (static_cast<uint32_t>(isProtected) << 0) | |
| 36 | (static_cast<uint32_t>(requiredUsage) << 1) | |
| 37 | (static_cast<uint32_t>(sampleCnt) << 9); |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 38 | } |