1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "media/capture/video/android/photo_capabilities.h"
6 
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "media/capture/video/android/capture_jni_headers/PhotoCapabilities_jni.h"
11 
12 using base::android::AttachCurrentThread;
13 
14 namespace media {
15 
PhotoCapabilities(base::android::ScopedJavaLocalRef<jobject> object)16 PhotoCapabilities::PhotoCapabilities(
17     base::android::ScopedJavaLocalRef<jobject> object)
18     : object_(object) {}
19 
~PhotoCapabilities()20 PhotoCapabilities::~PhotoCapabilities() {}
21 
getBool(PhotoCapabilityBool capability) const22 bool PhotoCapabilities::getBool(PhotoCapabilityBool capability) const {
23   DCHECK(!object_.is_null());
24   DCHECK(capability != PhotoCapabilityBool::NUM_ENTRIES);
25   return Java_PhotoCapabilities_getBool(
26       AttachCurrentThread(), object_,
27       JniIntWrapper(static_cast<int>(capability)));
28 }
29 
getDouble(PhotoCapabilityDouble capability) const30 double PhotoCapabilities::getDouble(PhotoCapabilityDouble capability) const {
31   DCHECK(!object_.is_null());
32   DCHECK(capability != PhotoCapabilityDouble::NUM_ENTRIES);
33   return Java_PhotoCapabilities_getDouble(
34       AttachCurrentThread(), object_,
35       JniIntWrapper(static_cast<int>(capability)));
36 }
37 
getInt(PhotoCapabilityInt capability) const38 int PhotoCapabilities::getInt(PhotoCapabilityInt capability) const {
39   DCHECK(!object_.is_null());
40   DCHECK(capability != PhotoCapabilityInt::NUM_ENTRIES);
41   return Java_PhotoCapabilities_getInt(
42       AttachCurrentThread(), object_,
43       JniIntWrapper(static_cast<int>(capability)));
44 }
45 
46 std::vector<PhotoCapabilities::AndroidFillLightMode>
getFillLightModeArray() const47 PhotoCapabilities::getFillLightModeArray() const {
48   DCHECK(!object_.is_null());
49 
50   JNIEnv* env = AttachCurrentThread();
51 
52   std::vector<AndroidFillLightMode> modes;
53   static_assert(
54       std::is_same<int,
55                    std::underlying_type<AndroidFillLightMode>::type>::value,
56       "AndroidFillLightMode underlying type should be int");
57 
58   base::android::ScopedJavaLocalRef<jintArray> jni_modes =
59       Java_PhotoCapabilities_getFillLightModeArray(env, object_);
60   if (jni_modes.obj()) {
61     base::android::JavaIntArrayToIntVector(
62         env, jni_modes, reinterpret_cast<std::vector<int>*>(&modes));
63   }
64   return modes;
65 }
66 
getMeteringMode(MeteringModeType type) const67 PhotoCapabilities::AndroidMeteringMode PhotoCapabilities::getMeteringMode(
68     MeteringModeType type) const {
69   DCHECK(!object_.is_null());
70   DCHECK(type != MeteringModeType::NUM_ENTRIES);
71   return static_cast<AndroidMeteringMode>(
72       Java_PhotoCapabilities_getMeteringMode(
73           AttachCurrentThread(), object_,
74           JniIntWrapper(static_cast<int>(type))));
75 }
76 
77 std::vector<PhotoCapabilities::AndroidMeteringMode>
getMeteringModeArray(MeteringModeType type) const78 PhotoCapabilities::getMeteringModeArray(MeteringModeType type) const {
79   DCHECK(!object_.is_null());
80   DCHECK(type != MeteringModeType::NUM_ENTRIES);
81 
82   JNIEnv* env = AttachCurrentThread();
83   std::vector<PhotoCapabilities::AndroidMeteringMode> modes;
84   static_assert(
85       std::is_same<int,
86                    std::underlying_type<
87                        PhotoCapabilities::AndroidMeteringMode>::type>::value,
88       "AndroidMeteringMode underlying type should be int");
89 
90   base::android::ScopedJavaLocalRef<jintArray> jni_modes =
91       Java_PhotoCapabilities_getMeteringModeArray(
92           env, object_, JniIntWrapper(static_cast<int>(type)));
93   if (jni_modes.obj()) {
94     base::android::JavaIntArrayToIntVector(
95         env, jni_modes, reinterpret_cast<std::vector<int>*>(&modes));
96   }
97   return modes;
98 }
99 
100 }  // namespace media
101