Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d604a4dc authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Trace when bitmaps are downscaled "a lot"" into main

parents 558e6e77 69b2d261
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

#include "RecordingCanvas.h"

#include <SkMesh.h>
#include <gui/TraceUtils.h>
#include <hwui/Paint.h>
#include <include/gpu/GpuTypes.h>
#include <include/gpu/ganesh/GrDirectContext.h>
@@ -387,6 +387,34 @@ struct DrawPicture final : Op {
    }
};

static void traceBitmapScaling(const SkCanvas* c, const sk_sp<const SkImage>& image,
                               const SkRect& src, const SkRect& dst) {
    // How big the source content has to be for us to care
    // The smaller the initial image, the more pronounced changes in destination size are to scale
    // However, the relative impact to RAM & bandwidth are not that significant, so ignore these
    static constexpr auto MinAreaToCare = 200 * 200;

    // How far it has to be downscaled to trigger a warning
    static constexpr auto WarnScaleFactor = .4f;

    if (src.width() * src.height() <= MinAreaToCare) {
        return;
    }

    const SkMatrix bitmapToLocal = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
    const SkMatrix localToDevice = c->getLocalToDeviceAs3x3();
    const SkMatrix totalTransform = SkMatrix::Concat(bitmapToLocal, localToDevice);
    const SkRect displayArea = totalTransform.mapRect(src);
    const float xScale = displayArea.width() / src.width();
    const float yScale = displayArea.height() / src.height();
    // RAM & bandwidth are only concerned if the source content are oversized for the area it
    // occupies, not undersized.
    if (xScale < WarnScaleFactor || yScale < WarnScaleFactor) {
        ATRACE_FORMAT_INSTANT("Image sized %dx%d being drawn to %.0fx%.0f", image->width(),
                              image->height(), displayArea.width(), displayArea.height());
    }
}

struct DrawImage final : Op {
    static const auto kType = Type::DrawImage;
    DrawImage(DrawImagePayload&& payload, SkScalar x, SkScalar y, const SkSamplingOptions& sampling,
@@ -411,6 +439,10 @@ struct DrawImage final : Op {
    SkGainmapInfo gainmapInfo;

    void draw(SkCanvas* c, const SkMatrix&) const {
        if (ATRACE_ENABLED()) {
            const SkRect src = SkRect::MakeWH(image->width(), image->height());
            traceBitmapScaling(c, image, src, SkRect::MakeXYWH(x, y, src.width(), src.height()));
        }
        if (gainmap) {
            SkRect src = SkRect::MakeWH(image->width(), image->height());
            SkRect dst = SkRect::MakeXYWH(x, y, src.width(), src.height());
@@ -456,6 +488,9 @@ struct DrawImageRect final : Op {
    SkGainmapInfo gainmapInfo;

    void draw(SkCanvas* c, const SkMatrix&) const {
        if (ATRACE_ENABLED()) {
            traceBitmapScaling(c, image, src, dst);
        }
        if (gainmap) {
            DrawGainmapBitmap(c, image, src, dst, sampling, &paint, constraint, gainmap,
                              gainmapInfo);
+3 −7
Original line number Diff line number Diff line
@@ -73,8 +73,6 @@ void logBitmapDecode(const SkImageInfo& info, bool hasGainmap) {
#ifdef __ANDROID__

    if (!statssocket::lazy::IsAvailable()) {
        std::once_flag once;
        std::call_once(once, []() { ALOGD("libstatssocket not available, dropping stats"); });
        return;
    }

@@ -86,11 +84,9 @@ void logBitmapDecode(const SkImageInfo& info, bool hasGainmap) {
        tfnType = skcms_TransferFunction_getType(&tfn);
    }

    auto status =
    stats::stats_write(uirenderer::stats::IMAGE_DECODED, static_cast<int32_t>(getuid()),
                       uirenderer::toStatsColorSpaceTransfer(tfnType), hasGainmap,
                       uirenderer::toStatsBitmapFormat(info.colorType()));
    ALOGW_IF(status != OK, "Image decoding logging dropped!");
#endif
}