-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathSkImageUtility.h
118 lines (108 loc) · 3.53 KB
/
SkImageUtility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (C) Texas Instruments - http://www.ti.com/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* ==============================================================================
* Texas Instruments OMAP (TM) Platform Software
* (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
*
* Use of this software is controlled by the terms and conditions found
* in the license agreement under which this software has been supplied.
* ============================================================================ */
#ifndef SKIAHW_UTILITY_H
#define SKIAHW_UTILITY_H
#include <string.h>
#include <time.h>
#include "SkBitmap.h"
#include "SkStream.h"
#include "SkTemplates.h"
#include <stdio.h>
#include <semaphore.h>
#include <utils/threads.h>
#include <utils/List.h>
#include <sys/types.h>
#include <time.h>
extern "C" {
#include "OMX_Component.h"
#include "OMX_IVCommon.h"
}
#define ALIGN_128_BYTE 128
template <class TYPE>
class WatchdogThread : public android::Thread
{
public:
WatchdogThread(TYPE* caller, void* caller_param, nsecs_t time):
android::Thread(false),
mCaller(caller),
mCallerParam(caller_param),
mTime(time){};
virtual ~WatchdogThread(){SkDebugf("~WatchdogThread()");}
void restart(){
android::Mutex::Autolock autolock(mLock);
mRestartTimer.signal();
}
virtual bool threadLoop(){
android::status_t err;
bool restart = false;
SkDebugf("WatchdogThread: Entering threadLoop()");
for(;;){
android::Mutex::Autolock autolock(mLock);
// SkDebugf("WatchdogThread: waitRelative %l", mTime);
err = mRestartTimer.waitRelative(mLock, mTime);
// SkDebugf("WatchdogThread: waitRelative done %d", err);
if(err == -ETIMEDOUT){
break;
}
}
// class that instantiates WatchdogThread must implement a "bool WatchdogCallback(void*)" function
// i know...not the best practice
restart = mCaller->WatchdogCallback(mCallerParam);
return restart;
}
private:
android::Condition mRestartTimer;
TYPE* mCaller;
void* mCallerParam;
android::Mutex mLock;
nsecs_t mTime;
};
template <class CODEC_TYPE, class WATCHDOG_TYPE>
class SkTIJPEGImageCodecList_Item
{
public:
CODEC_TYPE* Codec;
android::sp<WATCHDOG_TYPE> WatchdogTimer;
};
// gives a way to increment mLoad and automatically decrement when this class instantiation goes out of scope
class AutoTrackLoad
{
public:
AutoTrackLoad(int& load){
load++;
this->load_ptr = &load;
}
~AutoTrackLoad(){
(*load_ptr)--;
}
private:
int* load_ptr;
};
//Utility functions
OMX_COLOR_FORMATTYPE SkBitmapToOMXColorFormat(SkBitmap::Config config);
OMX_COLOR_FORMATTYPE JPEGToOMXColorFormat(int format);
#endif