Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSamplerManager.m
41159 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "MTLSamplerManager.h"26#include "MTLContext.h"27#include "sun_java2d_SunGraphics2D.h"28#import "common.h"2930@implementation MTLSamplerManager {31id<MTLSamplerState> _samplerNearestClamp;32id<MTLSamplerState> _samplerLinearClamp;33id<MTLSamplerState> _samplerNearestRepeat;34id<MTLSamplerState> _samplerLinearRepeat;35}3637- (id _Nonnull)initWithDevice:(id<MTLDevice>) device {38self = [super init];39if (self) {40MTLSamplerDescriptor *samplerDescriptor = [[MTLSamplerDescriptor new] autorelease];4142samplerDescriptor.rAddressMode = MTLSamplerAddressModeClampToEdge;43samplerDescriptor.sAddressMode = MTLSamplerAddressModeClampToEdge;44samplerDescriptor.tAddressMode = MTLSamplerAddressModeClampToEdge;4546samplerDescriptor.minFilter = MTLSamplerMinMagFilterNearest;47samplerDescriptor.magFilter = MTLSamplerMinMagFilterNearest;48_samplerNearestClamp = [device newSamplerStateWithDescriptor:samplerDescriptor];4950samplerDescriptor.minFilter = MTLSamplerMinMagFilterLinear;51samplerDescriptor.magFilter = MTLSamplerMinMagFilterLinear;52_samplerLinearClamp = [device newSamplerStateWithDescriptor:samplerDescriptor];5354samplerDescriptor.rAddressMode = MTLSamplerAddressModeRepeat;55samplerDescriptor.sAddressMode = MTLSamplerAddressModeRepeat;56samplerDescriptor.tAddressMode = MTLSamplerAddressModeRepeat;5758samplerDescriptor.minFilter = MTLSamplerMinMagFilterNearest;59samplerDescriptor.magFilter = MTLSamplerMinMagFilterNearest;60_samplerNearestRepeat = [device newSamplerStateWithDescriptor:samplerDescriptor];6162samplerDescriptor.minFilter = MTLSamplerMinMagFilterLinear;63samplerDescriptor.magFilter = MTLSamplerMinMagFilterLinear;64_samplerLinearRepeat = [device newSamplerStateWithDescriptor:samplerDescriptor];65}66return self;67}6869- (void) setSamplerWithEncoder:(id<MTLRenderCommandEncoder>) encoder70interpolation:(int) interpolation71repeat:(bool) repeat {72id<MTLSamplerState> sampler;73if (repeat) {74sampler = interpolation == INTERPOLATION_BILINEAR ? _samplerLinearRepeat : _samplerNearestRepeat;75} else {76sampler = interpolation == INTERPOLATION_BILINEAR ? _samplerLinearClamp : _samplerNearestClamp;77}78[encoder setFragmentSamplerState:sampler atIndex:0];79}8081- (void)dealloc {82[_samplerNearestClamp release];83[_samplerLinearClamp release];84[_samplerNearestRepeat release];85[_samplerLinearRepeat release];86[super dealloc];87}8889@end909192