1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "lite_proxy_surface.h"
17 #include "gfx_utils/graphic_log.h"
18
19 namespace OHOS {
LiteProxySurface(Surface * surface)20 LiteProxySurface::LiteProxySurface(Surface* surface)
21 : buffer_(nullptr), surface_(surface)
22 {
23 }
24
~LiteProxySurface()25 LiteProxySurface::~LiteProxySurface()
26 {
27 }
28
Lock(void ** buf,void ** phyMem,uint32_t * strideLen)29 void LiteProxySurface::Lock(void** buf, void** phyMem, uint32_t* strideLen)
30 {
31 GRAPHIC_LOGI("Lock");
32 if (surface_ == nullptr) {
33 return;
34 }
35
36 if (buffer_ == nullptr) {
37 buffer_ = surface_->RequestBuffer();
38 if (buffer_ == nullptr) {
39 GRAPHIC_LOGE("buffer_ is null!");
40 *buf = nullptr;
41 *phyMem = nullptr;
42 *strideLen = 0;
43 return;
44 }
45 }
46 *buf = buffer_->GetVirAddr();
47 uintptr_t phyAddr = buffer_->GetPhyAddr();
48 *phyMem = reinterpret_cast<void*>(phyAddr);
49 *strideLen = surface_->GetStride();
50 GRAPHIC_LOGI("strideLen=%d", *strideLen);
51 }
52
Unlock()53 void LiteProxySurface::Unlock()
54 {
55 if (surface_ == nullptr || buffer_ == nullptr) {
56 return;
57 }
58
59 GRAPHIC_LOGI("Unlock");
60 surface_->FlushBuffer(buffer_);
61 buffer_ = nullptr;
62 }
63 }