Lines Matching refs:ctx
216 copybit_context_t* ctx = (copybit_context_t*)(ptr); in c2d_wait_loop() local
221 while(ctx->stop_thread == false) { in c2d_wait_loop()
222 pthread_mutex_lock(&ctx->wait_cleanup_lock); in c2d_wait_loop()
223 while(ctx->wait_timestamp == false && !ctx->stop_thread) { in c2d_wait_loop()
224 pthread_cond_wait(&(ctx->wait_cleanup_cond), in c2d_wait_loop()
225 &(ctx->wait_cleanup_lock)); in c2d_wait_loop()
227 if(ctx->wait_timestamp) { in c2d_wait_loop()
228 if(LINK_c2dWaitTimestamp(ctx->time_stamp)) { in c2d_wait_loop()
231 ctx->wait_timestamp = false; in c2d_wait_loop()
234 if (ctx->mapped_gpu_addr[i]) { in c2d_wait_loop()
235 LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[i]); in c2d_wait_loop()
236 ctx->mapped_gpu_addr[i] = 0; in c2d_wait_loop()
240 ctx->blit_rgb_count = 0; in c2d_wait_loop()
241 ctx->blit_yuv_2_plane_count = 0; in c2d_wait_loop()
242 ctx->blit_yuv_3_plane_count = 0; in c2d_wait_loop()
243 ctx->blit_count = 0; in c2d_wait_loop()
245 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in c2d_wait_loop()
246 if(ctx->stop_thread) in c2d_wait_loop()
335 static uint32 c2d_get_gpuaddr(copybit_context_t* ctx, struct private_handle_t *handle, in c2d_get_gpuaddr() argument
363 if (ctx->mapped_gpu_addr[i] == 0) { in c2d_get_gpuaddr()
364 ctx->mapped_gpu_addr[i] = (uint32) gpuaddr; in c2d_get_gpuaddr()
375 static void unmap_gpuaddr(copybit_context_t* ctx, int mapped_idx) in unmap_gpuaddr() argument
377 if (!ctx || (mapped_idx == -1)) in unmap_gpuaddr()
380 if (ctx->mapped_gpu_addr[mapped_idx]) { in unmap_gpuaddr()
381 LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[mapped_idx]); in unmap_gpuaddr()
382 ctx->mapped_gpu_addr[mapped_idx] = 0; in unmap_gpuaddr()
487 static int set_image(copybit_context_t* ctx, uint32 surfaceId, in set_image() argument
515 gpuaddr = c2d_get_gpuaddr(ctx, handle, mapped_idx); in set_image()
544 unmap_gpuaddr(ctx, mapped_idx); in set_image()
562 unmap_gpuaddr(ctx, mapped_idx); in set_image()
583 unmap_gpuaddr(ctx, mapped_idx); in set_image()
588 unmap_gpuaddr(ctx, mapped_idx); in set_image()
596 static int msm_copybit(struct copybit_context_t *ctx, unsigned int target) in msm_copybit() argument
598 if (ctx->blit_count == 0) { in msm_copybit()
602 for (int i = 0; i < ctx->blit_count; i++) in msm_copybit()
604 ctx->blit_list[i].next = &(ctx->blit_list[i+1]); in msm_copybit()
606 ctx->blit_list[ctx->blit_count-1].next = NULL; in msm_copybit()
607 uint32_t target_transform = ctx->trg_transform; in msm_copybit()
608 if (ctx->c2d_driver_info.capabilities_mask & in msm_copybit()
613 if(LINK_c2dDraw(target, target_transform, 0x0, 0, 0, ctx->blit_list, in msm_copybit()
614 ctx->blit_count)) { in msm_copybit()
625 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in flush_get_fence_copybit() local
627 if (!ctx) in flush_get_fence_copybit()
629 pthread_mutex_lock(&ctx->wait_cleanup_lock); in flush_get_fence_copybit()
630 status = msm_copybit(ctx, ctx->dst[ctx->dst_surface_type]); in flush_get_fence_copybit()
632 if(LINK_c2dFlush(ctx->dst[ctx->dst_surface_type], &ctx->time_stamp)) { in flush_get_fence_copybit()
635 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in flush_get_fence_copybit()
638 if(LINK_c2dCreateFenceFD(ctx->dst[ctx->dst_surface_type], ctx->time_stamp, in flush_get_fence_copybit()
645 ctx->wait_timestamp = true; in flush_get_fence_copybit()
646 pthread_cond_signal(&ctx->wait_cleanup_cond); in flush_get_fence_copybit()
648 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in flush_get_fence_copybit()
654 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in finish_copybit() local
655 if (!ctx) in finish_copybit()
658 int status = msm_copybit(ctx, ctx->dst[ctx->dst_surface_type]); in finish_copybit()
660 if(LINK_c2dFinish(ctx->dst[ctx->dst_surface_type])) { in finish_copybit()
667 if (ctx->mapped_gpu_addr[i]) { in finish_copybit()
668 LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[i]); in finish_copybit()
669 ctx->mapped_gpu_addr[i] = 0; in finish_copybit()
674 ctx->blit_rgb_count = 0; in finish_copybit()
675 ctx->blit_yuv_2_plane_count = 0; in finish_copybit()
676 ctx->blit_yuv_3_plane_count = 0; in finish_copybit()
677 ctx->blit_count = 0; in finish_copybit()
688 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in clear_copybit() local
690 pthread_mutex_lock(&ctx->wait_cleanup_lock); in clear_copybit()
691 ret = set_image(ctx, ctx->dst[RGB_SURFACE], buf, in clear_copybit()
695 unmap_gpuaddr(ctx, mapped_dst_idx); in clear_copybit()
696 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in clear_copybit()
700 ret = LINK_c2dFillSurface(ctx->dst[RGB_SURFACE], 0x0, &c2drect); in clear_copybit()
701 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in clear_copybit()
707 static void set_rects(struct copybit_context_t *ctx, in set_rects() argument
714 if((ctx->trg_transform & C2D_TARGET_ROTATE_90) && in set_rects()
715 (ctx->trg_transform & C2D_TARGET_ROTATE_180)) { in set_rects()
718 c2dObject->target_rect.y = ctx->fb_width?(ALIGN(ctx->fb_width,32)- dst->r):dst->r; in set_rects()
722 } else if(ctx->trg_transform & C2D_TARGET_ROTATE_90) { in set_rects()
723 c2dObject->target_rect.x = ctx->fb_height?(ctx->fb_height - dst->b):dst->b; in set_rects()
728 } else if(ctx->trg_transform & C2D_TARGET_ROTATE_180) { in set_rects()
729 c2dObject->target_rect.y = ctx->fb_height?(ctx->fb_height - dst->b):dst->b; in set_rects()
731 c2dObject->target_rect.x = ctx->fb_width?(ALIGN(ctx->fb_width,32) - dst->r):dst->r; in set_rects()
766 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in set_parameter_copybit() local
768 if (!ctx) { in set_parameter_copybit()
773 pthread_mutex_lock(&ctx->wait_cleanup_lock); in set_parameter_copybit()
780 ctx->src_global_alpha = value; in set_parameter_copybit()
782 ctx->config_mask |= C2D_GLOBAL_ALPHA_BIT; in set_parameter_copybit()
784 ctx->config_mask &= ~C2D_GLOBAL_ALPHA_BIT; in set_parameter_copybit()
790 ctx->config_mask |= C2D_ALPHA_BLEND_NONE; in set_parameter_copybit()
791 ctx->is_premultiplied_alpha = true; in set_parameter_copybit()
793 ctx->is_premultiplied_alpha = true; in set_parameter_copybit()
795 ctx->config_mask &= ~C2D_ALPHA_BLEND_NONE; in set_parameter_copybit()
822 if (ctx->c2d_driver_info.capabilities_mask & in set_parameter_copybit()
824 ctx->config_mask |= config_mask; in set_parameter_copybit()
832 ctx->trg_transform = transform; in set_parameter_copybit()
836 ctx->fb_width = value; in set_parameter_copybit()
839 ctx->fb_height = value; in set_parameter_copybit()
852 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in set_parameter_copybit()
859 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in get() local
862 if (!ctx) { in get()
1055 static bool need_to_execute_draw(struct copybit_context_t* ctx, in need_to_execute_draw() argument
1077 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in stretch_copybit_internal() local
1084 if (!ctx) { in stretch_copybit_internal()
1128 if (ctx->blit_rgb_count == MAX_RGB_SURFACES || in stretch_copybit_internal()
1129 ctx->blit_yuv_2_plane_count == MAX_YUV_2_PLANE_SURFACES || in stretch_copybit_internal()
1130 ctx->blit_yuv_3_plane_count == MAX_YUV_2_PLANE_SURFACES || in stretch_copybit_internal()
1131 ctx->blit_count == MAX_BLIT_OBJECT_COUNT || in stretch_copybit_internal()
1132 ctx->dst_surface_type != dst_surface_type) { in stretch_copybit_internal()
1140 ctx->dst_surface_type = dst_surface_type; in stretch_copybit_internal()
1161 if (get_size(dst_info) != ctx->temp_dst_buffer.size) { in stretch_copybit_internal()
1162 free_temp_buffer(ctx->temp_dst_buffer); in stretch_copybit_internal()
1164 if (COPYBIT_FAILURE == get_temp_buffer(dst_info, ctx->temp_dst_buffer)) { in stretch_copybit_internal()
1170 dst_hnd->fd = ctx->temp_dst_buffer.fd; in stretch_copybit_internal()
1171 dst_hnd->size = ctx->temp_dst_buffer.size; in stretch_copybit_internal()
1172 dst_hnd->flags = ctx->temp_dst_buffer.allocType; in stretch_copybit_internal()
1173 dst_hnd->base = (int)(ctx->temp_dst_buffer.base); in stretch_copybit_internal()
1174 dst_hnd->offset = ctx->temp_dst_buffer.offset; in stretch_copybit_internal()
1179 status = set_image(ctx, ctx->dst[ctx->dst_surface_type], &dst_image, in stretch_copybit_internal()
1184 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1192 src_surface = ctx->blit_rgb_object[ctx->blit_rgb_count]; in stretch_copybit_internal()
1197 src_surface = ctx->blit_yuv_2_plane_object[ctx->blit_yuv_2_plane_count]; in stretch_copybit_internal()
1200 src_surface = ctx->blit_yuv_3_plane_object[ctx->blit_yuv_2_plane_count]; in stretch_copybit_internal()
1205 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1212 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1230 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1234 if (get_size(src_info) != ctx->temp_src_buffer.size) { in stretch_copybit_internal()
1235 free_temp_buffer(ctx->temp_src_buffer); in stretch_copybit_internal()
1238 ctx->temp_src_buffer)) { in stretch_copybit_internal()
1242 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1246 src_hnd->fd = ctx->temp_src_buffer.fd; in stretch_copybit_internal()
1247 src_hnd->size = ctx->temp_src_buffer.size; in stretch_copybit_internal()
1248 src_hnd->flags = ctx->temp_src_buffer.allocType; in stretch_copybit_internal()
1249 src_hnd->base = (int)(ctx->temp_src_buffer.base); in stretch_copybit_internal()
1250 src_hnd->offset = ctx->temp_src_buffer.offset; in stretch_copybit_internal()
1261 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1273 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1278 flags |= (ctx->is_premultiplied_alpha) ? FLAGS_PREMULTIPLIED_ALPHA : 0; in stretch_copybit_internal()
1279 flags |= (ctx->dst_surface_type != RGB_SURFACE) ? FLAGS_YUV_DESTINATION : 0; in stretch_copybit_internal()
1280 status = set_image(ctx, src_surface.surface_id, &src_image, in stretch_copybit_internal()
1286 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1287 unmap_gpuaddr(ctx, mapped_src_idx); in stretch_copybit_internal()
1291 src_surface.config_mask = C2D_NO_ANTIALIASING_BIT | ctx->config_mask; in stretch_copybit_internal()
1292 src_surface.global_alpha = ctx->src_global_alpha; in stretch_copybit_internal()
1300 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1301 unmap_gpuaddr(ctx, mapped_src_idx); in stretch_copybit_internal()
1310 ctx->blit_rgb_object[ctx->blit_rgb_count] = src_surface; in stretch_copybit_internal()
1311 ctx->blit_rgb_count++; in stretch_copybit_internal()
1313 ctx->blit_yuv_2_plane_object[ctx->blit_yuv_2_plane_count] = src_surface; in stretch_copybit_internal()
1314 ctx->blit_yuv_2_plane_count++; in stretch_copybit_internal()
1316 ctx->blit_yuv_3_plane_object[ctx->blit_yuv_3_plane_count] = src_surface; in stretch_copybit_internal()
1317 ctx->blit_yuv_3_plane_count++; in stretch_copybit_internal()
1322 set_rects(ctx, &(src_surface), dst_rect, src_rect, &clip); in stretch_copybit_internal()
1323 if (ctx->blit_count == MAX_BLIT_OBJECT_COUNT) { in stretch_copybit_internal()
1327 ctx->blit_list[ctx->blit_count] = src_surface; in stretch_copybit_internal()
1328 ctx->blit_count++; in stretch_copybit_internal()
1333 if (need_to_execute_draw(ctx, (eC2DFlags)flags)) in stretch_copybit_internal()
1346 unmap_gpuaddr(ctx, mapped_dst_idx); in stretch_copybit_internal()
1347 unmap_gpuaddr(ctx, mapped_src_idx); in stretch_copybit_internal()
1359 ctx->is_premultiplied_alpha = false; in stretch_copybit_internal()
1360 ctx->fb_width = 0; in stretch_copybit_internal()
1361 ctx->fb_height = 0; in stretch_copybit_internal()
1362 ctx->config_mask = 0; in stretch_copybit_internal()
1375 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in stretch_copybit() local
1377 bool needsBlending = (ctx->src_global_alpha != 0); in stretch_copybit()
1378 pthread_mutex_lock(&ctx->wait_cleanup_lock); in stretch_copybit()
1381 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in stretch_copybit()
1393 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in blit_copybit() local
1396 pthread_mutex_lock(&ctx->wait_cleanup_lock); in blit_copybit()
1398 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in blit_copybit()
1404 static void clean_up(copybit_context_t* ctx) in clean_up() argument
1407 if (!ctx) in clean_up()
1411 pthread_mutex_lock(&ctx->wait_cleanup_lock); in clean_up()
1412 ctx->stop_thread = true; in clean_up()
1414 pthread_cond_signal(&ctx->wait_cleanup_cond); in clean_up()
1415 pthread_mutex_unlock(&ctx->wait_cleanup_lock); in clean_up()
1417 pthread_join(ctx->wait_thread_id, &ret); in clean_up()
1418 pthread_mutex_destroy(&ctx->wait_cleanup_lock); in clean_up()
1419 pthread_cond_destroy (&ctx->wait_cleanup_cond); in clean_up()
1422 if (ctx->dst[i]) in clean_up()
1423 LINK_c2dDestroySurface(ctx->dst[i]); in clean_up()
1427 if (ctx->blit_rgb_object[i].surface_id) in clean_up()
1428 LINK_c2dDestroySurface(ctx->blit_rgb_object[i].surface_id); in clean_up()
1432 if (ctx->blit_yuv_2_plane_object[i].surface_id) in clean_up()
1433 LINK_c2dDestroySurface(ctx->blit_yuv_2_plane_object[i].surface_id); in clean_up()
1437 if (ctx->blit_yuv_3_plane_object[i].surface_id) in clean_up()
1438 LINK_c2dDestroySurface(ctx->blit_yuv_3_plane_object[i].surface_id); in clean_up()
1441 if (ctx->libc2d2) { in clean_up()
1442 ::dlclose(ctx->libc2d2); in clean_up()
1446 free(ctx); in clean_up()
1452 struct copybit_context_t* ctx = (struct copybit_context_t*)dev; in close_copybit() local
1453 if (ctx) { in close_copybit()
1454 free_temp_buffer(ctx->temp_src_buffer); in close_copybit()
1455 free_temp_buffer(ctx->temp_dst_buffer); in close_copybit()
1457 clean_up(ctx); in close_copybit()
1468 struct copybit_context_t *ctx; in open_copybit() local
1471 ctx = (struct copybit_context_t *)malloc(sizeof(struct copybit_context_t)); in open_copybit()
1472 if(!ctx) { in open_copybit()
1478 memset(ctx, 0, sizeof(*ctx)); in open_copybit()
1479 ctx->libc2d2 = ::dlopen("libC2D2.so", RTLD_NOW); in open_copybit()
1480 if (!ctx->libc2d2) { in open_copybit()
1482 clean_up(ctx); in open_copybit()
1487 *(void **)&LINK_c2dCreateSurface = ::dlsym(ctx->libc2d2, in open_copybit()
1489 *(void **)&LINK_c2dUpdateSurface = ::dlsym(ctx->libc2d2, in open_copybit()
1491 *(void **)&LINK_c2dReadSurface = ::dlsym(ctx->libc2d2, in open_copybit()
1493 *(void **)&LINK_c2dDraw = ::dlsym(ctx->libc2d2, "c2dDraw"); in open_copybit()
1494 *(void **)&LINK_c2dFlush = ::dlsym(ctx->libc2d2, "c2dFlush"); in open_copybit()
1495 *(void **)&LINK_c2dFinish = ::dlsym(ctx->libc2d2, "c2dFinish"); in open_copybit()
1496 *(void **)&LINK_c2dWaitTimestamp = ::dlsym(ctx->libc2d2, in open_copybit()
1498 *(void **)&LINK_c2dDestroySurface = ::dlsym(ctx->libc2d2, in open_copybit()
1500 *(void **)&LINK_c2dMapAddr = ::dlsym(ctx->libc2d2, in open_copybit()
1502 *(void **)&LINK_c2dUnMapAddr = ::dlsym(ctx->libc2d2, in open_copybit()
1504 *(void **)&LINK_c2dGetDriverCapabilities = ::dlsym(ctx->libc2d2, in open_copybit()
1506 *(void **)&LINK_c2dCreateFenceFD = ::dlsym(ctx->libc2d2, in open_copybit()
1508 *(void **)&LINK_c2dFillSurface = ::dlsym(ctx->libc2d2, in open_copybit()
1517 clean_up(ctx); in open_copybit()
1523 ctx->device.common.tag = HARDWARE_DEVICE_TAG; in open_copybit()
1524 ctx->device.common.version = 1; in open_copybit()
1525 ctx->device.common.module = (hw_module_t*)(module); in open_copybit()
1526 ctx->device.common.close = close_copybit; in open_copybit()
1527 ctx->device.set_parameter = set_parameter_copybit; in open_copybit()
1528 ctx->device.get = get; in open_copybit()
1529 ctx->device.blit = blit_copybit; in open_copybit()
1530 ctx->device.stretch = stretch_copybit; in open_copybit()
1531 ctx->device.finish = finish_copybit; in open_copybit()
1532 ctx->device.flush_get_fence = flush_get_fence_copybit; in open_copybit()
1533 ctx->device.clear = clear_copybit; in open_copybit()
1542 if (LINK_c2dCreateSurface(&(ctx->dst[RGB_SURFACE]), C2D_TARGET | C2D_SOURCE, in open_copybit()
1548 ctx->dst[RGB_SURFACE] = 0; in open_copybit()
1549 clean_up(ctx); in open_copybit()
1564 ctx->blit_rgb_object[i].surface_id = 0; in open_copybit()
1568 ctx->blit_rgb_object[i].surface_id = surface_id; in open_copybit()
1570 ctx->blit_rgb_object[i].surface_id); in open_copybit()
1575 clean_up(ctx); in open_copybit()
1592 if (LINK_c2dCreateSurface(&(ctx->dst[YUV_SURFACE_2_PLANES]), in open_copybit()
1599 ctx->dst[YUV_SURFACE_2_PLANES] = 0; in open_copybit()
1600 clean_up(ctx); in open_copybit()
1614 ctx->blit_yuv_2_plane_object[i].surface_id = 0; in open_copybit()
1618 ctx->blit_yuv_2_plane_object[i].surface_id = surface_id; in open_copybit()
1620 ctx->blit_yuv_2_plane_object[i].surface_id); in open_copybit()
1625 clean_up(ctx); in open_copybit()
1637 if (LINK_c2dCreateSurface(&(ctx->dst[YUV_SURFACE_3_PLANES]), in open_copybit()
1644 ctx->dst[YUV_SURFACE_3_PLANES] = 0; in open_copybit()
1645 clean_up(ctx); in open_copybit()
1660 ctx->blit_yuv_3_plane_object[i].surface_id = 0; in open_copybit()
1664 ctx->blit_yuv_3_plane_object[i].surface_id = surface_id; in open_copybit()
1666 ctx->blit_yuv_3_plane_object[i].surface_id); in open_copybit()
1671 clean_up(ctx); in open_copybit()
1677 if (LINK_c2dGetDriverCapabilities(&(ctx->c2d_driver_info))) { in open_copybit()
1679 clean_up(ctx); in open_copybit()
1685 ctx->trg_transform = C2D_TARGET_ROTATE_0; in open_copybit()
1687 ctx->temp_src_buffer.fd = -1; in open_copybit()
1688 ctx->temp_src_buffer.base = 0; in open_copybit()
1689 ctx->temp_src_buffer.size = 0; in open_copybit()
1691 ctx->temp_dst_buffer.fd = -1; in open_copybit()
1692 ctx->temp_dst_buffer.base = 0; in open_copybit()
1693 ctx->temp_dst_buffer.size = 0; in open_copybit()
1695 ctx->fb_width = 0; in open_copybit()
1696 ctx->fb_height = 0; in open_copybit()
1698 ctx->blit_rgb_count = 0; in open_copybit()
1699 ctx->blit_yuv_2_plane_count = 0; in open_copybit()
1700 ctx->blit_yuv_3_plane_count = 0; in open_copybit()
1701 ctx->blit_count = 0; in open_copybit()
1703 ctx->wait_timestamp = false; in open_copybit()
1704 ctx->stop_thread = false; in open_copybit()
1705 pthread_mutex_init(&(ctx->wait_cleanup_lock), NULL); in open_copybit()
1706 pthread_cond_init(&(ctx->wait_cleanup_cond), NULL); in open_copybit()
1712 pthread_create(&ctx->wait_thread_id, &attr, &c2d_wait_loop, in open_copybit()
1713 (void *)ctx); in open_copybit()
1716 *device = &ctx->device.common; in open_copybit()