• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6// mtl_common.mm:
7//      Implementation of mtl::Context, the MTLDevice container & error handler class.
8//
9
10#include "libANGLE/renderer/metal/mtl_common.h"
11
12#include <dispatch/dispatch.h>
13
14#include <cstring>
15
16#include "libANGLE/angletypes.h"
17#include "libANGLE/renderer/metal/DisplayMtl.h"
18
19namespace rx
20{
21namespace mtl
22{
23
24// ClearColorValue implementation
25ClearColorValue &ClearColorValue::operator=(const ClearColorValue &src)
26{
27    mType       = src.mType;
28    mValueBytes = src.mValueBytes;
29
30    return *this;
31}
32
33void ClearColorValue::setAsFloat(float r, float g, float b, float a)
34{
35    mType   = PixelType::Float;
36    mRedF   = r;
37    mGreenF = g;
38    mBlueF  = b;
39    mAlphaF = a;
40}
41
42void ClearColorValue::setAsInt(int32_t r, int32_t g, int32_t b, int32_t a)
43{
44    mType   = PixelType::Int;
45    mRedI   = r;
46    mGreenI = g;
47    mBlueI  = b;
48    mAlphaI = a;
49}
50
51void ClearColorValue::setAsUInt(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
52{
53    mType   = PixelType::UInt;
54    mRedU   = r;
55    mGreenU = g;
56    mBlueU  = b;
57    mAlphaU = a;
58}
59
60MTLClearColor ClearColorValue::toMTLClearColor() const
61{
62    switch (mType)
63    {
64        case PixelType::Int:
65            return MTLClearColorMake(mRedI, mGreenI, mBlueI, mAlphaI);
66        case PixelType::UInt:
67            return MTLClearColorMake(mRedU, mGreenU, mBlueU, mAlphaU);
68        case PixelType::Float:
69            return MTLClearColorMake(mRedF, mGreenF, mBlueF, mAlphaF);
70        default:
71            UNREACHABLE();
72            return MTLClearColorMake(0, 0, 0, 0);
73    }
74}
75
76// ImageNativeIndex implementation
77ImageNativeIndexIterator ImageNativeIndex::getLayerIterator(GLint layerCount) const
78{
79    return ImageNativeIndexIterator(mNativeIndex.getLayerIterator(layerCount));
80}
81
82// Context implementation
83Context::Context(DisplayMtl *display) : mDisplay(display) {}
84
85id<MTLDevice> Context::getMetalDevice() const
86{
87    return mDisplay->getMetalDevice();
88}
89
90mtl::CommandQueue &Context::cmdQueue()
91{
92    return mDisplay->cmdQueue();
93}
94
95}  // namespace mtl
96}  // namespace rx
97