• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 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 #ifndef UTILS_DEFINED
18 #define UTILS_DEFINED
19 
20 #include "SkStream.h"
21 
22 #include "android_util_Binder.h"
23 
24 #include <jni.h>
25 #include <androidfw/Asset.h>
26 
27 namespace android {
28 
29 class AssetStreamAdaptor : public SkStream {
30 public:
AssetStreamAdaptor(Asset * a)31     AssetStreamAdaptor(Asset* a) : fAsset(a) {}
32     virtual bool rewind();
33     virtual size_t read(void* buffer, size_t size);
34 
35 private:
36     Asset*  fAsset;
37 };
38 
39 
40 /** Restore the file descriptor's offset in our destructor
41  */
42 class AutoFDSeek {
43 public:
AutoFDSeek(int fd)44     AutoFDSeek(int fd) : fFD(fd) {
45         fCurr = ::lseek(fd, 0, SEEK_CUR);
46     }
~AutoFDSeek()47     ~AutoFDSeek() {
48         if (fCurr >= 0) {
49             ::lseek(fFD, fCurr, SEEK_SET);
50         }
51     }
52 private:
53     int     fFD;
54     off64_t   fCurr;
55 };
56 
57 jobject nullObjectReturn(const char msg[]);
58 
59 }; // namespace android
60 
61 #endif
62