Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/java2d/ShaderList.c
38829 views
/*1* Copyright (c) 2007, 2008, 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 <malloc.h>26#include <string.h>2728#include "ShaderList.h"29#include "Trace.h"3031/**32* Creates a new ShaderInfo that wraps the given fragment program handle33* and related data and stores it at the front of the provided ShaderList.34* If the addition causes the ShaderList to outgrow its defined capacity,35* the least-recently used item in the list (including its fragment program36* object) will be disposed.37*/38void39ShaderList_AddProgram(ShaderList *programList,40jlong programID,41jint compType, jint compMode, jint flags)42{43ShaderInfo *info;4445J2dTraceLn(J2D_TRACE_INFO, "ShaderList_AddProgram");4647// create new ShaderInfo48info = (ShaderInfo *)malloc(sizeof(ShaderInfo));49if (info == NULL) {50J2dTraceLn(J2D_TRACE_ERROR,51"OGLContext_AddProgram: could not allocate ShaderInfo");52return;53}5455// fill in the information56info->next = programList->head;57info->programID = programID;58info->compType = compType;59info->compMode = compMode;60info->flags = flags;6162// insert it at the head of the list63programList->head = info;6465// run through the list and see if we need to delete the least66// recently used item67{68int i = 1;69ShaderInfo *prev = NULL;70ShaderInfo *curr = info->next;71while (curr != NULL) {72if (i >= programList->maxItems) {73prev->next = NULL;74programList->dispose(curr->programID);75free(curr);76break;77}78i++;79prev = curr;80curr = curr->next;81}82}83}8485/**86* Locates a fragment program handle given a list of shader programs87* (ShaderInfos), using the provided composite state and flags as search88* parameters. The "flags" parameter is a bitwise-or'd value that helps89* differentiate one program for another; the interpretation of this value90* varies depending on the type of shader (BufImgOp, Paint, etc) but here91* it is only used to find another ShaderInfo with that same "flags" value.92* If no matching program can be located, this method returns 0.93*/94jlong95ShaderList_FindProgram(ShaderList *programList,96jint compType, jint compMode, jint flags)97{98ShaderInfo *prev = NULL;99ShaderInfo *info = programList->head;100101J2dTraceLn(J2D_TRACE_INFO, "ShaderList_FindProgram");102103while (info != NULL) {104if (compType == info->compType &&105compMode == info->compMode &&106flags == info->flags)107{108// it's a match: move it to the front of the list (if it's not109// there already) and patch up the links110if (info != programList->head) {111prev->next = info->next;112info->next = programList->head;113programList->head = info;114}115return info->programID;116}117prev = info;118info = info->next;119}120return 0;121}122123/**124* Disposes all entries (and their associated shader program objects)125* contained in the given ShaderList.126*/127void128ShaderList_Dispose(ShaderList *programList)129{130ShaderInfo *info = programList->head;131132J2dTraceLn(J2D_TRACE_INFO, "ShaderList_Dispose");133134while (info != NULL) {135ShaderInfo *tmp = info->next;136programList->dispose(info->programID);137free(info);138info = tmp;139}140141programList->head = NULL;142}143144145