1/*
2 * Copyright (C) 2017 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#include "LayerProtoHelper.h"
18
19namespace android {
20namespace surfaceflinger {
21void LayerProtoHelper::writeToProto(const Region& region, RegionProto* regionProto) {
22    Region::const_iterator head = region.begin();
23    Region::const_iterator const tail = region.end();
24    uint64_t address = reinterpret_cast<uint64_t>(&region);
25    regionProto->set_id(address);
26    while (head != tail) {
27        RectProto* rectProto = regionProto->add_rect();
28        writeToProto(*head, rectProto);
29        head++;
30    }
31}
32
33void LayerProtoHelper::writeToProto(const Rect& rect, RectProto* rectProto) {
34    rectProto->set_left(rect.left);
35    rectProto->set_top(rect.top);
36    rectProto->set_bottom(rect.bottom);
37    rectProto->set_right(rect.right);
38}
39
40void LayerProtoHelper::writeToProto(const FloatRect& rect, FloatRectProto* rectProto) {
41    rectProto->set_left(rect.left);
42    rectProto->set_top(rect.top);
43    rectProto->set_bottom(rect.bottom);
44    rectProto->set_right(rect.right);
45}
46
47void LayerProtoHelper::writeToProto(const half4 color, ColorProto* colorProto) {
48    colorProto->set_r(color.r);
49    colorProto->set_g(color.g);
50    colorProto->set_b(color.b);
51    colorProto->set_a(color.a);
52}
53
54void LayerProtoHelper::writeToProto(const Transform& transform, TransformProto* transformProto) {
55    transformProto->set_dsdx(transform[0][0]);
56    transformProto->set_dtdx(transform[0][1]);
57    transformProto->set_dsdy(transform[1][0]);
58    transformProto->set_dtdy(transform[1][1]);
59}
60
61void LayerProtoHelper::writeToProto(const sp<GraphicBuffer>& buffer,
62                                    ActiveBufferProto* activeBufferProto) {
63    activeBufferProto->set_width(buffer->getWidth());
64    activeBufferProto->set_height(buffer->getHeight());
65    activeBufferProto->set_stride(buffer->getStride());
66    activeBufferProto->set_format(buffer->format);
67}
68
69} // namespace surfaceflinger
70} // namespace android
71