public void dispose() { if (bctx != null) { bctx.dispose(); bctx = null; } }
@Override public void dispose() { super.dispose(); if (bctx != null) { bctx.dispose(); bctx = null; } } }
@Override protected void upload (Graphics gfx, Texture tex) { int width = pixelWidth, height = pixelHeight; if (width == 0 || height == 0) { ((RoboGraphics)gfx).plat.log().info("Ignoring texture update for empty image (" + width + "x" + height + ")."); return; } CGBitmapContext bctx = RoboGraphics.createCGBitmap(width, height); CGRect rect = new CGRect(0, 0, width, height); bctx.clearRect(rect); bctx.drawImage(rect, image); upload(gfx, tex.id, width, height, bctx.getData()); bctx.dispose(); }
void updateTexture(int tex, CGImage image) { int width = (int)image.getWidth(), height = (int)image.getHeight(); if (width <= 0 || height <= 0) { platform.log().warn( "Ignoring texture update for empty image (" + width + "x" + height + ")."); return; } CGBitmapContext bctx = RoboGraphics.createCGBitmap(width, height); CGRect rect = new CGRect(0, 0, width, height); bctx.clearRect(rect); bctx.drawImage(rect, image); updateTexture(tex, width, height, bctx.getData()); bctx.dispose(); }
@Override public Canvas fillText(TextLayout layout, float x, float y) { RoboGradient gradient = currentState().gradient; RoboTextLayout ilayout = (RoboTextLayout) layout; if (gradient == null) { ilayout.fill(bctx, x, y, fillColor); } else { // draw our text into a fresh context so we can use it as a mask for the gradient CGBitmapContext maskContext = RoboGraphics.createCGBitmap(texWidth, texHeight); maskContext.clearRect(new CGRect(0, 0, texWidth, texHeight)); // scale the context based on our scale factor maskContext.scaleCTM(ctx.scale.factor, ctx.scale.factor); // fill the text into this temp context in white for use as a mask setFillColor(maskContext, 0xFFFFFFFF); ilayout.fill(maskContext, 0, 0, fillColor); // now fill the gradient, using our temp context as a mask bctx.saveGState(); bctx.clipToMask(new CGRect(x, y, width, height), maskContext.toImage()); gradient.fill(bctx); bctx.restoreGState(); // finally free the temp context maskContext.dispose(); } isDirty = true; return this; }
@Override public Canvas fillText(TextLayout layout, float x, float y) { RoboGradient gradient = currentState().gradient; RoboTextLayout ilayout = (RoboTextLayout) layout; if (gradient == null) { ilayout.fill(bctx, x, y, fillColor); } else { // draw our text into a fresh context so we can use it as a mask for the gradient CGBitmapContext maskContext = RoboGraphics.createCGBitmap(texWidth(), texHeight()); maskContext.clearRect(new CGRect(0, 0, texWidth(), texHeight())); // scale the context based on our scale factor float scale = image.scale().factor; maskContext.scaleCTM(scale, scale); // fill the text into this temp context in white for use as a mask setFillColor(maskContext, 0xFFFFFFFF); ilayout.fill(maskContext, 0, 0, fillColor); // now fill the gradient, using our temp context as a mask bctx.saveGState(); bctx.clipToMask(new CGRect(x, y, width, height), maskContext.toImage()); gradient.fill(bctx); bctx.restoreGState(); // finally free the temp context maskContext.dispose(); } isDirty = true; return this; }