2 // Copyright (c) 2017 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef OS_LINUX_PIXELUPLOADER_H_
18 #define OS_LINUX_PIXELUPLOADER_H_
20 #include <platformdefines.h>
27 #include "hwcthread.h"
29 #include "fdhandler.h"
32 namespace hwcomposer {
34 class NativeBufferHandler;
36 class RawPixelUploadCallback {
38 virtual ~RawPixelUploadCallback() {
40 virtual void Callback(bool start_access, void* call_back_data) = 0;
43 class PixelUploaderLayerCallback {
45 virtual ~PixelUploaderLayerCallback() {
47 virtual void UploadDone() = 0;
50 class PixelUploader : public HWCThread {
52 PixelUploader(const NativeBufferHandler* buffer_handler);
53 ~PixelUploader() override;
57 void RegisterPixelUploaderCallback(
58 std::shared_ptr<RawPixelUploadCallback> callback);
60 void UpdateLayerPixelData(HWCNativeHandle handle, uint32_t original_width,
61 uint32_t original_height, uint32_t original_stride,
62 void* callback_data, uint8_t* byteaddr,
63 PixelUploaderLayerCallback* layer_callback,
64 HwcRect<int> surfaceDamage);
66 const NativeBufferHandler* GetNativeBufferHandler() const {
67 return buffer_handler_;
70 void HandleRoutine() override;
71 void HandleExit() override;
78 kNone = 0, // No tasks
79 kRefreshRawPixelMap = 1 << 1,
80 kHandleTextureUpload = 1 << 2
84 HWCNativeHandle handle_;
85 uint32_t original_width_ = 0;
86 uint32_t original_height_ = 0;
87 uint32_t original_stride_ = 0;
88 void* callback_data_ = 0;
89 uint8_t* data_ = NULL;
90 PixelUploaderLayerCallback* layer_callback_ = NULL;
91 HwcRect<int> surfaceDamage;
94 void HandleRawPixelUpdate();
95 void* Map(uint32_t prime_fd, size_t size);
96 void Unmap(uint32_t prime_fd, void* addr, size_t size);
99 std::shared_ptr<RawPixelUploadCallback> callback_ = NULL;
100 SpinLock tasks_lock_;
101 SpinLock pixel_data_lock_;
103 std::vector<PixelData> pixel_data_;
104 uint32_t tasks_ = kNone;
105 uint32_t gpu_fd_ = 0;
106 FDHandler fd_chandler_;
108 const NativeBufferHandler* buffer_handler_ = NULL;
111 } // namespace hwcomposer
112 #endif // COMMON_COMPOSITOR_PixelUploader_H_