blob: 747cf52691362f7a5c52fe0f38d63b99c209e740 [file] [log] [blame]
joshualitt3ebd0502016-02-09 07:18:08 -08001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef ThermalManager_DEFINED
9#define ThermalManager_DEFINED
10
bungemanbf521ff2016-02-17 13:13:44 -080011#include "../private/SkTArray.h"
joshualitt3ebd0502016-02-09 07:18:08 -080012#include "SkString.h"
joshualitt3ebd0502016-02-09 07:18:08 -080013
14#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
15# define THERMAL_MANAGER_SUPPORTED
16#endif
17
18#ifdef THERMAL_MANAGER_SUPPORTED
19
20/*
21 * This simple class monitors the thermal part of sysfs to ensure we don't trigger thermal events
22 */
23
24class ThermalManager {
25public:
26 ThermalManager(int32_t threshold, uint32_t sleepIntervalMs, uint32_t timeoutMs);
27
28 bool coolOffIfNecessary();
29
30private:
31 static int32_t OpenFileAndReadInt32(const char* path);
32
33 // current temperature can be read from /thermalZonePath/temp
34 static int32_t GetTemp(SkString thermalZonePath) {
35 SkString temperatureFilePath(thermalZonePath);
36 temperatureFilePath.appendf("/temp");
37 return OpenFileAndReadInt32(temperatureFilePath.c_str());
38 }
39
40 struct TripPoint {
41 TripPoint(SkString thermalZoneRoot, SkString pointName, int32_t threshold);
42
43 bool willTrip();
44
45 SkString fThermalZoneRoot;
46 SkString fPointName;
47 int32_t fBase;
48 int32_t fPoint;
49 int32_t fThreshold;
50
51 // Certain trip points seem to start tripped. For example, I have seen trip points of 0 or
52 // negative numbers.
53 bool fDisabled;
54 };
55
56 SkTArray<TripPoint> fTripPoints;
57 uint32_t fSleepIntervalMs;
58 uint32_t fTimeoutMs;
59};
60#endif
61#endif