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 | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame^] | 13 | static void build_key(GrResourceKey::Builder* builder, |
| 14 | const GrCaps& caps, |
| 15 | const GrBackendFormat& format, |
| 16 | SkISize dimensions, |
| 17 | GrAttachment::UsageFlags requiredUsage, |
| 18 | int sampleCnt, |
| 19 | GrProtected isProtected) { |
| 20 | SkASSERT(!dimensions.isEmpty()); |
| 21 | |
| 22 | SkASSERT(static_cast<uint32_t>(isProtected) <= 1); |
| 23 | SkASSERT(static_cast<uint32_t>(requiredUsage) < (1u << 8)); |
| 24 | SkASSERT(static_cast<uint32_t>(sampleCnt) < (1u << (32 - 9))); |
| 25 | |
| 26 | uint64_t formatKey = caps.computeFormatKey(format); |
| 27 | (*builder)[0] = dimensions.width(); |
| 28 | (*builder)[1] = dimensions.height(); |
| 29 | (*builder)[2] = formatKey & 0xFFFFFFFF; |
| 30 | (*builder)[3] = (formatKey >> 32) & 0xFFFFFFFF; |
| 31 | (*builder)[4] = (static_cast<uint32_t>(isProtected) << 0) | |
| 32 | (static_cast<uint32_t>(requiredUsage) << 1) | |
| 33 | (static_cast<uint32_t>(sampleCnt) << 9); |
| 34 | } |
| 35 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 36 | void GrAttachment::ComputeSharedAttachmentUniqueKey(const GrCaps& caps, |
| 37 | const GrBackendFormat& format, |
| 38 | SkISize dimensions, |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 39 | UsageFlags requiredUsage, |
| 40 | int sampleCnt, |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 41 | GrProtected isProtected, |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 42 | GrUniqueKey* key) { |
| 43 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 44 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 45 | GrUniqueKey::Builder builder(key, kDomain, 5); |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame^] | 46 | build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, isProtected); |
| 47 | } |
| 48 | |
| 49 | void GrAttachment::ComputeScratchKey(const GrCaps& caps, |
| 50 | const GrBackendFormat& format, |
| 51 | SkISize dimensions, |
| 52 | UsageFlags requiredUsage, |
| 53 | int sampleCnt, |
| 54 | GrProtected isProtected, |
| 55 | GrScratchKey* key) { |
| 56 | static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType(); |
| 57 | |
| 58 | SkASSERT(sampleCnt > 1); |
| 59 | |
| 60 | GrScratchKey::Builder builder(key, kType, 5); |
| 61 | build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, isProtected); |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 62 | } |