SurfaceComposerClient::Transaction::setGeometry

//#include <iostream>
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/Binder.h>
#include <binder/IBinder.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/IServiceManager.h>

#include <iostream>
#include <array>
#include <limits>
#include <set>
#include <unordered_map>

#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <optional>
#include <optional>

#include <chrono>
#include <mutex>
#include <thread>

#include <android/gui/IDisplayEventConnection.h>
#include <android/gui/ISurfaceComposer.h>
#include <binder/ProcessState.h>
#include <gui/BufferItemConsumer.h>
#include <gui/IProducerListener.h>
#include <gui/ISurfaceComposer.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SyncScreenCaptureListener.h>
#include <inttypes.h>
#include <private/gui/ComposerService.h>
#include <private/gui/ComposerServiceAIDL.h>
#include <sys/types.h>
#include <ui/BufferQueueDefs.h>
#include <ui/DisplayMode.h>
#include <ui/Rect.h>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <limits>
#include <thread>
#include "ColorUtils.h"
#include <utils/Log.h>
//
typedef uint8_t u8;
typedef int32_t u32;

#include <iostream>
#include <chrono>
#include <thread>

#include <android/gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SurfaceControl.h>
#include <gui/Surface.h>
#include <ui/Rect.h>

using namespace android;

// Function to fill a region with a specified color in ANativeWindow_Buffer
void fillANativeWindowBufferColor(const ANativeWindow_Buffer &buffer, const Rect &rect,
                                  const Color &color) {
    Rect r(0, 0, buffer.width, buffer.height);
    if (!r.intersect(rect, &r)) {
        return;
    }

    u32 width = r.right - r.left;
    u32 height = r.bottom - r.top;

    for (u32 row = 0; row < height; row++) {
        u8 *dst = static_cast<u8 *>(buffer.bits) +
                  (buffer.stride * (r.top + row) + r.left) * 4;
        for (u32 column = 0; column < width; column++) {
            dst[0] = color.r;
            dst[1] = color.g;
            dst[2] = color.b;
            dst[3] = color.a;
            dst += 4;
        }
    }
}

const int mLayerWidth = 900;
const int mLayerHeight = 900;
SurfaceComposerClient::Transaction t;

int main() {
    // Start the Binder thread pool
    ProcessState::self()->startThreadPool();

    // Initialize SurfaceComposerClient
    sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient;
    if (composerClient->initCheck() != NO_ERROR) {
        std::cerr << "Failed to initialize SurfaceComposerClient" << std::endl;
        return 1;
    }

    // Create a parent surface control
    sp<SurfaceControl> mParentLayer = composerClient->createSurface(
            String8("Parent Surface"), mLayerWidth, mLayerHeight, PIXEL_FORMAT_RGBA_8888, 0);

    if (mParentLayer == nullptr) {
        std::cerr << "Failed to create Parent SurfaceControl" << std::endl;
        return 1;
    }

    t.setLayer(mParentLayer,100)
    .show(mParentLayer)
    .apply();

    sp<Surface> surface = mParentLayer->getSurface();
    ANativeWindow_Buffer buffer = {};

    // Lock the child surface for drawing and fill with blue color
    surface->lock(&buffer, nullptr);
    const Rect topRect(0, 0, 400, 200);
    fillANativeWindowBufferColor(buffer, topRect, Color::RED); // Blue
    const Rect topRect2(0, 200, 400, 400);
    fillANativeWindowBufferColor(buffer, topRect2, Color::BLUE); // Blue
    surface->unlockAndPost();

    std::this_thread::sleep_for(std::chrono::seconds(3));

    Rect source = Rect(0, 0, 300, 300);
    Rect dest = Rect(600, 600, 900, 900);
    t.setGeometry(mParentLayer, source, dest, 0).apply();

    // Cleanup and exit
    IPCThreadState::self()->joinThreadPool();
    return 0;
}

在这里插入图片描述

在这里插入图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值