diff options
Diffstat (limited to 'libs/hwui')
| -rw-r--r-- | libs/hwui/Android.mk | 3 | ||||
| -rw-r--r-- | libs/hwui/Animator.h | 2 | ||||
| -rw-r--r-- | libs/hwui/CanvasProperty.h | 3 | ||||
| -rw-r--r-- | libs/hwui/DisplayList.h | 1 | ||||
| -rw-r--r-- | libs/hwui/DisplayListRenderer.cpp | 2 | ||||
| -rw-r--r-- | libs/hwui/Matrix.cpp | 4 | ||||
| -rw-r--r-- | libs/hwui/Matrix.h | 2 | ||||
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 43 | ||||
| -rw-r--r-- | libs/hwui/OpenGLRenderer.h | 14 | ||||
| -rw-r--r-- | libs/hwui/Rect.h | 8 | ||||
| -rw-r--r-- | libs/hwui/RenderNode.h | 1 | ||||
| -rw-r--r-- | libs/hwui/Snapshot.cpp | 26 | ||||
| -rw-r--r-- | libs/hwui/font/Font.cpp | 20 | ||||
| -rw-r--r-- | libs/hwui/utils/GLUtils.cpp | 52 | ||||
| -rw-r--r-- | libs/hwui/utils/GLUtils.h (renamed from libs/hwui/utils/VirtualLightRefBase.h) | 21 | ||||
| -rw-r--r-- | libs/hwui/utils/MathUtils.h | 2 |
16 files changed, 133 insertions, 71 deletions
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index eb0cac8..2cadf09 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -6,6 +6,7 @@ include $(CLEAR_VARS) ifeq ($(USE_OPENGL_RENDERER),true) LOCAL_SRC_FILES := \ utils/Blur.cpp \ + utils/GLUtils.cpp \ utils/SortedListImpl.cpp \ thread/TaskManager.cpp \ font/CacheTexture.cpp \ @@ -53,7 +54,7 @@ ifeq ($(USE_OPENGL_RENDERER),true) TextureCache.cpp \ TextDropShadowCache.cpp - # RenderThread stuff +# RenderThread stuff LOCAL_SRC_FILES += \ renderthread/CanvasContext.cpp \ renderthread/DrawFrameTask.cpp \ diff --git a/libs/hwui/Animator.h b/libs/hwui/Animator.h index 0b074cc..86fc7c3 100644 --- a/libs/hwui/Animator.h +++ b/libs/hwui/Animator.h @@ -17,13 +17,13 @@ #define ANIMATOR_H #include <cutils/compiler.h> +#include <utils/RefBase.h> #include <utils/StrongPointer.h> #include "CanvasProperty.h" #include "Interpolator.h" #include "TreeInfo.h" #include "utils/Macros.h" -#include "utils/VirtualLightRefBase.h" namespace android { namespace uirenderer { diff --git a/libs/hwui/CanvasProperty.h b/libs/hwui/CanvasProperty.h index 2e1d176..6074394 100644 --- a/libs/hwui/CanvasProperty.h +++ b/libs/hwui/CanvasProperty.h @@ -16,8 +16,9 @@ #ifndef CANVASPROPERTY_H #define CANVASPROPERTY_H +#include <utils/RefBase.h> + #include "utils/Macros.h" -#include "utils/VirtualLightRefBase.h" #include <SkPaint.h> diff --git a/libs/hwui/DisplayList.h b/libs/hwui/DisplayList.h index eaeb772..b2ead5b 100644 --- a/libs/hwui/DisplayList.h +++ b/libs/hwui/DisplayList.h @@ -41,7 +41,6 @@ #include "Matrix.h" #include "DeferredDisplayList.h" #include "RenderProperties.h" -#include "utils/VirtualLightRefBase.h" class SkBitmap; class SkPaint; diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index c2ce6ed..2391e80 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -58,7 +58,7 @@ DisplayListData* DisplayListRenderer::finishRecording() { void DisplayListRenderer::setViewport(int width, int height) { // TODO: DisplayListRenderer shouldn't have a projection matrix, as it should never be used - mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1); + mProjectionMatrix.loadOrtho(0, width, height, 0, -1, 1); initializeViewport(width, height); } diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp index f06106b..2268386 100644 --- a/libs/hwui/Matrix.cpp +++ b/libs/hwui/Matrix.cpp @@ -482,8 +482,8 @@ void Matrix4::decomposeScale(float& sx, float& sy) const { sy = copysignf(sqrtf(len), data[mat4::kScaleY]); } -void Matrix4::dump() const { - ALOGD("Matrix4[simple=%d, type=0x%x", isSimple(), getType()); +void Matrix4::dump(const char* label) const { + ALOGD("%s[simple=%d, type=0x%x", label ? label : "Matrix4", isSimple(), getType()); ALOGD(" %f %f %f %f", data[kScaleX], data[kSkewX], data[8], data[kTranslateX]); ALOGD(" %f %f %f %f", data[kSkewY], data[kScaleY], data[9], data[kTranslateY]); ALOGD(" %f %f %f %f", data[2], data[6], data[kScaleZ], data[kTranslateZ]); diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h index 26cb05f..e33a001 100644 --- a/libs/hwui/Matrix.h +++ b/libs/hwui/Matrix.h @@ -209,7 +209,7 @@ public: void decomposeScale(float& sx, float& sy) const; - void dump() const; + void dump(const char* label = NULL) const; static const Matrix4& identity(); diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 87b07b3..20b038d 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -37,6 +37,7 @@ #include "PathTessellator.h" #include "Properties.h" #include "ShadowTessellator.h" +#include "utils/GLUtils.h" #include "Vector.h" #include "VertexBuffer.h" @@ -170,7 +171,7 @@ void OpenGLRenderer::setViewport(int width, int height) { } void OpenGLRenderer::initViewport(int width, int height) { - mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1); + mProjectionMatrix.loadOrtho(0, width, height, 0, -1, 1); initializeViewport(width, height); } @@ -296,24 +297,7 @@ void OpenGLRenderer::finish() { if (!suppressErrorChecks()) { #if DEBUG_OPENGL - GLenum status = GL_NO_ERROR; - while ((status = glGetError()) != GL_NO_ERROR) { - ALOGD("GL error from OpenGLRenderer: 0x%x", status); - switch (status) { - case GL_INVALID_ENUM: - ALOGE(" GL_INVALID_ENUM"); - break; - case GL_INVALID_VALUE: - ALOGE(" GL_INVALID_VALUE"); - break; - case GL_INVALID_OPERATION: - ALOGE(" GL_INVALID_OPERATION"); - break; - case GL_OUT_OF_MEMORY: - ALOGE(" Out of memory!"); - break; - } - } + GLUtils::dumpGLErrors(); #endif #if DEBUG_MEMORY_USAGE @@ -644,7 +628,7 @@ void OpenGLRenderer::onSnapshotRestored(const Snapshot& removed, const Snapshot& if (restoreOrtho) { const Rect& r = restored.viewport; glViewport(r.left, r.top, r.right, r.bottom); - mViewProjMatrix.load(removed.orthoMatrix); // TODO: should ortho be stored in 'restored'? + mProjectionMatrix.load(removed.orthoMatrix); // TODO: should ortho be stored in 'restored'? } if (restoreClip) { @@ -870,7 +854,7 @@ bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, Rect& clip) { mSnapshot->resetClip(clip.left, clip.top, clip.right, clip.bottom); mSnapshot->viewport.set(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight()); mSnapshot->height = bounds.getHeight(); - mSnapshot->orthoMatrix.load(mViewProjMatrix); + mSnapshot->orthoMatrix.load(mProjectionMatrix); endTiling(); debugOverdraw(false, false); @@ -900,8 +884,7 @@ bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, Rect& clip) { // Change the ortho projection glViewport(0, 0, bounds.getWidth(), bounds.getHeight()); - // TODO: determine best way to support 3d drawing within HW layers - mViewProjMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f); + mProjectionMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f); return true; } @@ -1705,17 +1688,17 @@ void OpenGLRenderer::setupDrawDirtyRegionsDisabled() { void OpenGLRenderer::setupDrawModelView(ModelViewMode mode, bool offset, float left, float top, float right, float bottom, bool ignoreTransform) { - mModelView.loadTranslate(left, top, 0.0f); + mModelViewMatrix.loadTranslate(left, top, 0.0f); if (mode == kModelViewMode_TranslateAndScale) { - mModelView.scale(right - left, bottom - top, 1.0f); + mModelViewMatrix.scale(right - left, bottom - top, 1.0f); } bool dirty = right - left > 0.0f && bottom - top > 0.0f; if (!ignoreTransform) { - mCaches.currentProgram->set(mViewProjMatrix, mModelView, *currentTransform(), offset); + mCaches.currentProgram->set(mProjectionMatrix, mModelViewMatrix, *currentTransform(), offset); if (dirty && mTrackDirtyRegions) dirtyLayer(left, top, right, bottom, *currentTransform()); } else { - mCaches.currentProgram->set(mViewProjMatrix, mModelView, mat4::identity(), offset); + mCaches.currentProgram->set(mProjectionMatrix, mModelViewMatrix, mat4::identity(), offset); if (dirty && mTrackDirtyRegions) dirtyLayer(left, top, right, bottom); } } @@ -1740,11 +1723,11 @@ void OpenGLRenderer::setupDrawShaderUniforms(bool ignoreTransform) { // compensate. mat4 modelViewWithoutTransform; modelViewWithoutTransform.loadInverse(*currentTransform()); - modelViewWithoutTransform.multiply(mModelView); - mModelView.load(modelViewWithoutTransform); + modelViewWithoutTransform.multiply(mModelViewMatrix); + mModelViewMatrix.load(modelViewWithoutTransform); } mDrawModifiers.mShader->setupProgram(mCaches.currentProgram, - mModelView, *mSnapshot, &mTextureUnit); + mModelViewMatrix, *mSnapshot, &mTextureUnit); } } diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 1d46945..4f7f01e 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -930,8 +930,8 @@ private: */ Texture* getTexture(const SkBitmap* bitmap); - // Matrix used for view/projection in shaders - mat4 mViewProjMatrix; + // Ortho matrix used for projection in shaders + mat4 mProjectionMatrix; /** * Model-view matrix used to position/size objects @@ -939,15 +939,15 @@ private: * Stores operation-local modifications to the draw matrix that aren't incorporated into the * currentTransform(). * - * If generated with kModelViewMode_Translate, the mModelView will reflect an x/y offset, + * If generated with kModelViewMode_Translate, mModelViewMatrix will reflect an x/y offset, * e.g. the offset in drawLayer(). If generated with kModelViewMode_TranslateAndScale, - * mModelView will reflect a translation and scale, e.g. the translation and scale required to - * make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height of a - * bitmap. + * mModelViewMatrix will reflect a translation and scale, e.g. the translation and scale + * required to make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height + * of a bitmap. * * Used as input to SkiaShader transformation. */ - mat4 mModelView; + mat4 mModelViewMatrix; // State used to define the clipping region Rect mTilingClip; diff --git a/libs/hwui/Rect.h b/libs/hwui/Rect.h index 92964a8..f38d8b7 100644 --- a/libs/hwui/Rect.h +++ b/libs/hwui/Rect.h @@ -175,6 +175,10 @@ public: bottom += dy; } + void inset(float delta) { + outset(-delta); + } + void outset(float delta) { left -= delta; top -= delta; @@ -230,8 +234,8 @@ public: bottom = ceilf(bottom); } - void dump() const { - ALOGD("Rect[l=%f t=%f r=%f b=%f]", left, top, right, bottom); + void dump(const char* label) const { + ALOGD("%s[l=%f t=%f r=%f b=%f]", label ? label : "Rect", left, top, right, bottom); } private: diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h index 159903c..bc62ee1 100644 --- a/libs/hwui/RenderNode.h +++ b/libs/hwui/RenderNode.h @@ -45,7 +45,6 @@ #include "DisplayList.h" #include "RenderProperties.h" #include "TreeInfo.h" -#include "utils/VirtualLightRefBase.h" class SkBitmap; class SkPaint; diff --git a/libs/hwui/Snapshot.cpp b/libs/hwui/Snapshot.cpp index d26ee38..6bfa203 100644 --- a/libs/hwui/Snapshot.cpp +++ b/libs/hwui/Snapshot.cpp @@ -27,9 +27,15 @@ namespace uirenderer { // Constructors /////////////////////////////////////////////////////////////////////////////// -Snapshot::Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), - invisible(false), empty(false), alpha(1.0f) { - +Snapshot::Snapshot() + : flags(0) + , previous(NULL) + , layer(NULL) + , fbo(0) + , invisible(false) + , empty(false) + , height(0) + , alpha(1.0f) { transform = &mTransformRoot; clipRect = &mClipRectRoot; region = NULL; @@ -40,10 +46,16 @@ Snapshot::Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), * Copies the specified snapshot/ The specified snapshot is stored as * the previous snapshot. */ -Snapshot::Snapshot(const sp<Snapshot>& s, int saveFlags): - flags(0), previous(s), layer(s->layer), fbo(s->fbo), - invisible(s->invisible), empty(false), - viewport(s->viewport), height(s->height), alpha(s->alpha) { +Snapshot::Snapshot(const sp<Snapshot>& s, int saveFlags) + : flags(0) + , previous(s) + , layer(s->layer) + , fbo(s->fbo) + , invisible(s->invisible) + , empty(false) + , viewport(s->viewport) + , height(s->height) + , alpha(s->alpha) { if (saveFlags & SkCanvas::kMatrix_SaveFlag) { mTransformRoot.load(*s->transform); diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp index d22cb8a..08e9a1a 100644 --- a/libs/hwui/font/Font.cpp +++ b/libs/hwui/font/Font.cpp @@ -214,18 +214,28 @@ void Font::drawCachedGlyphBitmap(CachedGlyphInfo* glyph, int x, int y, uint8_t* int dstY = y + glyph->mBitmapTop; CacheTexture* cacheTexture = glyph->mCacheTexture; + PixelBuffer* pixelBuffer = cacheTexture->getPixelBuffer(); + uint32_t formatSize = PixelBuffer::formatSize(pixelBuffer->getFormat()); uint32_t cacheWidth = cacheTexture->getWidth(); - uint32_t startY = glyph->mStartY * cacheWidth; - uint32_t endY = startY + (glyph->mBitmapHeight * cacheWidth); + uint32_t srcStride = formatSize * cacheWidth; + uint32_t startY = glyph->mStartY * srcStride; + uint32_t endY = startY + (glyph->mBitmapHeight * srcStride); - PixelBuffer* pixelBuffer = cacheTexture->getPixelBuffer(); const uint8_t* cacheBuffer = pixelBuffer->map(); for (uint32_t cacheY = startY, bitmapY = dstY * bitmapWidth; cacheY < endY; - cacheY += cacheWidth, bitmapY += bitmapWidth) { - memcpy(&bitmap[bitmapY + dstX], &cacheBuffer[cacheY + glyph->mStartX], glyph->mBitmapWidth); + cacheY += srcStride, bitmapY += bitmapWidth) { + + if (formatSize == 1) { + memcpy(&bitmap[bitmapY + dstX], &cacheBuffer[cacheY + glyph->mStartX], glyph->mBitmapWidth); + } else { + for (uint32_t i = 0; i < glyph->mBitmapWidth; ++i) { + bitmap[bitmapY + dstX + i] = cacheBuffer[cacheY + (glyph->mStartX + i)*formatSize]; + } + } } + } void Font::drawCachedGlyph(CachedGlyphInfo* glyph, float x, float hOffset, float vOffset, diff --git a/libs/hwui/utils/GLUtils.cpp b/libs/hwui/utils/GLUtils.cpp new file mode 100644 index 0000000..9b298ca --- /dev/null +++ b/libs/hwui/utils/GLUtils.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "OpenGLRenderer" + +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + +#include <utils/Log.h> + +#include "GLUtils.h" + +namespace android { +namespace uirenderer { + +void GLUtils::dumpGLErrors() { + GLenum status = GL_NO_ERROR; + while ((status = glGetError()) != GL_NO_ERROR) { + switch (status) { + case GL_INVALID_ENUM: + ALOGE("GL error: GL_INVALID_ENUM"); + break; + case GL_INVALID_VALUE: + ALOGE("GL error: GL_INVALID_VALUE"); + break; + case GL_INVALID_OPERATION: + ALOGE("GL error: GL_INVALID_OPERATION"); + break; + case GL_OUT_OF_MEMORY: + ALOGE("GL error: Out of memory!"); + break; + default: + ALOGE("GL error: 0x%x", status); + } + } +} + +}; // namespace uirenderer +}; // namespace android diff --git a/libs/hwui/utils/VirtualLightRefBase.h b/libs/hwui/utils/GLUtils.h index b545aab..890e374 100644 --- a/libs/hwui/utils/VirtualLightRefBase.h +++ b/libs/hwui/utils/GLUtils.h @@ -13,22 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef VIRTUALLIGHTREFBASE_H -#define VIRTUALLIGHTREFBASE_H - -#include <utils/RefBase.h> +#ifndef GLUTILS_H +#define GLUTILS_H namespace android { namespace uirenderer { -// This is a wrapper around LightRefBase that simply enforces a virtual -// destructor to eliminate the template requirement of LightRefBase -class VirtualLightRefBase : public LightRefBase<VirtualLightRefBase> { +class GLUtils { +private: public: - virtual ~VirtualLightRefBase() {} -}; + /** + * Print out any GL errors with ALOGE + */ + static void dumpGLErrors(); + +}; // class GLUtils } /* namespace uirenderer */ } /* namespace android */ -#endif /* VIRTUALLIGHTREFBASE_H */ +#endif /* GLUTILS_H */ diff --git a/libs/hwui/utils/MathUtils.h b/libs/hwui/utils/MathUtils.h index 7deabe9..8ba44dc 100644 --- a/libs/hwui/utils/MathUtils.h +++ b/libs/hwui/utils/MathUtils.h @@ -38,4 +38,4 @@ public: } /* namespace uirenderer */ } /* namespace android */ -#endif /* RENDERNODE_H */ +#endif /* MATHUTILS_H */ |
