From 2055abaa0a590c35e27e1ae2e7d7cfccdfb98b59 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Fri, 18 Jan 2013 16:42:51 -0800 Subject: Allow layers with a stencil buffer to be resized on the fly Bug #7146141 This change moves the resizeLayer() from LayerCache (where it should never have been anyway) to Layer. This makes a little more sense. Change-Id: I8b2f9c19c558e738405a58b9e71ec5799fc6be88 --- libs/hwui/Layer.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'libs/hwui/Layer.cpp') diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp index 1d85b704e5ad..79dbfb0fc3a5 100644 --- a/libs/hwui/Layer.cpp +++ b/libs/hwui/Layer.cpp @@ -54,6 +54,51 @@ Layer::~Layer() { deleteTexture(); } +uint32_t Layer::computeIdealWidth(uint32_t layerWidth) { + return uint32_t(ceilf(layerWidth / float(LAYER_SIZE)) * LAYER_SIZE); +} + +uint32_t Layer::computeIdealHeight(uint32_t layerHeight) { + return uint32_t(ceilf(layerHeight / float(LAYER_SIZE)) * LAYER_SIZE); +} + +bool Layer::resize(const uint32_t width, const uint32_t height) { + uint32_t desiredWidth = computeIdealWidth(width); + uint32_t desiredHeight = computeIdealWidth(height); + + if (desiredWidth <= getWidth() && desiredHeight <= getHeight()) { + return true; + } + + uint32_t oldWidth = getWidth(); + uint32_t oldHeight = getHeight(); + + setSize(desiredWidth, desiredHeight); + + if (fbo) { + Caches::getInstance().activeTexture(0); + bindTexture(); + allocateTexture(GL_RGBA, GL_UNSIGNED_BYTE); + + if (glGetError() != GL_NO_ERROR) { + setSize(oldWidth, oldHeight); + return false; + } + } + + if (stencil) { + bindStencilRenderBuffer(); + allocateStencilRenderBuffer(); + + if (glGetError() != GL_NO_ERROR) { + setSize(oldWidth, oldHeight); + return false; + } + } + + return true; +} + void Layer::removeFbo(bool flush) { if (stencil) { // TODO: recycle & cache instead of simply deleting -- cgit v1.2.3-59-g8ed1b