dom/camera/GonkCameraParameters.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 /*
michael@0 2 * Copyright (C) 2013-2014 Mozilla Foundation
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #ifndef DOM_CAMERA_GONKCAMERAPARAMETERS_H
michael@0 18 #define DOM_CAMERA_GONKCAMERAPARAMETERS_H
michael@0 19
michael@0 20 #include <math.h>
michael@0 21 #include "camera/CameraParameters.h"
michael@0 22 #include "nsTArray.h"
michael@0 23 #include "nsString.h"
michael@0 24 #include "AutoRwLock.h"
michael@0 25 #include "nsPrintfCString.h"
michael@0 26 #include "ICameraControl.h"
michael@0 27
michael@0 28 namespace mozilla {
michael@0 29
michael@0 30 class GonkCameraParameters
michael@0 31 {
michael@0 32 public:
michael@0 33 GonkCameraParameters();
michael@0 34 virtual ~GonkCameraParameters();
michael@0 35
michael@0 36 // IMPORTANT: This class is read and written by multiple threads --
michael@0 37 // ALL public methods must hold mLock, for either reading or writing,
michael@0 38 // for the life of their operation. Not doing so was the cause of
michael@0 39 // bug 928856, which was -painful- to track down.
michael@0 40 template<class T> nsresult
michael@0 41 Set(uint32_t aKey, const T& aValue)
michael@0 42 {
michael@0 43 RwLockAutoEnterWrite lock(mLock);
michael@0 44 nsresult rv = SetTranslated(aKey, aValue);
michael@0 45 mDirty = mDirty || NS_SUCCEEDED(rv);
michael@0 46 return rv;
michael@0 47 }
michael@0 48
michael@0 49 template<class T> nsresult
michael@0 50 Get(uint32_t aKey, T& aValue)
michael@0 51 {
michael@0 52 RwLockAutoEnterRead lock(mLock);
michael@0 53 return GetTranslated(aKey, aValue);
michael@0 54 }
michael@0 55
michael@0 56 bool
michael@0 57 TestAndClearDirtyFlag()
michael@0 58 {
michael@0 59 bool dirty;
michael@0 60
michael@0 61 RwLockAutoEnterWrite lock(mLock);
michael@0 62 dirty = mDirty;
michael@0 63 mDirty = false;
michael@0 64 return dirty;
michael@0 65 }
michael@0 66
michael@0 67 android::String8
michael@0 68 Flatten() const
michael@0 69 {
michael@0 70 RwLockAutoEnterRead lock(mLock);
michael@0 71 return mParams.flatten();
michael@0 72 }
michael@0 73
michael@0 74 nsresult
michael@0 75 Unflatten(const android::String8& aFlatParameters)
michael@0 76 {
michael@0 77 RwLockAutoEnterWrite lock(mLock);
michael@0 78 mParams.unflatten(aFlatParameters);
michael@0 79 if (mInitialized) {
michael@0 80 return NS_OK;
michael@0 81 }
michael@0 82
michael@0 83 // We call Initialize() once when the parameter set is first loaded,
michael@0 84 // to set up any constant values this class requires internally,
michael@0 85 // e.g. the exposure compensation step and limits.
michael@0 86 return Initialize();
michael@0 87 }
michael@0 88
michael@0 89 protected:
michael@0 90 PRRWLock* mLock;
michael@0 91 bool mDirty;
michael@0 92 bool mInitialized;
michael@0 93
michael@0 94 // Required internal properties
michael@0 95 double mExposureCompensationMin;
michael@0 96 double mExposureCompensationStep;
michael@0 97 nsTArray<int> mZoomRatios;
michael@0 98 nsTArray<nsString> mIsoModes;
michael@0 99
michael@0 100 // This subclass of android::CameraParameters just gives
michael@0 101 // all of the AOSP getters and setters the same signature.
michael@0 102 class Parameters : public android::CameraParameters
michael@0 103 {
michael@0 104 public:
michael@0 105 using android::CameraParameters::set;
michael@0 106 using android::CameraParameters::get;
michael@0 107 using android::CameraParameters::TRUE;
michael@0 108 using android::CameraParameters::FALSE;
michael@0 109
michael@0 110 void set(const char* aKey, float aValue) { setFloat(aKey, aValue); }
michael@0 111 void set(const char* aKey, double aValue) { setFloat(aKey, aValue); }
michael@0 112 void set(const char* aKey, bool aValue) { set(aKey, aValue ? TRUE : FALSE); }
michael@0 113 void get(const char* aKey, float& aRet) { aRet = getFloat(aKey); }
michael@0 114 void get(const char* aKey, double& aRet) { aRet = getFloat(aKey); }
michael@0 115 void get(const char* aKey, const char*& aRet) { aRet = get(aKey); }
michael@0 116 void get(const char* aKey, int& aRet) { aRet = getInt(aKey); }
michael@0 117 void get(const char* aKey, bool& aRet) { aRet = strcmp(get(aKey), FALSE); }
michael@0 118
michael@0 119 static const char* GetTextKey(uint32_t aKey);
michael@0 120 };
michael@0 121
michael@0 122 Parameters mParams;
michael@0 123
michael@0 124 // The *Impl() templates handle converting the parameter keys from
michael@0 125 // their enum values to string types, if necessary. These are the
michael@0 126 // bottom layer accessors to mParams.
michael@0 127 template<typename T> nsresult
michael@0 128 SetImpl(uint32_t aKey, const T& aValue)
michael@0 129 {
michael@0 130 const char* key = Parameters::GetTextKey(aKey);
michael@0 131 NS_ENSURE_TRUE(key, NS_ERROR_NOT_AVAILABLE);
michael@0 132
michael@0 133 mParams.set(key, aValue);
michael@0 134 return NS_OK;
michael@0 135 }
michael@0 136
michael@0 137 template<typename T> nsresult
michael@0 138 GetImpl(uint32_t aKey, T& aValue)
michael@0 139 {
michael@0 140 const char* key = Parameters::GetTextKey(aKey);
michael@0 141 NS_ENSURE_TRUE(key, NS_ERROR_NOT_AVAILABLE);
michael@0 142
michael@0 143 mParams.get(key, aValue);
michael@0 144 return NS_OK;
michael@0 145 }
michael@0 146
michael@0 147 template<class T> nsresult
michael@0 148 SetImpl(const char* aKey, const T& aValue)
michael@0 149 {
michael@0 150 mParams.set(aKey, aValue);
michael@0 151 return NS_OK;
michael@0 152 }
michael@0 153
michael@0 154 template<class T> nsresult
michael@0 155 GetImpl(const char* aKey, T& aValue)
michael@0 156 {
michael@0 157 mParams.get(aKey, aValue);
michael@0 158 return NS_OK;
michael@0 159 }
michael@0 160
michael@0 161 // The *Translated() functions allow us to handle special cases;
michael@0 162 // for example, where the thumbnail size setting is exposed as an
michael@0 163 // ICameraControl::Size object, but is handled by the AOSP layer
michael@0 164 // as two separate parameters.
michael@0 165 nsresult SetTranslated(uint32_t aKey, const nsAString& aValue);
michael@0 166 nsresult GetTranslated(uint32_t aKey, nsAString& aValue);
michael@0 167 nsresult SetTranslated(uint32_t aKey, const ICameraControl::Size& aSize);
michael@0 168 nsresult GetTranslated(uint32_t aKey, ICameraControl::Size& aSize);
michael@0 169 nsresult GetTranslated(uint32_t aKey, nsTArray<ICameraControl::Size>& aSizes);
michael@0 170 nsresult SetTranslated(uint32_t aKey, const nsTArray<ICameraControl::Region>& aRegions);
michael@0 171 nsresult GetTranslated(uint32_t aKey, nsTArray<ICameraControl::Region>& aRegions);
michael@0 172 nsresult SetTranslated(uint32_t aKey, const ICameraControl::Position& aPosition);
michael@0 173 nsresult SetTranslated(uint32_t aKey, const int64_t& aValue);
michael@0 174 nsresult GetTranslated(uint32_t aKey, int64_t& aValue);
michael@0 175 nsresult SetTranslated(uint32_t aKey, const double& aValue);
michael@0 176 nsresult GetTranslated(uint32_t aKey, double& aValue);
michael@0 177 nsresult SetTranslated(uint32_t aKey, const int& aValue);
michael@0 178 nsresult GetTranslated(uint32_t aKey, int& aValue);
michael@0 179 nsresult SetTranslated(uint32_t aKey, const uint32_t& aValue);
michael@0 180 nsresult GetTranslated(uint32_t aKey, uint32_t& aValue);
michael@0 181 nsresult SetTranslated(uint32_t aKey, const bool& aValue);
michael@0 182 nsresult GetTranslated(uint32_t aKey, bool& aValue);
michael@0 183 nsresult GetTranslated(uint32_t aKey, nsTArray<nsString>& aValues);
michael@0 184 nsresult GetTranslated(uint32_t aKey, nsTArray<double>& aValues);
michael@0 185
michael@0 186 template<class T> nsresult GetListAsArray(uint32_t aKey, nsTArray<T>& aArray);
michael@0 187 nsresult MapIsoToGonk(const nsAString& aIso, nsACString& aIsoOut);
michael@0 188 nsresult MapIsoFromGonk(const char* aIso, nsAString& aIsoOut);
michael@0 189
michael@0 190 nsresult Initialize();
michael@0 191 };
michael@0 192
michael@0 193 } // namespace mozilla
michael@0 194
michael@0 195 #endif // DOM_CAMERA_GONKCAMERAPARAMETERS_H

mercurial