Home | History | Annotate | Download | only in transforms
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.gltrace.state.transforms;
     18 
     19 import com.android.ide.eclipse.gltrace.state.GLIntegerProperty;
     20 import com.android.ide.eclipse.gltrace.state.GLStateType;
     21 import com.android.ide.eclipse.gltrace.state.IGLProperty;
     22 
     23 public class CurrentProgramPropertyAccessor implements IGLPropertyAccessor {
     24     private final int mContextId;
     25     private final GLStateType mStateCategory;
     26     private final int mLocation;
     27     private final GLStateType mStateType;
     28     private final IGLPropertyAccessor mCurrentProgramAccessor;
     29 
     30     public CurrentProgramPropertyAccessor(int contextid, GLStateType stateCategory,
     31             int location, GLStateType stateType) {
     32         mContextId = contextid;
     33         mStateCategory = stateCategory;
     34         mLocation = location;
     35         mStateType = stateType;
     36 
     37         mCurrentProgramAccessor = GLPropertyAccessor.makeAccessor(contextid,
     38                 GLStateType.PROGRAM_STATE,
     39                 GLStateType.CURRENT_PROGRAM);
     40     }
     41 
     42     @Override
     43     public IGLProperty getProperty(IGLProperty state) {
     44         // obtain the current program
     45         IGLProperty currentProgramProperty = mCurrentProgramAccessor.getProperty(state);
     46         if (!(currentProgramProperty instanceof GLIntegerProperty)) {
     47             return null;
     48         }
     49 
     50         Integer program = (Integer) currentProgramProperty.getValue();
     51 
     52         // now access the required program property
     53         return GLPropertyAccessor.makeAccessor(mContextId,
     54                                                GLStateType.PROGRAM_STATE,
     55                                                GLStateType.PROGRAMS,
     56                                                program,
     57                                                mStateCategory,
     58                                                Integer.valueOf(mLocation),
     59                                                mStateType).getProperty(state);
     60     }
     61 
     62     @Override
     63     public String getPath() {
     64         return String.format("PROGRAM_STATE/PROGRAMS/${program}/%s/%d/%s",
     65                 mStateCategory, mLocation, mStateType);
     66     }
     67 }
     68