本文整理汇总了C++中ANativeWindow::dequeueBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ ANativeWindow::dequeueBuffer方法的具体用法?C++ ANativeWindow::dequeueBuffer怎么用?C++ ANativeWindow::dequeueBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ANativeWindow
的用法示例。
在下文中一共展示了ANativeWindow::dequeueBuffer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ANativeWindowBuffer*
GonkDisplayICS::DequeueBuffer()
{
ANativeWindow *window = static_cast<ANativeWindow *>(mFBSurface.get());
ANativeWindowBuffer *buf = nullptr;
window->dequeueBuffer(window, &buf);
return buf;
}
示例2: clientInit
int MokoidSurface::clientInit(int x, int y, int w, int h, int *stride)
{
int depth = 16;
int fmt;
surfaceflinger_client = new SurfaceComposerClient;
if (surfaceflinger_client == NULL) {
LOGE("failed to create client\n");
return 0;
}
fmt = getFormat(depth);
if (fmt == PIXEL_FORMAT_UNKNOWN) {
LOGE("failed to find a format for depth %d\n", depth);
return 0;
}
// Refactor in Android 4.0
surfaceflinger_surfaceControl =
surfaceflinger_client->createSurface(getpid(), 0, w, h, fmt);
if (surfaceflinger_surfaceControl == NULL) {
LOGE("failed to create surfaceControl\n");
return 0;
}
// Refactor in Android 4.0
surfaceflinger_surface = surfaceflinger_surfaceControl->getSurface();
//surfaceflinger_client->openGlobalTransaction();
SurfaceComposerClient::openGlobalTransaction();
surfaceflinger_surfaceControl->setPosition(x, y);
surfaceflinger_surfaceControl->setLayer(INT_MAX);
//surfaceflinger_client->closeGlobalTransaction();
SurfaceComposerClient::closeGlobalTransaction();
if (stride)
*stride = w * depth / 8;
// Get native window
Parcel parcel;
SurfaceControl::writeSurfaceToParcel(surfaceflinger_surfaceControl, &parcel);
parcel.setDataPosition(0);
sp<Surface> surface = Surface::readFromParcel(parcel);
ANativeWindow* window = surface.get();
LOGI("mokoid native window = %p", window);
int err = native_window_set_buffer_count(window, 4);
ANativeWindowBuffer* buffer;
for (int i = 0; i < 4; i++) {
window->dequeueBuffer(window, &buffer);
LOGI("mokoid buffer %d: %p\n", i, buffer);
}
return 1;
}
示例3: swapBuffers
EGLBoolean egl_window_surface_t::swapBuffers()
{
DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
rcEnc->rcFlushWindowColorBuffer(rcEnc, rcSurface);
nativeWindow->queueBuffer(nativeWindow, buffer);
if (nativeWindow->dequeueBuffer(nativeWindow, &buffer)) {
buffer = NULL;
setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE);
}
nativeWindow->lockBuffer(nativeWindow, buffer);
rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface,
((cb_handle_t *)(buffer->handle))->hostHandle);
return EGL_TRUE;
}
示例4: init
EGLBoolean egl_window_surface_t::init()
{
if (nativeWindow->dequeueBuffer(nativeWindow, &buffer) != NO_ERROR) {
setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE);
}
nativeWindow->lockBuffer(nativeWindow, buffer);
DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uint32_t)config,
getWidth(), getHeight());
if (!rcSurface) {
ALOGE("rcCreateWindowSurface returned 0");
return EGL_FALSE;
}
rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface,
((cb_handle_t*)(buffer->handle))->hostHandle);
return EGL_TRUE;
}
示例5: IOMXHWBuffer_Dequeue
int IOMXHWBuffer_Dequeue( void *window, void **pp_handle )
{
ANativeWindow *anw = (ANativeWindow *)window;
ANativeWindowBuffer_t *anb;
status_t err = NO_ERROR;
CHECK_ANW();
#if ANDROID_API >= 18
err = anw->dequeueBuffer_DEPRECATED( anw, &anb );
#else
err = anw->dequeueBuffer( anw, &anb );
#endif
CHECK_ERR();
*pp_handle = anb;
return 0;
}
示例6: main
int main(int argc, char** argv)
{
// set up the thread-pool
sp<ProcessState> proc(ProcessState::self());
ProcessState::self()->startThreadPool();
// create a client to surfaceflinger
sp<SurfaceComposerClient> client = new SurfaceComposerClient();
sp<SurfaceControl> surfaceControl = client->createSurface(
String8("surface"), 160, 240, PIXEL_FORMAT_RGB_565, 0);
SurfaceComposerClient::openGlobalTransaction();
surfaceControl->setLayer(100000);
SurfaceComposerClient::closeGlobalTransaction();
// pretend it went cross-process
Parcel parcel;
SurfaceControl::writeSurfaceToParcel(surfaceControl, &parcel);
parcel.setDataPosition(0);
sp<Surface> surface = Surface::readFromParcel(parcel);
ANativeWindow* window = surface.get();
printf("window=%p\n", window);
int err = native_window_set_buffer_count(window, 8);
ANativeWindowBuffer* buffer;
for (int i=0 ; i<8 ; i++) {
window->dequeueBuffer(window, &buffer);
printf("buffer %d: %p\n", i, buffer);
}
printf("test complete. CTRL+C to finish.\n");
IPCThreadState::self()->joinThreadPool();
return 0;
}
示例7: printf
status_t s3d_camera_test(void)
{
printf("[Unit Test] SurfaceFlinger 3D display test !\n\n");
sp<SurfaceComposerClient> client;
//sp<SurfaceControl> u;
//sp<SurfaceControl> c;
sp<Surface> s;
Surface::SurfaceInfo i;
SkBitmap sbs;
SkBitmap cam;
// ready the png image file
if (false == SkImageDecoder::DecodeFile("/data/3D_Camera_SBS.png", &sbs) ||
false == SkImageDecoder::DecodeFile("/data/camera.png", &cam)) {
printf("fail load file");
return INVALID_OPERATION;
}
// create layer env
client = new SurfaceComposerClient();
printf("screen (w, h) = (%d, %d)\n\n",
(int)client->getDisplayWidth(0), (int)client->getDisplayHeight(0));
// test set to side by side mode, and pull to topest layer in transaction
printf("*** camera test ...\n");
u = client->createSurface(String8("test-ui"), 0, DRAW_FHD_W, DRAW_FHD_H, PIXEL_FORMAT_BGRA_8888);
c = client->createSurface(String8("test-camera"), 0, DRAW_FHD_W, DRAW_FHD_H, PIXEL_FORMAT_RGBX_8888);
client->openGlobalTransaction();
{
u->setLayer(210000);
c->setLayer(200000);
}
client->closeGlobalTransaction();
ANativeWindow *w; // fill camera surface
ANativeWindowBuffer *buf;
void *ptr;
const Rect rect0(544, 960);
const Rect rect1(960, 540);
s = u->getSurface(); // fill ui surface
s->lock(&i);
{
printf("lock ui, i.s=%d, i.h=%d\n",i.s, i.h);
memset(i.bits, 0, i.s * i.h * 4);
memcpy(i.bits, cam.getPixels(), 544 * 960 * 4);//buffer stride is bigger then ...
}
s->unlockAndPost();
s = c->getSurface();
w = s.get();
native_window_api_connect(w, NATIVE_WINDOW_API_CAMERA);
native_window_set_buffers_dimensions(w, 960, 540);
native_window_set_buffers_format(w, HAL_PIXEL_FORMAT_RGBX_8888);
native_window_set_usage(w, GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_S3D_TOP_AND_BOTTOM);
native_window_set_scaling_mode(w, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
native_window_set_buffers_transform(w, HAL_TRANSFORM_ROT_90);
w->dequeueBuffer(w, &buf);
GraphicBufferMapper::getInstance().lock(buf->handle, GRALLOC_USAGE_SW_WRITE_OFTEN, rect1, &ptr);
{
memcpy(ptr, sbs.getPixels(), 960 * 540 * 4);
}
GraphicBufferMapper::getInstance().unlock(buf->handle); // inlock to return buffer
w->queueBuffer(w, buf); // queue to display
uint8_t j = 0x80;
client->openGlobalTransaction();
{
u->setAlpha(j);
}
client->closeGlobalTransaction();
sleep(1);
client->dispose();
return NO_ERROR;
}
示例8: dlopen
extern "C" void
Java_org_mozilla_testuniversalsurfacetexture_TestUniversalSurfaceTexture_attachTexture(JNIEnv*
aJEnv, jclass klass, jobject aSurface, int aDestroyed)
{
__android_log_print(ANDROID_LOG_ERROR, "TUST", "### point a");
if (!sSurfaceClass) {
sSurfaceClass = reinterpret_cast<jclass>
(aJEnv->NewGlobalRef(aJEnv->FindClass("android/view/Surface")));
sNativeSurfaceField = aJEnv->GetFieldID(sSurfaceClass, "mNativeSurface", "I");
sSurfaceControlField = aJEnv->GetFieldID(sSurfaceClass, "mSurfaceControl", "I");
void* lib = dlopen("libui.so", RTLD_LAZY);
sw_gralloc_handle_t_lock = (typeof(sw_gralloc_handle_t_lock))
dlsym(lib, "_ZN7android19sw_gralloc_handle_t4lockEPS0_iiiiiPPv");
sw_gralloc_handle_t_unlock = (typeof(sw_gralloc_handle_t_unlock))
dlsym(lib, "_ZN7android19sw_gralloc_handle_t6unlockEPS0_");
__android_log_print(ANDROID_LOG_ERROR, "TUST", "### Lock=%p, unlock=%p",
sw_gralloc_handle_t_lock, sw_gralloc_handle_t_unlock);
lib = dlopen("libhardware.so", RTLD_LAZY);
hw_get_module = (typeof(hw_get_module))dlsym(lib, "hw_get_module");
hw_module_t* pModule;
hw_get_module("gralloc", &pModule);
sModule = reinterpret_cast<gralloc_module_t*>(pModule);
__android_log_print(ANDROID_LOG_ERROR, "TUST", "### Gralloc module=%p", pModule);
}
if (!sImage) {
ANativeWindow* nativeWindow = reinterpret_cast<ANativeWindow*>
(aJEnv->GetIntField(aSurface, sNativeSurfaceField) + 8);
/*Rect rect;
rect.left = rect.top = rect.right = rect.bottom = 0;
nativeWindow->perform(nativeWindow, NATIVE_WINDOW_SET_CROP, &rect);*/
// NB: nativeWindow->common.magic is '_wnd' as a FourCC.
// My version is 104.
__android_log_print(ANDROID_LOG_ERROR, "TUST",
"### Native window ptr %p, magic %08x, version %d, reserved %p, flags %d, dpi %g\n",
nativeWindow, (unsigned)nativeWindow->common.magic,
nativeWindow->common.version, nativeWindow->common.reserved[0],
(int)nativeWindow->flags, (double)nativeWindow->xdpi);
nativeWindow->dequeueBuffer(nativeWindow, &sBuffer);
nativeWindow->lockBuffer(nativeWindow, sBuffer);
// Must increment the refcount on the native window to avoid crashes on Mali (Galaxy S2).
nativeWindow->common.incRef(&nativeWindow->common);
const EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
sBuffer->common.incRef(&sBuffer->common);
sImage = eglCreateImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID,
reinterpret_cast<EGLClientBuffer>(sBuffer), eglImgAttrs);
//nativeWindow->queueBuffer(nativeWindow, sBuffer);
}
uint8_t *bits = 0;
int err = sModule->lock(sModule, sBuffer->handle, GRALLOC_USAGE_SW_READ_OFTEN |
GRALLOC_USAGE_SW_WRITE_OFTEN, 0, 0, 512, 512, (void**)&bits);
__android_log_print(ANDROID_LOG_ERROR, "TUST",
"### Buffer width=%d height=%d stride=%d format=%d usage=%d Bits are: %p, err=%d",
sBuffer->width, sBuffer->height, sBuffer->stride, sBuffer->format, sBuffer->usage,
bits, err);
struct timeval tv;
gettimeofday(&tv, NULL);
static int x = 0;
for (int i = 0; i < 512*512*2; i += 2) {
bits[i] = bits[i+1] = (tv.tv_usec / 100000) % 256;
}
sModule->unlock(sModule, sBuffer->handle);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, sImage);
__android_log_print(ANDROID_LOG_ERROR, "TUST", "### Success! GL error is: %d",
(int)glGetError());
}