VGImage vgCreateImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality) { struct vg_context *ctx = vg_current_context(); if (!supported_image_format(format)) { vg_set_error(ctx, VG_UNSUPPORTED_IMAGE_FORMAT_ERROR); return VG_INVALID_HANDLE; } if (width <= 0 || height <= 0) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return VG_INVALID_HANDLE; } if (width > vgGeti(VG_MAX_IMAGE_WIDTH) || height > vgGeti(VG_MAX_IMAGE_HEIGHT)) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return VG_INVALID_HANDLE; } if (width * height > vgGeti(VG_MAX_IMAGE_PIXELS)) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return VG_INVALID_HANDLE; } if (!(allowedQuality & ((VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER)))) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return VG_INVALID_HANDLE; } return (VGImage)image_create(format, width, height); }
void InitializeOpenVGContext() { vgSeti(VG_PIXEL_LAYOUT, vgGeti(VG_SCREEN_LAYOUT)); vgSetf(VG_STROKE_LINE_WIDTH, 4); vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); }
void QVGPixmapDropShadowFilter::draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const { if (src.isNull()) return; if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) { // The pixmap data is not an instance of QVGPixmapData, so fall // back to the default drop shadow filter implementation. QPixmapDropShadowFilter::draw(painter, dest, src, srcRect); return; } QVGPixmapData *pd = static_cast<QVGPixmapData *>(src.pixmapData()); VGImage srcImage = pd->toVGImage(); if (srcImage == VG_INVALID_HANDLE) return; QSize size = pd->size(); VGImage dstImage = QVGImagePool::instance()->createTemporaryImage (VG_A_8, size.width(), size.height(), VG_IMAGE_QUALITY_FASTER, pd); if (dstImage == VG_INVALID_HANDLE) return; // Clamp the radius range. We divide by 2 because the OpenVG blur // is "too blurry" compared to the default raster implementation. VGfloat maxRadius = VGfloat(vgGeti(VG_MAX_GAUSSIAN_STD_DEVIATION)); VGfloat radiusF = VGfloat(blurRadius()) / 2.0f; if (radiusF < 0.001f) radiusF = 0.001f; else if (radiusF > maxRadius) radiusF = maxRadius; // Blur the blackened source image. vgGaussianBlur(dstImage, srcImage, radiusF, radiusF, VG_TILE_PAD); VGImage child = VG_INVALID_HANDLE; QRect srect; if (srcRect.isNull() || (srcRect.topLeft().isNull() && srcRect.size() == size)) { child = dstImage; srect = QRect(0, 0, size.width(), size.height()); } else { srect = srcRect.toRect(); child = vgChildImage(dstImage, srect.x(), srect.y(), srect.width(), srect.height()); } qt_vg_drawVGImageStencil(painter, dest + offset(), child, color()); if(child != dstImage) vgDestroyImage(child); QVGImagePool::instance()->releaseImage(0, dstImage); // Now draw the actual pixmap over the top. painter->drawPixmap(dest, src, srect); }
void CNVGCSIcon::UpdateClientMatrices() { iMatrixMode = vgGeti(VG_MATRIX_MODE); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgGetMatrix(iPathMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgGetMatrix(iImageMatrix); vgSeti(VG_MATRIX_MODE, iMatrixMode); }
void HbNvgEnginePrivate::updateClientMatrices() { mMatrixMode = vgGeti(VG_MATRIX_MODE); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgGetMatrix(mPathMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgGetMatrix(mImageMatrix); vgSeti(VG_MATRIX_MODE, mMatrixMode); }
void QVGPixmapBlurFilter::draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const { if (src.isNull()) return; if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) { // The pixmap data is not an instance of QVGPixmapData, so fall // back to the default blur filter implementation. QPixmapBlurFilter::draw(painter, dest, src, srcRect); return; } QVGPixmapData *pd = static_cast<QVGPixmapData *>(src.pixmapData()); VGImage srcImage = pd->toVGImage(); if (srcImage == VG_INVALID_HANDLE) return; QSize size = pd->size(); VGImage dstImage = QVGImagePool::instance()->createTemporaryImage (VG_sARGB_8888_PRE, size.width(), size.height(), VG_IMAGE_QUALITY_FASTER, pd); if (dstImage == VG_INVALID_HANDLE) return; // Clamp the radius range. We divide by 2 because the OpenVG blur // is "too blurry" compared to the default raster implementation. VGfloat maxRadius = VGfloat(vgGeti(VG_MAX_GAUSSIAN_STD_DEVIATION)); VGfloat radiusF = VGfloat(radius()) / 2.0f; if (radiusF < 0.001f) radiusF = 0.001f; else if (radiusF > maxRadius) radiusF = maxRadius; vgGaussianBlur(dstImage, srcImage, radiusF, radiusF, VG_TILE_PAD); VGImage child = VG_INVALID_HANDLE; if (srcRect.isNull() || (srcRect.topLeft().isNull() && srcRect.size() == size)) { child = dstImage; } else { QRect src = srcRect.toRect(); child = vgChildImage(dstImage, src.x(), src.y(), src.width(), src.height()); } qt_vg_drawVGImage(painter, dest, child); if(child != dstImage) vgDestroyImage(child); QVGImagePool::instance()->releaseImage(0, dstImage); }
void vegaSeparableConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernelX, const VGshort * kernelY, VGfloat scale, VGfloat bias, VGTilingMode tilingMode) { struct vg_context *ctx = vg_current_context(); VGshort *kernel; VGint i, j, idx = 0; const VGint max_kernel_size = vgGeti(VG_MAX_SEPARABLE_KERNEL_SIZE); if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { vg_set_error(ctx, VG_BAD_HANDLE_ERROR); return; } if (kernelWidth <= 0 || kernelHeight <= 0 || kernelWidth > max_kernel_size || kernelHeight > max_kernel_size) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } if (!kernelX || !kernelY || !is_aligned_to(kernelX, 2) || !is_aligned_to(kernelY, 2)) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } if (tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } kernel = malloc(sizeof(VGshort)*kernelWidth*kernelHeight); for (i = 0; i < kernelWidth; ++i) { for (j = 0; j < kernelHeight; ++j) { kernel[idx] = kernelX[i] * kernelY[j]; ++idx; } } vgConvolve(dst, src, kernelWidth, kernelHeight, shiftX, shiftY, kernel, scale, bias, tilingMode); free(kernel); }
/*!*********************************************************************** @Function OutputAPIInfo @description When prefOutputInfo is set to true this function outputs various pieces of API dependent information via PVRShellOutputDebug. *************************************************************************/ void PVRShellInit::OutputAPIInfo() { // Output API dependent information if(m_pShell->PVRShellGet(prefOutputInfo)) { int i32Values[5]; m_pShell->PVRShellOutputDebug("\n"); #ifndef BUILD_OVG m_pShell->PVRShellOutputDebug("GL:\n"); m_pShell->PVRShellOutputDebug(" Vendor: %s\n", (char*) glGetString(GL_VENDOR)); m_pShell->PVRShellOutputDebug(" Renderer: %s\n", (char*) glGetString(GL_RENDERER)); m_pShell->PVRShellOutputDebug(" Version: %s\n", (char*) glGetString(GL_VERSION)); #else m_pShell->PVRShellOutputDebug("VG:\n"); m_pShell->PVRShellOutputDebug(" Vendor: %s\n", (char*) vgGetString(VG_VENDOR)); m_pShell->PVRShellOutputDebug(" Renderer: %s\n", (char*) vgGetString(VG_RENDERER)); m_pShell->PVRShellOutputDebug(" Version: %s\n", (char*) vgGetString(VG_VERSION)); #endif m_pShell->PVRShellOutputDebug("\n"); m_pShell->PVRShellOutputDebug("EGL:\n"); m_pShell->PVRShellOutputDebug(" Vendor: %s\n" , (char*) eglQueryString(gEglDisplay, EGL_VENDOR)); m_pShell->PVRShellOutputDebug(" Version: %s\n" , (char*) eglQueryString(gEglDisplay, EGL_VERSION)); #ifdef EGL_VERSION_1_2 m_pShell->PVRShellOutputDebug(" Client APIs: %s\n" , (char*) eglQueryString(gEglDisplay, EGL_CLIENT_APIS)); #endif m_pShell->PVRShellOutputDebug("\n"); m_pShell->PVRShellOutputDebug("Window Width: %i\n" , m_pShell->PVRShellGet(prefWidth)); m_pShell->PVRShellOutputDebug("Window Height: %i\n" , m_pShell->PVRShellGet(prefHeight)); m_pShell->PVRShellOutputDebug("Is Rotated: %s\n", m_pShell->PVRShellGet(prefIsRotated) ? "Yes" : "No"); m_pShell->PVRShellOutputDebug("\n"); // Colour buffer m_pShell->PVRShellOutputDebug("EGL Surface:\n"); eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_BUFFER_SIZE , &i32Values[0]); eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_RED_SIZE , &i32Values[1]); eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_GREEN_SIZE , &i32Values[2]); eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_BLUE_SIZE , &i32Values[3]); eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_ALPHA_SIZE , &i32Values[4]); m_pShell->PVRShellOutputDebug(" Colour Buffer: %i bits (R%i G%i B%i A%i)\n", i32Values[0],i32Values[1],i32Values[2],i32Values[3],i32Values[4]); // Depth buffer eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_DEPTH_SIZE , &i32Values[0]); m_pShell->PVRShellOutputDebug(" Depth Buffer: %i bits\n", i32Values[0]); // Stencil Buffer eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_STENCIL_SIZE , &i32Values[0]); m_pShell->PVRShellOutputDebug(" Stencil Buffer: %i bits\n", i32Values[0]); // EGL surface bits support eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_SURFACE_TYPE , &i32Values[0]); m_pShell->PVRShellOutputDebug(" Surface type: %s%s%s\n", i32Values[0] & EGL_WINDOW_BIT ? "WINDOW " : "", i32Values[1] & EGL_PBUFFER_BIT ? "PBUFFER " : "", i32Values[2] & EGL_PIXMAP_BIT ? "PIXMAP " : ""); // EGL renderable type #ifdef EGL_VERSION_1_2 eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_RENDERABLE_TYPE , &i32Values[0]); m_pShell->PVRShellOutputDebug(" Renderable type: %s%s%s%s\n", i32Values[0] & EGL_OPENVG_BIT ? "OPENVG " : "", i32Values[0] & EGL_OPENGL_ES_BIT ? "OPENGL_ES " : "", #ifdef EGL_OPENGL_BIT i32Values[0] & EGL_OPENGL_BIT ? "OPENGL " : #endif "", i32Values[0] & EGL_OPENGL_ES2_BIT ? "OPENGL_ES2 " : ""); #endif #ifndef BUILD_OVG eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_SAMPLE_BUFFERS , &i32Values[0]); eglGetConfigAttrib(gEglDisplay, gEglConfig, EGL_SAMPLES , &i32Values[1]); m_pShell->PVRShellOutputDebug(" Sample buffer No.: %i\n", i32Values[0]); m_pShell->PVRShellOutputDebug(" Samples per pixel: %i\n", i32Values[1]); #else m_pShell->PVRShellOutputDebug("\n"); switch(vgGeti(VG_RENDERING_QUALITY)) { case VG_RENDERING_QUALITY_BETTER: m_pShell->PVRShellOutputDebug("Rendering quality: VG_RENDERING_QUALITY_BETTER\n"); break; case VG_RENDERING_QUALITY_FASTER: m_pShell->PVRShellOutputDebug("Rendering quality: VG_RENDERING_QUALITY_FASTER\n"); break; default: m_pShell->PVRShellOutputDebug("Rendering quality: VG_RENDERING_QUALITY_NONANTIALIASED\n"); } #endif } }
void process_vg_info(writer &p_vg_writer, egl_scope const &p_egl_scope) { EGLint attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT, EGL_RED_SIZE, 1, EGL_GREEN_SIZE, 1, EGL_BLUE_SIZE, 1, EGL_NONE }; EGLint num_configs; EGLConfig config; if (!eglChooseConfig(p_egl_scope.get_display(), attribs, &config, 1, &num_configs) || (num_configs < 1)) { PRINT_EGL_ERROR("Could not find config for OpenVG (perhaps this API is unsupported?)"); return; } EGLint vid; if (!eglGetConfigAttrib(p_egl_scope.get_display(), config, EGL_NATIVE_VISUAL_ID, &vid)) { PRINT_EGL_ERROR("Could not get native visual ID from chosen config"); return; } native_window window(p_egl_scope.get_native_display(), vid); eglBindAPI(EGL_OPENVG_API); scoped_context context(p_egl_scope.get_display(), eglCreateContext(p_egl_scope.get_display(), config, EGL_NO_CONTEXT, NULL)); scoped_surface surface(p_egl_scope.get_display(), eglCreateWindowSurface(p_egl_scope.get_display(), config, window.get_egl_native_window(), NULL)); if (!eglMakeCurrent(p_egl_scope.get_display(), surface.get_surface(), surface.get_surface(), context.get_context())) { PRINT_EGL_ERROR("eglMakeCurrent() failed"); return; } p_vg_writer.write_main_vg_info( reinterpret_cast < char const * > (vgGetString(VG_VENDOR)) , reinterpret_cast < char const * > (vgGetString(VG_VERSION)) , reinterpret_cast < char const * > (vgGetString(VG_RENDERER)) , reinterpret_cast < char const * > (vgGetString(VG_EXTENSIONS)) ); openvg_stats stats; stats.m_max_scissor_rects = vgGeti(VG_MAX_SCISSOR_RECTS); stats.m_max_dash_count = vgGeti(VG_MAX_DASH_COUNT); stats.m_max_kernel_size = vgGeti(VG_MAX_KERNEL_SIZE); stats.m_max_separable_kernel_size = vgGeti(VG_MAX_SEPARABLE_KERNEL_SIZE); stats.m_max_color_ramp_stops = vgGeti(VG_MAX_COLOR_RAMP_STOPS); stats.m_max_image_width = vgGeti(VG_MAX_IMAGE_WIDTH); stats.m_max_image_height = vgGeti(VG_MAX_IMAGE_HEIGHT); stats.m_max_image_pixels = vgGeti(VG_MAX_IMAGE_PIXELS); stats.m_max_image_bytes = vgGeti(VG_MAX_IMAGE_BYTES); stats.m_max_gaussian_std_deviation = vgGeti(VG_MAX_GAUSSIAN_STD_DEVIATION); p_vg_writer.write_vg_stats(stats); p_vg_writer.begin_write_vg_image_format_acceleration(); for (image_format_accel_entry const *accel_entry = image_format_accel_table; accel_entry->m_name != NULL; ++accel_entry) { VGHardwareQueryResult acceleration = vgHardwareQuery(VG_IMAGE_FORMAT_QUERY, accel_entry->m_format); p_vg_writer.write_vg_image_format_acceleration(accel_entry->m_format, accel_entry->m_name, (acceleration == VG_HARDWARE_ACCELERATED)); } p_vg_writer.end_write_vg_image_format_acceleration(); p_vg_writer.write_vg_path_datatype_acceleration( get_path_datatype_acceleration(VG_PATH_DATATYPE_S_8) , get_path_datatype_acceleration(VG_PATH_DATATYPE_S_16) , get_path_datatype_acceleration(VG_PATH_DATATYPE_S_32) , get_path_datatype_acceleration(VG_PATH_DATATYPE_F) ); eglMakeCurrent(p_egl_scope.get_display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); }
void vegaConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernel, VGfloat scale, VGfloat bias, VGTilingMode tilingMode) { struct vg_context *ctx = vg_current_context(); VGfloat *buffer; VGint buffer_len; VGint i, j; VGint idx = 0; struct vg_image *d, *s; VGint kernel_size = kernelWidth * kernelHeight; struct filter_info info; const VGint max_kernel_size = vgGeti(VG_MAX_KERNEL_SIZE); if (dst == VG_INVALID_HANDLE || src == VG_INVALID_HANDLE) { vg_set_error(ctx, VG_BAD_HANDLE_ERROR); return; } if (kernelWidth <= 0 || kernelHeight <= 0 || kernelWidth > max_kernel_size || kernelHeight > max_kernel_size) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } if (!kernel || !is_aligned_to(kernel, 2)) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } if (tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } d = (struct vg_image*)dst; s = (struct vg_image*)src; if (vg_image_overlaps(d, s)) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } vg_validate_state(ctx); buffer_len = 8 + 2 * 4 * kernel_size; buffer = (VGfloat*)malloc(buffer_len * sizeof(VGfloat)); buffer[0] = 0.f; buffer[1] = 1.f; buffer[2] = 2.f; /*unused*/ buffer[3] = 4.f; /*unused*/ buffer[4] = kernelWidth * kernelHeight; buffer[5] = scale; buffer[6] = bias; buffer[7] = 0.f; idx = 8; for (j = 0; j < kernelHeight; ++j) { for (i = 0; i < kernelWidth; ++i) { VGint index = j * kernelWidth + i; VGfloat x, y; x = texture_offset(s->width, kernelWidth, i, shiftX); y = texture_offset(s->height, kernelHeight, j, shiftY); buffer[idx + index*4 + 0] = x; buffer[idx + index*4 + 1] = y; buffer[idx + index*4 + 2] = 0.f; buffer[idx + index*4 + 3] = 0.f; } } idx += kernel_size * 4; for (j = 0; j < kernelHeight; ++j) { for (i = 0; i < kernelWidth; ++i) { /* transpose the kernel */ VGint index = j * kernelWidth + i; VGint kindex = (kernelWidth - i - 1) * kernelHeight + (kernelHeight - j - 1); buffer[idx + index*4 + 0] = kernel[kindex]; buffer[idx + index*4 + 1] = kernel[kindex]; buffer[idx + index*4 + 2] = kernel[kindex]; buffer[idx + index*4 + 3] = kernel[kindex]; } } info.dst = d; info.src = s; info.setup_shader = &setup_convolution; info.user_data = (void*)(long)(buffer_len/4); info.const_buffer = buffer; info.const_buffer_len = buffer_len * sizeof(VGfloat); info.tiling_mode = tilingMode; info.extra_texture_view = NULL; execute_filter(ctx, &info); free(buffer); }