1 /*
2 * Copyright (C) 2019 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 #define LOG_TAG "TestUtils"
18 #include <log/log.h>
19
20 #include <gtest/gtest.h>
21 #include <hardware/gralloc.h>
22
23 #include "test_utils.h"
24
25 namespace android {
26 namespace google_camera_hal {
27 namespace test_utils {
28
GetDummyPreviewStream(Stream * stream,uint32_t width,uint32_t height,bool is_physical_camera_stream=false,uint32_t physical_camera_id=0,uint32_t stream_id=0)29 void GetDummyPreviewStream(Stream* stream, uint32_t width, uint32_t height,
30 bool is_physical_camera_stream = false,
31 uint32_t physical_camera_id = 0,
32 uint32_t stream_id = 0) {
33 ASSERT_NE(stream, nullptr);
34
35 *stream = {};
36 stream->id = stream_id;
37 stream->stream_type = StreamType::kOutput;
38 stream->width = width;
39 stream->height = height;
40 stream->format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
41 stream->usage = GRALLOC_USAGE_HW_TEXTURE;
42 stream->data_space = HAL_DATASPACE_ARBITRARY;
43 stream->rotation = StreamRotation::kRotation0;
44 stream->is_physical_camera_stream = is_physical_camera_stream;
45 stream->physical_camera_id = physical_camera_id;
46 }
47
GetPreviewOnlyStreamConfiguration(StreamConfiguration * config,uint32_t width,uint32_t height)48 void GetPreviewOnlyStreamConfiguration(StreamConfiguration* config,
49 uint32_t width, uint32_t height) {
50 ASSERT_NE(config, nullptr);
51
52 Stream preview_stream = {};
53 GetDummyPreviewStream(&preview_stream, width, height);
54
55 *config = {};
56 config->streams.push_back(preview_stream);
57 config->operation_mode = StreamConfigurationMode::kNormal;
58 }
59
GetPhysicalPreviewStreamConfiguration(StreamConfiguration * config,const std::vector<uint32_t> & physical_camera_ids,uint32_t width,uint32_t height)60 void GetPhysicalPreviewStreamConfiguration(
61 StreamConfiguration* config,
62 const std::vector<uint32_t>& physical_camera_ids, uint32_t width,
63 uint32_t height) {
64 ASSERT_NE(config, nullptr);
65
66 *config = {};
67 config->operation_mode = StreamConfigurationMode::kNormal;
68
69 int32_t stream_id = 0;
70 for (auto& camera_id : physical_camera_ids) {
71 Stream preview_stream;
72 GetDummyPreviewStream(&preview_stream, width, height,
73 /*is_physical_camera_stream=*/true, camera_id,
74 stream_id++);
75 config->streams.push_back(preview_stream);
76 }
77 }
78
IsLogicalCamera(CameraDeviceSessionHwl * session_hwl)79 bool IsLogicalCamera(CameraDeviceSessionHwl* session_hwl) {
80 return session_hwl->GetPhysicalCameraIds().size() > 1;
81 }
82
83 } // namespace test_utils
84 } // namespace google_camera_hal
85 } // namespace android
86