blob: 273b8a2982c8b9bd84355f0413298092613598a5 [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 Danielb8949bd2020-10-12 15:21:02 -040013void GrAttachment::ComputeSharedAttachmentUniqueKey(const GrCaps& caps,
14 const GrBackendFormat& format,
15 SkISize dimensions,
Greg Danielc0d69152020-10-08 14:59:00 -040016 UsageFlags requiredUsage,
17 int sampleCnt,
Greg Danielb8949bd2020-10-12 15:21:02 -040018 GrProtected isProtected,
Greg Danielc0d69152020-10-08 14:59:00 -040019 GrUniqueKey* key) {
20 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
21
Greg Danielb8949bd2020-10-12 15:21:02 -040022 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 Danielc0d69152020-10-08 14:59:00 -040031 builder[0] = dimensions.width();
32 builder[1] = dimensions.height();
Greg Danielb8949bd2020-10-12 15:21:02 -040033 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 Danielc0d69152020-10-08 14:59:00 -040038}