blob: 35fdbf27214e228d3075202e1b7f6dd558ce1d0b [file] [log] [blame]
Greg Danielc0d69152020-10-08 14:59:00 -04001/*
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 Danielb8949bd2020-10-12 15:21:02 -040011#include "src/gpu/GrCaps.h"
Greg Danielc0d69152020-10-08 14:59:00 -040012
Greg Daniel5d0330e2020-10-12 16:05:21 -040013static 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 Danielb8949bd2020-10-12 15:21:02 -040036void GrAttachment::ComputeSharedAttachmentUniqueKey(const GrCaps& caps,
37 const GrBackendFormat& format,
38 SkISize dimensions,
Greg Danielc0d69152020-10-08 14:59:00 -040039 UsageFlags requiredUsage,
40 int sampleCnt,
Greg Danielb8949bd2020-10-12 15:21:02 -040041 GrProtected isProtected,
Greg Danielc0d69152020-10-08 14:59:00 -040042 GrUniqueKey* key) {
43 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
44
Greg Danielb8949bd2020-10-12 15:21:02 -040045 GrUniqueKey::Builder builder(key, kDomain, 5);
Greg Daniel5d0330e2020-10-12 16:05:21 -040046 build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, isProtected);
47}
48
49void 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 Danielc0d69152020-10-08 14:59:00 -040062}