Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
jchuang | fa1f143 | 2015-02-20 08:22:30 | [diff] [blame] | 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 "ppapi/cpp/private/camera_device_private.h" |
| 6 | |
| 7 | #include "ppapi/c/pp_bool.h" |
| 8 | #include "ppapi/c/pp_errors.h" |
| 9 | #include "ppapi/cpp/completion_callback.h" |
| 10 | #include "ppapi/cpp/instance_handle.h" |
| 11 | #include "ppapi/cpp/module_impl.h" |
| 12 | #include "ppapi/cpp/private/camera_capabilities_private.h" |
| 13 | |
| 14 | namespace pp { |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | template <> |
| 19 | const char* interface_name<PPB_CameraDevice_Private_0_1>() { |
| 20 | return PPB_CAMERADEVICE_PRIVATE_INTERFACE_0_1; |
| 21 | } |
| 22 | |
| 23 | } // namespace |
| 24 | |
| 25 | CameraDevice_Private::CameraDevice_Private() { |
| 26 | } |
| 27 | |
| 28 | CameraDevice_Private::CameraDevice_Private(const CameraDevice_Private& other) |
| 29 | : Resource(other) { |
| 30 | } |
| 31 | |
| 32 | CameraDevice_Private::CameraDevice_Private(const Resource& resource) |
| 33 | : Resource(resource) { |
| 34 | PP_DCHECK(IsCameraDevice(resource)); |
| 35 | } |
| 36 | |
| 37 | CameraDevice_Private::CameraDevice_Private(const InstanceHandle& instance) { |
| 38 | if (has_interface<PPB_CameraDevice_Private_0_1>()) { |
| 39 | PassRefFromConstructor( |
| 40 | get_interface<PPB_CameraDevice_Private_0_1>()->Create( |
| 41 | instance.pp_instance())); |
| 42 | return; |
| 43 | } |
| 44 | PP_DCHECK(false); |
| 45 | } |
| 46 | |
| 47 | CameraDevice_Private::CameraDevice_Private(PassRef, PP_Resource resource) |
| 48 | : Resource(PASS_REF, resource) { |
| 49 | } |
| 50 | |
| 51 | CameraDevice_Private::~CameraDevice_Private() { |
| 52 | } |
| 53 | |
| 54 | int32_t CameraDevice_Private::Open(const Var& device_id, |
| 55 | const CompletionCallback& callback) { |
| 56 | if (!has_interface<PPB_CameraDevice_Private_0_1>()) |
| 57 | return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 58 | |
| 59 | return get_interface<PPB_CameraDevice_Private_0_1>()->Open( |
| 60 | pp_resource(), device_id.pp_var(), callback.pp_completion_callback()); |
| 61 | } |
| 62 | |
| 63 | void CameraDevice_Private::Close() { |
| 64 | if (has_interface<PPB_CameraDevice_Private_0_1>()) |
| 65 | get_interface<PPB_CameraDevice_Private_0_1>()->Close(pp_resource()); |
| 66 | } |
| 67 | |
| 68 | int32_t CameraDevice_Private::GetCameraCapabilities( |
| 69 | const CompletionCallbackWithOutput<CameraCapabilities_Private>& callback) { |
| 70 | if (!has_interface<PPB_CameraDevice_Private_0_1>()) |
| 71 | return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 72 | |
| 73 | return get_interface<PPB_CameraDevice_Private_0_1>()->GetCameraCapabilities( |
| 74 | pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 75 | } |
| 76 | |
| 77 | // static |
| 78 | bool CameraDevice_Private::IsCameraDevice(const Resource& resource) { |
| 79 | if (!has_interface<PPB_CameraDevice_Private_0_1>()) |
| 80 | return false; |
| 81 | |
| 82 | return PP_ToBool( |
| 83 | get_interface<PPB_CameraDevice_Private_0_1>()->IsCameraDevice( |
| 84 | resource.pp_resource())); |
| 85 | } |
| 86 | |
| 87 | } // namespace pp |