Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLUtils.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 "MTLUtils.h"2627#include <jni.h>28#include <simd/simd.h>29#import <ThreadUtilities.h>30#import <PropertiesUtilities.h>31#include "common.h"32#include "Trace.h"3334extern void J2dTraceImpl(int level, jboolean cr, const char *string, ...);35void J2dTraceTraceVector(simd_float4 pt) {36J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_FALSE, "[%lf %lf %lf %lf]", pt.x, pt.y, pt.z, pt.w);37}3839void checkTransform(float * position, simd_float4x4 transform4x4) {40J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_FALSE, "check transform: ");4142simd_float4 fpt = simd_make_float4(position[0], position[1], position[2], 1.f);43simd_float4 fpt_trans = simd_mul(transform4x4, fpt);44J2dTraceTraceVector(fpt);45J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_FALSE, " ===>>> ");46J2dTraceTraceVector(fpt_trans);47J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_TRUE, " ");48}4950static void traceMatrix(simd_float4x4 * mtx) {51for (int row = 0; row < 4; ++row) {52J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_FALSE, " [%lf %lf %lf %lf]",53mtx->columns[0][row], mtx->columns[1][row], mtx->columns[2][row], mtx->columns[3][row]);54}55}5657void traceRaster(char * p, int width, int height, int stride) {58for (int y = 0; y < height; ++y) {59for (int x = 0; x < width; ++x) {60unsigned char pix0 = p[y*stride + x*4];61unsigned char pix1 = p[y*stride + x*4 + 1];62unsigned char pix2 = p[y*stride + x*4 + 2];63unsigned char pix3 = p[y*stride + x*4 + 3];64J2dTraceImpl(J2D_TRACE_INFO, JNI_FALSE,"[%u,%u,%u,%u], ", pix0, pix1, pix2, pix3);65}66J2dTraceImpl(J2D_TRACE_INFO, JNI_TRUE, "");67}68}6970void tracePoints(jint nPoints, jint *xPoints, jint *yPoints) {71for (int i = 0; i < nPoints; i++)72J2dTraceImpl(J2D_TRACE_INFO, JNI_TRUE, "\t(%d, %d)", *(xPoints++), *(yPoints++));73}747576jboolean isOptionEnabled(const char * option) {77JNIEnv *env = [ThreadUtilities getJNIEnvUncached];7879NSString * optionProp = [PropertiesUtilities80javaSystemPropertyForKey:[NSString stringWithUTF8String:option] withEnv:env];81NSString * lowerCaseProp = [optionProp localizedLowercaseString];82return [@"true" isEqual:lowerCaseProp];83}848586