Skip to content

anyshu/GraphicBuffer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphicBuffer

Use GraphicBuffer class in Android native code in your project, without compiling with Android source code.

Inspired by tcuAndroidInternals.cpp

How to use

The usage is exactly the same with android::GraphicBuffer

#include "GraphicBuffer.h"

Intialize

int usage = GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_READ_OFTEN | GraphicBuffer::USAGE_SW_WRITE_RARELY;
auto graphicBuf = std::make_unique<GraphicBuffer>(width, height, PIXEL_FORMAT_RGBA_8888, usage);

Get ANativeWindowBuffer (or EGLClientBuffer)

auto clientBuf = (EGLClientBuffer) graphicBuf->getNativeBuffer();

Get content image:

void *readPtr, *writePtr;
graphicBuf->lock(GraphicBuffer::USAGE_SW_READ_OFTEN, &readPtr);
writePtr = image.data;
int stride = graphicBuf->getStride();
for (int row = 0; row < height; row++) {
    memcpy(writePtr, readPtr, width * 4);
    readPtr = (void *)(int(readPtr) + stride * 4);
    writePtr = (void *)(int(writePtr) + width * 4);
}
graphicBuf->unlock();

About

use GraphicBuffer of Android native code in your project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 100.0%