Move WebGPU platform code to platform/graphics/gpu
[WebKit-https.git] / Source / WebCore / platform / graphics / gpu / legacy / cocoa / GPULegacyTextureDescriptorMetal.mm
1 /*
2  * Copyright (C) 2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "config.h"
27 #import "GPULegacyTextureDescriptor.h"
28
29 #if ENABLE(WEBMETAL)
30
31 #import "Logging.h"
32 #import <Metal/Metal.h>
33
34 namespace WebCore {
35
36 GPULegacyTextureDescriptor::GPULegacyTextureDescriptor(unsigned pixelFormat, unsigned width, unsigned height, bool mipmapped)
37 {
38     LOG(WebMetal, "GPULegacyTextureDescriptor::GPULegacyTextureDescriptor()");
39
40     m_metal = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:static_cast<MTLPixelFormat>(pixelFormat) width:width height:height mipmapped:mipmapped];
41 }
42
43 unsigned GPULegacyTextureDescriptor::width() const
44 {
45     return [m_metal width];
46 }
47
48 void GPULegacyTextureDescriptor::setWidth(unsigned newWidth) const
49 {
50     ASSERT(m_metal);
51     [m_metal setWidth:newWidth];
52 }
53
54 unsigned GPULegacyTextureDescriptor::height() const
55 {
56     return [m_metal height];
57 }
58
59 void GPULegacyTextureDescriptor::setHeight(unsigned newHeight) const
60 {
61     ASSERT(m_metal);
62     [m_metal setHeight:newHeight];
63 }
64
65 unsigned GPULegacyTextureDescriptor::sampleCount() const
66 {
67     return [m_metal sampleCount];
68 }
69
70 void GPULegacyTextureDescriptor::setSampleCount(unsigned newSampleCount) const
71 {
72     ASSERT(m_metal);
73     [m_metal setSampleCount:newSampleCount];
74 }
75
76 unsigned GPULegacyTextureDescriptor::textureType() const
77 {
78     return [m_metal textureType];
79 }
80
81 void GPULegacyTextureDescriptor::setTextureType(unsigned newTextureType) const
82 {
83     ASSERT(m_metal);
84     [m_metal setTextureType:static_cast<MTLTextureType>(newTextureType)];
85 }
86
87 unsigned GPULegacyTextureDescriptor::storageMode() const
88 {
89     return [m_metal storageMode];
90 }
91
92 void GPULegacyTextureDescriptor::setStorageMode(unsigned newStorageMode) const
93 {
94     [m_metal setStorageMode:static_cast<MTLStorageMode>(newStorageMode)];
95 }
96
97 unsigned GPULegacyTextureDescriptor::usage() const
98 {
99     return [m_metal usage];
100 }
101
102 void GPULegacyTextureDescriptor::setUsage(unsigned newUsage) const
103 {
104     ASSERT(m_metal);
105     [m_metal setUsage:newUsage];
106 }
107
108 MTLTextureDescriptor *GPULegacyTextureDescriptor::metal() const
109 {
110     return m_metal.get();
111 }
112
113 } // namespace WebCore
114
115 #endif