• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #include "NinePatchPeeker.h"
18 
19 #include <hwui/Canvas.h>
20 
21 #include <jni.h>
22 
23 class SkAndroidCodec;
24 
25 using namespace android;
26 
27 struct ImageDecoder {
28     // These need to stay in sync with ImageDecoder.java's Allocator constants.
29     enum Allocator {
30         kDefault_Allocator      = 0,
31         kSoftware_Allocator     = 1,
32         kSharedMemory_Allocator = 2,
33         kHardware_Allocator     = 3,
34     };
35 
36     // These need to stay in sync with ImageDecoder.java's Error constants.
37     enum Error {
38         kSourceException     = 1,
39         kSourceIncomplete    = 2,
40         kSourceMalformedData = 3,
41     };
42 
43     // These need to stay in sync with PixelFormat.java's Format constants.
44     enum PixelFormat {
45         kUnknown     =  0,
46         kTranslucent = -3,
47         kOpaque      = -1,
48     };
49 
50     std::unique_ptr<SkAndroidCodec> mCodec;
51     sk_sp<NinePatchPeeker> mPeeker;
52 
ImageDecoderImageDecoder53     ImageDecoder()
54         :mPeeker(new NinePatchPeeker)
55     {}
56 };
57 
58 // Creates a Java Canvas object from canvas, calls jimageDecoder's PostProcess on it, and then
59 // releases the Canvas.
60 // Caller needs to check for exceptions.
61 jint postProcessAndRelease(JNIEnv* env, jobject jimageDecoder, std::unique_ptr<Canvas> canvas);
62