Merge "Updated permission for layer trace proto file."
diff --git a/cmds/cmd/cmd.cpp b/cmds/cmd/cmd.cpp
index 7b4aeb2..8dad475 100644
--- a/cmds/cmd/cmd.cpp
+++ b/cmds/cmd/cmd.cpp
@@ -223,7 +223,8 @@
sp<MyResultReceiver> result = new MyResultReceiver();
#if DEBUG
- ALOGD("cmd: Invoking %s in=%d, out=%d, err=%d", cmd, in, out, err);
+ ALOGD("cmd: Invoking %.*s in=%d, out=%d, err=%d",
+ static_cast<int>(cmd.size()), cmd.data(), in, out, err);
#endif
// TODO: block until a result is returned to MyResultReceiver.
diff --git a/include/android/imagedecoder.h b/include/android/imagedecoder.h
index 469b088..31efa65 100644
--- a/include/android/imagedecoder.h
+++ b/include/android/imagedecoder.h
@@ -133,7 +133,7 @@
/**
* Choose the desired output format.
*
- * @param format AndroidBitmapFormat to use
+ * @param format {@link AndroidBitmapFormat} to use for the output.
* @return {@link ANDROID_IMAGE_DECODER_SUCCESS} if the format is compatible
* with the image and {@link ANDROID_IMAGE_DECODER_INVALID_CONVERSION}
* otherwise. In the latter case, the AImageDecoder uses the
@@ -196,7 +196,7 @@
* pointer is null, width or height is <= 0, or any existing crop is
* not contained by the image dimensions.
*/
-int AImageDecoder_setTargetSize(AImageDecoder*, int width, int height) __INTRODUCED_IN(30);
+int AImageDecoder_setTargetSize(AImageDecoder*, int32_t width, int32_t height) __INTRODUCED_IN(30);
/**
@@ -219,7 +219,7 @@
* @return ANDROID_IMAGE_DECODER result code.
*/
int AImageDecoder_computeSampledSize(const AImageDecoder*, int sampleSize,
- int* width, int* height) __INTRODUCED_IN(30);
+ int32_t* width, int32_t* height) __INTRODUCED_IN(30);
/**
* Specify how to crop the output after scaling (if any).
*
@@ -276,18 +276,12 @@
const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
/**
- * Report whether the encoded image represents an animation.
- */
-bool AImageDecoderHeaderInfo_isAnimated(
- const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
-
-/**
- * Report the AndroidBitmapFormat the AImageDecoder will decode to
+ * Report the {@link AndroidBitmapFormat} the AImageDecoder will decode to
* by default. AImageDecoder will try to choose one that is sensible
* for the image and the system. Note that this does not indicate the
* encoded format of the image.
*/
-AndroidBitmapFormat AImageDecoderHeaderInfo_getAndroidBitmapFormat(
+int32_t AImageDecoderHeaderInfo_getAndroidBitmapFormat(
const AImageDecoderHeaderInfo*) __INTRODUCED_IN(30);
/**
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index 31abb66..157b424 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -407,6 +407,33 @@
#endif // __ANDROID_API__ >= 29
+#if __ANDROID_API__ >= 30
+
+/*
+ * Sets the intended frame rate for |surface_control|.
+ *
+ * On devices that are capable of running the display at different refresh rates, the system may
+ * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't
+ * directly affect the application's frame production pipeline. However, because the system may
+ * change the display refresh rate, calls to this function may result in changes to Choreographer
+ * callback timings, and changes to the time interval at which the system releases buffers back to
+ * the application.
+ *
+ * |frameRate| is the intended frame rate of this surface. 0 is a special value that indicates the
+ * app will accept the system's choice for the display frame rate, which is the default behavior if
+ * this function isn't called. The frameRate param does *not* need to be a valid refresh rate for
+ * this device's display - e.g., it's fine to pass 30fps to a device that can only run the display
+ * at 60fps.
+ *
+ * Available since API level 30.
+ */
+void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction,
+ ASurfaceControl* surface_control,
+ float frameRate)
+ __INTRODUCED_IN(30);
+
+#endif // __ANDROID_API__ >= 30
+
__END_DECLS
#endif // ANDROID_SURFACE_CONTROL_H
diff --git a/libs/nativewindow/ANativeWindow.cpp b/libs/nativewindow/ANativeWindow.cpp
index 842af18..a60bc4d 100644
--- a/libs/nativewindow/ANativeWindow.cpp
+++ b/libs/nativewindow/ANativeWindow.cpp
@@ -158,6 +158,13 @@
return query(window, NATIVE_WINDOW_DATASPACE);
}
+int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) {
+ if (!window || !query(window, NATIVE_WINDOW_IS_VALID) || frameRate < 0) {
+ return -EINVAL;
+ }
+ return native_window_set_frame_rate(window, frameRate);
+}
+
/**************************************************************************************************
* vndk-stable
**************************************************************************************************/
diff --git a/libs/nativewindow/include/android/native_window.h b/libs/nativewindow/include/android/native_window.h
index 3e436e3..0637db3 100644
--- a/libs/nativewindow/include/android/native_window.h
+++ b/libs/nativewindow/include/android/native_window.h
@@ -230,6 +230,39 @@
#endif // __ANDROID_API__ >= 28
+#if __ANDROID_API__ >= 30
+
+/**
+ * Sets the intended frame rate for this window.
+ *
+ * On devices that are capable of running the display at different refresh
+ * rates, the system may choose a display refresh rate to better match this
+ * window's frame rate. Usage of this API won't introduce frame rate throttling,
+ * or affect other aspects of the application's frame production
+ * pipeline. However, because the system may change the display refresh rate,
+ * calls to this function may result in changes to Choreographer callback
+ * timings, and changes to the time interval at which the system releases
+ * buffers back to the application.
+ *
+ * Note that this only has an effect for windows presented on the display. If
+ * this ANativeWindow is consumed by something other than the system compositor,
+ * e.g. a media codec, this call has no effect.
+ *
+ * Available since API level 30.
+ *
+ * \param frameRate The intended frame rate of this window. 0 is a special value
+ * that indicates the app will accept the system's choice for the display frame
+ * rate, which is the default behavior if this function isn't called. The
+ * frameRate param does *not* need to be a valid refresh rate for this device's
+ * display - e.g., it's fine to pass 30fps to a device that can only run the
+ * display at 60fps.
+ *
+ * \return 0 for success, -EINVAL if the window or frame rate are invalid.
+ */
+int32_t ANativeWindow_setFrameRate(ANativeWindow* window, float frameRate) __INTRODUCED_IN(30);
+
+#endif // __ANDROID_API__ >= 30
+
#ifdef __cplusplus
};
#endif
diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt
index f59e8f0..3002da2 100644
--- a/libs/nativewindow/libnativewindow.map.txt
+++ b/libs/nativewindow/libnativewindow.map.txt
@@ -43,6 +43,7 @@
ANativeWindow_setDequeueTimeout; # apex # introduced=30
ANativeWindow_setSharedBufferMode; # llndk
ANativeWindow_setSwapInterval; # llndk
+ ANativeWindow_setFrameRate; # introduced=30
ANativeWindow_setUsage; # llndk
ANativeWindow_unlockAndPost;
local:
diff --git a/libs/renderengine/gl/filters/BlurFilter.cpp b/libs/renderengine/gl/filters/BlurFilter.cpp
index a554687..a18a999 100644
--- a/libs/renderengine/gl/filters/BlurFilter.cpp
+++ b/libs/renderengine/gl/filters/BlurFilter.cpp
@@ -42,9 +42,20 @@
ATRACE_NAME("BlurFilter::setAsDrawTarget");
if (!mTexturesAllocated) {
- const uint32_t fboWidth = floorf(display.physicalDisplay.width() * kFboScale);
- const uint32_t fboHeight = floorf(display.physicalDisplay.height() * kFboScale);
- mCompositionFbo.allocateBuffers(fboWidth, fboHeight);
+ mDisplayWidth = display.physicalDisplay.width();
+ mDisplayHeight = display.physicalDisplay.height();
+ mCompositionFbo.allocateBuffers(mDisplayWidth, mDisplayHeight);
+
+ // Let's use mimap filtering on the offscreen composition texture,
+ // this will drastically improve overall shader quality.
+ glBindTexture(GL_TEXTURE_2D, mCompositionFbo.getTextureName());
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ const uint32_t fboWidth = floorf(mDisplayWidth * kFboScale);
+ const uint32_t fboHeight = floorf(mDisplayHeight * kFboScale);
mBlurredFbo.allocateBuffers(fboWidth, fboHeight);
allocateTextures();
mTexturesAllocated = true;
diff --git a/libs/renderengine/gl/filters/BlurFilter.h b/libs/renderengine/gl/filters/BlurFilter.h
index 2b5ea58..e265b51 100644
--- a/libs/renderengine/gl/filters/BlurFilter.h
+++ b/libs/renderengine/gl/filters/BlurFilter.h
@@ -30,7 +30,7 @@
class BlurFilter {
public:
// Downsample FBO to improve performance
- static constexpr float kFboScale = 0.35f;
+ static constexpr float kFboScale = 0.25f;
explicit BlurFilter(GLESRenderEngine& engine);
virtual ~BlurFilter(){};
@@ -54,6 +54,8 @@
GLFramebuffer mCompositionFbo;
// Frame buffer holding the blur result.
GLFramebuffer mBlurredFbo;
+ uint32_t mDisplayWidth;
+ uint32_t mDisplayHeight;
private:
bool mTexturesAllocated = false;
diff --git a/libs/renderengine/gl/filters/GaussianBlurFilter.cpp b/libs/renderengine/gl/filters/GaussianBlurFilter.cpp
index b1ad72c..f5ba02a 100644
--- a/libs/renderengine/gl/filters/GaussianBlurFilter.cpp
+++ b/libs/renderengine/gl/filters/GaussianBlurFilter.cpp
@@ -77,12 +77,14 @@
// set uniforms
auto width = mVerticalPassFbo.getBufferWidth();
auto height = mVerticalPassFbo.getBufferHeight();
+ auto radiusF = fmax(1.0f, radius * kFboScale);
glViewport(0, 0, width, height);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mCompositionFbo.getTextureName());
+ glGenerateMipmap(GL_TEXTURE_2D);
glUniform1i(mVTextureLoc, 0);
glUniform2f(mVSizeLoc, width, height);
- glUniform1f(mVRadiusLoc, radius * kFboScale);
+ glUniform1f(mVRadiusLoc, radiusF);
mEngine.checkErrors("Setting vertical-diagonal pass uniforms");
drawMesh(mVUvLoc, mVPosLoc);
@@ -96,7 +98,7 @@
glBindTexture(GL_TEXTURE_2D, mVerticalPassFbo.getTextureName());
glUniform1i(mHTextureLoc, 0);
glUniform2f(mHSizeLoc, width, height);
- glUniform1f(mHRadiusLoc, radius * kFboScale);
+ glUniform1f(mHRadiusLoc, radiusF);
mEngine.checkErrors("Setting vertical pass uniforms");
drawMesh(mHUvLoc, mHPosLoc);
@@ -122,8 +124,7 @@
uniform vec2 uSize;
uniform float uRadius;
- in mediump vec2 vUV;
-
+ mediump in vec2 vUV;
out vec4 fragColor;
#define PI 3.14159265359
@@ -131,7 +132,7 @@
#define MU 0.0
#define A 1.0 / (THETA * sqrt(2.0 * PI))
#define K 1.0 / (2.0 * THETA * THETA)
- #define MAX_SAMPLES 12
+ #define MAX_SAMPLES 10
float gaussianBellCurve(float x) {
float tmp = (x - MU);
@@ -139,14 +140,14 @@
}
vec3 gaussianBlur(sampler2D texture, mediump vec2 uv, float size,
- vec2 direction, float radius) {
+ mediump vec2 direction, float radius) {
float totalWeight = 0.0;
vec3 blurred = vec3(0.);
- int samples = min(int(floor(radius / 2.0)), MAX_SAMPLES);
+ int samples = min(int(ceil(radius / 2.0)), MAX_SAMPLES);
float inc = radius / (size * 2.0);
for (int i = -samples; i <= samples; i++) {
- float normalized = (float(i) / float(samples));
+ float normalized = float(i) / float(samples);
float weight = gaussianBellCurve(normalized);
float radInc = inc * normalized;
blurred += weight * (texture(texture, uv + radInc * direction)).rgb;;
@@ -162,7 +163,7 @@
#else
vec3 color = gaussianBlur(uTexture, vUV, uSize.y, vec2(0.0, 1.0), uRadius);
#endif
- fragColor = vec4(color.r, color.g, color.b, texture(uTexture, vUV).a);
+ fragColor = vec4(color, 1.0);
}
)SHADER";
diff --git a/libs/renderengine/gl/filters/LensBlurFilter.cpp b/libs/renderengine/gl/filters/LensBlurFilter.cpp
index 386bd91..799deac 100644
--- a/libs/renderengine/gl/filters/LensBlurFilter.cpp
+++ b/libs/renderengine/gl/filters/LensBlurFilter.cpp
@@ -86,12 +86,14 @@
// set uniforms
auto width = mVerticalDiagonalPassFbo.getBufferWidth();
auto height = mVerticalDiagonalPassFbo.getBufferHeight();
+ auto radiusF = fmax(1.0f, radius * kFboScale);
glViewport(0, 0, width, height);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mCompositionFbo.getTextureName());
+ glGenerateMipmap(GL_TEXTURE_2D);
glUniform1i(mVDTexture0Loc, 0);
- glUniform2f(mVDSizeLoc, width, height);
- glUniform1f(mVDRadiusLoc, radius * kFboScale);
+ glUniform2f(mVDSizeLoc, mDisplayWidth, mDisplayHeight);
+ glUniform1f(mVDRadiusLoc, radiusF);
glUniform1i(mVDNumSamplesLoc, kNumSamples);
mEngine.checkErrors("Setting vertical-diagonal pass uniforms");
@@ -108,8 +110,8 @@
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, mVerticalDiagonalPassFbo.getSecondaryTextureName());
glUniform1i(mCTexture1Loc, 1);
- glUniform2f(mCSizeLoc, width, height);
- glUniform1f(mCRadiusLoc, radius * kFboScale);
+ glUniform2f(mCSizeLoc, mDisplayWidth, mDisplayHeight);
+ glUniform1f(mCRadiusLoc, radiusF);
glUniform1i(mCNumSamplesLoc, kNumSamples);
mEngine.checkErrors("Setting vertical pass uniforms");
@@ -134,7 +136,6 @@
shader += R"SHADER(
precision lowp float;
- #define BOKEH_ANGLE 0.0
#define PI 3.14159265359
uniform sampler2D uTexture0;
@@ -142,7 +143,7 @@
uniform float uRadius;
uniform int uNumSamples;
- in mediump vec2 vUV;
+ mediump in vec2 vUV;
#if DIRECTION == 0
layout(location = 0) out vec4 fragColor0;
@@ -152,61 +153,55 @@
out vec4 fragColor;
#endif
- vec4 blur(const sampler2D tex, in vec2 uv, const vec2 direction, float radius,
- in int samples, float intensity) {
- vec4 finalColor = vec4(vec3(0.0), 1.0);
- float blurAmount = 0.0;
+ const vec2 verticalMult = vec2(cos(PI / 2.0), sin(PI / 2.0));
+ const vec2 diagonalMult = vec2(cos(-PI / 6.0), sin(-PI / 6.0));
+ const vec2 diagonal2Mult = vec2(cos(-5.0 * PI / 6.0), sin(-5.0 * PI / 6.0));
+
+ vec3 blur(const sampler2D tex, vec2 uv, const vec2 direction, float radius,
+ int samples, float intensity) {
+ vec3 finalColor = vec3(0.0);
uv += direction * 0.5;
for (int i = 0; i < samples; i++){
float delta = radius * float(i) / float(samples);
- vec4 color = texture(tex, uv + direction * delta);
+ vec3 color = texture(tex, uv + direction * delta).rgb;
color.rgb *= intensity;
- color *= color.a;
- blurAmount += color.a;
finalColor += color;
}
- return finalColor / blurAmount;
+ return finalColor / float(samples);
}
- vec4 blur(const sampler2D tex, in vec2 uv, const vec2 direction, float radius,
- in int samples) {
+ vec3 blur(const sampler2D tex, vec2 uv, const vec2 direction, float radius,
+ int samples) {
return blur(tex, uv, direction, radius, samples, 1.0);
}
vec4[2] verticalDiagonalLensBlur (vec2 uv, sampler2D texture, vec2 resolution,
float radius, int samples) {
- float coc = texture(texture, uv).a;
-
// Vertical Blur
- vec2 blurDirV = (coc / resolution.xy) * vec2(cos(BOKEH_ANGLE + PI / 2.0),
- sin(BOKEH_ANGLE + PI / 2.0));
- vec3 colorV = blur(texture, uv, blurDirV, radius, samples).rgb * coc;
+ vec2 blurDirV = 1.0 / resolution.xy * verticalMult;
+ vec3 colorV = blur(texture, uv, blurDirV, radius, samples);
// Diagonal Blur
- vec2 blurDirD = (coc / resolution.xy) * vec2(cos(BOKEH_ANGLE - PI / 6.0),
- sin(BOKEH_ANGLE - PI / 6.0));
- vec3 colorD = blur(texture, uv, blurDirD, radius, samples).rgb * coc;
+ vec2 blurDirD = 1.0 / resolution.xy * diagonalMult;
+ vec3 colorD = blur(texture, uv, blurDirD, radius, samples);
vec4 composed[2];
- composed[0] = vec4(colorV, coc);
+ composed[0] = vec4(colorV, 1.0);
// added * 0.5, to remap
- composed[1] = vec4((colorD + colorV) * 0.5, coc);
+ composed[1] = vec4((colorD + colorV) * 0.5, 1.0);
return composed;
}
vec4 rhombiLensBlur (vec2 uv, sampler2D texture0, sampler2D texture1, vec2 resolution,
float radius, int samples) {
- float coc1 = texture(texture0, uv).a;
- float coc2 = texture(texture1, uv).a;
+ vec2 blurDirection1 = 1.0 / resolution.xy * diagonalMult;
+ vec3 color1 = blur(texture0, uv, blurDirection1, radius, samples);
- vec2 blurDirection1 = coc1 / resolution.xy * vec2(cos(BOKEH_ANGLE - PI / 6.0), sin(BOKEH_ANGLE - PI / 6.0));
- vec3 color1 = blur(texture0, uv, blurDirection1, radius, samples).rgb * coc1;
-
- vec2 blurDirection2 = coc2 / resolution.xy * vec2(cos(BOKEH_ANGLE - 5.0 * PI / 6.0), sin(BOKEH_ANGLE - 5.0 * PI / 6.0));
- vec3 color2 = blur(texture1, uv, blurDirection2, radius, samples, 2.0).rgb * coc2;
+ vec2 blurDirection2 = 1.0 / resolution.xy * diagonal2Mult;
+ vec3 color2 = blur(texture1, uv, blurDirection2, radius, samples, 2.0);
return vec4((color1 + color2) * 0.33, 1.0);
}
diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp
index 55a0c0a..be4a462 100644
--- a/services/gpuservice/GpuService.cpp
+++ b/services/gpuservice/GpuService.cpp
@@ -28,12 +28,7 @@
#include <utils/String8.h>
#include <utils/Trace.h>
-#include <array>
-#include <fstream>
-#include <sstream>
-#include <sys/types.h>
#include <vkjson.h>
-#include <unistd.h>
#include "gpustats/GpuStats.h"
@@ -45,7 +40,6 @@
status_t cmdHelp(int out);
status_t cmdVkjson(int out, int err);
void dumpGameDriverInfo(std::string* result);
-void dumpMemoryInfo(std::string* result, const GpuMemoryMap& memories, uint32_t pid);
} // namespace
const String16 sDump("android.permission.DUMP");
@@ -78,147 +72,6 @@
mGpuStats->insertTargetStats(appPackageName, driverVersionCode, stats, value);
}
-bool isExpectedFormat(const char* str) {
- // Should match in order:
- // gpuaddr useraddr size id flags type usage sglen mapsize eglsrf eglimg
- std::istringstream iss;
- iss.str(str);
-
- std::string word;
- iss >> word;
- if (word != "gpuaddr") { return false; }
- iss >> word;
- if (word != "useraddr") { return false; }
- iss >> word;
- if (word != "size") { return false; }
- iss >> word;
- if (word != "id") { return false; }
- iss >> word;
- if (word != "flags") { return false; }
- iss >> word;
- if (word != "type") { return false; }
- iss >> word;
- if (word != "usage") { return false; }
- iss >> word;
- if (word != "sglen") { return false; }
- iss >> word;
- if (word != "mapsize") { return false; }
- iss >> word;
- if (word != "eglsrf") { return false; }
- iss >> word;
- if (word != "eglimg") { return false; }
- return true;
-}
-
-
-// Queries gpu memory via Qualcomm's /d/kgsl/proc/*/mem interface.
-status_t GpuService::getQCommGpuMemoryInfo(GpuMemoryMap* memories, std::string* result, int32_t dumpPid) const {
- const std::string kDirectoryPath = "/d/kgsl/proc";
- DIR* directory = opendir(kDirectoryPath.c_str());
- if (!directory) { return PERMISSION_DENIED; }
-
- // File Format:
- // gpuaddr useraddr size id flags type usage sglen mapsize eglsrf eglimg
- // 0000000000000000 0000000000000000 8359936 23 --w--pY-- gpumem VK/others( 38) 0 0 0 0
- // 0000000000000000 0000000000000000 16293888 24 --wL--N-- ion surface 41 0 0 1
-
- const bool dumpAll = dumpPid == 0;
- static constexpr size_t kMaxLineLength = 1024;
- static char line[kMaxLineLength];
- while(dirent* subdir = readdir(directory)) {
- // Skip "." and ".." in directory.
- if (strcmp(subdir->d_name, ".") == 0 || strcmp(subdir->d_name, "..") == 0 ) { continue; }
-
- std::string pid_str(subdir->d_name);
- const uint32_t pid(stoi(pid_str));
-
- if (!dumpAll && dumpPid != pid) {
- continue;
- }
-
- std::string filepath(kDirectoryPath + "/" + pid_str + "/mem");
- std::ifstream file(filepath);
-
- // Check first line
- file.getline(line, kMaxLineLength);
- if (!isExpectedFormat(line)) {
- continue;
- }
-
- if (result) {
- StringAppendF(result, "%d:\n%s\n", pid, line);
- }
-
- while( file.getline(line, kMaxLineLength) ) {
- if (result) {
- StringAppendF(result, "%s\n", line);
- }
-
- std::istringstream iss;
- iss.str(line);
-
- // Skip gpuaddr, useraddr.
- const char delimiter = ' ';
- iss >> std::ws;
- iss.ignore(kMaxLineLength, delimiter);
- iss >> std::ws;
- iss.ignore(kMaxLineLength, delimiter);
-
- // Get size.
- int64_t memsize;
- iss >> memsize;
-
- // Skip id, flags.
- iss >> std::ws;
- iss.ignore(kMaxLineLength, delimiter);
- iss >> std::ws;
- iss.ignore(kMaxLineLength, delimiter);
-
- // Get type, usage.
- std::string memtype;
- std::string usage;
- iss >> memtype >> usage;
-
- // Adjust for the space in VK/others( #)
- if (usage == "VK/others(") {
- std::string vkTypeEnd;
- iss >> vkTypeEnd;
- usage.append(vkTypeEnd);
- }
-
- // Skip sglen.
- iss >> std::ws;
- iss.ignore(kMaxLineLength, delimiter);
-
- // Get mapsize.
- int64_t mapsize;
- iss >> mapsize;
-
- if (memsize == 0 && mapsize == 0) {
- continue;
- }
-
- if (memtype == "gpumem") {
- (*memories)[pid][usage].gpuMemory += memsize;
- } else {
- (*memories)[pid][usage].ionMemory += memsize;
- }
-
- if (mapsize > 0) {
- (*memories)[pid][usage].mappedMemory += mapsize;
- }
- }
-
- if (result) {
- StringAppendF(result, "\n");
- }
- }
-
- closedir(directory);
-
- return OK;
-}
-
status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) {
ATRACE_CALL();
@@ -248,9 +101,7 @@
bool dumpAll = true;
bool dumpDriverInfo = false;
bool dumpStats = false;
- bool dumpMemory = false;
size_t numArgs = args.size();
- int32_t pid = 0;
if (numArgs) {
dumpAll = false;
@@ -259,11 +110,6 @@
dumpStats = true;
} else if (args[index] == String16("--gpudriverinfo")) {
dumpDriverInfo = true;
- } else if (args[index] == String16("--gpumem")) {
- dumpMemory = true;
- } else if (args[index].startsWith(String16("--gpumem="))) {
- dumpMemory = true;
- pid = atoi(String8(&args[index][9]));
}
}
}
@@ -276,14 +122,6 @@
mGpuStats->dump(args, &result);
result.append("\n");
}
- if (dumpAll || dumpMemory) {
- GpuMemoryMap memories;
- // Currently only queries Qualcomm gpu memory. More will be added later.
- if (getQCommGpuMemoryInfo(&memories, &result, pid) == OK) {
- dumpMemoryInfo(&result, memories, pid);
- result.append("\n");
- }
- }
}
write(fd, result.c_str(), result.size());
@@ -335,34 +173,6 @@
StringAppendF(result, "Pre-release Game Driver: %s\n", preReleaseGameDriver);
}
-// Read and print all memory info for each process from /d/kgsl/proc/<pid>/mem.
-void dumpMemoryInfo(std::string* result, const GpuMemoryMap& memories, uint32_t pid) {
- if (!result) return;
-
- // Write results.
- StringAppendF(result, "GPU Memory Summary:\n");
- for(auto& mem : memories) {
- uint32_t process = mem.first;
- if (pid != 0 && pid != process) {
- continue;
- }
-
- StringAppendF(result, "%d:\n", process);
- for(auto& memStruct : mem.second) {
- StringAppendF(result, " %s", memStruct.first.c_str());
-
- if(memStruct.second.gpuMemory > 0)
- StringAppendF(result, ", GPU memory = %" PRId64, memStruct.second.gpuMemory);
- if(memStruct.second.mappedMemory > 0)
- StringAppendF(result, ", Mapped memory = %" PRId64, memStruct.second.mappedMemory);
- if(memStruct.second.ionMemory > 0)
- StringAppendF(result, ", Ion memory = %" PRId64, memStruct.second.ionMemory);
-
- StringAppendF(result, "\n");
- }
- }
-}
-
} // anonymous namespace
} // namespace android
diff --git a/services/inputflinger/InputReaderBase.cpp b/services/inputflinger/InputReaderBase.cpp
index 2d6f2c1..b2dadf8 100644
--- a/services/inputflinger/InputReaderBase.cpp
+++ b/services/inputflinger/InputReaderBase.cpp
@@ -125,6 +125,16 @@
return std::nullopt;
}
+std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportById(
+ int32_t displayId) const {
+ for (const DisplayViewport& currentViewport : mDisplays) {
+ if (currentViewport.displayId == displayId) {
+ return std::make_optional(currentViewport);
+ }
+ }
+ return std::nullopt;
+}
+
void InputReaderConfiguration::setDisplayViewports(const std::vector<DisplayViewport>& viewports) {
mDisplays = viewports;
}
@@ -151,4 +161,4 @@
y = newY;
}
-} // namespace android
\ No newline at end of file
+} // namespace android
diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h
index 56c0a73..f8d5351 100644
--- a/services/inputflinger/include/InputReaderBase.h
+++ b/services/inputflinger/include/InputReaderBase.h
@@ -169,6 +169,9 @@
// Used to determine which DisplayViewport should be tied to which InputDevice.
std::unordered_map<std::string, uint8_t> portAssociations;
+ // The suggested display ID to show the cursor.
+ int32_t defaultPointerDisplayId;
+
// Velocity control parameters for mouse pointer movements.
VelocityControlParameters pointerVelocityControlParameters;
@@ -273,6 +276,7 @@
std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
const;
std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const;
+ std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const;
void setDisplayViewports(const std::vector<DisplayViewport>& viewports);
@@ -352,4 +356,4 @@
} // namespace android
-#endif // _UI_INPUT_READER_COMMON_H
\ No newline at end of file
+#endif // _UI_INPUT_READER_COMMON_H
diff --git a/services/inputflinger/include/PointerControllerInterface.h b/services/inputflinger/include/PointerControllerInterface.h
index 0ff28e4..194c665 100644
--- a/services/inputflinger/include/PointerControllerInterface.h
+++ b/services/inputflinger/include/PointerControllerInterface.h
@@ -17,6 +17,7 @@
#ifndef _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H
#define _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H
+#include <input/DisplayViewport.h>
#include <input/Input.h>
#include <utils/BitSet.h>
#include <utils/RefBase.h>
@@ -101,6 +102,9 @@
/* Gets the id of the display where the pointer should be shown. */
virtual int32_t getDisplayId() const = 0;
+
+ /* Sets the associated display of this pointer. Pointer should show on that display. */
+ virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
};
} // namespace android
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
index f69138e..69a75ba 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
@@ -189,12 +189,32 @@
// Update the PointerController if viewports changed.
if (mParameters.mode == Parameters::MODE_POINTER) {
- getPolicy()->obtainPointerController(getDeviceId());
+ updatePointerControllerDisplayViewport(*config);
}
bumpGeneration();
}
}
+void CursorInputMapper::updatePointerControllerDisplayViewport(
+ const InputReaderConfiguration& config) {
+ std::optional<DisplayViewport> viewport =
+ config.getDisplayViewportById(config.defaultPointerDisplayId);
+ if (!viewport) {
+ ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
+ "mapper. Fall back to default display",
+ config.defaultPointerDisplayId);
+ viewport = config.getDisplayViewportById(ADISPLAY_ID_DEFAULT);
+ }
+
+ if (!viewport) {
+ ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to"
+ " PointerController.");
+ return;
+ }
+
+ mPointerController->setDisplayViewport(*viewport);
+}
+
void CursorInputMapper::configureParameters() {
mParameters.mode = Parameters::MODE_POINTER;
String8 cursorModeString;
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h
index 77d122a..d56f9be 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.h
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.h
@@ -117,8 +117,9 @@
void dumpParameters(std::string& dump);
void sync(nsecs_t when);
+ void updatePointerControllerDisplayViewport(const InputReaderConfiguration& config);
};
} // namespace android
-#endif // _UI_INPUTREADER_CURSOR_INPUT_MAPPER_H
\ No newline at end of file
+#endif // _UI_INPUTREADER_CURSOR_INPUT_MAPPER_H
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index c80a2dc..b66caca 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -552,9 +552,10 @@
* Determine which DisplayViewport to use.
* 1. If display port is specified, return the matching viewport. If matching viewport not
* found, then return.
- * 2. If a device has associated display, get the matching viewport by either unique id or by
+ * 2. Always use the suggested viewport from WindowManagerService for pointers.
+ * 3. If a device has associated display, get the matching viewport by either unique id or by
* the display type (internal or external).
- * 3. Otherwise, use a non-display viewport.
+ * 4. Otherwise, use a non-display viewport.
*/
std::optional<DisplayViewport> TouchInputMapper::findViewport() {
if (mParameters.hasAssociatedDisplay) {
@@ -564,6 +565,17 @@
return mDevice->getAssociatedViewport();
}
+ if (mDeviceMode == DEVICE_MODE_POINTER) {
+ std::optional<DisplayViewport> viewport =
+ mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
+ if (viewport) {
+ return viewport;
+ } else {
+ ALOGW("Can't find designated display viewport with ID %" PRId32 " for pointers.",
+ mConfig.defaultPointerDisplayId);
+ }
+ }
+
// Check if uniqueDisplayId is specified in idc file.
if (!mParameters.uniqueDisplayId.empty()) {
return mConfig.getDisplayViewportByUniqueId(mParameters.uniqueDisplayId);
@@ -749,6 +761,7 @@
(mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
if (mPointerController == nullptr || viewportChanged) {
mPointerController = getPolicy()->obtainPointerController(getDeviceId());
+ mPointerController->setDisplayViewport(mViewport);
}
} else {
mPointerController.clear();
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index a9d7793..8ca7e4a 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -90,10 +90,6 @@
mMaxY = maxY;
}
- void setDisplayId(int32_t displayId) {
- mDisplayId = displayId;
- }
-
virtual void setPosition(float x, float y) {
mX = x;
mY = y;
@@ -116,6 +112,10 @@
return mDisplayId;
}
+ virtual void setDisplayViewport(const DisplayViewport& viewport) {
+ mDisplayId = viewport.displayId;
+ }
+
const std::map<int32_t, std::vector<int32_t>>& getSpots() {
return mSpotsByDisplay;
}
@@ -280,6 +280,10 @@
mConfig.showTouches = enabled;
}
+ void setDefaultPointerDisplayId(int32_t pointerDisplayId) {
+ mConfig.defaultPointerDisplayId = pointerDisplayId;
+ }
+
private:
DisplayViewport createDisplayViewport(int32_t displayId, int32_t width, int32_t height,
int32_t orientation, const std::string& uniqueId, std::optional<uint8_t> physicalPort,
@@ -3432,12 +3436,18 @@
CursorInputMapper* mapper = new CursorInputMapper(mDevice);
addMapperAndConfigure(mapper);
- // Setup PointerController for second display.
+ // Setup for second display.
constexpr int32_t SECOND_DISPLAY_ID = 1;
+ const std::string SECOND_DISPLAY_UNIQUE_ID = "local:1";
+ mFakePolicy->addDisplayViewport(SECOND_DISPLAY_ID, 800, 480, DISPLAY_ORIENTATION_0,
+ SECOND_DISPLAY_UNIQUE_ID, NO_PORT,
+ ViewportType::VIEWPORT_EXTERNAL);
+ mFakePolicy->setDefaultPointerDisplayId(SECOND_DISPLAY_ID);
+ configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+
mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
mFakePointerController->setPosition(100, 200);
mFakePointerController->setButtonState(0);
- mFakePointerController->setDisplayId(SECOND_DISPLAY_ID);
NotifyMotionArgs args;
process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 10);
@@ -6539,14 +6549,16 @@
}
TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShouldHandleDisplayId) {
- // Setup PointerController for second display.
+ // Setup for second display.
sp<FakePointerController> fakePointerController = new FakePointerController();
- fakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
+ fakePointerController->setBounds(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1);
fakePointerController->setPosition(100, 200);
fakePointerController->setButtonState(0);
- fakePointerController->setDisplayId(SECONDARY_DISPLAY_ID);
mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
+ mFakePolicy->setDefaultPointerDisplayId(SECONDARY_DISPLAY_ID);
+ prepareSecondaryDisplay(ViewportType::VIEWPORT_EXTERNAL);
+
MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
prepareDisplay(DISPLAY_ORIENTATION_0);
prepareAxes(POSITION);
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 11ae46d..67810fc 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -144,7 +144,7 @@
mFlinger->onLayerDestroyed(this);
}
-LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client>& client,
+LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client> client,
std::string name, uint32_t w, uint32_t h, uint32_t flags,
LayerMetadata metadata)
: flinger(flinger),
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 6acf5fb..fae976d 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -78,11 +78,11 @@
// ---------------------------------------------------------------------------
struct LayerCreationArgs {
- LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client>& client, std::string name,
+ LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client> client, std::string name,
uint32_t w, uint32_t h, uint32_t flags, LayerMetadata metadata);
SurfaceFlinger* flinger;
- const sp<Client>& client;
+ const sp<Client> client;
std::string name;
uint32_t w;
uint32_t h;
diff --git a/services/surfaceflinger/Scheduler/PhaseOffsets.cpp b/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
index 106aa9b..896c2a5 100644
--- a/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
+++ b/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
@@ -209,6 +209,32 @@
: vsyncDuration - (appDuration + sfDuration) % vsyncDuration;
}
+PhaseDurations::Offsets PhaseDurations::constructOffsets(nsecs_t vsyncDuration) const {
+ return Offsets{
+ {
+ mSfEarlyDuration < vsyncDuration
+ ? sfDurationToOffset(mSfEarlyDuration, vsyncDuration)
+ : sfDurationToOffset(mSfEarlyDuration, vsyncDuration) - vsyncDuration,
+
+ appDurationToOffset(mAppEarlyDuration, mSfEarlyDuration, vsyncDuration),
+ },
+ {
+ mSfEarlyGlDuration < vsyncDuration
+ ? sfDurationToOffset(mSfEarlyGlDuration, vsyncDuration)
+ : sfDurationToOffset(mSfEarlyGlDuration, vsyncDuration) - vsyncDuration,
+
+ appDurationToOffset(mAppEarlyGlDuration, mSfEarlyGlDuration, vsyncDuration),
+ },
+ {
+ mSfDuration < vsyncDuration
+ ? sfDurationToOffset(mSfDuration, vsyncDuration)
+ : sfDurationToOffset(mSfDuration, vsyncDuration) - vsyncDuration,
+
+ appDurationToOffset(mAppDuration, mSfDuration, vsyncDuration),
+ },
+ };
+}
+
static std::vector<float> getRefreshRatesFromConfigs(
const android::scheduler::RefreshRateConfigs& refreshRateConfigs) {
const auto& allRefreshRates = refreshRateConfigs.getAllRefreshRates();
@@ -227,41 +253,7 @@
std::unordered_map<float, Offsets> offsets;
for (const auto fps : refreshRates) {
- const nsecs_t vsyncDuration = static_cast<nsecs_t>(1e9f / fps);
- offsets.emplace(fps,
- Offsets{
- {
- mSfEarlyDuration < vsyncDuration
- ? sfDurationToOffset(mSfEarlyDuration,
- vsyncDuration)
- : sfDurationToOffset(mSfEarlyDuration,
- vsyncDuration) -
- vsyncDuration,
-
- appDurationToOffset(mAppEarlyDuration, mSfEarlyDuration,
- vsyncDuration),
- },
- {
- mSfEarlyGlDuration < vsyncDuration
- ? sfDurationToOffset(mSfEarlyGlDuration,
- vsyncDuration)
- : sfDurationToOffset(mSfEarlyGlDuration,
- vsyncDuration) -
- vsyncDuration,
-
- appDurationToOffset(mAppEarlyGlDuration, mSfEarlyGlDuration,
- vsyncDuration),
- },
- {
- mSfDuration < vsyncDuration
- ? sfDurationToOffset(mSfDuration, vsyncDuration)
- : sfDurationToOffset(mSfDuration, vsyncDuration) -
- vsyncDuration,
-
- appDurationToOffset(mAppDuration, mSfDuration,
- vsyncDuration),
- },
- });
+ offsets.emplace(fps, constructOffsets(static_cast<nsecs_t>(1e9f / fps)));
}
return offsets;
}
@@ -295,8 +287,16 @@
const auto iter = std::find_if(mOffsets.begin(), mOffsets.end(), [=](const auto& candidateFps) {
return fpsEqualsWithMargin(fps, candidateFps.first);
});
- LOG_ALWAYS_FATAL_IF(iter == mOffsets.end());
- return iter->second;
+
+ if (iter != mOffsets.end()) {
+ return iter->second;
+ }
+
+ // Unknown refresh rate. This might happen if we get a hotplug event for the default display.
+ // This happens only during tests and not during regular device operation.
+ // In this case just construct the offset.
+ ALOGW("Can't find offset for %.2f fps", fps);
+ return constructOffsets(static_cast<nsecs_t>(1e9f / fps));
}
void PhaseDurations::dump(std::string& result) const {
diff --git a/services/surfaceflinger/Scheduler/PhaseOffsets.h b/services/surfaceflinger/Scheduler/PhaseOffsets.h
index 7b1bdfd..b7d4eae 100644
--- a/services/surfaceflinger/Scheduler/PhaseOffsets.h
+++ b/services/surfaceflinger/Scheduler/PhaseOffsets.h
@@ -108,6 +108,7 @@
private:
std::unordered_map<float, Offsets> initializeOffsets(const std::vector<float>&) const;
+ PhaseDurations::Offsets constructOffsets(nsecs_t vsyncDuration) const;
const nsecs_t mSfDuration;
const nsecs_t mAppDuration;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 8c271f9..d716c54 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -5620,11 +5620,10 @@
repaintEverythingForHWC();
}
- auto configId = HwcConfigIndexType(defaultConfig);
- display->setActiveConfig(configId);
+ display->setActiveConfig(defaultConfig);
const nsecs_t vsyncPeriod =
- mRefreshRateConfigs->getRefreshRateFromConfigId(configId).vsyncPeriod;
- mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value, configId,
+ getHwComposer().getConfigs(*displayId)[defaultConfig.value()]->getVsyncPeriod();
+ mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value, defaultConfig,
vsyncPeriod);
return NO_ERROR;
}
diff --git a/services/surfaceflinger/tests/SurfaceFlinger_test.filter b/services/surfaceflinger/tests/SurfaceFlinger_test.filter
index e5a7774..2bedd7d 100644
--- a/services/surfaceflinger/tests/SurfaceFlinger_test.filter
+++ b/services/surfaceflinger/tests/SurfaceFlinger_test.filter
@@ -1,5 +1,5 @@
{
"presubmit": {
- "filter": "*:-LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadius/2:LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadius/3:LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadiusChildCrop/2:LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadiusChildCrop/3:MirrorLayerTest.MirrorBufferLayer"
+ "filter": "*:-LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadius/2:LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadius/3:LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadiusChildCrop/2:LayerTypeAndRenderTypeTransactionTests/LayerTypeAndRenderTypeTransactionTest.SetCornerRadiusChildCrop/3"
}
}