def _render_prepare(self, cr): """Prepares a blank pixbuf & other details for later rendering. Called when handling "draw" events. The size and shape of the returned pixbuf (wrapped in a tile-accessible and read/write lib.pixbufsurface.Surface) is determined by the Cairo clipping region that expresses what we've been asked to redraw, and by the TDW's own view transformation of the document. """ # Determine what to draw, and the nature of the reveal. allocation = self.get_allocation() w, h = allocation.width, allocation.height device_bbox = (0, 0, w, h) clip_rect, sparse = self._render_get_clip_region(cr, device_bbox) x, y, w, h = device_bbox # Use a copy of the cached translation matrix for this # rendering. It'll need scaling if using a mipmap level # greater than zero. transformation = cairo.Matrix(*self._get_model_view_transformation()) # HQ rendering causes a very clear slowdown on some hardware. # Probably could avoid this entirely by rendering differently, # but for now, if the canvas is being panned around, # just render more simply. if self._hq_rendering: mipmap_level = max(0, int(floor(log(1.0/self.scale, 2)))) else: mipmap_level = max(0, int(ceil(log(1/self.scale, 2)))) # OPTIMIZE: If we would render tile scanlines, # OPTIMIZE: we could probably use the better one above... mipmap_level = min(mipmap_level, tiledsurface.MAX_MIPMAP_LEVEL) transformation.scale(2**mipmap_level, 2**mipmap_level) # bye bye device coordinates cr.save() # >>>CONTEXT1 cr.transform(transformation) cr.save() # >>>CONTEXT2 # calculate the final model bbox with all the clipping above x1, y1, x2, y2 = cr.clip_extents() if not self.is_translation_only(): # Looks like cairo needs one extra pixel rendered for interpolation at the border. # If we don't do this, we get dark stripe artefacts when panning while zoomed. x1 -= 1 y1 -= 1 x2 += 1 y2 += 1 x1, y1 = int(floor(x1)), int(floor(y1)) x2, y2 = int(ceil(x2)), int(ceil(y2)) # We always render with alpha to get hardware acceleration, # even when we could avoid using the alpha channel. Speedup # factor 3 for ATI/Radeon Xorg driver (and hopefully others). # https://bugs.freedesktop.org/show_bug.cgi?id=28670 surface = pixbufsurface.Surface(x1, y1, x2-x1+1, y2-y1+1) return transformation, surface, sparse, mipmap_level, clip_rect
def render_prepare(self, cr, device_bbox): if device_bbox is None: allocation = self.get_allocation() w, h = allocation.width, allocation.height device_bbox = (0, 0, w, h) # logger.debug('device bbox: %r', tuple(device_bbox)) clip_region, sparse = self.render_get_clip_region(cr, device_bbox) x, y, w, h = device_bbox # fill it all white, though not required in the most common case if self.visualize_rendering: # grey tmp = random.random() cr.set_source_rgb(tmp, tmp, tmp) cr.paint() transformation = cairo.Matrix(*self._get_model_view_transformation()) # choose best mipmap hq_zoom = False if self.app and self.app.preferences['view.high_quality_zoom']: hq_zoom = True if hq_zoom: # can cause a very clear slowdown on some hardware # (we probably could avoid this by doing rendering differently) mipmap_level = max(0, int(floor(log(1.0/self.scale, 2)))) else: mipmap_level = max(0, int(ceil(log(1/self.scale, 2)))) # OPTIMIZE: if we would render tile scanlines, we could probably use the better one above... mipmap_level = min(mipmap_level, tiledsurface.MAX_MIPMAP_LEVEL) transformation.scale(2**mipmap_level, 2**mipmap_level) # bye bye device coordinates cr.save() # >>>CONTEXT1 cr.transform(transformation) cr.save() # >>>CONTEXT2 # calculate the final model bbox with all the clipping above x1, y1, x2, y2 = cr.clip_extents() if not self.is_translation_only(): # Looks like cairo needs one extra pixel rendered for interpolation at the border. # If we don't do this, we get dark stripe artefacts when panning while zoomed. x1 -= 1 y1 -= 1 x2 += 1 y2 += 1 x1, y1 = int(floor(x1)), int(floor(y1)) x2, y2 = int(ceil(x2)), int(ceil(y2)) # We render with alpha just to get hardware acceleration, we # don't actually use the alpha channel. Speedup factor 3 for # ATI/Radeon Xorg driver (and hopefully others). # https://bugs.freedesktop.org/show_bug.cgi?id=28670 surface = pixbufsurface.Surface(x1, y1, x2-x1+1, y2-y1+1) return transformation, surface, sparse, mipmap_level, clip_region
def render_prepare(self, device_bbox): if device_bbox is None: w, h = self.window.get_size() device_bbox = (0, 0, w, h) #print 'device bbox', tuple(device_bbox) gdk_clip_region = self.window.get_clip_region() x, y, w, h = device_bbox sparse = not gdk_clip_region.point_in(x + w / 2, y + h / 2) cr = self.window.cairo_create() # actually this is only neccessary if we are not answering an expose event cr.rectangle(*device_bbox) cr.clip() # fill it all white, though not required in the most common case if self.visualize_rendering: # grey tmp = random.random() cr.set_source_rgb(tmp, tmp, tmp) cr.paint() # bye bye device coordinates self.get_model_coordinates_cairo_context(cr) # choose best mipmap hq_zoom = False if self.app and self.app.preferences['view.high_quality_zoom']: hq_zoom = True if hq_zoom: # can cause a very clear slowdown on some hardware # (we probably could avoid this by doing rendering differently) mipmap_level = max(0, int(floor(log(1.0 / self.scale, 2)))) else: mipmap_level = max(0, int(ceil(log(1 / self.scale, 2)))) # OPTIMIZE: if we would render tile scanlines, we could probably use the better one above... mipmap_level = min(mipmap_level, tiledsurface.MAX_MIPMAP_LEVEL) cr.scale(2**mipmap_level, 2**mipmap_level) translation_only = self.is_translation_only() # calculate the final model bbox with all the clipping above x1, y1, x2, y2 = cr.clip_extents() if not translation_only: # Looks like cairo needs one extra pixel rendered for interpolation at the border. # If we don't do this, we get dark stripe artefacts when panning while zoomed. x1 -= 1 y1 -= 1 x2 += 1 y2 += 1 x1, y1 = int(floor(x1)), int(floor(y1)) x2, y2 = int(ceil(x2)), int(ceil(y2)) # alpha=True is just to get hardware acceleration, we don't # actually use the alpha channel. Speedup factor 3 for # ATI/Radeon Xorg driver (and hopefully others). # https://bugs.freedesktop.org/show_bug.cgi?id=28670 surface = pixbufsurface.Surface(x1, y1, x2 - x1 + 1, y2 - y1 + 1, alpha=True) del x1, y1, x2, y2, w, h return cr, surface, sparse, mipmap_level, gdk_clip_region