/src/skia/src/gpu/GrAttachment.cpp
Line | Count | Source (jump to first uncovered line) |
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" |
11 | | #include "src/gpu/GrBackendUtils.h" |
12 | | #include "src/gpu/GrCaps.h" |
13 | | #include "src/gpu/GrDataUtils.h" |
14 | | #include "src/gpu/GrGpu.h" |
15 | | |
16 | 136 | size_t GrAttachment::onGpuMemorySize() const { |
17 | | // The GrTexture[RenderTarget] is built up by a bunch of attachments each of which are their |
18 | | // own GrGpuResource. Ideally the GrRenderTarget would not be a GrGpuResource and the GrTexture |
19 | | // would just merge with the new GrSurface/Attachment world. Then we could just depend on each |
20 | | // attachment to give its own size since we don't have GrGpuResources owning other |
21 | | // GrGpuResources. Until we get to that point we need to live in some hybrid world. We will let |
22 | | // the msaa and stencil attachments track their own size because they do get cached separately. |
23 | | // For all GrTexture* based things we will continue to to use the GrTexture* to report size and |
24 | | // the owned attachments will have no size and be uncached. |
25 | 136 | if (!(fSupportedUsages & UsageFlags::kTexture)) { |
26 | 136 | GrBackendFormat format = this->backendFormat(); |
27 | 136 | SkImage::CompressionType compression = GrBackendFormatToCompressionType(format); |
28 | | |
29 | 136 | uint64_t size = GrNumBlocks(compression, this->dimensions()); |
30 | 136 | size *= GrBackendFormatBytesPerBlock(this->backendFormat()); |
31 | 136 | size *= this->numSamples(); |
32 | 136 | return size; |
33 | 136 | } |
34 | 0 | return 0; |
35 | 0 | } |
36 | | |
37 | | static void build_key(GrResourceKey::Builder* builder, |
38 | | const GrCaps& caps, |
39 | | const GrBackendFormat& format, |
40 | | SkISize dimensions, |
41 | | GrAttachment::UsageFlags requiredUsage, |
42 | | int sampleCnt, |
43 | | GrMipmapped mipmapped, |
44 | 136 | GrProtected isProtected) { |
45 | 136 | SkASSERT(!dimensions.isEmpty()); |
46 | | |
47 | 136 | SkASSERT(static_cast<uint32_t>(isProtected) <= 1); |
48 | 136 | SkASSERT(static_cast<uint32_t>(requiredUsage) < (1u << 8)); |
49 | 136 | SkASSERT(static_cast<uint32_t>(sampleCnt) < (1u << (32 - 9))); |
50 | | |
51 | 136 | uint64_t formatKey = caps.computeFormatKey(format); |
52 | 136 | (*builder)[0] = dimensions.width(); |
53 | 136 | (*builder)[1] = dimensions.height(); |
54 | 136 | (*builder)[2] = formatKey & 0xFFFFFFFF; |
55 | 136 | (*builder)[3] = (formatKey >> 32) & 0xFFFFFFFF; |
56 | 136 | (*builder)[4] = (static_cast<uint32_t>(isProtected) << 0) | |
57 | 136 | (static_cast<uint32_t>(requiredUsage) << 1) | |
58 | 136 | (static_cast<uint32_t>(sampleCnt) << 9); |
59 | 136 | } |
60 | | |
61 | | void GrAttachment::ComputeSharedAttachmentUniqueKey(const GrCaps& caps, |
62 | | const GrBackendFormat& format, |
63 | | SkISize dimensions, |
64 | | UsageFlags requiredUsage, |
65 | | int sampleCnt, |
66 | | GrMipmapped mipmapped, |
67 | | GrProtected isProtected, |
68 | 136 | GrUniqueKey* key) { |
69 | 136 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
70 | | |
71 | 136 | GrUniqueKey::Builder builder(key, kDomain, 5); |
72 | 136 | build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected); |
73 | 136 | } |
74 | | |
75 | | void GrAttachment::ComputeScratchKey(const GrCaps& caps, |
76 | | const GrBackendFormat& format, |
77 | | SkISize dimensions, |
78 | | UsageFlags requiredUsage, |
79 | | int sampleCnt, |
80 | | GrMipmapped mipmapped, |
81 | | GrProtected isProtected, |
82 | 0 | GrScratchKey* key) { |
83 | 0 | static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType(); |
84 | |
|
85 | 0 | GrScratchKey::Builder builder(key, kType, 5); |
86 | 0 | build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected); |
87 | 0 | } |
88 | | |
89 | 136 | void GrAttachment::computeScratchKey(GrScratchKey* key) const { |
90 | 136 | if (!SkToBool(fSupportedUsages & UsageFlags::kStencilAttachment)) { |
91 | 0 | auto isProtected = this->isProtected() ? GrProtected::kYes : GrProtected::kNo; |
92 | 0 | ComputeScratchKey(*this->getGpu()->caps(), this->backendFormat(), this->dimensions(), |
93 | 0 | fSupportedUsages, this->numSamples(), this->mipmapped(), isProtected, |
94 | 0 | key); |
95 | 0 | } |
96 | 136 | } |