//#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
const Rect topRect3(200, 0, 400, 400);
fillANativeWindowBufferColor(buffer, topRect3, Color::GREEN); // 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, HAL_TRANSFORM_ROT_90).apply();
// Cleanup and exit
IPCThreadState::self()->joinThreadPool();
return 0;
}
after HAL_TRANSFORM_ROT_90