copybit: Use proper type casts and pointers

- Remove unused variables
- Use proper type casts for pointers.

Change-Id: Ie07c67d759d76f418fae08accdcfb1855511dedf
diff --git a/libcopybit/copybit.cpp b/libcopybit/copybit.cpp
index c0246e3..645cd81 100644
--- a/libcopybit/copybit.cpp
+++ b/libcopybit/copybit.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2010 - 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2010 - 2014, The Linux Foundation. All rights reserved.
  *
  * Not a Contribution, Apache license notifications and license are retained
  * for attribution purposes only.
@@ -154,7 +154,7 @@
     img->width      = rhs->w;
     img->height     = rhs->h;
     img->format     = get_format(rhs->format);
-    img->offset     = hnd->offset;
+    img->offset     = (uint32_t)hnd->offset;
     img->memory_id  = hnd->fd;
 }
 /** setup rectangles */
@@ -162,9 +162,7 @@
                       struct mdp_blit_req *e,
                       const struct copybit_rect_t *dst,
                       const struct copybit_rect_t *src,
-                      const struct copybit_rect_t *scissor,
-                      uint32_t horiz_padding,
-                      uint32_t vert_padding) {
+                      const struct copybit_rect_t *scissor) {
     struct copybit_rect_t clip;
     intersect(&clip, scissor, dst);
 
@@ -312,7 +310,7 @@
             case COPYBIT_PLANE_ALPHA:
                 if (value < 0)      value = MDP_ALPHA_NOP;
                 if (value >= 256)   value = 255;
-                ctx->mAlpha = value;
+                ctx->mAlpha = (uint8_t)value;
                 break;
             case COPYBIT_DITHER:
                 if (value == COPYBIT_ENABLE) {
@@ -491,7 +489,8 @@
                 return -EINVAL;
             }
         }
-        const uint32_t maxCount = sizeof(list->req)/sizeof(list->req[0]);
+        const uint32_t maxCount =
+                (uint32_t)(sizeof(list->req)/sizeof(list->req[0]));
         const struct copybit_rect_t bounds = { 0, 0, (int)dst->w, (int)dst->h };
         struct copybit_rect_t clip;
         status = 0;
@@ -508,7 +507,7 @@
             set_infos(ctx, req, flags);
             set_image(&req->dst, dst);
             set_image(&req->src, src);
-            set_rects(ctx, req, dst_rect, src_rect, &clip, src->horiz_padding, src->vert_padding);
+            set_rects(ctx, req, dst_rect, src_rect, &clip);
 
             if (req->src_rect.w<=0 || req->src_rect.h<=0)
                 continue;
@@ -553,6 +552,9 @@
 static int finish_copybit(struct copybit_device_t *dev)
 {
     // NOP for MDP copybit
+    if(!dev)
+       return -EINVAL;
+
     return 0;
 }
 static int clear_copybit(struct copybit_device_t *dev,
@@ -702,6 +704,10 @@
                         struct hw_device_t** device)
 {
     int status = -EINVAL;
+
+    if (!strcmp(name, COPYBIT_HARDWARE_COPYBIT0)) {
+        return COPYBIT_FAILURE;
+    }
     copybit_context_t *ctx;
     ctx = (copybit_context_t *)malloc(sizeof(copybit_context_t));
     memset(ctx, 0, sizeof(*ctx));
diff --git a/libcopybit/copybit_c2d.cpp b/libcopybit/copybit_c2d.cpp
index 231bb2d..852b8c0 100644
--- a/libcopybit/copybit_c2d.cpp
+++ b/libcopybit/copybit_c2d.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
  *
  * Not a Contribution, Apache license notifications and license are retained
  * for attribution purposes only.
@@ -80,8 +80,8 @@
 
 C2D_STATUS (*LINK_c2dDestroySurface)( uint32 surface_id );
 
-C2D_STATUS (*LINK_c2dMapAddr) ( int mem_fd, void * hostptr, uint32 len,
-                                uint32 offset, uint32 flags, void ** gpuaddr);
+C2D_STATUS (*LINK_c2dMapAddr) ( int mem_fd, void * hostptr, size_t len,
+                                size_t offset, uint32 flags, void ** gpuaddr);
 
 C2D_STATUS (*LINK_c2dUnMapAddr) ( void * gpuaddr);
 
@@ -147,7 +147,7 @@
     alloc_data temp_src_buffer;
     alloc_data temp_dst_buffer;
     unsigned int dst[NUM_SURFACE_TYPES]; // dst surfaces
-    unsigned int mapped_gpu_addr[MAX_SURFACES]; // GPU addresses mapped inside copybit
+    uintptr_t mapped_gpu_addr[MAX_SURFACES]; // GPU addresses mapped inside copybit
     int blit_rgb_count;         // Total RGB surfaces being blit
     int blit_yuv_2_plane_count; // Total 2 plane YUV surfaces being
     int blit_yuv_3_plane_count; // Total 3 plane YUV  surfaces being blit
@@ -182,8 +182,8 @@
     int yStride;       //luma stride
     int plane1_stride;
     int plane2_stride;
-    int plane1_offset;
-    int plane2_offset;
+    size_t plane1_offset;
+    size_t plane2_offset;
 };
 
 /**
@@ -334,10 +334,11 @@
     return c2dBpp;
 }
 
-static uint32 c2d_get_gpuaddr(copybit_context_t* ctx,
+static size_t c2d_get_gpuaddr(copybit_context_t* ctx,
                               struct private_handle_t *handle, int &mapped_idx)
 {
-    uint32 memtype, *gpuaddr = 0;
+    uint32 memtype;
+    size_t *gpuaddr = 0;
     C2D_STATUS rc;
     int freeindex = 0;
     bool mapaddr = false;
@@ -374,11 +375,11 @@
         if (rc == C2D_STATUS_OK) {
             // We have mapped the GPU address inside copybit. We need to unmap
             // this address after the blit. Store this address
-            ctx->mapped_gpu_addr[freeindex] = (uint32) gpuaddr;
+            ctx->mapped_gpu_addr[freeindex] = (size_t)gpuaddr;
             mapped_idx = freeindex;
         }
     }
-    return (uint32) gpuaddr;
+    return (size_t)gpuaddr;
 }
 
 static void unmap_gpuaddr(copybit_context_t* ctx, int mapped_idx)
@@ -498,7 +499,7 @@
     struct private_handle_t* handle = (struct private_handle_t*)rhs->handle;
     C2D_SURFACE_TYPE surfaceType;
     int status = COPYBIT_SUCCESS;
-    uint32 gpuaddr = 0;
+    uintptr_t gpuaddr = 0;
     int c2d_format;
     mapped_idx = -1;
 
@@ -542,7 +543,7 @@
             ((flags & FLAGS_PREMULTIPLIED_ALPHA) ? C2D_FORMAT_PREMULTIPLIED : 0);
         surfaceDef.width = rhs->w;
         surfaceDef.height = rhs->h;
-        int aligned_width = ALIGN(surfaceDef.width,32);
+        int aligned_width = ALIGN((int)surfaceDef.width,32);
         surfaceDef.stride = (aligned_width * c2diGetBpp(surfaceDef.format))>>3;
 
         if(LINK_c2dUpdateSurface( surfaceId,C2D_TARGET | C2D_SOURCE, surfaceType,
@@ -730,7 +731,8 @@
        (ctx->trg_transform & C2D_TARGET_ROTATE_180)) {
         /* target rotation is 270 */
         c2dObject->target_rect.x        = (dst->t)<<16;
-        c2dObject->target_rect.y        = ctx->fb_width?(ALIGN(ctx->fb_width,32)- dst->r):dst->r;
+        c2dObject->target_rect.y        = ctx->fb_width?
+                (ALIGN(ctx->fb_width,32)- dst->r):dst->r;
         c2dObject->target_rect.y        = c2dObject->target_rect.y<<16;
         c2dObject->target_rect.height   = ((dst->r) - (dst->l))<<16;
         c2dObject->target_rect.width    = ((dst->b) - (dst->t))<<16;
@@ -743,7 +745,8 @@
     } else if(ctx->trg_transform & C2D_TARGET_ROTATE_180) {
         c2dObject->target_rect.y        = ctx->fb_height?(ctx->fb_height - dst->b):dst->b;
         c2dObject->target_rect.y        = c2dObject->target_rect.y<<16;
-        c2dObject->target_rect.x        = ctx->fb_width?(ALIGN(ctx->fb_width,32) - dst->r):dst->r;
+        c2dObject->target_rect.x        = ctx->fb_width?
+                (ALIGN(ctx->fb_width,32) - dst->r):dst->r;
         c2dObject->target_rect.x        = c2dObject->target_rect.x<<16;
         c2dObject->target_rect.height   = ((dst->b) - (dst->t))<<16;
         c2dObject->target_rect.width    = ((dst->r) - (dst->l))<<16;
@@ -957,7 +960,7 @@
  */
 static size_t get_size(const bufferInfo& info)
 {
-    size_t size = 0;
+    int size = 0;
     int w = info.width;
     int h = info.height;
     int aligned_w = ALIGN(w, 32);
@@ -1067,8 +1070,7 @@
     }
 }
 
-static bool need_to_execute_draw(struct copybit_context_t* ctx,
-                                          eC2DFlags flags)
+static bool need_to_execute_draw(eC2DFlags flags)
 {
     if (flags & FLAGS_TEMP_SRC_DST) {
         return true;
@@ -1185,7 +1187,7 @@
         dst_hnd->fd = ctx->temp_dst_buffer.fd;
         dst_hnd->size = ctx->temp_dst_buffer.size;
         dst_hnd->flags = ctx->temp_dst_buffer.allocType;
-        dst_hnd->base = (int)(ctx->temp_dst_buffer.base);
+        dst_hnd->base = (uintptr_t)(ctx->temp_dst_buffer.base);
         dst_hnd->offset = ctx->temp_dst_buffer.offset;
         dst_hnd->gpuaddr = 0;
         dst_image.handle = dst_hnd;
@@ -1270,7 +1272,7 @@
         src_hnd->fd = ctx->temp_src_buffer.fd;
         src_hnd->size = ctx->temp_src_buffer.size;
         src_hnd->flags = ctx->temp_src_buffer.allocType;
-        src_hnd->base = (int)(ctx->temp_src_buffer.base);
+        src_hnd->base = (uintptr_t)(ctx->temp_src_buffer.base);
         src_hnd->offset = ctx->temp_src_buffer.offset;
         src_hnd->gpuaddr = 0;
         src_image.handle = src_hnd;
@@ -1354,7 +1356,7 @@
 
     // Check if we need to perform an early draw-finish.
     flags |= (need_temp_dst || need_temp_src) ? FLAGS_TEMP_SRC_DST : 0;
-    if (need_to_execute_draw(ctx, (eC2DFlags)flags))
+    if (need_to_execute_draw((eC2DFlags)flags))
     {
         finish_copybit(dev);
     }
@@ -1388,8 +1390,11 @@
 }
 
 static int set_sync_copybit(struct copybit_device_t *dev,
-    int acquireFenceFd)
+    int /*acquireFenceFd*/)
 {
+    if(!dev)
+        return -EINVAL;
+
     return 0;
 }
 
@@ -1432,9 +1437,12 @@
 static int fill_color(struct copybit_device_t *dev,
                       struct copybit_image_t const *dst,
                       struct copybit_rect_t const *rect,
-                      uint32_t color)
+                      uint32_t /*color*/)
 {
     // TODO: Implement once c2d driver supports color fill
+    if(!dev || !dst || !rect)
+       return -EINVAL;
+
     return -EINVAL;
 }
 
@@ -1502,10 +1510,13 @@
                         struct hw_device_t** device)
 {
     int status = COPYBIT_SUCCESS;
+    if (strcmp(name, COPYBIT_HARDWARE_COPYBIT0)) {
+        return COPYBIT_FAILURE;
+    }
+
     C2D_RGB_SURFACE_DEF surfDefinition = {0};
     C2D_YUV_SURFACE_DEF yuvSurfaceDef = {0} ;
     struct copybit_context_t *ctx;
-    char fbName[64];
 
     ctx = (struct copybit_context_t *)malloc(sizeof(struct copybit_context_t));
     if(!ctx) {
diff --git a/libcopybit/software_converter.cpp b/libcopybit/software_converter.cpp
index e26b795..71e685e 100644
--- a/libcopybit/software_converter.cpp
+++ b/libcopybit/software_converter.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -52,7 +52,7 @@
     unsigned int   width   = src->w - src->horiz_padding;
     unsigned int   height  = src->h;
     unsigned int   y_size  = stride * src->h;
-    unsigned int   c_width = ALIGN(stride/2, 16);
+    unsigned int   c_width = ALIGN(stride/2, (unsigned int)16);
     unsigned int   c_size  = c_width * src->h/2;
     unsigned int   chromaPadding = c_width - width/2;
     unsigned int   chromaSize = c_size * 2;
@@ -128,19 +128,20 @@
     int height;
     int src_stride;
     int dst_stride;
-    int src_plane1_offset;
-    int src_plane2_offset;
-    int dst_plane1_offset;
-    int dst_plane2_offset;
+    size_t src_plane1_offset;
+    size_t src_plane2_offset;
+    size_t dst_plane1_offset;
+    size_t dst_plane2_offset;
 };
 
 /* Internal function to do the actual copy of source to destination */
-static int copy_source_to_destination(const int src_base, const int dst_base,
+static int copy_source_to_destination(const uintptr_t src_base,
+                                      const uintptr_t dst_base,
                                       copyInfo& info)
 {
     if (!src_base || !dst_base) {
-        ALOGE("%s: invalid memory src_base = 0x%x dst_base=0x%x",
-             __FUNCTION__, src_base, dst_base);
+        ALOGE("%s: invalid memory src_base = 0x%p dst_base=0x%p",
+             __FUNCTION__, (void*)src_base, (void*)dst_base);
          return COPYBIT_FAILURE;
     }