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

Commit 37994f55 authored by Anton Ivanov's avatar Anton Ivanov Committed by Android (Google) Code Review
Browse files

Merge "Fix shadow variable warning in screencap.cpp" into main

parents 67d9264f eca08d7a
Loading
Loading
Loading
Loading
+48 −54
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@
#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>

#include "utils/Errors.h"
#include "screencap_utils.h"
#include "utils/Errors.h"

using namespace android;

@@ -63,9 +63,9 @@ If FILENAME is not given, the results will be printed to stdout.
            pname,
            displayIdOpt
                    .transform([](DisplayId id) {
                    return std::string(ftl::Concat(
                    " (If the id is not given, it defaults to ", id.value,')'
                    ).str());
                        return std::string(ftl::Concat(" (If the id is not given, it defaults to ",
                                                       id.value, ')')
                                                   .str());
                    })
                    .value_or(std::string())
                    .c_str());
@@ -87,8 +87,7 @@ static const struct option LONG_OPTIONS[] = {{"png", no_argument, nullptr, 'p'},
                                              LongOpts::HintForSeamless},
                                             {0, 0, 0, 0}};

static int32_t flinger2bitmapFormat(PixelFormat f)
{
static int32_t flinger2bitmapFormat(PixelFormat f) {
    switch (f) {
        case PIXEL_FORMAT_RGB_565:
            return ANDROID_BITMAP_FORMAT_RGB_565;
@@ -97,8 +96,7 @@ static int32_t flinger2bitmapFormat(PixelFormat f)
    }
}

static uint32_t dataSpaceToInt(ui::Dataspace d)
{
static uint32_t dataSpaceToInt(ui::Dataspace d) {
    switch (d) {
        case ui::Dataspace::V0_SRGB:
            return COLORSPACE_SRGB;
@@ -112,15 +110,10 @@ static uint32_t dataSpaceToInt(ui::Dataspace d)
static status_t notifyMediaScanner(const char* fileName) {
    std::string filePath("file://");
    filePath.append(fileName);
    char *cmd[] = {
        (char*) "am",
        (char*) "broadcast",
        (char*) "-a",
        (char*) "android.intent.action.MEDIA_SCANNER_SCAN_FILE",
        (char*) "-d",
        &filePath[0],
        nullptr
    };
    char* cmd[] = {(char*)"am", (char*)"broadcast",
                   (char*)"-a", (char*)"android.intent.action.MEDIA_SCANNER_SCAN_FILE",
                   (char*)"-d", &filePath[0],
                   nullptr};

    int status;
    int pid = fork();
@@ -216,10 +209,11 @@ status_t saveImage(const char* fn, std::optional<AndroidBitmapCompressFormat> fo
        info.height = buffer->getHeight();
        info.stride = buffer->getStride() * bytesPerPixel(buffer->getPixelFormat());

        int result;
        int bitmapResult;

        if (gainmapBase) {
            result = ABitmap_compressWithGainmap(&info, static_cast<ADataSpace>(dataspace), base,
            bitmapResult =
                    ABitmap_compressWithGainmap(&info, static_cast<ADataSpace>(dataspace), base,
                                                gainmapBase, captureResults.hdrSdrRatio, *format,
                                                100, &fd,
                                                [](void* fdPtr, const void* data,
@@ -230,17 +224,18 @@ status_t saveImage(const char* fn, std::optional<AndroidBitmapCompressFormat> fo
                                                    return bytesWritten == size;
                                                });
        } else {
            result = AndroidBitmap_compress(&info, static_cast<int32_t>(dataspace), base, *format,
            bitmapResult =
                    AndroidBitmap_compress(&info, static_cast<int32_t>(dataspace), base, *format,
                                           100, &fd,
                                           [](void* fdPtr, const void* data, size_t size) -> bool {
                                                int bytesWritten = write(*static_cast<int*>(fdPtr),
                                                                         data, size);
                                               int bytesWritten =
                                                       write(*static_cast<int*>(fdPtr), data, size);
                                               return bytesWritten == size;
                                           });
        }

        if (result != ANDROID_BITMAP_RESULT_SUCCESS) {
            fprintf(stderr, "Failed to compress (error code: %d)\n", result);
        if (bitmapResult != ANDROID_BITMAP_RESULT_SUCCESS) {
            fprintf(stderr, "Failed to compress (error code: %d)\n", bitmapResult);
        }

        if (fn != NULL) {
@@ -276,8 +271,7 @@ status_t saveImage(const char* fn, std::optional<AndroidBitmapCompressFormat> fo
    return 0;
}

int main(int argc, char** argv)
{
int main(int argc, char** argv) {
    const std::vector<PhysicalDisplayId> physicalDisplays =
            SurfaceComposerClient::getPhysicalDisplayIds();