OSDN Git Service

Reformat files with clang-format
[android-x86/external-IA-Hardware-Composer.git] / os / linux / pixeluploader.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
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 #ifndef OS_LINUX_PIXELUPLOADER_H_
18 #define OS_LINUX_PIXELUPLOADER_H_
19
20 #include <platformdefines.h>
21 #include <spinlock.h>
22
23 #include <memory>
24 #include <vector>
25
26 #include "factory.h"
27 #include "hwcthread.h"
28
29 #include "fdhandler.h"
30 #include "hwcevent.h"
31
32 namespace hwcomposer {
33
34 class NativeBufferHandler;
35
36 class RawPixelUploadCallback {
37  public:
38   virtual ~RawPixelUploadCallback() {
39   }
40   virtual void Callback(bool start_access, void* call_back_data) = 0;
41 };
42
43 class PixelUploaderLayerCallback {
44  public:
45   virtual ~PixelUploaderLayerCallback() {
46   }
47   virtual void UploadDone() = 0;
48 };
49
50 class PixelUploader : public HWCThread {
51  public:
52   PixelUploader(const NativeBufferHandler* buffer_handler);
53   ~PixelUploader() override;
54
55   void Initialize();
56
57   void RegisterPixelUploaderCallback(
58       std::shared_ptr<RawPixelUploadCallback> callback);
59
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);
65
66   const NativeBufferHandler* GetNativeBufferHandler() const {
67     return buffer_handler_;
68   }
69
70   void HandleRoutine() override;
71   void HandleExit() override;
72   void ExitThread();
73
74   void Synchronize();
75
76  private:
77   enum Tasks {
78     kNone = 0,  // No tasks
79     kRefreshRawPixelMap = 1 << 1,
80     kHandleTextureUpload = 1 << 2
81   };
82
83   struct PixelData {
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;
92   };
93
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);
97   void Wait();
98
99   std::shared_ptr<RawPixelUploadCallback> callback_ = NULL;
100   SpinLock tasks_lock_;
101   SpinLock pixel_data_lock_;
102   SpinLock sync_lock_;
103   std::vector<PixelData> pixel_data_;
104   uint32_t tasks_ = kNone;
105   uint32_t gpu_fd_ = 0;
106   FDHandler fd_chandler_;
107   HWCEvent cevent_;
108   const NativeBufferHandler* buffer_handler_ = NULL;
109 };
110
111 }  // namespace hwcomposer
112 #endif  // COMMON_COMPOSITOR_PixelUploader_H_