OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaliSamplesActivity.java
Go to the documentation of this file.
1 /* Copyright (c) 2012-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 package com.arm.malideveloper.openglessdk;
22 
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.RandomAccessFile;
27 import android.os.Bundle;
28 import android.util.Log;
29 import android.app.Activity;
30 import android.content.res.AssetFileDescriptor;
31 import android.content.res.AssetManager;
32 
33 public abstract class MaliSamplesActivity extends Activity
34 {
35  public static android.content.Context mAppContext = null;
36  protected static String LOG_TAG = "MaliSamplesActivity";
37 
38  @Override
39  protected void onCreate(Bundle savedInstanceState) {
40  super.onCreate(savedInstanceState);
41 
42  mAppContext = getApplicationContext();
43 
44  /* Extract font assets. */
45  extractAssetToRes("font.frag");
46  extractAssetToRes("font.png");
47  extractAssetToRes("font.raw");
48  extractAssetToRes("font.vert");
49  }
50 
51  private void extractAssetToRes(String filename)
52  {
53  String res = "/data/data/"+this.getPackageName();
54  extractAsset(res, filename);
55  }
56 
57  public static int[] openAsset( String path )
58  {
59  AssetFileDescriptor ad = null;
60  try
61  {
62  if ( null == mAppContext )
63  {
64  return null;
65  }
66  ad = mAppContext.getResources().getAssets().openFd( path );
67  int off = (int) ad.getStartOffset();
68  int len = (int) ad.getLength();
69  int res[] = { off, len };
70  ad.close();
71  return res;
72  }
73  catch(IOException e)
74  {
75  Log.e(LOG_TAG, "MaliSamples.openAsset(): " + e.toString());
76  }
77  return null;
78  }
79 
80  public static void extractAsset(String resource_file_dir, String asset_path)
81  {
82  String resource_file_path = resource_file_dir + "/" + asset_path;
83  try
84  {
85  File resfile = new File(resource_file_path);
86  if(resfile.exists())
87  {
88  return;
89  }
90  File dirs = new File(resource_file_dir);
91  dirs.mkdirs();
92  resfile.createNewFile();
93  RandomAccessFile out = new RandomAccessFile(resfile, "rw");
94 
95  /* Get the local asset manager. */
96  AssetManager am = mAppContext.getResources().getAssets();
97 
98  /* Open the input stream for reading. */
99  InputStream inputStream = am.open( asset_path );
100 
101  byte buffer[] = new byte[1024];
102  int count = inputStream.read(buffer, 0, 1024);
103 
104  /* Do the reading. */
105  while (count > 0)
106  {
107  out.write(buffer, 0, count);
108  count = inputStream.read(buffer, 0, 1024);
109  }
110 
111  out.close();
112  inputStream.close();
113  }
114  catch(Exception e)
115  {
116  Log.e(LOG_TAG, "MaliSamples.extractAsset(): " + e.toString() + " " + resource_file_path);
117  }
118  Log.d(LOG_TAG, resource_file_path);
119  File resfile = new File(resource_file_path);
120  if(resfile.exists())
121  {
122  Log.d(LOG_TAG, "File loaded successfully");
123  }
124  }
125 }
precision highp int
Definition: hiz_cull.cs:38
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
static void extractAsset(String resource_file_dir, String asset_path)
GLenum GLuint buffer
Definition: gl2ext.h:628