How do you use the GPU offscreen render API in 2.8?
The following code shows the essential steps to write the 3D view into a Blender image. 

The main caveat is that the currently offscreen.draw_view3d() is called within draw() using bpy.types.SpaceView3D.draw_handler_add. 
This has a few consequences:


one must ensure that the 3D view is redrawn, for example by clicking onto some object in the 3D view
the function is called multiple times


When moving offscreen.draw_view3d() outside of draw(), I received  the following error message: TypeError: expected 'SpaceView3D' type found 'SpaceTextEditor' instead. So currently, I'm stuck setting the correct context. Any help would be highly appreciated - I'll update the post correspondingly.

import bpy
import bgl
import gpu
from mathutils import Matrix
from gpu.types import GPUOffScreen


def draw():

    print('draw: bpy.context.area.type',  bpy.context.area.type)
    global write_view_3d

    if write_view_3d:

        # Write the image into the offscreen buffer
        offscreen.draw_view3d(
            scene=scene,
            view_layer=bpy.context.view_layer,
            view3d=bpy.context.space_data,
            region=bpy.context.region,
            view_matrix=view_matrix,
            projection_matrix=projection_matrix)

        buffer = bgl.Buffer(bgl.GL_BYTE, width * height * 4)
        bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer)

        if(image_name not in bpy.data.images):
            bpy.data.images.new(image_name, width, height)
        image = bpy.data.images[image_name]
        image.pixels = [v / 255 for v in buffer]

        print('write_view_3d', write_view_3d)
        write_view_3d = False
    else:
        print('write_view_3d', write_view_3d)

image_name = "Result"
scene = bpy.context.scene
render = bpy.context.scene.render
width = bpy.context.region.width
height = bpy.context.region.height

offscreen = gpu.types.GPUOffScreen(width, height)
view_matrix = scene.camera.matrix_world.inverted()
projection_matrix = scene.camera.calc_matrix_camera(
    bpy.context.evaluated_depsgraph_get(), 
    x=width,
    y=height)

write_view_3d = True
current_draw_handler = bpy.types.SpaceView3D.draw_handler_add(
    draw, (), 'WINDOW', 'POST_PIXEL')