diff options
author | Chris Craik <ccraik@google.com> | 2014-05-09 16:11:14 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2014-05-09 16:11:14 -0700 |
commit | 0c0ec26366045e515790a6acdab782965efc63b4 (patch) | |
tree | e33da53a3d1082d9e1bc242ca7995b975a93c887 /libs | |
parent | f992066731fb27a6d9fc8bae673c638093610292 (diff) | |
download | frameworks_base-0c0ec26366045e515790a6acdab782965efc63b4.zip frameworks_base-0c0ec26366045e515790a6acdab782965efc63b4.tar.gz frameworks_base-0c0ec26366045e515790a6acdab782965efc63b4.tar.bz2 |
Simplify projection matrix management.
Store in and use from snapshot, and remove the kFlagOrthoDirty flag,
as it's redundant with kFlagIsFboLayer.
Change-Id: I2bd380192d50117f4ce1fd2058213669a886f406
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/DisplayListRenderer.cpp | 3 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 28 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h | 3 | ||||
-rw-r--r-- | libs/hwui/Snapshot.cpp | 1 | ||||
-rw-r--r-- | libs/hwui/Snapshot.h | 11 |
5 files changed, 19 insertions, 27 deletions
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index 2391e80..a4bce3a 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -57,9 +57,6 @@ DisplayListData* DisplayListRenderer::finishRecording() { } void DisplayListRenderer::setViewport(int width, int height) { - // TODO: DisplayListRenderer shouldn't have a projection matrix, as it should never be used - mProjectionMatrix.loadOrtho(0, width, height, 0, -1, 1); - initializeViewport(width, height); } diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 20b038d..091cdf4 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -171,7 +171,7 @@ void OpenGLRenderer::setViewport(int width, int height) { } void OpenGLRenderer::initViewport(int width, int height) { - mProjectionMatrix.loadOrtho(0, width, height, 0, -1, 1); + mSnapshot->orthoMatrix.loadOrtho(0, width, height, 0, -1, 1); initializeViewport(width, height); } @@ -621,14 +621,13 @@ void OpenGLRenderer::flushLayerUpdates() { /////////////////////////////////////////////////////////////////////////////// void OpenGLRenderer::onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) { - bool restoreOrtho = removed.flags & Snapshot::kFlagDirtyOrtho; + bool restoreViewport = removed.flags & Snapshot::kFlagIsFboLayer; bool restoreClip = removed.flags & Snapshot::kFlagClipSet; bool restoreLayer = removed.flags & Snapshot::kFlagIsLayer; - if (restoreOrtho) { + if (restoreViewport) { const Rect& r = restored.viewport; glViewport(r.left, r.top, r.right, r.bottom); - mProjectionMatrix.load(removed.orthoMatrix); // TODO: should ortho be stored in 'restored'? } if (restoreClip) { @@ -847,14 +846,12 @@ bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, Rect& clip) { layer->setFbo(mCaches.fboCache.get()); mSnapshot->region = &mSnapshot->layer->region; - mSnapshot->flags |= Snapshot::kFlagFboTarget | Snapshot::kFlagIsFboLayer | - Snapshot::kFlagDirtyOrtho; + mSnapshot->flags |= Snapshot::kFlagFboTarget | Snapshot::kFlagIsFboLayer; mSnapshot->fbo = layer->getFbo(); mSnapshot->resetTransform(-bounds.left, -bounds.top, 0.0f); 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(mProjectionMatrix); endTiling(); debugOverdraw(false, false); @@ -883,8 +880,7 @@ bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, Rect& clip) { // Change the ortho projection glViewport(0, 0, bounds.getWidth(), bounds.getHeight()); - - mProjectionMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f); + mSnapshot->orthoMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f); return true; } @@ -1694,12 +1690,14 @@ void OpenGLRenderer::setupDrawModelView(ModelViewMode mode, bool offset, } bool dirty = right - left > 0.0f && bottom - top > 0.0f; - if (!ignoreTransform) { - mCaches.currentProgram->set(mProjectionMatrix, mModelViewMatrix, *currentTransform(), offset); - if (dirty && mTrackDirtyRegions) dirtyLayer(left, top, right, bottom, *currentTransform()); - } else { - mCaches.currentProgram->set(mProjectionMatrix, mModelViewMatrix, mat4::identity(), offset); - if (dirty && mTrackDirtyRegions) dirtyLayer(left, top, right, bottom); + const Matrix4& transformMatrix = ignoreTransform ? Matrix4::identity() : *currentTransform(); + mCaches.currentProgram->set(mSnapshot->orthoMatrix, mModelViewMatrix, transformMatrix, offset); + if (dirty && mTrackDirtyRegions) { + if (!ignoreTransform) { + dirtyLayer(left, top, right, bottom, *currentTransform()); + } else { + dirtyLayer(left, top, right, bottom); + } } } diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 4f7f01e..d140428 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -930,9 +930,6 @@ private: */ Texture* getTexture(const SkBitmap* bitmap); - // Ortho matrix used for projection in shaders - mat4 mProjectionMatrix; - /** * Model-view matrix used to position/size objects * diff --git a/libs/hwui/Snapshot.cpp b/libs/hwui/Snapshot.cpp index 6bfa203..b2df86f 100644 --- a/libs/hwui/Snapshot.cpp +++ b/libs/hwui/Snapshot.cpp @@ -55,6 +55,7 @@ Snapshot::Snapshot(const sp<Snapshot>& s, int saveFlags) , empty(false) , viewport(s->viewport) , height(s->height) + , orthoMatrix(s->orthoMatrix) , alpha(s->alpha) { if (saveFlags & SkCanvas::kMatrix_SaveFlag) { diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h index 038aea8..aede079 100644 --- a/libs/hwui/Snapshot.h +++ b/libs/hwui/Snapshot.h @@ -65,17 +65,16 @@ public: * Indicates that this snapshot is a special type of layer * backed by an FBO. This flag only makes sense when the * flag kFlagIsLayer is also set. + * + * Viewport has been modified to fit the new Fbo, and must be + * restored when this snapshot is restored. */ kFlagIsFboLayer = 0x4, /** - * Indicates that this snapshot has changed the ortho matrix. - */ - kFlagDirtyOrtho = 0x8, - /** * Indicates that this snapshot or an ancestor snapshot is * an FBO layer. */ - kFlagFboTarget = 0x10 + kFlagFboTarget = 0x8, }; /** @@ -183,7 +182,7 @@ public: int height; /** - * Contains the previous ortho matrix. + * Contains the current orthographic, projection matrix. */ mat4 orthoMatrix; |