ColorFilter.java revision 6097eca72134034fcc6086c110673b5df94913b0
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// This file was generated from the C++ include file: SkColorFilter.h
18// Any changes made to this file will be discarded by the build.
19// To change this file, either edit the include, or device/tools/gluemaker/main.cpp,
20// or one of the auxilary file specifications in device/tools/gluemaker.
21
22package android.graphics;
23
24/**
25 * A color filter can be used with a {@link Paint} to modify the color of
26 * each pixel drawn with that paint. This is an abstract class that should
27 * never be used directly.
28 */
29public class ColorFilter {
30    /**
31     * @deprecated Use subclass constructors directly instead.
32     */
33    @Deprecated
34    public ColorFilter() {}
35
36    /**
37     * Holds the pointer to the native SkColorFilter instance.
38     */
39    private long mNativeInstance;
40
41    long createNativeInstance() {
42        return 0;
43    }
44
45    void discardNativeInstance() {
46        if (mNativeInstance != 0) {
47            nSafeUnref(mNativeInstance);
48            mNativeInstance = 0;
49        }
50    }
51
52    @Override
53    protected void finalize() throws Throwable {
54        try {
55            if (mNativeInstance != 0) {
56                nSafeUnref(mNativeInstance);
57            }
58            mNativeInstance = -1;
59        } finally {
60            super.finalize();
61        }
62    }
63
64    /** @hide */
65    public long getNativeInstance() {
66        if (mNativeInstance == -1) {
67            throw new IllegalStateException("attempting to use a finalized ColorFilter");
68        }
69
70        if (mNativeInstance == 0) {
71            mNativeInstance = createNativeInstance();
72        }
73        return mNativeInstance;
74
75    }
76
77    static native void nSafeUnref(long native_instance);
78}
79