summaryrefslogtreecommitdiff
path: root/libs/hwui/pipeline/skia/SkiaPipeline.h
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2020-08-31 21:21:38 -0700
committerXin Li <delphij@google.com>2020-08-31 21:21:38 -0700
commit628590d7ec80e10a3fc24b1c18a1afb55cca10a8 (patch)
tree4b1c3f52d86d7fb53afbe9e9438468588fa489f8 /libs/hwui/pipeline/skia/SkiaPipeline.h
parentb11b8ec3aec8bb42f2c07e1c5ac7942da293baa8 (diff)
parentd2d3a20624d968199353ccf6ddbae6f3ac39c9af (diff)
Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507 Merged-In: I3d92a6de21a938f6b352ec26dc23420c0fe02b27 Change-Id: Ifdb80563ef042738778ebb8a7581a97c4e3d96e2
Diffstat (limited to 'libs/hwui/pipeline/skia/SkiaPipeline.h')
-rw-r--r--libs/hwui/pipeline/skia/SkiaPipeline.h123
1 files changed, 53 insertions, 70 deletions
diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.h b/libs/hwui/pipeline/skia/SkiaPipeline.h
index 41d864653b67..8341164edc19 100644
--- a/libs/hwui/pipeline/skia/SkiaPipeline.h
+++ b/libs/hwui/pipeline/skia/SkiaPipeline.h
@@ -17,12 +17,15 @@
#pragma once
#include <SkSurface.h>
+#include <SkDocument.h>
+#include <SkMultiPictureDocument.h>
#include "Lighting.h"
#include "hwui/AnimatedImageDrawable.h"
#include "renderthread/CanvasContext.h"
#include "renderthread/IRenderPipeline.h"
class SkPictureRecorder;
+struct SkSharingSerialContext;
namespace android {
namespace uirenderer {
@@ -38,14 +41,16 @@ public:
bool pinImages(std::vector<SkImage*>& mutableImages) override;
bool pinImages(LsaVector<sk_sp<Bitmap>>& images) override { return false; }
void unpinImages() override;
- void onPrepareTree() override;
void renderLayers(const LightGeometry& lightGeometry, LayerUpdateQueue* layerUpdateQueue,
bool opaque, const LightInfo& lightInfo) override;
+ // If the given node didn't have a layer surface, or had one of the wrong size, this method
+ // creates a new one and returns true. Otherwise does nothing and returns false.
bool createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator,
ErrorHandler* errorHandler) override;
+ void setSurfaceColorProperties(renderthread::ColorMode colorMode) override;
SkColorType getSurfaceColorType() const override { return mSurfaceColorType; }
sk_sp<SkColorSpace> getSurfaceColorSpace() override { return mSurfaceColorSpace; }
@@ -54,70 +59,29 @@ public:
const Rect& contentDrawBounds, sk_sp<SkSurface> surface,
const SkMatrix& preTransform);
- std::vector<VectorDrawableRoot*>* getVectorDrawables() { return &mVectorDrawables; }
-
static void prepareToDraw(const renderthread::RenderThread& thread, Bitmap* bitmap);
void renderLayersImpl(const LayerUpdateQueue& layers, bool opaque);
- static float getLightRadius() {
- if (CC_UNLIKELY(Properties::overrideLightRadius > 0)) {
- return Properties::overrideLightRadius;
- }
- return mLightRadius;
- }
-
- static uint8_t getAmbientShadowAlpha() {
- if (CC_UNLIKELY(Properties::overrideAmbientShadowStrength >= 0)) {
- return Properties::overrideAmbientShadowStrength;
- }
- return mAmbientShadowAlpha;
- }
-
- static uint8_t getSpotShadowAlpha() {
- if (CC_UNLIKELY(Properties::overrideSpotShadowStrength >= 0)) {
- return Properties::overrideSpotShadowStrength;
- }
- return mSpotShadowAlpha;
- }
-
- static Vector3 getLightCenter() {
- if (CC_UNLIKELY(Properties::overrideLightPosY > 0 || Properties::overrideLightPosZ > 0)) {
- Vector3 adjustedLightCenter = mLightCenter;
- if (CC_UNLIKELY(Properties::overrideLightPosY > 0)) {
- // negated since this shifts up
- adjustedLightCenter.y = -Properties::overrideLightPosY;
- }
- if (CC_UNLIKELY(Properties::overrideLightPosZ > 0)) {
- adjustedLightCenter.z = Properties::overrideLightPosZ;
- }
- return adjustedLightCenter;
- }
- return mLightCenter;
- }
-
- static void updateLighting(const LightGeometry& lightGeometry, const LightInfo& lightInfo) {
- mLightRadius = lightGeometry.radius;
- mAmbientShadowAlpha = lightInfo.ambientShadowAlpha;
- mSpotShadowAlpha = lightInfo.spotShadowAlpha;
- mLightCenter = lightGeometry.center;
- }
-
+ // Sets the recording callback to the provided function and the recording mode
+ // to CallbackAPI
void setPictureCapturedCallback(
const std::function<void(sk_sp<SkPicture>&&)>& callback) override {
mPictureCapturedCallback = callback;
+ mCaptureMode = callback ? CaptureMode::CallbackAPI : CaptureMode::None;
}
protected:
void dumpResourceCacheUsage() const;
- void setSurfaceColorProperties(renderthread::ColorMode colorMode);
renderthread::RenderThread& mRenderThread;
+
+ renderthread::ColorMode mColorMode = renderthread::ColorMode::SRGB;
SkColorType mSurfaceColorType;
sk_sp<SkColorSpace> mSurfaceColorSpace;
private:
- void renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip,
+ void renderFrameImpl(const SkRect& clip,
const std::vector<sp<RenderNode>>& nodes, bool opaque,
const Rect& contentDrawBounds, SkCanvas* canvas,
const SkMatrix& preTransform);
@@ -126,48 +90,67 @@ private:
* Debugging feature. Draws a semi-transparent overlay on each pixel, indicating
* how many times it has been drawn.
*/
- void renderOverdraw(const LayerUpdateQueue& layers, const SkRect& clip,
+ void renderOverdraw(const SkRect& clip,
const std::vector<sp<RenderNode>>& nodes, const Rect& contentDrawBounds,
sk_sp<SkSurface> surface, const SkMatrix& preTransform);
- /**
- * Render mVectorDrawables into offscreen buffers.
- */
- void renderVectorDrawableCache();
-
- SkCanvas* tryCapture(SkSurface* surface);
+ // Called every frame. Normally returns early with screen canvas.
+ // But when capture is enabled, returns an nwaycanvas where commands are also recorded.
+ SkCanvas* tryCapture(SkSurface* surface, RenderNode* root, const LayerUpdateQueue& dirtyLayers);
+ // Called at the end of every frame, closes the recording if necessary.
void endCapture(SkSurface* surface);
+ // Determine if a new file-based capture should be started.
+ // If so, sets mCapturedFile and mCaptureSequence and returns true.
+ // Should be called every frame when capture is enabled.
+ // sets mCaptureMode.
+ bool shouldStartNewFileCapture();
+ // Set up a multi frame capture.
+ bool setupMultiFrameCapture();
std::vector<sk_sp<SkImage>> mPinnedImages;
- /**
- * populated by prepareTree with dirty VDs
- */
- std::vector<VectorDrawableRoot*> mVectorDrawables;
-
// Block of properties used only for debugging to record a SkPicture and save it in a file.
+ // There are three possible ways of recording drawing commands.
+ enum class CaptureMode {
+ // return to this mode when capture stops.
+ None,
+ // A mode where every frame is recorded into an SkPicture and sent to a provided callback,
+ // until that callback is cleared
+ CallbackAPI,
+ // A mode where a finite number of frames are recorded to a file with
+ // SkMultiPictureDocument
+ MultiFrameSKP,
+ // A mode which records a single frame to a normal SKP file.
+ SingleFrameSKP,
+ };
+ CaptureMode mCaptureMode = CaptureMode::None;
+
/**
- * mCapturedFile is used to enforce we don't capture more than once for a given name (cause
- * permissions don't allow to reset a property from render thread).
+ * mCapturedFile - the filename to write a recorded SKP to in either MultiFrameSKP or
+ * SingleFrameSKP mode.
*/
std::string mCapturedFile;
/**
- * mCaptureSequence counts how many frames are left to take in the sequence.
+ * mCaptureSequence counts down how many frames are left to take in the sequence. Applicable
+ * only to MultiFrameSKP or SingleFrameSKP mode.
*/
int mCaptureSequence = 0;
+ // Multi frame serialization stream and writer used when serializing more than one frame.
+ std::unique_ptr<SkFILEWStream> mOpenMultiPicStream;
+ sk_sp<SkDocument> mMultiPic;
+ std::unique_ptr<SkSharingSerialContext> mSerialContext;
+
/**
- * mRecorder holds the current picture recorder. We could store it on the stack to support
- * parallel tryCapture calls (not really needed).
+ * mRecorder holds the current picture recorder when serializing in either SingleFrameSKP or
+ * CallbackAPI modes.
*/
std::unique_ptr<SkPictureRecorder> mRecorder;
std::unique_ptr<SkNWayCanvas> mNwayCanvas;
- std::function<void(sk_sp<SkPicture>&&)> mPictureCapturedCallback;
- static float mLightRadius;
- static uint8_t mAmbientShadowAlpha;
- static uint8_t mSpotShadowAlpha;
- static Vector3 mLightCenter;
+ // Set by setPictureCapturedCallback and when set, CallbackAPI mode recording is ongoing.
+ // Not used in other recording modes.
+ std::function<void(sk_sp<SkPicture>&&)> mPictureCapturedCallback;
};
} /* namespace skiapipeline */