blob: 372ac94d9dca97103c095e0d31c9c0c09c1e5ca7 [file] [log] [blame]
Andy Qiu8a427142013-04-05 17:41:58 -07001/*
2 * Copyright © 2012 Intel Corporation
3 * All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * Authors:
25 * Jackie Li <yaodong.li@intel.com>
26 *
27 */
28#ifndef VIRTUAL_DEVICE_H
29#define VIRTUAL_DEVICE_H
30
Andy Qiu8a427142013-04-05 17:41:58 -070031#include <IDisplayDevice.h>
Ashish Singhi196e5bd2013-04-17 18:26:37 -070032#include "IFrameServer.h"
Andy Qiu8a427142013-04-05 17:41:58 -070033
34namespace android {
35namespace intel {
36
37class Hwcomposer;
38class DisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070039class IVideoPayloadManager;
Andy Qiu8a427142013-04-05 17:41:58 -070040
Ashish Singhi196e5bd2013-04-17 18:26:37 -070041class VirtualDevice : public IDisplayDevice, public BnFrameServer {
Ashish Singhi77b747d2013-04-26 14:30:05 -070042protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -070043 struct CachedBuffer : public android::RefBase {
mamatha balgurid2483962013-07-11 13:38:48 -070044 CachedBuffer(BufferManager *mgr, uint32_t handle);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070045 ~CachedBuffer();
46 BufferManager *manager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070047 BufferMapper *mapper;
48 };
mamatha balgurid2483962013-07-11 13:38:48 -070049 struct HeldCscBuffer : public android::RefBase {
50 HeldCscBuffer(const android::sp<VirtualDevice>& vd, uint32_t handle);
51 virtual ~HeldCscBuffer();
52 android::sp<VirtualDevice> vd;
53 uint32_t handle;
54 };
55 struct HeldDecoderBuffer : public android::RefBase {
56 HeldDecoderBuffer(const sp<VirtualDevice>& vd, const android::sp<CachedBuffer>& cachedBuffer);
57 virtual ~HeldDecoderBuffer();
58 android::sp<VirtualDevice> vd;
59 android::sp<CachedBuffer> cachedBuffer;
60 };
Ashish Singhi77b747d2013-04-26 14:30:05 -070061 struct Configuration {
62 sp<IFrameTypeChangeListener> typeChangeListener;
63 sp<IFrameListener> frameListener;
64 FrameProcessingPolicy policy;
65 bool extendedModeEnabled;
66 bool forceNotify;
67 };
68 Mutex mConfigLock;
69 Configuration mCurrentConfig;
70 Configuration mNextConfig;
mamatha balgurid2483962013-07-11 13:38:48 -070071 size_t mLayerToSend;
Ashish Singhi77b747d2013-04-26 14:30:05 -070072
73 uint32_t mExtLastKhandle;
74 int64_t mExtLastTimestamp;
75
mamatha balgurid2483962013-07-11 13:38:48 -070076 int64_t mRenderTimestamp;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070077
mamatha balgurid2483962013-07-11 13:38:48 -070078 // colorspace conversion
79 Mutex mCscLock;
80 android::List<uint32_t> mAvailableCscBuffers;
81 int mCscBuffersToCreate;
82 uint32_t mCscWidth;
83 uint32_t mCscHeight;
84
85 FrameInfo mLastInputFrameInfo;
86 FrameInfo mLastOutputFrameInfo;
87
88 android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070089 android::Mutex mHeldBuffersLock;
mamatha balgurid2483962013-07-11 13:38:48 -070090 android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070091
92private:
mamatha balgurid2483962013-07-11 13:38:48 -070093 android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
94 void sendToWidi(const hwc_layer_1_t& layer);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070095
Andy Qiu8a427142013-04-05 17:41:58 -070096public:
97 VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
98 virtual ~VirtualDevice();
99
100public:
101 virtual bool prePrepare(hwc_display_contents_1_t *display);
102 virtual bool prepare(hwc_display_contents_1_t *display);
103 virtual bool commit(hwc_display_contents_1_t *display,
Andy Qiu4b834ce2013-04-09 18:23:20 -0700104 IDisplayContext *context);
Andy Qiu8a427142013-04-05 17:41:58 -0700105
Andy Qiueb726af2013-05-31 11:51:49 +0800106 virtual bool vsyncControl(bool enabled);
107 virtual bool blank(bool blank);
Andy Qiu0131f122013-07-19 14:51:20 -0700108 virtual bool getDisplaySize(int *width, int *height);
Andy Qiu8a427142013-04-05 17:41:58 -0700109 virtual bool getDisplayConfigs(uint32_t *configs,
110 size_t *numConfigs);
111 virtual bool getDisplayAttributes(uint32_t config,
112 const uint32_t *attributes,
113 int32_t *values);
114 virtual bool compositionComplete();
115 virtual bool initialize();
fu jine2ad4c02013-05-28 13:47:51 -0700116 virtual void deinitialize();
Andy Qiu8a427142013-04-05 17:41:58 -0700117 virtual bool isConnected() const;
118 virtual const char* getName() const;
119 virtual int getType() const;
120 virtual void dump(Dump& d);
121
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700122 // IFrameServer methods
Ashish Singhi77b747d2013-04-26 14:30:05 -0700123 virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener, bool disableExtVideoMode);
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700124 virtual android::status_t stop(bool isConnected);
125 virtual android::status_t notifyBufferReturned(int index);
Ashish Singhi77b747d2013-04-26 14:30:05 -0700126 virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener);
Andy Qiu8a427142013-04-05 17:41:58 -0700127protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700128 virtual IVideoPayloadManager* createVideoPayloadManager() = 0;
Andy Qiu8a427142013-04-05 17:41:58 -0700129
130protected:
131 bool mInitialized;
132 Hwcomposer& mHwc;
133 DisplayPlaneManager& mDisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700134 IVideoPayloadManager *mPayloadManager;
Andy Qiu8a427142013-04-05 17:41:58 -0700135};
136
137}
138}
139
140#endif /* VIRTUAL_DEVICE_H */