Loading libs/hwui/pipeline/skia/SkiaPipeline.cpp +26 −2 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <SkMultiPictureDocument.h> #include <SkMultiPictureDocument.h> #include <SkOverdrawCanvas.h> #include <SkOverdrawCanvas.h> #include <SkOverdrawColorFilter.h> #include <SkOverdrawColorFilter.h> #include <SkPaintFilterCanvas.h> #include <SkPicture.h> #include <SkPicture.h> #include <SkPictureRecorder.h> #include <SkPictureRecorder.h> #include <SkRect.h> #include <SkRect.h> Loading @@ -36,15 +37,15 @@ #include <SkStream.h> #include <SkStream.h> #include <SkString.h> #include <SkString.h> #include <SkTypeface.h> #include <SkTypeface.h> #include "include/gpu/GpuTypes.h" // from Skia #include <android-base/properties.h> #include <android-base/properties.h> #include <gui/TraceUtils.h> #include <unistd.h> #include <unistd.h> #include <sstream> #include <sstream> #include <gui/TraceUtils.h> #include "LightingInfo.h" #include "LightingInfo.h" #include "VectorDrawable.h" #include "VectorDrawable.h" #include "include/gpu/GpuTypes.h" // from Skia #include "thread/CommonPool.h" #include "thread/CommonPool.h" #include "tools/SkSharingProc.h" #include "tools/SkSharingProc.h" #include "utils/Color.h" #include "utils/Color.h" Loading Loading @@ -449,6 +450,23 @@ void SkiaPipeline::endCapture(SkSurface* surface) { } } } } class ForceDitherCanvas : public SkPaintFilterCanvas { public: ForceDitherCanvas(SkCanvas* canvas) : SkPaintFilterCanvas(canvas) {} protected: bool onFilter(SkPaint& paint) const override { paint.setDither(true); return true; } void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override { // We unroll the drawable using "this" canvas, so that draw calls contained inside will // get dithering applied drawable->draw(this, matrix); } }; void SkiaPipeline::renderFrame(const LayerUpdateQueue& layers, const SkRect& clip, void SkiaPipeline::renderFrame(const LayerUpdateQueue& layers, const SkRect& clip, const std::vector<sp<RenderNode>>& nodes, bool opaque, const std::vector<sp<RenderNode>>& nodes, bool opaque, const Rect& contentDrawBounds, sk_sp<SkSurface> surface, const Rect& contentDrawBounds, sk_sp<SkSurface> surface, Loading Loading @@ -503,6 +521,12 @@ void SkiaPipeline::renderFrameImpl(const SkRect& clip, canvas->clear(SK_ColorTRANSPARENT); canvas->clear(SK_ColorTRANSPARENT); } } std::optional<ForceDitherCanvas> forceDitherCanvas; if (shouldForceDither()) { forceDitherCanvas.emplace(canvas); canvas = &forceDitherCanvas.value(); } if (1 == nodes.size()) { if (1 == nodes.size()) { if (!nodes[0]->nothingToDraw()) { if (!nodes[0]->nothingToDraw()) { RenderNodeDrawable root(nodes[0].get(), canvas); RenderNodeDrawable root(nodes[0].get(), canvas); Loading libs/hwui/pipeline/skia/SkiaPipeline.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,8 @@ protected: bool isCapturingSkp() const { return mCaptureMode != CaptureMode::None; } bool isCapturingSkp() const { return mCaptureMode != CaptureMode::None; } virtual bool shouldForceDither() const { return mColorMode != ColorMode::Default; } private: private: void renderFrameImpl(const SkRect& clip, void renderFrameImpl(const SkRect& clip, const std::vector<sp<RenderNode>>& nodes, bool opaque, const std::vector<sp<RenderNode>>& nodes, bool opaque, Loading libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -203,6 +203,11 @@ sk_sp<Bitmap> SkiaVulkanPipeline::allocateHardwareBitmap(renderthread::RenderThr return nullptr; return nullptr; } } bool SkiaVulkanPipeline::shouldForceDither() const { if (mVkSurface && mVkSurface->isBeyond8Bit()) return false; return SkiaPipeline::shouldForceDither(); } void SkiaVulkanPipeline::onContextDestroyed() { void SkiaVulkanPipeline::onContextDestroyed() { if (mVkSurface) { if (mVkSurface) { vulkanManager().destroySurface(mVkSurface); vulkanManager().destroySurface(mVkSurface); Loading libs/hwui/pipeline/skia/SkiaVulkanPipeline.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -64,6 +64,8 @@ public: protected: protected: void onContextDestroyed() override; void onContextDestroyed() override; bool shouldForceDither() const override; private: private: renderthread::VulkanManager& vulkanManager(); renderthread::VulkanManager& vulkanManager(); renderthread::VulkanSurface* mVkSurface = nullptr; renderthread::VulkanSurface* mVkSurface = nullptr; Loading libs/hwui/renderthread/VulkanSurface.cpp +10 −0 Original line number Original line Diff line number Diff line Loading @@ -545,6 +545,16 @@ void VulkanSurface::setColorSpace(sk_sp<SkColorSpace> colorSpace) { } } } } bool VulkanSurface::isBeyond8Bit() const { switch (mWindowInfo.bufferFormat) { case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: return true; default: return false; } } } /* namespace renderthread */ } /* namespace renderthread */ } /* namespace uirenderer */ } /* namespace uirenderer */ } /* namespace android */ } /* namespace android */ Loading
libs/hwui/pipeline/skia/SkiaPipeline.cpp +26 −2 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <SkMultiPictureDocument.h> #include <SkMultiPictureDocument.h> #include <SkOverdrawCanvas.h> #include <SkOverdrawCanvas.h> #include <SkOverdrawColorFilter.h> #include <SkOverdrawColorFilter.h> #include <SkPaintFilterCanvas.h> #include <SkPicture.h> #include <SkPicture.h> #include <SkPictureRecorder.h> #include <SkPictureRecorder.h> #include <SkRect.h> #include <SkRect.h> Loading @@ -36,15 +37,15 @@ #include <SkStream.h> #include <SkStream.h> #include <SkString.h> #include <SkString.h> #include <SkTypeface.h> #include <SkTypeface.h> #include "include/gpu/GpuTypes.h" // from Skia #include <android-base/properties.h> #include <android-base/properties.h> #include <gui/TraceUtils.h> #include <unistd.h> #include <unistd.h> #include <sstream> #include <sstream> #include <gui/TraceUtils.h> #include "LightingInfo.h" #include "LightingInfo.h" #include "VectorDrawable.h" #include "VectorDrawable.h" #include "include/gpu/GpuTypes.h" // from Skia #include "thread/CommonPool.h" #include "thread/CommonPool.h" #include "tools/SkSharingProc.h" #include "tools/SkSharingProc.h" #include "utils/Color.h" #include "utils/Color.h" Loading Loading @@ -449,6 +450,23 @@ void SkiaPipeline::endCapture(SkSurface* surface) { } } } } class ForceDitherCanvas : public SkPaintFilterCanvas { public: ForceDitherCanvas(SkCanvas* canvas) : SkPaintFilterCanvas(canvas) {} protected: bool onFilter(SkPaint& paint) const override { paint.setDither(true); return true; } void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override { // We unroll the drawable using "this" canvas, so that draw calls contained inside will // get dithering applied drawable->draw(this, matrix); } }; void SkiaPipeline::renderFrame(const LayerUpdateQueue& layers, const SkRect& clip, void SkiaPipeline::renderFrame(const LayerUpdateQueue& layers, const SkRect& clip, const std::vector<sp<RenderNode>>& nodes, bool opaque, const std::vector<sp<RenderNode>>& nodes, bool opaque, const Rect& contentDrawBounds, sk_sp<SkSurface> surface, const Rect& contentDrawBounds, sk_sp<SkSurface> surface, Loading Loading @@ -503,6 +521,12 @@ void SkiaPipeline::renderFrameImpl(const SkRect& clip, canvas->clear(SK_ColorTRANSPARENT); canvas->clear(SK_ColorTRANSPARENT); } } std::optional<ForceDitherCanvas> forceDitherCanvas; if (shouldForceDither()) { forceDitherCanvas.emplace(canvas); canvas = &forceDitherCanvas.value(); } if (1 == nodes.size()) { if (1 == nodes.size()) { if (!nodes[0]->nothingToDraw()) { if (!nodes[0]->nothingToDraw()) { RenderNodeDrawable root(nodes[0].get(), canvas); RenderNodeDrawable root(nodes[0].get(), canvas); Loading
libs/hwui/pipeline/skia/SkiaPipeline.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,8 @@ protected: bool isCapturingSkp() const { return mCaptureMode != CaptureMode::None; } bool isCapturingSkp() const { return mCaptureMode != CaptureMode::None; } virtual bool shouldForceDither() const { return mColorMode != ColorMode::Default; } private: private: void renderFrameImpl(const SkRect& clip, void renderFrameImpl(const SkRect& clip, const std::vector<sp<RenderNode>>& nodes, bool opaque, const std::vector<sp<RenderNode>>& nodes, bool opaque, Loading
libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -203,6 +203,11 @@ sk_sp<Bitmap> SkiaVulkanPipeline::allocateHardwareBitmap(renderthread::RenderThr return nullptr; return nullptr; } } bool SkiaVulkanPipeline::shouldForceDither() const { if (mVkSurface && mVkSurface->isBeyond8Bit()) return false; return SkiaPipeline::shouldForceDither(); } void SkiaVulkanPipeline::onContextDestroyed() { void SkiaVulkanPipeline::onContextDestroyed() { if (mVkSurface) { if (mVkSurface) { vulkanManager().destroySurface(mVkSurface); vulkanManager().destroySurface(mVkSurface); Loading
libs/hwui/pipeline/skia/SkiaVulkanPipeline.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -64,6 +64,8 @@ public: protected: protected: void onContextDestroyed() override; void onContextDestroyed() override; bool shouldForceDither() const override; private: private: renderthread::VulkanManager& vulkanManager(); renderthread::VulkanManager& vulkanManager(); renderthread::VulkanSurface* mVkSurface = nullptr; renderthread::VulkanSurface* mVkSurface = nullptr; Loading
libs/hwui/renderthread/VulkanSurface.cpp +10 −0 Original line number Original line Diff line number Diff line Loading @@ -545,6 +545,16 @@ void VulkanSurface::setColorSpace(sk_sp<SkColorSpace> colorSpace) { } } } } bool VulkanSurface::isBeyond8Bit() const { switch (mWindowInfo.bufferFormat) { case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: return true; default: return false; } } } /* namespace renderthread */ } /* namespace renderthread */ } /* namespace uirenderer */ } /* namespace uirenderer */ } /* namespace android */ } /* namespace android */