Exemplo n.º 1
0
/*!
    \internal
    Creates an in-memory, linear accessible surface of dimensions \a w * \a h.
    This is the main surface that QWS blits to.
*/
static inline bool createMemSurface(QQnxScreenContext * const d, int w, int h)
{
#ifndef QT_NO_QWS_MULTIPROCESS
    if (QApplication::type() != QApplication::GuiServer) {
        unsigned sidlist[64];
        int n = gf_surface_sidlist(d->device, sidlist); // undocumented API
        for (int i = 0; i < n; ++i) {
            int ret = gf_surface_attach_by_sid(&d->memSurface, d->device, sidlist[i]);
            if (ret == GF_ERR_OK) {
                gf_surface_get_info(d->memSurface, &d->memSurfaceInfo);
                if (d->memSurfaceInfo.sid != unsigned(GF_SID_INVALID)) {
                    // can we use the surface's vaddr?
                    unsigned flags = GF_SURFACE_CPU_LINEAR_READABLE | GF_SURFACE_CPU_LINEAR_WRITEABLE;
                    if ((d->memSurfaceInfo.flags & flags) == flags)
                        return true;
                }

                gf_surface_free(d->memSurface);
                d->memSurface = 0;
            }
        }
        qWarning("QQnxScreen: cannot attach to an usable surface; create a new one.");
    }
#endif
    int ret = gf_surface_create(&d->memSurface, d->device, w, h, d->displayInfo.format, 0,
                GF_SURFACE_CREATE_CPU_FAST_ACCESS | GF_SURFACE_CREATE_CPU_LINEAR_ACCESSIBLE
                | GF_SURFACE_CREATE_PHYS_CONTIG | GF_SURFACE_CREATE_SHAREABLE);
    if (ret != GF_ERR_OK) {
        qWarning("QQnxScreen: gf_surface_create(%dx%d) failed with error code %d",
                 w, h, ret);
        return false;
    }

    gf_surface_get_info(d->memSurface, &d->memSurfaceInfo);

    if (d->memSurfaceInfo.sid == unsigned(GF_SID_INVALID)) {
        qWarning("QQnxScreen: gf_surface_get_info() failed.");
        return false;
    }

    return true;
}
Exemplo n.º 2
0
/*! \internal
  Creates an in-memory, linear accessible surface of dimensions \a w * \a h.
  This is the main surface that QWS blits to.
 */
static bool createMemSurface(QQnxScreenContext * const d, int w, int h)
{
    // Note: gf_surface_attach() could also be used, so we'll create the buffer
    // and let the surface point to it. Here, we use surface_create instead.

    int ret = gf_surface_create(&d->memSurface, d->device, w, h,
                GF_FORMAT_ARGB8888, 0,
                GF_SURFACE_CREATE_CPU_FAST_ACCESS | GF_SURFACE_CREATE_CPU_LINEAR_ACCESSIBLE
                | GF_SURFACE_PHYS_CONTIG | GF_SURFACE_CREATE_SHAREABLE);
    if (ret != GF_ERR_OK) {
        qWarning("QQnxScreen: gf_surface_create(%dx%d) failed with error code %d",
                w, h, ret);
        return false;
    }

    gf_surface_get_info(d->memSurface, &d->memSurfaceInfo);

    if (d->memSurfaceInfo.sid == unsigned(GF_SID_INVALID)) {
        qWarning("QQnxScreen: gf_surface_get_info() failed.");
        return false;
    }

    return true;
}
Exemplo n.º 3
0
static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags)
{
   SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(window);
   SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata;
   SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata;
   SDL_Renderer* renderer = NULL;
   SDL_RenderData* rdata = NULL;
   uint32_t it;
   int32_t  jt;
   int32_t  status;

   /* Check if it is OpenGL ES window */
   if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
   {
      /* No error, just no need to create 2D renderer for OpenGL ES window */
      return NULL;
   }

   /* Allocate new renderer structure */
   renderer=(SDL_Renderer*)SDL_calloc(1, sizeof(SDL_Renderer));
   if (renderer==NULL)
   {
      SDL_OutOfMemory();
      return NULL;
   }

   /* Allocate renderer data */
   rdata=(SDL_RenderData*)SDL_calloc(1, sizeof(SDL_RenderData));
   if (rdata==NULL)
   {
      SDL_free(renderer);
      SDL_OutOfMemory();
      return NULL;
   }

   renderer->DisplayModeChanged=gf_displaymodechanged;
   renderer->ActivateRenderer=gf_activaterenderer;
   renderer->CreateTexture=gf_createtexture;
   renderer->QueryTexturePixels=gf_querytexturepixels;
   renderer->SetTexturePalette=gf_settexturepalette;
   renderer->GetTexturePalette=gf_gettexturepalette;
   renderer->SetTextureAlphaMod=gf_settexturealphamod;
   renderer->SetTextureColorMod=gf_settexturecolormod;
   renderer->SetTextureBlendMode=gf_settextureblendmode;
   renderer->SetTextureScaleMode=gf_settexturescalemode;
   renderer->UpdateTexture=gf_updatetexture;
   renderer->LockTexture=gf_locktexture;
   renderer->UnlockTexture=gf_unlocktexture;
   renderer->DirtyTexture=gf_dirtytexture;
   renderer->RenderPoint=gf_renderpoint;
   renderer->RenderLine=gf_renderline;
   renderer->RenderFill=gf_renderfill;
   renderer->RenderCopy=gf_rendercopy;
   renderer->RenderPresent = gf_renderpresent;
   renderer->DestroyTexture = gf_destroytexture;
   renderer->DestroyRenderer = gf_destroyrenderer;
   renderer->info = gf_renderdriver.info;
   renderer->window = window->id;
   renderer->driverdata = rdata;

   /* Set render acceleration flag in case it is accelerated */
   if ((didata->caps & SDL_GF_ACCELERATED)==SDL_GF_ACCELERATED)
   {
      renderer->info.flags=SDL_RENDERER_ACCELERATED;
   }
   else
   {
      renderer->info.flags&=~(SDL_RENDERER_ACCELERATED);
   }

   rdata->window=window;

   /* Check if upper level requested synchronization on vsync signal */
   if ((flags & SDL_RENDERER_PRESENTVSYNC)==SDL_RENDERER_PRESENTVSYNC)
   {
       rdata->enable_vsync=SDL_TRUE;
   }
   else
   {
      rdata->enable_vsync=SDL_FALSE;
   }

   /* Check what buffer copy/flip scheme is requested */
   rdata->surfaces_count=0;
   if ((flags & SDL_RENDERER_SINGLEBUFFER)==SDL_RENDERER_SINGLEBUFFER)
   {
      if ((flags & SDL_RENDERER_PRESENTDISCARD)==SDL_RENDERER_PRESENTDISCARD)
      {
         renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD;
      }
      else
      {
         renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
      }
      rdata->surfaces_count=1;
      rdata->surface_visible_idx=0;
      rdata->surface_render_idx=0;
   }
   else
   {
      if ((flags & SDL_RENDERER_PRESENTFLIP2)==SDL_RENDERER_PRESENTFLIP2)
      {
         renderer->info.flags|=SDL_RENDERER_PRESENTFLIP2;
         rdata->surfaces_count=2;
         rdata->surface_visible_idx=0;
         rdata->surface_render_idx=1;
      }
      else
      {
         if ((flags & SDL_RENDERER_PRESENTFLIP3)==SDL_RENDERER_PRESENTFLIP3)
         {
            renderer->info.flags|=SDL_RENDERER_PRESENTFLIP3;
            rdata->surfaces_count=3;
            rdata->surface_visible_idx=0;
            rdata->surface_render_idx=1;
         }
         else
         {
            renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
            rdata->surfaces_count=1;
            rdata->surface_visible_idx=0;
            rdata->surface_render_idx=0;
         }
      }
   }

   /* Create layer surfaces, which could be visible */
   for (it=0; it<rdata->surfaces_count; it++)
   {
      /* TODO: add palette creation */

      /* Create displayable surfaces */
      status=gf_surface_create_layer(&rdata->surface[it], &didata->layer, 1, 0,
             didata->current_mode.w, didata->current_mode.h,
             qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), NULL, 
             GF_SURFACE_CREATE_2D_ACCESSIBLE);

      if (status!=GF_ERR_OK)
      {
         /* Free already allocated surfaces */
         for (jt=it-1; jt>0; jt--)
         {
            gf_surface_free(rdata->surface[jt]);
            rdata->surface[jt]=NULL;
         }
         SDL_free(rdata);
         SDL_free(renderer);
         if (status==GF_ERR_MEM)
         {
            SDL_SetError("unsufficient free video memory");
         }
         else
         {
            SDL_SetError("error during displayable surface creation");
         }
         return NULL;
      }

      /* Get detailed information about allocated surface */
      gf_surface_get_info(rdata->surface[it], &rdata->surface_info[it]);
   }

   return renderer;
}
Exemplo n.º 4
0
int
gf_setup(gf_setup_t *setup,
	int argc,
	char * const argv[],
	unsigned flags)
{
	gf_dev_t	gdev;
	unsigned	dispno = 0;
	const char 	*dev_name = NULL;
	int			layer_idx = GF_SETUP_LAYER_MAIN,
				rc,
				verbose = 0;
	gf_sid_t	sid = GF_SID_INVALID;
	unsigned	vx1 = 0, vx2 = ~0,
				vy1 = 0, vy2 = ~0;

	

	memset(setup, 0, sizeof *setup);

	setup->fname = strdup("tt0419m_.ttf");

#ifdef _MSC_VER
#else
	opterr = 0;

	while ((rc = getopt(argc, argv, "d:D:l:s:vx:y:f:")) != -1) {
		switch (rc) {
			case 'd':
				if (isdigit(*optarg)) {
					dev_name = GF_DEVICE_INDEX(atoi(optarg));
				} else {
					dev_name = optarg;
				}
				break;
			case 'D':
				dispno = atoi(optarg);
				break;
			case 'l':
				layer_idx = atoi(optarg);
				break;
			case 's':
				sid = (gf_sid_t)atoi(optarg);
				break;
			case 'v':
				verbose = ~0;
				break;
			case 'x':
				switch (*optarg++) {
					case '1':
						vx1 = atoi(optarg);
						break;
					case '2':
						vx2 = atoi(optarg);
						break;
					default:
						break;
				}

				break;
			case 'y':
				switch (*optarg++) {
					case '1':
						vy1 = atoi(optarg);
						break;
					case '2':
						vy2 = atoi(optarg);
						break;
					default:
						break;
				}

				break;
			case 'f':
				setup->fname = strdup(optarg);
				break;
			default:
				break;
		}
	}

#endif

	if ((rc = gf_dev_attach(&gdev, dev_name, NULL)) == GF_ERR_OK) {
		if (sid != GF_SID_INVALID) {
			gf_surface_t	surface;

			if ((rc = gf_surface_attach_by_sid(&surface, gdev, sid)) == GF_ERR_OK) {
				gf_context_t	context;

				if ((rc = gf_context_create(&context)) == GF_ERR_OK) {
					if ((rc = gf_context_set_surface(context, surface)) == GF_ERR_OK) {
						gf_surface_info_t	sinfo;

						gf_surface_get_info(surface, &sinfo);
						--sinfo.w;
						--sinfo.h;

						if (vx2 > sinfo.w) {
							vx2 = sinfo.w;
						}

						if (vy2 > sinfo.h) {
							vy2 = sinfo.h;
						}

						if (vx1 <= vx2 && vy1 <= vy2 &&
							(vx1 || vy1 || vx2 < sinfo.w || vy2 < sinfo.h)) {
							gf_context_set_clipping(context, vx1, vy1, vx2, vy2);
							setup->x1 = vx1;
							setup->x2 = vx2;
							setup->y1 = vy1;
							setup->y2 = vy2;
						}

						setup->surface1 = surface;
						setup->context = context;
						setup->gdev = gdev;

						return GF_ERR_OK;
					}

					gf_context_free(context);
				}

				gf_surface_free(surface);
			}
		} else {
			gf_display_t display;
			gf_display_info_t dinfo;

			if ((rc = gf_display_attach(&display, gdev, dispno, &dinfo)) == GF_ERR_OK) {
				gf_layer_t	layer;

				if (verbose) {
					fprintf(stderr, "Display %d:\n\tResolution: %dX%d\n",
						dispno, dinfo.xres, dinfo.yres);
					fprintf(stderr, "\tRefresh rate: %d\n\tPixel format: ", dinfo.refresh);
					switch (dinfo.format) {
						case GF_FORMAT_PAL8:
							fprintf(stderr, "PAL8");
							break;
						case GF_FORMAT_PACK_ARGB1555:
							fprintf(stderr, "ARGB1555");
							break;
						case GF_FORMAT_PACK_RGB565:
							fprintf(stderr, "RGB565");
							break;
						case GF_FORMAT_BGR888:
							fprintf(stderr, "BGR888");
							break;
						case GF_FORMAT_BGRA8888:
							fprintf(stderr, "BGRA8888");
							break;
						default:
							fprintf(stderr, "%x", (unsigned)dinfo.format);
							break;
					}

					fprintf(stderr, "\n\tNumber of layers: %d\n", dinfo.nlayers);
					fprintf(stderr, "\tMain layer index: %d\n", dinfo.main_layer_index);
				}

				if ((rc = gf_layer_attach(&layer, display, 
					layer_idx == GF_SETUP_LAYER_MAIN ? dinfo.main_layer_index : layer_idx,
					0)) == GF_ERR_OK) {
					gf_surface_t surface1, surface2 = NULL;
					int layer_format;

					layer_format = find_rgb_format(layer);
					if(verbose && layer_format != dinfo.format) {
						fprintf(stderr, "\tChoosing non-default layer format: ");
						switch (layer_format) {
							case GF_FORMAT_PAL8:
								fprintf(stderr, "PAL8");
								break;
							case GF_FORMAT_PACK_ARGB1555:
								fprintf(stderr, "ARGB1555");
								break;
							case GF_FORMAT_PACK_RGB565:
								fprintf(stderr, "RGB565");
								break;
							case GF_FORMAT_BGR888:
								fprintf(stderr, "BGR888");
								break;
							case GF_FORMAT_BGRA8888:
								fprintf(stderr, "BGRA8888");
								break;
							default:
								fprintf(stderr, "%x", (unsigned)layer_format);
								break;
						}
						fprintf(stderr, "\n");
					}
					dinfo.format = layer_format;

					if ((rc = gf_surface_create_layer(&surface1, &layer, 1, 0,
						dinfo.xres, dinfo.yres, 
						dinfo.format, NULL, 0)) == GF_ERR_OK &&
						(!(flags & GF_SETUP_FLAG_DBLBUFFER) || 
						 (rc = gf_surface_create_layer(&surface2, &layer, 1, 0,
						 dinfo.xres, dinfo.yres,
						 dinfo.format, NULL, 0)) == GF_ERR_OK)) {

						if (verbose) {
							gf_surface_info_t	sinfo;

							gf_surface_get_info(surface1, &sinfo);
							fprintf(stderr, "Surface:\n\tSID = %d\n", (unsigned)sinfo.sid);
							fprintf(stderr, "\tFlags = %x\n", sinfo.flags);
						}

						gf_layer_set_surfaces(layer, &surface1, 1);

						if ((rc = gf_layer_update(layer, 0)) == GF_ERR_OK) {
							gf_context_t context = NULL;

							if ((flags & GF_SETUP_FLAG_NOCONTEXT) ||
								((rc = gf_context_create(&context)) == GF_ERR_OK &&
								 (rc = gf_context_set_surface(context, surface1)) == GF_ERR_OK)) {
								setup->gdev = gdev;
								setup->display = display;
								memcpy(&setup->display_info, &dinfo, sizeof dinfo);
								setup->layer = layer;
								setup->surface1 = surface1;
								setup->surface2 = surface2;
								setup->context = context;
								return GF_ERR_OK;
							}
					
							if (context != NULL) {		
								gf_context_free(context);
							}
						}
					}
				}
			}
		}
	
		gf_dev_detach(gdev);
	}

	return rc;
}