static void
mic_shutdown(struct pci_dev *pdev) {
	mic_ctx_t *mic_ctx;
	mic_ctx = get_device_context(pdev);

	if(!mic_ctx)
		return;

	adapter_stop_device(mic_ctx, !RESET_WAIT , !RESET_REATTEMPT);
	return;
}
void D3DUniformBuffer::upload_data(const GraphicContextPtr &gc, const void *data, int data_size)
{
    if (data_size != size)
        throw Exception("Upload data size does not match vertex array buffer");

    auto d3d_window = static_cast<D3DGraphicContext*>(gc.get())->get_window();
    const auto &device = d3d_window->get_device();
    const auto &device_context = d3d_window->get_device_context();

    device_context->UpdateSubresource(get_handles(device).buffer, 0, 0, data, 0, 0);
}
void D3DUniformBuffer::copy_to(const GraphicContextPtr  &gc, const StagingBufferPtr &buffer, int dest_pos, int src_pos, int copy_size)
{
    auto d3d_window = static_cast<D3DGraphicContext*>(gc.get())->get_window();
    const auto &device = d3d_window->get_device();
    const auto &device_context = d3d_window->get_device_context();

    ComPtr<ID3D11Buffer> &staging_buffer = static_cast<D3DStagingBuffer*>(buffer.get())->get_buffer(device);
    int staging_buffer_size = static_cast<D3DStagingBuffer*>(buffer.get())->get_size();

    if (copy_size == -1)
        copy_size = staging_buffer_size;

    if (dest_pos < 0 || copy_size < 0 || dest_pos + copy_size > staging_buffer_size || src_pos < 0 || src_pos + copy_size > size)
        throw Exception("Out of bounds!");

    D3D11_BOX box;
    box.left = dest_pos;
    box.right = dest_pos + copy_size;
    box.top = 0;
    box.bottom = 1;
    box.front = 0;
    box.back = 1;
    device_context->CopySubresourceRegion(staging_buffer, 0, src_pos, 0, 0, get_handles(device).buffer, 0, &box);
}
	void OpenGLWindowProvider::flip(int interval)
	{
		OpenGL::set_active(get_gc());
		glFlush();
		if (shadow_window)
		{
			int width = get_viewport().get_width();
			int height = get_viewport().get_height();

			if (using_gl3)
			{
				if (double_buffered)
				{
					glDrawBuffer(GL_BACK);
					glReadBuffer(GL_FRONT);
				}

				PixelBuffer pixelbuffer(width, height, tf_bgra8);
				glPixelStorei(GL_PACK_ALIGNMENT, 1);
				glPixelStorei(GL_PACK_ROW_LENGTH, pixelbuffer.get_pitch() / pixelbuffer.get_bytes_per_pixel());
				glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
				glPixelStorei(GL_PACK_SKIP_ROWS, 0);
				glReadPixels(
					0, 0,
					width, height,
					GL_BGRA,
					GL_UNSIGNED_BYTE,
					pixelbuffer.get_data());

				win32_window.update_layered(pixelbuffer);
			}
			else
			{
				GLint old_viewport[4], old_matrix_mode;
				GLfloat old_matrix_projection[16], old_matrix_modelview[16];
				glGetIntegerv(GL_VIEWPORT, old_viewport);
				glGetIntegerv(GL_MATRIX_MODE, &old_matrix_mode);
				glGetFloatv(GL_PROJECTION_MATRIX, old_matrix_projection);
				glGetFloatv(GL_MODELVIEW_MATRIX, old_matrix_modelview);
				GLboolean blending = glIsEnabled(GL_BLEND);
				glDisable(GL_BLEND);

				glViewport(0, 0, width, height);
				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();
				glMultMatrixf(Mat4f::ortho_2d(0.0f, (float)width, 0.0f, (float)height, handed_right, clip_negative_positive_w));
				glMatrixMode(GL_MODELVIEW);
				glLoadIdentity();

				if (double_buffered)
				{
					glReadBuffer(GL_BACK);
				}
				glRasterPos2i(0, 0);
				glPixelZoom(1.0f, 1.0f);

				PixelBuffer pixelbuffer(width, height, tf_rgba8);
				glPixelStorei(GL_PACK_ALIGNMENT, 1);
				glPixelStorei(GL_PACK_ROW_LENGTH, pixelbuffer.get_pitch() / pixelbuffer.get_bytes_per_pixel());
				glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
				glPixelStorei(GL_PACK_SKIP_ROWS, 0);
				glReadPixels(
					0, 0,
					width, height,
					GL_RGBA,
					GL_UNSIGNED_BYTE,
					pixelbuffer.get_data());

				win32_window.update_layered(pixelbuffer);

				if (blending)
					glEnable(GL_BLEND);
				glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);
				glMatrixMode(GL_PROJECTION);
				glLoadMatrixf(old_matrix_projection);
				glMatrixMode(GL_MODELVIEW);
				glLoadMatrixf(old_matrix_modelview);
				glMatrixMode(old_matrix_mode);
			}
		}
		else
		{
			if (interval != -1 && interval != swap_interval)
			{
				swap_interval = interval;
				if (wglSwapIntervalEXT)
					wglSwapIntervalEXT(swap_interval);
			}

			BOOL retval = SwapBuffers(get_device_context());

			if (dwm_layered)
			{
				int width = get_viewport().get_width();
				int height = get_viewport().get_height();

				glReadBuffer(GL_FRONT);

				PixelBuffer pixelbuffer(width, height, tf_r8);
				glPixelStorei(GL_PACK_ALIGNMENT, 1);
				glPixelStorei(GL_PACK_ROW_LENGTH, pixelbuffer.get_pitch() / pixelbuffer.get_bytes_per_pixel());
				glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
				glPixelStorei(GL_PACK_SKIP_ROWS, 0);
				glReadPixels(
					0, 0,
					width, height,
					GL_ALPHA,
					GL_BYTE, // use GL_BITMAP here for even less transfer?
					pixelbuffer.get_data());

				win32_window.update_layered(pixelbuffer);
			}
		}
		OpenGL::check_error();
	}
Exemple #5
0
int main(int argc, char *argv[])
{
	char *device_name = NULL;
	struct ibv_async_event event;
	struct ibv_context *ctx;
	int ret = 0;

	/* parse command line options */
	while (1) {
		int c;

		c = getopt(argc, argv, "d:h");
		if (c == -1)
			break;

		switch (c) {
		case 'd':
			device_name = strdup(optarg);
			if (!device_name) {
				fprintf(stderr, "Error, failed to allocate memory for the device name\n");
				return -1;
			}
			break;

		case 'h':
			usage(argv[0]);
			exit(1);

		default:
			fprintf(stderr, "Bad command line was used\n\n");
			usage(argv[0]);
			exit(1);
		}
	}

	if (!device_name) {
		fprintf(stderr, "Error, the device name is mandatory\n");
		return -1;
	}

	ctx = get_device_context(device_name);
	if (!ctx) {
		fprintf(stderr, "Error, the context of the device name '%s' could not be opened\n", device_name);
		free(device_name);
		return -1;
	}

	printf("Listening on events for the device '%s'\n", device_name);

	while (1) {
		/* wait for the next async event */
		ret = ibv_get_async_event(ctx, &event);
		if (ret) {
			fprintf(stderr, "Error, ibv_get_async_event() failed\n");
			goto out;
		}

		/* print the event */
		print_async_event(ctx, &event);

		/* ack the event */
		ibv_ack_async_event(&event);
	}

	ret = 0;

out:
	if (ibv_close_device(ctx)) {
		fprintf(stderr, "Error, failed to close the context of the device '%s'\n", device_name);
		return -1;
	}

	printf("The context of the device name '%s' was closed\n", device_name);
	free(device_name);

	return ret;
}