gecko-dev/dom/camera/GonkCameraManager.cpp
Nathan Froyd 01583602a9 Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat
The bulk of this commit was generated with a script, executed at the top
level of a typical source code checkout.  The only non-machine-generated
part was modifying MFBT's moz.build to reflect the new naming.

CLOSED TREE makes big refactorings like this a piece of cake.

 # The main substitution.
find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \
    xargs perl -p -i -e '
 s/nsRefPtr\.h/RefPtr\.h/g; # handle includes
 s/nsRefPtr ?</RefPtr</g;   # handle declarations and variables
'

 # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h.
perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h

 # Handle nsRefPtr.h itself, a couple places that define constructors
 # from nsRefPtr, and code generators specially.  We do this here, rather
 # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename
 # things like nsRefPtrHashtable.
perl -p -i -e 's/nsRefPtr/RefPtr/g' \
     mfbt/nsRefPtr.h \
     xpcom/glue/nsCOMPtr.h \
     xpcom/base/OwningNonNull.h \
     ipc/ipdl/ipdl/lower.py \
     ipc/ipdl/ipdl/builtin.py \
     dom/bindings/Codegen.py \
     python/lldbutils/lldbutils/utils.py

 # In our indiscriminate substitution above, we renamed
 # nsRefPtrGetterAddRefs, the class behind getter_AddRefs.  Fix that up.
find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \
    xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g'

if [ -d .git ]; then
    git mv mfbt/nsRefPtr.h mfbt/RefPtr.h
else
    hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h
fi

--HG--
rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 01:24:48 -04:00

138 lines
3.8 KiB
C++

/*
* Copyright (C) 2012-2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ICameraControl.h"
#include "CameraCommon.h"
#include "GonkCameraControl.h"
#include "CameraPreferences.h"
#include "TestGonkCameraControl.h"
#ifdef MOZ_WIDGET_GONK
#include <camera/Camera.h>
#else
#include "FallbackCameraPlatform.h"
#endif
using namespace mozilla;
// From ICameraControl, gonk-specific management functions
nsresult
ICameraControl::GetNumberOfCameras(int32_t& aDeviceCount)
{
aDeviceCount = android::Camera::getNumberOfCameras();
return NS_OK;
}
nsresult
ICameraControl::GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName)
{
int32_t count = android::Camera::getNumberOfCameras();
int32_t deviceNum = static_cast<int32_t>(aDeviceNum);
DOM_CAMERA_LOGI("GetCameraName : getNumberOfCameras() returned %d\n", count);
if (deviceNum < 0 || deviceNum > count) {
DOM_CAMERA_LOGE("GetCameraName : invalid device number (%u)\n", aDeviceNum);
return NS_ERROR_INVALID_ARG;
}
android::CameraInfo info;
int rv = android::Camera::getCameraInfo(deviceNum, &info);
if (rv != 0) {
DOM_CAMERA_LOGE("GetCameraName : get_camera_info(%d) failed: %d\n", deviceNum, rv);
return NS_ERROR_NOT_AVAILABLE;
}
switch (info.facing) {
case CAMERA_FACING_BACK:
aDeviceName.AssignLiteral("back");
break;
case CAMERA_FACING_FRONT:
aDeviceName.AssignLiteral("front");
break;
default:
aDeviceName.AssignLiteral("extra-camera-");
aDeviceName.AppendInt(deviceNum);
break;
}
return NS_OK;
}
nsresult
ICameraControl::GetListOfCameras(nsTArray<nsString>& aList)
{
int32_t count = android::Camera::getNumberOfCameras();
DOM_CAMERA_LOGI("getListOfCameras : getNumberOfCameras() returned %d\n", count);
if (count <= 0) {
aList.Clear();
return NS_OK;
}
// Allocate 2 extra slots to reserve space for 'front' and 'back' cameras
// at the front of the array--we will collapse any empty slots below.
aList.SetLength(2);
uint32_t extraIdx = 2;
bool gotFront = false;
bool gotBack = false;
while (count--) {
nsCString cameraName;
nsresult result = GetCameraName(count, cameraName);
if (result != NS_OK) {
continue;
}
// The first camera we find named 'back' gets slot 0; and the first
// we find named 'front' gets slot 1. All others appear after these.
if (cameraName.EqualsLiteral("back")) {
CopyUTF8toUTF16(cameraName, aList[0]);
gotBack = true;
} else if (cameraName.EqualsLiteral("front")) {
CopyUTF8toUTF16(cameraName, aList[1]);
gotFront = true;
} else {
CopyUTF8toUTF16(cameraName, *aList.InsertElementAt(extraIdx));
extraIdx++;
}
}
if (!gotFront) {
aList.RemoveElementAt(1);
}
if (!gotBack) {
aList.RemoveElementAt(0);
}
return NS_OK;
}
// implementation-specific camera factory
already_AddRefed<ICameraControl>
ICameraControl::Create(uint32_t aCameraId)
{
nsCString test;
CameraPreferences::GetPref("camera.control.test.enabled", test);
RefPtr<nsGonkCameraControl> control;
if (test.EqualsASCII("control")) {
NS_WARNING("Using test CameraControl layer");
control = new TestGonkCameraControl(aCameraId);
} else {
control = new nsGonkCameraControl(aCameraId);
}
return control.forget();
}