SurfaceComposerClient::mirrorSurface
compose
compose - Docker Compose是一个用于定义和运行多容器Docker应用程序的工具,通过Compose文件格式简化应用部署过程。
项目地址:https://gitcode.com/gh_mirrors/compose/compose
免费下载资源
·
//#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;
}
}
}
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"), 1300, 1300, PIXEL_FORMAT_RGBA_8888, 0);
if (mParentLayer == nullptr) {
std::cerr << "Failed to create Parent SurfaceControl" << std::endl;
return 1;
}
// Create a child surface control
sp<SurfaceControl> mChildLayer = composerClient->createSurface(
String8("Child Surface"), 500, 500, PIXEL_FORMAT_RGBA_8888, 0, mParentLayer->getHandle());
if (mChildLayer == nullptr) {
std::cerr << "Failed to create Child SurfaceControl" << std::endl;
return 1;
}
// Mirror the child layer
sp<SurfaceControl> mirrorLayer = composerClient->mirrorSurface(mChildLayer.get());
// Create a transaction to set surface properties
SurfaceComposerClient::Transaction transaction;
// Example: Set layer, size, position, and show child and mirror layers
transaction.setLayer(mChildLayer, 5)
.setSize(mChildLayer, 500, 500)
.setPosition(mChildLayer, 200, 0)
.show(mChildLayer)
.reparent(mirrorLayer, mParentLayer)
.setPosition(mirrorLayer, 200, 700)
.show(mirrorLayer)
.apply();
// Wait for user input or delay to observe the initial setup
// std::this_thread::sleep_for(std::chrono::seconds(3));
// Get the surface from SurfaceControl
sp<Surface> surface = mChildLayer->getSurface();
ANativeWindow_Buffer buffer = {};
// Lock the child surface for drawing and fill with blue color
surface->lock(&buffer, nullptr);
const Rect topRect(0, 0, 500, 500);
fillANativeWindowBufferColor(buffer, topRect, Color::RED); // Blue
surface->unlockAndPost();
// Wait for user input or delay to observe the changes after reparenting
std::this_thread::sleep_for(std::chrono::seconds(2));
// memset();
// // Lock the child surface again for drawing and fill with modified blue color
surface->lock(&buffer, nullptr);
const Rect topRect2(0, 0, 100, 100);
const Rect topRect3(100, 100, 500, 500);
fillANativeWindowBufferColor(buffer, topRect2, {255, 234, 0, 255}); // Modified Blue
fillANativeWindowBufferColor(buffer, topRect3, {0, 123, 87, 255});
surface->unlockAndPost();
// Cleanup and exit
IPCThreadState::self()->joinThreadPool();
return 0;
}
GitHub 加速计划 / compose / compose
33.27 K
5.15 K
下载
compose - Docker Compose是一个用于定义和运行多容器Docker应用程序的工具,通过Compose文件格式简化应用部署过程。
最近提交(Master分支:2 个月前 )
501b5acd
Add `jhrotko` to Core Maintainers.
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
7 天前
f51bc4cd
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
7 天前
更多推荐
已为社区贡献2条内容
所有评论(0)