blob: 6f950c0c25a9cf90e408079346d3f42e9c92aadf [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
13* * Neither the name of Code Aurora Forum, Inc. nor the names of its
14* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifndef OVERLAY_IMPL_H
31#define OVERLAY_IMPL_H
32
33#include "overlayUtils.h"
34#include "overlayRotator.h"
35
Naseer Ahmed29a26812012-06-14 00:56:20 -070036namespace overlay {
37
38// Interface only. No member, no definiton (except ~ which can
39// also be =0 with impl in cpp)
40class OverlayImplBase {
41public:
42 /* empty dtor. can be =0 with cpp impl*/
43 virtual ~OverlayImplBase() {}
44
Naseer Ahmedf48aef62012-07-20 09:05:53 -070045 /* Init pipe/rot for one dest */
46 virtual bool initPipe(RotatorBase* rot, utils::eDest dest) = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -070047
48 /* Close pipe/rot for all specified dest */
49 virtual bool closePipe(utils::eDest dest) = 0;
50
51 /* Copy specified pipe/rot from ov passed in (used by state machine only) */
52 virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest) = 0;
53
Naseer Ahmedf48aef62012-07-20 09:05:53 -070054 /* Init all pipes
55 * To init just one pipe, use initPipe()
Naseer Ahmed29a26812012-06-14 00:56:20 -070056 * */
Naseer Ahmedf48aef62012-07-20 09:05:53 -070057 virtual bool init(RotatorBase* rot0,
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 RotatorBase* rot1,
59 RotatorBase* rot2) = 0;
60
61 /* Close all pipes
62 * To close just one pipe, use closePipe()
63 * */
64 virtual bool close() = 0;
65
66 /*
67 * Commit changes to the overlay
68 * */
69 virtual bool commit(utils::eDest dest = utils::OV_PIPE_ALL) = 0;
70
Naseer Ahmedf48aef62012-07-20 09:05:53 -070071 /* Queue buffer with fd from an offset*/
72 virtual bool queueBuffer(int fd, uint32_t offset,
Naseer Ahmed29a26812012-06-14 00:56:20 -070073 utils::eDest dest = utils::OV_PIPE_ALL) = 0;
74
75 /* Wait for vsync to be done on dest */
76 virtual bool waitForVsync(utils::eDest dest = utils::OV_PIPE1) = 0;
77
78 /* Crop existing destination using Dim coordinates */
79 virtual bool setCrop(const utils::Dim& d,
80 utils::eDest dest = utils::OV_PIPE_ALL) = 0;
81
82 /* Set new position using Dim */
83 virtual bool setPosition(const utils::Dim& dim,
84 utils::eDest dest = utils::OV_PIPE_ALL) = 0;
85
86 /* Set parameters - usually needed for Rotator, but would
87 * be passed down the stack as well */
Naseer Ahmedf48aef62012-07-20 09:05:53 -070088 virtual bool setTransform(const utils::eTransform& param,
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 utils::eDest dest = utils::OV_PIPE_ALL) = 0;
90
91 /* Set new source including orientation */
92 virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES],
93 utils::eDest dest = utils::OV_PIPE_ALL) = 0;
94
Naseer Ahmed29a26812012-06-14 00:56:20 -070095 /* Get the overlay pipe type */
96 virtual utils::eOverlayPipeType getOvPipeType(utils::eDest dest) const = 0;
97
98 /* Dump underlying state */
99 virtual void dump() const = 0;
100};
101
102class NullPipe {
103public:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 bool init(RotatorBase* rot) { return true; }
105 bool close() { return true; }
106 bool start(const utils::PipeArgs& args) { return true; }
107 bool commit() { return true; }
108 bool setCrop(const utils::Dim& d) { return true; }
109 bool setPosition(const utils::Dim& dim) { return true; }
110 bool setTransform(const utils::eTransform& param) { return true; }
111 bool setSource(const utils::PipeArgs& args) { return true; }
112 bool queueBuffer(int fd, uint32_t offset) { return true; }
113 bool waitForVsync() { return true; }
114 // NullPipe will return by val here as opposed to other Pipes.
115 utils::eOverlayPipeType getOvPipeType() const {
116 return utils::OV_PIPE_TYPE_NULL;
117 }
118 void dump() const {}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119};
120
121/*
122* Each pipe is not specific to a display (primary/external). The order in the
123* template params, will setup the priorities of the pipes.
124* */
125template <class P0, class P1=NullPipe, class P2=NullPipe>
126class OverlayImpl : public OverlayImplBase {
127public:
128 typedef P0 pipe0;
129 typedef P1 pipe1;
130 typedef P2 pipe2;
131
132 /* ctor */
133 OverlayImpl();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134
135 /*
136 * Comments of the below functions are the same as the one
137 * in OverlayImplBase.
138 * */
139 virtual ~OverlayImpl();
140
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700141 virtual bool initPipe(RotatorBase* rot, utils::eDest dest);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700142 virtual bool closePipe(utils::eDest dest);
143 virtual bool copyOvPipe(OverlayImplBase* ov, utils::eDest dest);
144
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700145 virtual bool init(RotatorBase* rot0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700146 RotatorBase* rot1,
147 RotatorBase* rot2);
148 virtual bool close();
149 virtual bool commit(utils::eDest dest = utils::OV_PIPE_ALL);
150 virtual bool setCrop(const utils::Dim& d,
151 utils::eDest dest = utils::OV_PIPE_ALL);
152 virtual bool setPosition(const utils::Dim& dim,
153 utils::eDest dest = utils::OV_PIPE_ALL);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700154 virtual bool setTransform(const utils::eTransform& param,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155 utils::eDest dest = utils::OV_PIPE_ALL);
156 virtual bool setSource(const utils::PipeArgs[utils::MAX_PIPES],
157 utils::eDest dest = utils::OV_PIPE_ALL);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700158 virtual bool queueBuffer(int fd, uint32_t offset,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700159 utils::eDest dest = utils::OV_PIPE_ALL);
160 virtual bool waitForVsync(utils::eDest dest = utils::OV_PIPE1);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161 virtual utils::eOverlayPipeType getOvPipeType(utils::eDest dest) const;
162 virtual void dump() const;
163
164private:
165 P0* mPipe0;
166 P1* mPipe1;
167 P2* mPipe2;
168 // More Px here in the future as needed
169
170 /* */
171
172 /* Each Px has it's own Rotator here.
173 * will pass rotator to the lower layer in stack
174 * but only overlay is allowed to control the lifetime
175 * of the rotator instace */
176 RotatorBase* mRotP0;
177 RotatorBase* mRotP1;
178 RotatorBase* mRotP2;
179};
180
181
182
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183//-----------Inlines and Template defn---------------------------------
184
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185/**** OverlayImpl ****/
186
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187template <class P0, class P1, class P2>
188OverlayImpl<P0, P1, P2>::OverlayImpl() :
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189 mPipe0(0), mPipe1(0), mPipe2(0),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190 mRotP0(0), mRotP1(0), mRotP2(0)
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700191{
192 //Do not create a pipe here.
193 //Either initPipe can create a pipe OR
194 //copyOvPipe can assign a pipe.
195}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196
197template <class P0, class P1, class P2>
198OverlayImpl<P0, P1, P2>::~OverlayImpl()
199{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700200 //Do not delete pipes.
201 //closePipe will close and delete.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202}
203
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700204/* Init only one pipe/rot pair per call */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700205template <class P0, class P1, class P2>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700206bool OverlayImpl<P0, P1, P2>::initPipe(RotatorBase* rot, utils::eDest dest)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207{
208 OVASSERT(rot, "%s: OverlayImpl rot is null", __FUNCTION__);
209 OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d",
210 __FUNCTION__, dest);
211
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212 bool ret = true;
213
214 if (utils::OV_PIPE0 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700215 ALOGE_IF(DEBUG_OVERLAY, "init pipe0");
216
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217 mRotP0 = rot;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700218 ret = mRotP0->init();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 if(!ret) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700220 ALOGE("%s: OverlayImpl rot0 failed to init", __FUNCTION__);
221 return false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700222 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700223
224 mPipe0 = new P0();
225 OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__);
226 ret = mPipe0->init(rot);
227 if(!ret) {
228 ALOGE("%s: OverlayImpl pipe0 failed to init", __FUNCTION__);
229 return false;
230 }
231
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232 return ret;
233 }
234
235 if (utils::OV_PIPE1 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700236 ALOGE_IF(DEBUG_OVERLAY, "init pipe1");
237
Naseer Ahmed29a26812012-06-14 00:56:20 -0700238 mRotP1 = rot;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700239 ret = mRotP1->init();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240 if(!ret) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700241 ALOGE("%s: OverlayImpl rot1 failed to init", __FUNCTION__);
242 return false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700244
245 mPipe1 = new P1();
246 OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__);
247 ret = mPipe1->init(rot);
248 if(!ret) {
249 ALOGE("%s: OverlayImpl pipe1 failed to init", __FUNCTION__);
250 return false;
251 }
252
Naseer Ahmed29a26812012-06-14 00:56:20 -0700253 return ret;
254 }
255
256 if (utils::OV_PIPE2 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700257 ALOGE_IF(DEBUG_OVERLAY, "init pipe2");
258
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259 mRotP2 = rot;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700260 ret = mRotP2->init();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700261 if(!ret) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700262 ALOGE("%s: OverlayImpl rot2 failed to init", __FUNCTION__);
263 return false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700264 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700265
266 mPipe2 = new P2();
267 OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__);
268 ret = mPipe2->init(rot);
269 if(!ret) {
270 ALOGE("%s: OverlayImpl pipe2 failed to init", __FUNCTION__);
271 return false;
272 }
273
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274 return ret;
275 }
276
277 // Should have returned by here
278 return false;
279}
280
281/* Close pipe/rot for all specified dest */
282template <class P0, class P1, class P2>
283bool OverlayImpl<P0, P1, P2>::closePipe(utils::eDest dest)
284{
285 OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d",
286 __FUNCTION__, dest);
287
288 if (utils::OV_PIPE0 & dest) {
289 // Close pipe0
290 OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__);
291 ALOGE_IF(DEBUG_OVERLAY, "Close pipe0");
292 if (!mPipe0->close()) {
293 ALOGE("%s: OverlayImpl failed to close pipe0", __FUNCTION__);
294 return false;
295 }
296 delete mPipe0;
297 mPipe0 = 0;
298
299 // Close the rotator for pipe0
300 OVASSERT(mRotP0, "%s: OverlayImpl rot0 is null", __FUNCTION__);
301 if (!mRotP0->close()) {
302 ALOGE("%s: OverlayImpl failed to close rot for pipe0", __FUNCTION__);
303 }
304 delete mRotP0;
305 mRotP0 = 0;
306 }
307
308 if (utils::OV_PIPE1 & dest) {
309 // Close pipe1
310 OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__);
311 ALOGE_IF(DEBUG_OVERLAY, "Close pipe1");
312 if (!mPipe1->close()) {
313 ALOGE("%s: OverlayImpl failed to close pipe1", __FUNCTION__);
314 return false;
315 }
316 delete mPipe1;
317 mPipe1 = 0;
318
319 // Close the rotator for pipe1
320 OVASSERT(mRotP1, "%s: OverlayImpl rot1 is null", __FUNCTION__);
321 if (!mRotP1->close()) {
322 ALOGE("%s: OverlayImpl failed to close rot for pipe1", __FUNCTION__);
323 }
324 delete mRotP1;
325 mRotP1 = 0;
326 }
327
328 if (utils::OV_PIPE2 & dest) {
329 // Close pipe2
330 OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__);
331 ALOGE_IF(DEBUG_OVERLAY, "Close pipe2");
332 if (!mPipe2->close()) {
333 ALOGE("%s: OverlayImpl failed to close pipe2", __FUNCTION__);
334 return false;
335 }
336 delete mPipe2;
337 mPipe2 = 0;
338
339 // Close the rotator for pipe2
340 OVASSERT(mRotP2, "%s: OverlayImpl rot2 is null", __FUNCTION__);
341 if (!mRotP2->close()) {
342 ALOGE("%s: OverlayImpl failed to close rot for pipe2", __FUNCTION__);
343 }
344 delete mRotP2;
345 mRotP2 = 0;
346 }
347
348 return true;
349}
350
351/* Copy pipe/rot from ov for all specified dest */
352template <class P0, class P1, class P2>
353bool OverlayImpl<P0, P1, P2>::copyOvPipe(OverlayImplBase* ov,
354 utils::eDest dest)
355{
356 OVASSERT(ov, "%s: OverlayImpl ov is null", __FUNCTION__);
357 OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d",
358 __FUNCTION__, dest);
359
360 OverlayImpl<P0, P1, P2>* ovimpl = static_cast<OverlayImpl<P0, P1, P2>*>(ov);
361
362 if (utils::OV_PIPE0 & dest) {
363 mPipe0 = ovimpl->mPipe0;
364 mRotP0 = ovimpl->mRotP0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700365 ovimpl->mPipe0 = 0;
366 ovimpl->mRotP0 = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367 }
368
369 if (utils::OV_PIPE1 & dest) {
370 mPipe1 = ovimpl->mPipe1;
371 mRotP1 = ovimpl->mRotP1;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700372 ovimpl->mPipe1 = 0;
373 ovimpl->mRotP1 = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374 }
375
376 if (utils::OV_PIPE2 & dest) {
377 mPipe2 = ovimpl->mPipe2;
378 mRotP2 = ovimpl->mRotP2;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700379 ovimpl->mPipe2 = 0;
380 ovimpl->mRotP2 = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 }
382
383 return true;
384}
385
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700386/* Init all pipes/rot */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700387template <class P0, class P1, class P2>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700388bool OverlayImpl<P0, P1, P2>::init(RotatorBase* rot0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700389 RotatorBase* rot1,
390 RotatorBase* rot2)
391{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700392 if (!this->initPipe(rot0, utils::OV_PIPE0)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700393 if (!this->close()) {
394 ALOGE("%s: failed to close at least one pipe", __FUNCTION__);
395 }
396 return false;
397 }
398
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700399 if (!this->initPipe(rot1, utils::OV_PIPE1)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400 if (!this->close()) {
401 ALOGE("%s: failed to close at least one pipe", __FUNCTION__);
402 }
403 return false;
404 }
405
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700406 if (!this->initPipe(rot2, utils::OV_PIPE2)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700407 if (!this->close()) {
408 ALOGE("%s: failed to close at least one pipe", __FUNCTION__);
409 }
410 return false;
411 }
412
413 return true;
414}
415
416/* Close all pipes/rot */
417template <class P0, class P1, class P2>
418bool OverlayImpl<P0, P1, P2>::close()
419{
420 if (!this->closePipe(utils::OV_PIPE_ALL)) {
421 return false;
422 }
423
424 return true;
425}
426
427template <class P0, class P1, class P2>
428bool OverlayImpl<P0, P1, P2>::commit(utils::eDest dest)
429{
430 OVASSERT(mPipe0 && mPipe1 && mPipe2,
431 "%s: Pipes are null p0=%p p1=%p p2=%p",
432 __FUNCTION__, mPipe0, mPipe1, mPipe2);
433
434 if (utils::OV_PIPE0 & dest) {
435 if(!mPipe0->commit()) {
436 ALOGE("OverlayImpl p0 failed to commit");
437 return false;
438 }
439 }
440
441 if (utils::OV_PIPE1 & dest) {
442 if(!mPipe1->commit()) {
443 ALOGE("OverlayImpl p1 failed to commit");
444 return false;
445 }
446 }
447
448 if (utils::OV_PIPE2 & dest) {
449 if(!mPipe2->commit()) {
450 ALOGE("OverlayImpl p2 failed to commit");
451 return false;
452 }
453 }
454
455 return true;
456}
457
458template <class P0, class P1, class P2>
459bool OverlayImpl<P0, P1, P2>::setCrop(const utils::Dim& d, utils::eDest dest)
460{
461 OVASSERT(mPipe0 && mPipe1 && mPipe2,
462 "%s: Pipes are null p0=%p p1=%p p2=%p",
463 __FUNCTION__, mPipe0, mPipe1, mPipe2);
464
465 if (utils::OV_PIPE0 & dest) {
466 if(!mPipe0->setCrop(d)) {
467 ALOGE("OverlayImpl p0 failed to crop");
468 return false;
469 }
470 }
471
472 if (utils::OV_PIPE1 & dest) {
473 if(!mPipe1->setCrop(d)) {
474 ALOGE("OverlayImpl p1 failed to crop");
475 return false;
476 }
477 }
478
479 if (utils::OV_PIPE2 & dest) {
480 if(!mPipe2->setCrop(d)) {
481 ALOGE("OverlayImpl p2 failed to crop");
482 return false;
483 }
484 }
485
486 return true;
487}
488
489template <class P0, class P1, class P2>
490bool OverlayImpl<P0, P1, P2>::setPosition(const utils::Dim& d,
491 utils::eDest dest)
492{
493 OVASSERT(mPipe0 && mPipe1 && mPipe2,
494 "%s: Pipes are null p0=%p p1=%p p2=%p",
495 __FUNCTION__, mPipe0, mPipe1, mPipe2);
496
497 if (utils::OV_PIPE0 & dest) {
498 if(!mPipe0->setPosition(d)) {
499 ALOGE("OverlayImpl p0 failed to setpos");
500 return false;
501 }
502 }
503
504 if (utils::OV_PIPE1 & dest) {
505 if(!mPipe1->setPosition(d)) {
506 ALOGE("OverlayImpl p1 failed to setpos");
507 return false;
508 }
509 }
510
511 if (utils::OV_PIPE2 & dest) {
512 if(!mPipe2->setPosition(d)) {
513 ALOGE("OverlayImpl p2 failed to setpos");
514 return false;
515 }
516 }
517
518 return true;
519}
520
521template <class P0, class P1, class P2>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700522bool OverlayImpl<P0, P1, P2>::setTransform(const utils::eTransform& param,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700523 utils::eDest dest)
524{
525 OVASSERT(mPipe0 && mPipe1 && mPipe2,
526 "%s: Pipes are null p0=%p p1=%p p2=%p",
527 __FUNCTION__, mPipe0, mPipe1, mPipe2);
528
529 if (utils::OV_PIPE0 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700530 if(!mPipe0->setTransform(param)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700531 ALOGE("OverlayImpl p0 failed to setparam");
532 return false;
533 }
534 }
535
536 if (utils::OV_PIPE1 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700537 if(!mPipe1->setTransform(param)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700538 ALOGE("OverlayImpl p1 failed to setparam");
539 return false;
540 }
541 }
542
543 if (utils::OV_PIPE2 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700544 if(!mPipe2->setTransform(param)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700545 ALOGE("OverlayImpl p2 failed to setparam");
546 return false;
547 }
548 }
549
550 return true;
551}
552
553template <class P0, class P1, class P2>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700554bool OverlayImpl<P0, P1, P2>::setSource(
555 const utils::PipeArgs args[utils::MAX_PIPES],
Naseer Ahmed29a26812012-06-14 00:56:20 -0700556 utils::eDest dest)
557{
558 OVASSERT(mPipe0 && mPipe1 && mPipe2,
559 "%s: Pipes are null p0=%p p1=%p p2=%p",
560 __FUNCTION__, mPipe0, mPipe1, mPipe2);
561
562 if (utils::OV_PIPE0 & dest) {
563 if(!mPipe0->setSource(args[0])) {
564 ALOGE("OverlayImpl p0 failed to setsrc");
565 return false;
566 }
567 }
568
569 if (utils::OV_PIPE1 & dest) {
570 if(!mPipe1->setSource(args[1])) {
571 ALOGE("OverlayImpl p1 failed to setsrc");
572 return false;
573 }
574 }
575
576 if (utils::OV_PIPE2 & dest) {
577 if(!mPipe2->setSource(args[2])) {
578 ALOGE("OverlayImpl p2 failed to setsrc");
579 return false;
580 }
581 }
582
583 return true;
584}
585
586template <class P0, class P1, class P2>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700587bool OverlayImpl<P0, P1, P2>::queueBuffer(int fd, uint32_t offset,
588 utils::eDest dest)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700589{
590 OVASSERT(mPipe0 && mPipe1 && mPipe2,
591 "%s: Pipes are null p0=%p p1=%p p2=%p",
592 __FUNCTION__, mPipe0, mPipe1, mPipe2);
593
594 if (utils::OV_PIPE0 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700595 if(!mPipe0->queueBuffer(fd, offset)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700596 ALOGE("OverlayImpl p0 failed to queueBuffer");
597 return false;
598 }
599 }
600
601 if (utils::OV_PIPE1 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700602 if(!mPipe1->queueBuffer(fd, offset)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700603 ALOGE("OverlayImpl p1 failed to queueBuffer");
604 return false;
605 }
606 }
607
608 if (utils::OV_PIPE2 & dest) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700609 if(!mPipe2->queueBuffer(fd, offset)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700610 ALOGE("OverlayImpl p2 failed to queueBuffer");
611 return false;
612 }
613 }
614
615 return true;
616}
617
618template <class P0, class P1, class P2>
Naseer Ahmed29a26812012-06-14 00:56:20 -0700619bool OverlayImpl<P0, P1, P2>::waitForVsync(utils::eDest dest)
620{
621 OVASSERT(mPipe0 && mPipe1 && mPipe2,
622 "%s: Pipes are null p0=%p p1=%p p2=%p",
623 __FUNCTION__, mPipe0, mPipe1, mPipe2);
624
625 if (utils::OV_PIPE0 & dest) {
626 if(!mPipe0->waitForVsync()) {
627 ALOGE("OverlayImpl p0 failed to waitForVsync");
628 return false;
629 }
630 }
631
632 if (utils::OV_PIPE1 & dest) {
633 if(!mPipe1->waitForVsync()) {
634 ALOGE("OverlayImpl p1 failed to waitForVsync");
635 return false;
636 }
637 }
638
639 if (utils::OV_PIPE2 & dest) {
640 if(!mPipe2->waitForVsync()) {
641 ALOGE("OverlayImpl p2 failed to waitForVsync");
642 return false;
643 }
644 }
645
646 return true;
647}
648
649template <class P0, class P1, class P2>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700650utils::eOverlayPipeType OverlayImpl<P0, P1, P2>::getOvPipeType(
651 utils::eDest dest) const
Naseer Ahmed29a26812012-06-14 00:56:20 -0700652{
653 OVASSERT(utils::isValidDest(dest), "%s: OverlayImpl invalid dest=%d",
654 __FUNCTION__, dest);
655
656 if (utils::OV_PIPE0 & dest) {
657 OVASSERT(mPipe0, "%s: OverlayImpl pipe0 is null", __FUNCTION__);
658 return mPipe0->getOvPipeType();
659 }
660
661 if (utils::OV_PIPE1 & dest) {
662 OVASSERT(mPipe1, "%s: OverlayImpl pipe1 is null", __FUNCTION__);
663 return mPipe1->getOvPipeType();
664 }
665
666 if (utils::OV_PIPE2 & dest) {
667 OVASSERT(mPipe2, "%s: OverlayImpl pipe2 is null", __FUNCTION__);
668 return mPipe2->getOvPipeType();
669 }
670
671 // Should never get here
672 return utils::OV_PIPE_TYPE_NULL;
673}
674
675template <class P0, class P1, class P2>
676void OverlayImpl<P0, P1, P2>::dump() const
677{
678 OVASSERT(mPipe0 && mPipe1 && mPipe2,
679 "%s: Pipes are null p0=%p p1=%p p2=%p",
680 __FUNCTION__, mPipe0, mPipe1, mPipe2);
681 ALOGE("== Dump OverlayImpl dump start ROT p0 ==");
682 mRotP0->dump();
683 ALOGE("== Dump OverlayImpl dump end ROT p0 ==");
684 ALOGE("== Dump OverlayImpl dump start ROT p1 ==");
685 mRotP1->dump();
686 ALOGE("== Dump OverlayImpl dump end ROT p1 ==");
687 ALOGE("== Dump OverlayImpl dump start ROT p2 ==");
688 mRotP2->dump();
689 ALOGE("== Dump OverlayImpl dump end ROT p2 ==");
690 ALOGE("== Dump OverlayImpl dump start p0 ==");
691 mPipe0->dump();
692 ALOGE("== Dump OverlayImpl dump end p0 ==");
693 ALOGE("== Dump OverlayImpl dump start p1 ==");
694 mPipe1->dump();
695 ALOGE("== Dump OverlayImpl dump end p1 ==");
696 ALOGE("== Dump OverlayImpl dump start p2 ==");
697 mPipe2->dump();
698 ALOGE("== Dump OverlayImpl dump end p2 ==");
699}
700
701
702} // overlay
703
704#endif // OVERLAY_IMPL_H