Fix subtle copying bug in primeShaderCache
Move the declaration of vectors to the innermost loop that uses them.
We loop through a bunch of different LayerSettings to draw content that
will prime the shader cache. In several places, we create a vector
initialized with multiple LayerSettings, and then inside a loop, we
modify the originals. When this code was written, we created a
vector<const LayerSettings*>. In
I87847d01e2e330ddec88272cd8608f0b78c0a2cd, the RenderEngine API was
changed to accept a vector<LayerSettings>. The problem is, when
constructing a vector<LayerSettings>, we get a *copy* of the items in
the initializer list. So when the loop modifies the originals, the
vector stays as it is, and only the first iteraton of the loop caches
any shaders. On my test device, we have only cached 6 shaders at the end
of primeShaderCache. With this change, we are back up to 93 shaders.
Bug: 190487656
Bug: 222355787
Test: manual - logcat + perfetto
Change-Id: I9f0e9e8535feee48700f1c896f26833b6095764d
diff --git a/libs/renderengine/skia/Cache.cpp b/libs/renderengine/skia/Cache.cpp
index a3a1969..5c137a4 100644
--- a/libs/renderengine/skia/Cache.cpp
+++ b/libs/renderengine/skia/Cache.cpp
@@ -96,7 +96,6 @@
.alpha = 1,
};
- auto layers = std::vector<LayerSettings>{layer, caster};
// Four combinations of settings are used (two transforms here, and drawShadowLayers is
// called with two different destination data spaces) They're all rounded rect.
// Three of these are cache misses that generate new shaders.
@@ -115,6 +114,8 @@
for (auto transform : {mat4(), kFlip}) {
layer.geometry.positionTransform = transform;
caster.geometry.positionTransform = transform;
+
+ auto layers = std::vector<LayerSettings>{layer, caster};
renderengine->drawLayers(display, layers, dstTexture, kUseFrameBufferCache,
base::unique_fd());
}
@@ -141,7 +142,6 @@
}},
};
- auto layers = std::vector<LayerSettings>{layer};
for (auto dataspace : {kDestDataSpace, kOtherDataSpace}) {
layer.sourceDataspace = dataspace;
// Cache shaders for both rects and round rects.
@@ -153,6 +153,7 @@
layer.source.buffer.isOpaque = isOpaque;
for (auto alpha : {half(.2f), half(1.0f)}) {
layer.alpha = alpha;
+ auto layers = std::vector<LayerSettings>{layer};
renderengine->drawLayers(display, layers, dstTexture, kUseFrameBufferCache,
base::unique_fd());
}
@@ -177,11 +178,11 @@
.alpha = 0.5,
};
- auto layers = std::vector<LayerSettings>{layer};
for (auto transform : {mat4(), kScaleAndTranslate}) {
layer.geometry.positionTransform = transform;
for (float roundedCornersRadius : {0.0f, 50.f}) {
layer.geometry.roundedCornersRadius = roundedCornersRadius;
+ auto layers = std::vector<LayerSettings>{layer};
renderengine->drawLayers(display, layers, dstTexture, kUseFrameBufferCache,
base::unique_fd());
}
@@ -202,10 +203,10 @@
.skipContentDraw = true,
};
- auto layers = std::vector<LayerSettings>{layer};
// Different blur code is invoked for radii less and greater than 30 pixels
for (int radius : {9, 60}) {
layer.backgroundBlurRadius = radius;
+ auto layers = std::vector<LayerSettings>{layer};
renderengine->drawLayers(display, layers, dstTexture, kUseFrameBufferCache,
base::unique_fd());
}
@@ -243,7 +244,6 @@
},
};
- auto layers = std::vector<LayerSettings>{layer};
for (auto pixelSource : {bufferSource, bufferOpaque, colorSource}) {
layer.source = pixelSource;
for (auto dataspace : {kDestDataSpace, kOtherDataSpace}) {
@@ -252,7 +252,8 @@
for (auto transform : {kScaleAndTranslate, kScaleAsymmetric}) {
layer.geometry.positionTransform = transform;
for (float alpha : {0.5f, 1.f}) {
- layer.alpha = alpha,
+ layer.alpha = alpha;
+ auto layers = std::vector<LayerSettings>{layer};
renderengine->drawLayers(display, layers, dstTexture, kUseFrameBufferCache,
base::unique_fd());
}