Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 17 | #define LOG_TAG "OpenGLRenderer" |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 18 | |
| 19 | #include <stdlib.h> |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 23 | #include <SkCanvas.h> |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 24 | #include <SkPathMeasure.h> |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 25 | #include <SkTypeface.h> |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 26 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 27 | #include <utils/Log.h> |
Romain Guy | e2d345e | 2010-09-24 18:39:22 -0700 | [diff] [blame] | 28 | #include <utils/StopWatch.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 29 | |
Romain Guy | 08aa2cb | 2011-03-17 11:06:57 -0700 | [diff] [blame] | 30 | #include <private/hwui/DrawGlInfo.h> |
| 31 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 32 | #include <ui/Rect.h> |
| 33 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 34 | #include "OpenGLRenderer.h" |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 35 | #include "DeferredDisplayList.h" |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 36 | #include "DisplayListRenderer.h" |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 37 | #include "PathTessellator.h" |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 38 | #include "Properties.h" |
Romain Guy | a957eea | 2010-12-08 18:34:42 -0800 | [diff] [blame] | 39 | #include "Vector.h" |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 40 | |
| 41 | namespace android { |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 42 | namespace uirenderer { |
| 43 | |
| 44 | /////////////////////////////////////////////////////////////////////////////// |
| 45 | // Defines |
| 46 | /////////////////////////////////////////////////////////////////////////////// |
| 47 | |
Romain Guy | 759ea80 | 2010-09-16 20:49:46 -0700 | [diff] [blame] | 48 | #define RAD_TO_DEG (180.0f / 3.14159265f) |
| 49 | #define MIN_ANGLE 0.001f |
| 50 | |
Romain Guy | f877308 | 2012-07-12 18:01:00 -0700 | [diff] [blame] | 51 | #define ALPHA_THRESHOLD 0 |
Romain Guy | dbc26d2 | 2010-10-11 17:58:29 -0700 | [diff] [blame] | 52 | |
Romain Guy | 713e1bb | 2012-10-16 18:44:09 -0700 | [diff] [blame] | 53 | #define FILTER(paint) (!paint || paint->isFilterBitmap() ? GL_LINEAR : GL_NEAREST) |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 54 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 55 | /////////////////////////////////////////////////////////////////////////////// |
| 56 | // Globals |
| 57 | /////////////////////////////////////////////////////////////////////////////// |
| 58 | |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Structure mapping Skia xfermodes to OpenGL blending factors. |
| 61 | */ |
| 62 | struct Blender { |
| 63 | SkXfermode::Mode mode; |
| 64 | GLenum src; |
| 65 | GLenum dst; |
| 66 | }; // struct Blender |
| 67 | |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 68 | // In this array, the index of each Blender equals the value of the first |
| 69 | // entry. For instance, gBlends[1] == gBlends[SkXfermode::kSrc_Mode] |
| 70 | static const Blender gBlends[] = { |
Romain Guy | 2ffefd4 | 2011-09-08 15:33:03 -0700 | [diff] [blame] | 71 | { SkXfermode::kClear_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }, |
| 72 | { SkXfermode::kSrc_Mode, GL_ONE, GL_ZERO }, |
| 73 | { SkXfermode::kDst_Mode, GL_ZERO, GL_ONE }, |
| 74 | { SkXfermode::kSrcOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA }, |
| 75 | { SkXfermode::kDstOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE }, |
| 76 | { SkXfermode::kSrcIn_Mode, GL_DST_ALPHA, GL_ZERO }, |
| 77 | { SkXfermode::kDstIn_Mode, GL_ZERO, GL_SRC_ALPHA }, |
| 78 | { SkXfermode::kSrcOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO }, |
| 79 | { SkXfermode::kDstOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }, |
| 80 | { SkXfermode::kSrcATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, |
| 81 | { SkXfermode::kDstATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA }, |
| 82 | { SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, |
| 83 | { SkXfermode::kPlus_Mode, GL_ONE, GL_ONE }, |
Derek Sollenberger | d81ec45 | 2013-02-04 15:42:26 -0500 | [diff] [blame] | 84 | { SkXfermode::kModulate_Mode, GL_ZERO, GL_SRC_COLOR }, |
Romain Guy | 2ffefd4 | 2011-09-08 15:33:03 -0700 | [diff] [blame] | 85 | { SkXfermode::kScreen_Mode, GL_ONE, GL_ONE_MINUS_SRC_COLOR } |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 86 | }; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 87 | |
Romain Guy | 87a7657 | 2010-09-13 18:11:21 -0700 | [diff] [blame] | 88 | // This array contains the swapped version of each SkXfermode. For instance |
| 89 | // this array's SrcOver blending mode is actually DstOver. You can refer to |
| 90 | // createLayer() for more information on the purpose of this array. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 91 | static const Blender gBlendsSwap[] = { |
Romain Guy | 2ffefd4 | 2011-09-08 15:33:03 -0700 | [diff] [blame] | 92 | { SkXfermode::kClear_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO }, |
| 93 | { SkXfermode::kSrc_Mode, GL_ZERO, GL_ONE }, |
| 94 | { SkXfermode::kDst_Mode, GL_ONE, GL_ZERO }, |
| 95 | { SkXfermode::kSrcOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE }, |
| 96 | { SkXfermode::kDstOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA }, |
| 97 | { SkXfermode::kSrcIn_Mode, GL_ZERO, GL_SRC_ALPHA }, |
| 98 | { SkXfermode::kDstIn_Mode, GL_DST_ALPHA, GL_ZERO }, |
| 99 | { SkXfermode::kSrcOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA }, |
| 100 | { SkXfermode::kDstOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO }, |
| 101 | { SkXfermode::kSrcATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA }, |
| 102 | { SkXfermode::kDstATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, |
| 103 | { SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, |
| 104 | { SkXfermode::kPlus_Mode, GL_ONE, GL_ONE }, |
Derek Sollenberger | d81ec45 | 2013-02-04 15:42:26 -0500 | [diff] [blame] | 105 | { SkXfermode::kModulate_Mode, GL_DST_COLOR, GL_ZERO }, |
Romain Guy | 2ffefd4 | 2011-09-08 15:33:03 -0700 | [diff] [blame] | 106 | { SkXfermode::kScreen_Mode, GL_ONE_MINUS_DST_COLOR, GL_ONE } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 109 | /////////////////////////////////////////////////////////////////////////////// |
| 110 | // Constructors/destructor |
| 111 | /////////////////////////////////////////////////////////////////////////////// |
| 112 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 113 | OpenGLRenderer::OpenGLRenderer(): |
| 114 | mCaches(Caches::getInstance()), mExtensions(Extensions::getInstance()) { |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 115 | mDrawModifiers.mShader = NULL; |
| 116 | mDrawModifiers.mColorFilter = NULL; |
| 117 | mDrawModifiers.mHasShadow = false; |
| 118 | mDrawModifiers.mHasDrawFilter = false; |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 119 | |
Romain Guy | ac670c0 | 2010-07-27 17:39:27 -0700 | [diff] [blame] | 120 | memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices)); |
| 121 | |
Romain Guy | ae5575b | 2010-07-29 18:48:04 -0700 | [diff] [blame] | 122 | mFirstSnapshot = new Snapshot; |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 123 | mFrameStarted = false; |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 124 | |
| 125 | mScissorOptimizationDisabled = false; |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 128 | OpenGLRenderer::~OpenGLRenderer() { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 129 | // The context has already been destroyed at this point, do not call |
| 130 | // GL APIs. All GL state should be kept in Caches.h |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 133 | void OpenGLRenderer::initProperties() { |
| 134 | char property[PROPERTY_VALUE_MAX]; |
| 135 | if (property_get(PROPERTY_DISABLE_SCISSOR_OPTIMIZATION, property, "false")) { |
| 136 | mScissorOptimizationDisabled = !strcasecmp(property, "true"); |
| 137 | INIT_LOGD(" Scissor optimization %s", |
| 138 | mScissorOptimizationDisabled ? "disabled" : "enabled"); |
| 139 | } else { |
| 140 | INIT_LOGD(" Scissor optimization enabled"); |
| 141 | } |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 145 | // Setup |
| 146 | /////////////////////////////////////////////////////////////////////////////// |
| 147 | |
Romain Guy | ef35927 | 2013-01-31 19:07:29 -0800 | [diff] [blame] | 148 | void OpenGLRenderer::setName(const char* name) { |
| 149 | if (name) { |
| 150 | mName.setTo(name); |
| 151 | } else { |
| 152 | mName.clear(); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | const char* OpenGLRenderer::getName() const { |
| 157 | return mName.string(); |
| 158 | } |
| 159 | |
Romain Guy | 49c5fc0 | 2012-05-15 11:10:01 -0700 | [diff] [blame] | 160 | bool OpenGLRenderer::isDeferred() { |
| 161 | return false; |
| 162 | } |
| 163 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 164 | void OpenGLRenderer::setViewport(int width, int height) { |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 165 | initViewport(width, height); |
| 166 | |
| 167 | glDisable(GL_DITHER); |
| 168 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 169 | |
| 170 | glEnableVertexAttribArray(Program::kBindingPosition); |
| 171 | } |
| 172 | |
| 173 | void OpenGLRenderer::initViewport(int width, int height) { |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 174 | mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 175 | |
| 176 | mWidth = width; |
| 177 | mHeight = height; |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 178 | |
| 179 | mFirstSnapshot->height = height; |
| 180 | mFirstSnapshot->viewport.set(0, 0, width, height); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 183 | void OpenGLRenderer::setupFrameState(float left, float top, |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 184 | float right, float bottom, bool opaque) { |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 185 | mCaches.clearGarbage(); |
| 186 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 187 | mOpaque = opaque; |
Romain Guy | 8aef54f | 2010-09-01 15:13:49 -0700 | [diff] [blame] | 188 | mSnapshot = new Snapshot(mFirstSnapshot, |
| 189 | SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
Romain Guy | 84962f2 | 2011-03-02 15:43:44 -0800 | [diff] [blame] | 190 | mSnapshot->fbo = getTargetFbo(); |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 191 | mSaveCount = 1; |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 192 | |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 193 | mSnapshot->setClip(left, top, right, bottom); |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 194 | mTilingClip.set(left, top, right, bottom); |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | status_t OpenGLRenderer::startFrame() { |
| 198 | if (mFrameStarted) return DrawGlInfo::kStatusDone; |
| 199 | mFrameStarted = true; |
| 200 | |
Romain Guy | 41308e2 | 2012-10-22 20:02:43 -0700 | [diff] [blame] | 201 | mDirtyClip = true; |
Romain Guy | ddf7437 | 2012-05-22 14:07:07 -0700 | [diff] [blame] | 202 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 203 | discardFramebuffer(mTilingClip.left, mTilingClip.top, mTilingClip.right, mTilingClip.bottom); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 204 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 205 | glViewport(0, 0, mWidth, mHeight); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 206 | |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 207 | // Functors break the tiling extension in pretty spectacular ways |
| 208 | // This ensures we don't use tiling when a functor is going to be |
| 209 | // invoked during the frame |
| 210 | mSuppressTiling = mCaches.hasRegisteredFunctors(); |
| 211 | |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 212 | startTiling(mSnapshot, true); |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 213 | |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 214 | debugOverdraw(true, true); |
| 215 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 216 | return clear(mTilingClip.left, mTilingClip.top, |
| 217 | mTilingClip.right, mTilingClip.bottom, mOpaque); |
| 218 | } |
| 219 | |
| 220 | status_t OpenGLRenderer::prepare(bool opaque) { |
| 221 | return prepareDirty(0.0f, 0.0f, mWidth, mHeight, opaque); |
| 222 | } |
| 223 | |
| 224 | status_t OpenGLRenderer::prepareDirty(float left, float top, |
| 225 | float right, float bottom, bool opaque) { |
| 226 | setupFrameState(left, top, right, bottom, opaque); |
| 227 | |
| 228 | // Layer renderers will start the frame immediately |
| 229 | // The framebuffer renderer will first defer the display list |
| 230 | // for each layer and wait until the first drawing command |
| 231 | // to start the frame |
| 232 | if (mSnapshot->fbo == 0) { |
| 233 | syncState(); |
| 234 | updateLayers(); |
| 235 | } else { |
| 236 | return startFrame(); |
| 237 | } |
| 238 | |
| 239 | return DrawGlInfo::kStatusDone; |
Romain Guy | 7c25aab | 2012-10-18 15:05:02 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Romain Guy | dcfc836 | 2013-01-03 13:08:57 -0800 | [diff] [blame] | 242 | void OpenGLRenderer::discardFramebuffer(float left, float top, float right, float bottom) { |
| 243 | // If we know that we are going to redraw the entire framebuffer, |
| 244 | // perform a discard to let the driver know we don't need to preserve |
| 245 | // the back buffer for this frame. |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 246 | if (mExtensions.hasDiscardFramebuffer() && |
Romain Guy | dcfc836 | 2013-01-03 13:08:57 -0800 | [diff] [blame] | 247 | left <= 0.0f && top <= 0.0f && right >= mWidth && bottom >= mHeight) { |
Romain Guy | f158198 | 2013-01-31 17:20:30 -0800 | [diff] [blame] | 248 | const bool isFbo = getTargetFbo() == 0; |
| 249 | const GLenum attachments[] = { |
| 250 | isFbo ? (const GLenum) GL_COLOR_EXT : (const GLenum) GL_COLOR_ATTACHMENT0, |
| 251 | isFbo ? (const GLenum) GL_STENCIL_EXT : (const GLenum) GL_STENCIL_ATTACHMENT }; |
Romain Guy | dcfc836 | 2013-01-03 13:08:57 -0800 | [diff] [blame] | 252 | glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, attachments); |
| 253 | } |
| 254 | } |
| 255 | |
Romain Guy | 7c25aab | 2012-10-18 15:05:02 -0700 | [diff] [blame] | 256 | status_t OpenGLRenderer::clear(float left, float top, float right, float bottom, bool opaque) { |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 257 | if (!opaque) { |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 258 | mCaches.enableScissor(); |
Romain Guy | ddf7437 | 2012-05-22 14:07:07 -0700 | [diff] [blame] | 259 | mCaches.setScissor(left, mSnapshot->height - bottom, right - left, bottom - top); |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 260 | glClear(GL_COLOR_BUFFER_BIT); |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 261 | return DrawGlInfo::kStatusDrew; |
Romain Guy | ddf7437 | 2012-05-22 14:07:07 -0700 | [diff] [blame] | 262 | } |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 263 | |
Romain Guy | 7c25aab | 2012-10-18 15:05:02 -0700 | [diff] [blame] | 264 | mCaches.resetScissor(); |
Chet Haase | 44b2fe3 | 2012-06-06 19:03:58 -0700 | [diff] [blame] | 265 | return DrawGlInfo::kStatusDone; |
Romain Guy | ddf7437 | 2012-05-22 14:07:07 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void OpenGLRenderer::syncState() { |
Romain Guy | ddf7437 | 2012-05-22 14:07:07 -0700 | [diff] [blame] | 269 | if (mCaches.blend) { |
| 270 | glEnable(GL_BLEND); |
| 271 | } else { |
| 272 | glDisable(GL_BLEND); |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 273 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Romain Guy | 57b5268 | 2012-09-20 17:38:46 -0700 | [diff] [blame] | 276 | void OpenGLRenderer::startTiling(const sp<Snapshot>& s, bool opaque) { |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 277 | if (!mSuppressTiling) { |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 278 | Rect* clip = &mTilingClip; |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 279 | if (s->flags & Snapshot::kFlagFboTarget) { |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 280 | clip = &(s->layer->clipRect); |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 281 | } |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 282 | |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 283 | startTiling(*clip, s->height, opaque); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | void OpenGLRenderer::startTiling(const Rect& clip, int windowHeight, bool opaque) { |
| 288 | if (!mSuppressTiling) { |
| 289 | mCaches.startTiling(clip.left, windowHeight - clip.bottom, |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 290 | clip.right - clip.left, clip.bottom - clip.top, opaque); |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 291 | } |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void OpenGLRenderer::endTiling() { |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 295 | if (!mSuppressTiling) mCaches.endTiling(); |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 298 | void OpenGLRenderer::finish() { |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 299 | renderOverdraw(); |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 300 | endTiling(); |
| 301 | |
Romain Guy | ca89e2a | 2013-03-08 17:44:20 -0800 | [diff] [blame] | 302 | // When finish() is invoked on FBO 0 we've reached the end |
| 303 | // of the current frame |
| 304 | if (getTargetFbo() == 0) { |
| 305 | mCaches.pathCache.trim(); |
| 306 | } |
| 307 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 308 | if (!suppressErrorChecks()) { |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 309 | #if DEBUG_OPENGL |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 310 | GLenum status = GL_NO_ERROR; |
| 311 | while ((status = glGetError()) != GL_NO_ERROR) { |
| 312 | ALOGD("GL error from OpenGLRenderer: 0x%x", status); |
| 313 | switch (status) { |
| 314 | case GL_INVALID_ENUM: |
| 315 | ALOGE(" GL_INVALID_ENUM"); |
| 316 | break; |
| 317 | case GL_INVALID_VALUE: |
| 318 | ALOGE(" GL_INVALID_VALUE"); |
| 319 | break; |
| 320 | case GL_INVALID_OPERATION: |
| 321 | ALOGE(" GL_INVALID_OPERATION"); |
| 322 | break; |
| 323 | case GL_OUT_OF_MEMORY: |
| 324 | ALOGE(" Out of memory!"); |
| 325 | break; |
| 326 | } |
Romain Guy | a07105b | 2011-01-10 21:14:18 -0800 | [diff] [blame] | 327 | } |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 328 | #endif |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 329 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 330 | #if DEBUG_MEMORY_USAGE |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 331 | mCaches.dumpMemoryUsage(); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 332 | #else |
| 333 | if (mCaches.getDebugLevel() & kDebugMemory) { |
| 334 | mCaches.dumpMemoryUsage(); |
| 335 | } |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 336 | #endif |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 337 | } |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 338 | |
| 339 | mFrameStarted = false; |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 342 | void OpenGLRenderer::interrupt() { |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 343 | if (mCaches.currentProgram) { |
| 344 | if (mCaches.currentProgram->isInUse()) { |
| 345 | mCaches.currentProgram->remove(); |
| 346 | mCaches.currentProgram = NULL; |
| 347 | } |
| 348 | } |
Romain Guy | 50c0f09 | 2010-10-19 11:42:22 -0700 | [diff] [blame] | 349 | mCaches.unbindMeshBuffer(); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 350 | mCaches.unbindIndicesBuffer(); |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 351 | mCaches.resetVertexPointers(); |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 352 | mCaches.disableTexCoordsVertexArray(); |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 353 | debugOverdraw(false, false); |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 356 | void OpenGLRenderer::resume() { |
Chet Haase | 08837c2 | 2011-11-28 11:53:21 -0800 | [diff] [blame] | 357 | sp<Snapshot> snapshot = (mSnapshot != NULL) ? mSnapshot : mFirstSnapshot; |
Chet Haase | 08837c2 | 2011-11-28 11:53:21 -0800 | [diff] [blame] | 358 | glViewport(0, 0, snapshot->viewport.getWidth(), snapshot->viewport.getHeight()); |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 359 | glBindFramebuffer(GL_FRAMEBUFFER, snapshot->fbo); |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 360 | debugOverdraw(true, false); |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 361 | |
Romain Guy | 3e263fa | 2011-12-12 16:47:48 -0800 | [diff] [blame] | 362 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 363 | |
Chet Haase | 8025061 | 2012-08-15 13:46:54 -0700 | [diff] [blame] | 364 | mCaches.scissorEnabled = glIsEnabled(GL_SCISSOR_TEST); |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 365 | mCaches.enableScissor(); |
Romain Guy | 82bc7a7 | 2012-01-03 14:13:39 -0800 | [diff] [blame] | 366 | mCaches.resetScissor(); |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 367 | dirtyClip(); |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 368 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 369 | mCaches.activeTexture(0); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 370 | |
Romain Guy | 50c0f09 | 2010-10-19 11:42:22 -0700 | [diff] [blame] | 371 | mCaches.blend = true; |
| 372 | glEnable(GL_BLEND); |
| 373 | glBlendFunc(mCaches.lastSrcMode, mCaches.lastDstMode); |
| 374 | glBlendEquation(GL_FUNC_ADD); |
Romain Guy | da8532c | 2010-08-31 11:50:35 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 377 | void OpenGLRenderer::resumeAfterLayer() { |
| 378 | sp<Snapshot> snapshot = (mSnapshot != NULL) ? mSnapshot : mFirstSnapshot; |
| 379 | glViewport(0, 0, snapshot->viewport.getWidth(), snapshot->viewport.getHeight()); |
| 380 | glBindFramebuffer(GL_FRAMEBUFFER, snapshot->fbo); |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 381 | debugOverdraw(true, false); |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 382 | |
| 383 | mCaches.resetScissor(); |
| 384 | dirtyClip(); |
| 385 | } |
| 386 | |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 387 | void OpenGLRenderer::detachFunctor(Functor* functor) { |
Chris Craik | 932b7f6 | 2012-06-06 13:59:33 -0700 | [diff] [blame] | 388 | mFunctors.remove(functor); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void OpenGLRenderer::attachFunctor(Functor* functor) { |
| 392 | mFunctors.add(functor); |
| 393 | } |
| 394 | |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 395 | status_t OpenGLRenderer::invokeFunctors(Rect& dirty) { |
| 396 | status_t result = DrawGlInfo::kStatusDone; |
Romain Guy | 3d745c0 | 2012-04-23 20:36:17 -0700 | [diff] [blame] | 397 | size_t count = mFunctors.size(); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 398 | |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 399 | if (count > 0) { |
Chris Craik | d15321b | 2012-11-28 14:45:04 -0800 | [diff] [blame] | 400 | interrupt(); |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 401 | SortedVector<Functor*> functors(mFunctors); |
| 402 | mFunctors.clear(); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 403 | |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 404 | DrawGlInfo info; |
| 405 | info.clipLeft = 0; |
| 406 | info.clipTop = 0; |
| 407 | info.clipRight = 0; |
| 408 | info.clipBottom = 0; |
| 409 | info.isLayer = false; |
| 410 | info.width = 0; |
| 411 | info.height = 0; |
| 412 | memset(info.transform, 0, sizeof(float) * 16); |
| 413 | |
| 414 | for (size_t i = 0; i < count; i++) { |
| 415 | Functor* f = functors.itemAt(i); |
| 416 | result |= (*f)(DrawGlInfo::kModeProcess, &info); |
| 417 | |
Chris Craik | c2c9543 | 2012-04-25 15:13:52 -0700 | [diff] [blame] | 418 | if (result & DrawGlInfo::kStatusDraw) { |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 419 | Rect localDirty(info.dirtyLeft, info.dirtyTop, info.dirtyRight, info.dirtyBottom); |
| 420 | dirty.unionWith(localDirty); |
Chris Craik | c2c9543 | 2012-04-25 15:13:52 -0700 | [diff] [blame] | 421 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 422 | |
Chris Craik | c2c9543 | 2012-04-25 15:13:52 -0700 | [diff] [blame] | 423 | if (result & DrawGlInfo::kStatusInvoke) { |
| 424 | mFunctors.add(f); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
Chris Craik | d15321b | 2012-11-28 14:45:04 -0800 | [diff] [blame] | 427 | resume(); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | return result; |
| 431 | } |
| 432 | |
| 433 | status_t OpenGLRenderer::callDrawGLFunction(Functor* functor, Rect& dirty) { |
Chris Craik | 408eb12 | 2013-03-26 18:55:15 -0700 | [diff] [blame] | 434 | if (mSnapshot->isIgnored()) return DrawGlInfo::kStatusDone; |
| 435 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 436 | interrupt(); |
Chris Craik | 932b7f6 | 2012-06-06 13:59:33 -0700 | [diff] [blame] | 437 | detachFunctor(functor); |
Chris Craik | c8538ade | 2012-05-22 11:54:06 -0700 | [diff] [blame] | 438 | |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 439 | mCaches.enableScissor(); |
Romain Guy | f90f817 | 2011-01-25 22:53:24 -0800 | [diff] [blame] | 440 | if (mDirtyClip) { |
| 441 | setScissorFromClip(); |
| 442 | } |
Romain Guy | d643bb5 | 2011-03-01 14:55:21 -0800 | [diff] [blame] | 443 | |
Romain Guy | 80911b8 | 2011-03-16 15:30:12 -0700 | [diff] [blame] | 444 | Rect clip(*mSnapshot->clipRect); |
| 445 | clip.snapToPixelBoundaries(); |
| 446 | |
Romain Guy | d643bb5 | 2011-03-01 14:55:21 -0800 | [diff] [blame] | 447 | // Since we don't know what the functor will draw, let's dirty |
| 448 | // tne entire clip region |
| 449 | if (hasLayer()) { |
Romain Guy | d643bb5 | 2011-03-01 14:55:21 -0800 | [diff] [blame] | 450 | dirtyLayerUnchecked(clip, getRegion()); |
| 451 | } |
Romain Guy | d643bb5 | 2011-03-01 14:55:21 -0800 | [diff] [blame] | 452 | |
Romain Guy | 08aa2cb | 2011-03-17 11:06:57 -0700 | [diff] [blame] | 453 | DrawGlInfo info; |
| 454 | info.clipLeft = clip.left; |
| 455 | info.clipTop = clip.top; |
| 456 | info.clipRight = clip.right; |
| 457 | info.clipBottom = clip.bottom; |
| 458 | info.isLayer = hasLayer(); |
Chet Haase | 7b6a758 | 2012-04-11 14:32:02 -0700 | [diff] [blame] | 459 | info.width = getSnapshot()->viewport.getWidth(); |
| 460 | info.height = getSnapshot()->height; |
Romain Guy | 08aa2cb | 2011-03-17 11:06:57 -0700 | [diff] [blame] | 461 | getSnapshot()->transform->copyTo(&info.transform[0]); |
Romain Guy | 80911b8 | 2011-03-16 15:30:12 -0700 | [diff] [blame] | 462 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 463 | status_t result = (*functor)(DrawGlInfo::kModeDraw, &info) | DrawGlInfo::kStatusDrew; |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 464 | |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 465 | if (result != DrawGlInfo::kStatusDone) { |
Romain Guy | 08aa2cb | 2011-03-17 11:06:57 -0700 | [diff] [blame] | 466 | Rect localDirty(info.dirtyLeft, info.dirtyTop, info.dirtyRight, info.dirtyBottom); |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 467 | dirty.unionWith(localDirty); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 468 | |
Chris Craik | 65924a3 | 2012-04-05 17:52:11 -0700 | [diff] [blame] | 469 | if (result & DrawGlInfo::kStatusInvoke) { |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 470 | mFunctors.add(functor); |
Romain Guy | 8f3b8e3 | 2012-03-27 16:33:45 -0700 | [diff] [blame] | 471 | } |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 474 | resume(); |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 475 | return result; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 478 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 479 | // Debug |
| 480 | /////////////////////////////////////////////////////////////////////////////// |
| 481 | |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 482 | void OpenGLRenderer::eventMark(const char* name) const { |
| 483 | mCaches.eventMark(0, name); |
| 484 | } |
| 485 | |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 486 | void OpenGLRenderer::startMark(const char* name) const { |
| 487 | mCaches.startMark(0, name); |
| 488 | } |
| 489 | |
| 490 | void OpenGLRenderer::endMark() const { |
| 491 | mCaches.endMark(); |
| 492 | } |
| 493 | |
| 494 | void OpenGLRenderer::debugOverdraw(bool enable, bool clear) { |
| 495 | if (mCaches.debugOverdraw && getTargetFbo() == 0) { |
| 496 | if (clear) { |
| 497 | mCaches.disableScissor(); |
| 498 | mCaches.stencil.clear(); |
| 499 | } |
| 500 | if (enable) { |
| 501 | mCaches.stencil.enableDebugWrite(); |
| 502 | } else { |
| 503 | mCaches.stencil.disable(); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | void OpenGLRenderer::renderOverdraw() { |
| 509 | if (mCaches.debugOverdraw && getTargetFbo() == 0) { |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 510 | const Rect* clip = &mTilingClip; |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 511 | |
| 512 | mCaches.enableScissor(); |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 513 | mCaches.setScissor(clip->left, mFirstSnapshot->height - clip->bottom, |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 514 | clip->right - clip->left, clip->bottom - clip->top); |
| 515 | |
| 516 | mCaches.stencil.enableDebugTest(2); |
| 517 | drawColor(0x2f0000ff, SkXfermode::kSrcOver_Mode); |
| 518 | mCaches.stencil.enableDebugTest(3); |
| 519 | drawColor(0x2f00ff00, SkXfermode::kSrcOver_Mode); |
| 520 | mCaches.stencil.enableDebugTest(4); |
| 521 | drawColor(0x3fff0000, SkXfermode::kSrcOver_Mode); |
| 522 | mCaches.stencil.enableDebugTest(4, true); |
| 523 | drawColor(0x7fff0000, SkXfermode::kSrcOver_Mode); |
| 524 | mCaches.stencil.disable(); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 529 | // Layers |
| 530 | /////////////////////////////////////////////////////////////////////////////// |
| 531 | |
| 532 | bool OpenGLRenderer::updateLayer(Layer* layer, bool inFrame) { |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 533 | if (layer->deferredUpdateScheduled && layer->renderer && |
| 534 | layer->displayList && layer->displayList->isRenderable()) { |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 535 | Rect& dirty = layer->dirtyRect; |
| 536 | |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 537 | if (inFrame) { |
| 538 | endTiling(); |
| 539 | debugOverdraw(false, false); |
| 540 | } |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 541 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 542 | if (CC_UNLIKELY(inFrame || mCaches.drawDeferDisabled)) { |
| 543 | OpenGLRenderer* renderer = layer->renderer; |
| 544 | renderer->setViewport(layer->layer.getWidth(), layer->layer.getHeight()); |
| 545 | renderer->prepareDirty(dirty.left, dirty.top, dirty.right, dirty.bottom, |
| 546 | !layer->isBlend()); |
| 547 | renderer->drawDisplayList(layer->displayList, dirty, |
| 548 | DisplayList::kReplayFlag_ClipChildren); |
| 549 | renderer->finish(); |
| 550 | } else { |
| 551 | layer->defer(); |
| 552 | } |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 553 | |
| 554 | if (inFrame) { |
| 555 | resumeAfterLayer(); |
| 556 | startTiling(mSnapshot); |
| 557 | } |
| 558 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 559 | if (CC_UNLIKELY(inFrame || mCaches.drawDeferDisabled)) { |
| 560 | dirty.setEmpty(); |
| 561 | layer->renderer = NULL; |
| 562 | } |
| 563 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 564 | layer->deferredUpdateScheduled = false; |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 565 | layer->displayList = NULL; |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 566 | layer->debugDrawUpdate = mCaches.debugLayersUpdates; |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 567 | |
| 568 | return true; |
| 569 | } |
| 570 | |
| 571 | return false; |
| 572 | } |
| 573 | |
| 574 | void OpenGLRenderer::updateLayers() { |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 575 | // If draw deferring is enabled this method will simply defer |
| 576 | // the display list of each individual layer. The layers remain |
| 577 | // in the layer updates list which will be cleared by flushLayers(). |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 578 | int count = mLayerUpdates.size(); |
| 579 | if (count > 0) { |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 580 | if (CC_UNLIKELY(mCaches.drawDeferDisabled)) { |
| 581 | startMark("Layer Updates"); |
| 582 | } else { |
| 583 | startMark("Defer Layer Updates"); |
| 584 | } |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 585 | |
| 586 | // Note: it is very important to update the layers in reverse order |
| 587 | for (int i = count - 1; i >= 0; i--) { |
| 588 | Layer* layer = mLayerUpdates.itemAt(i); |
| 589 | updateLayer(layer, false); |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 590 | if (CC_UNLIKELY(mCaches.drawDeferDisabled)) { |
| 591 | mCaches.resourceCache.decrementRefcount(layer); |
| 592 | } |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 593 | } |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 594 | |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 595 | if (CC_UNLIKELY(mCaches.drawDeferDisabled)) { |
| 596 | mLayerUpdates.clear(); |
| 597 | glBindFramebuffer(GL_FRAMEBUFFER, getTargetFbo()); |
| 598 | } |
| 599 | endMark(); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | void OpenGLRenderer::flushLayers() { |
| 604 | int count = mLayerUpdates.size(); |
| 605 | if (count > 0) { |
| 606 | startMark("Apply Layer Updates"); |
| 607 | char layerName[12]; |
| 608 | |
| 609 | // Note: it is very important to update the layers in reverse order |
| 610 | for (int i = count - 1; i >= 0; i--) { |
| 611 | sprintf(layerName, "Layer #%d", i); |
| 612 | startMark(layerName); { |
| 613 | Layer* layer = mLayerUpdates.itemAt(i); |
| 614 | layer->flush(); |
| 615 | mCaches.resourceCache.decrementRefcount(layer); |
| 616 | } |
| 617 | endMark(); |
| 618 | } |
| 619 | |
| 620 | mLayerUpdates.clear(); |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 621 | glBindFramebuffer(GL_FRAMEBUFFER, getTargetFbo()); |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 622 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 623 | endMark(); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | void OpenGLRenderer::pushLayerUpdate(Layer* layer) { |
| 628 | if (layer) { |
| 629 | mLayerUpdates.push_back(layer); |
| 630 | mCaches.resourceCache.incrementRefcount(layer); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | void OpenGLRenderer::clearLayerUpdates() { |
| 635 | size_t count = mLayerUpdates.size(); |
| 636 | if (count > 0) { |
| 637 | mCaches.resourceCache.lock(); |
| 638 | for (size_t i = 0; i < count; i++) { |
| 639 | mCaches.resourceCache.decrementRefcountLocked(mLayerUpdates.itemAt(i)); |
| 640 | } |
| 641 | mCaches.resourceCache.unlock(); |
| 642 | mLayerUpdates.clear(); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 647 | // State management |
| 648 | /////////////////////////////////////////////////////////////////////////////// |
| 649 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 650 | int OpenGLRenderer::getSaveCount() const { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 651 | return mSaveCount; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | int OpenGLRenderer::save(int flags) { |
Romain Guy | 8aef54f | 2010-09-01 15:13:49 -0700 | [diff] [blame] | 655 | return saveSnapshot(flags); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void OpenGLRenderer::restore() { |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 659 | if (mSaveCount > 1) { |
| 660 | restoreSnapshot(); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 661 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | void OpenGLRenderer::restoreToCount(int saveCount) { |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 665 | if (saveCount < 1) saveCount = 1; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 666 | |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 667 | while (mSaveCount > saveCount) { |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 668 | restoreSnapshot(); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 669 | } |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Romain Guy | 8aef54f | 2010-09-01 15:13:49 -0700 | [diff] [blame] | 672 | int OpenGLRenderer::saveSnapshot(int flags) { |
| 673 | mSnapshot = new Snapshot(mSnapshot, flags); |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 674 | return mSaveCount++; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | bool OpenGLRenderer::restoreSnapshot() { |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 678 | bool restoreClip = mSnapshot->flags & Snapshot::kFlagClipSet; |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 679 | bool restoreLayer = mSnapshot->flags & Snapshot::kFlagIsLayer; |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 680 | bool restoreOrtho = mSnapshot->flags & Snapshot::kFlagDirtyOrtho; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 681 | |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 682 | sp<Snapshot> current = mSnapshot; |
| 683 | sp<Snapshot> previous = mSnapshot->previous; |
| 684 | |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 685 | if (restoreOrtho) { |
| 686 | Rect& r = previous->viewport; |
| 687 | glViewport(r.left, r.top, r.right, r.bottom); |
| 688 | mOrthoMatrix.load(current->orthoMatrix); |
| 689 | } |
| 690 | |
Romain Guy | 8b55f37 | 2010-08-18 17:10:07 -0700 | [diff] [blame] | 691 | mSaveCount--; |
| 692 | mSnapshot = previous; |
| 693 | |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 694 | if (restoreClip) { |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 695 | dirtyClip(); |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 696 | } |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 697 | |
Romain Guy | 5ec9924 | 2010-11-03 16:19:08 -0700 | [diff] [blame] | 698 | if (restoreLayer) { |
| 699 | composeLayer(current, previous); |
| 700 | } |
| 701 | |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 702 | return restoreClip; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 705 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 706 | // Layers |
| 707 | /////////////////////////////////////////////////////////////////////////////// |
| 708 | |
| 709 | int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom, |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 710 | int alpha, SkXfermode::Mode mode, int flags) { |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 711 | const GLuint previousFbo = mSnapshot->fbo; |
| 712 | const int count = saveSnapshot(flags); |
Romain Guy | d55a861 | 2010-06-28 17:42:46 -0700 | [diff] [blame] | 713 | |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 714 | if (!mSnapshot->isIgnored()) { |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 715 | createLayer(left, top, right, bottom, alpha, mode, flags, previousFbo); |
Romain Guy | dbc26d2 | 2010-10-11 17:58:29 -0700 | [diff] [blame] | 716 | } |
Romain Guy | d55a861 | 2010-06-28 17:42:46 -0700 | [diff] [blame] | 717 | |
| 718 | return count; |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 721 | void OpenGLRenderer::calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer) { |
| 722 | const Rect untransformedBounds(bounds); |
| 723 | |
| 724 | currentTransform().mapRect(bounds); |
| 725 | |
| 726 | // Layers only make sense if they are in the framebuffer's bounds |
| 727 | if (bounds.intersect(*mSnapshot->clipRect)) { |
| 728 | // We cannot work with sub-pixels in this case |
| 729 | bounds.snapToPixelBoundaries(); |
| 730 | |
| 731 | // When the layer is not an FBO, we may use glCopyTexImage so we |
| 732 | // need to make sure the layer does not extend outside the bounds |
| 733 | // of the framebuffer |
| 734 | if (!bounds.intersect(mSnapshot->previous->viewport)) { |
| 735 | bounds.setEmpty(); |
| 736 | } else if (fboLayer) { |
| 737 | clip.set(bounds); |
| 738 | mat4 inverse; |
| 739 | inverse.loadInverse(currentTransform()); |
| 740 | inverse.mapRect(clip); |
| 741 | clip.snapToPixelBoundaries(); |
| 742 | if (clip.intersect(untransformedBounds)) { |
| 743 | clip.translate(-untransformedBounds.left, -untransformedBounds.top); |
| 744 | bounds.set(untransformedBounds); |
| 745 | } else { |
| 746 | clip.setEmpty(); |
| 747 | } |
| 748 | } |
| 749 | } else { |
| 750 | bounds.setEmpty(); |
| 751 | } |
| 752 | } |
| 753 | |
Chris Craik | 408eb12 | 2013-03-26 18:55:15 -0700 | [diff] [blame] | 754 | void OpenGLRenderer::updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip, |
| 755 | bool fboLayer, int alpha) { |
| 756 | if (bounds.isEmpty() || bounds.getWidth() > mCaches.maxTextureSize || |
| 757 | bounds.getHeight() > mCaches.maxTextureSize || |
| 758 | (fboLayer && clip.isEmpty())) { |
| 759 | mSnapshot->empty = fboLayer; |
| 760 | } else { |
| 761 | mSnapshot->invisible = mSnapshot->invisible || (alpha <= ALPHA_THRESHOLD && fboLayer); |
| 762 | } |
| 763 | } |
| 764 | |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 765 | int OpenGLRenderer::saveLayerDeferred(float left, float top, float right, float bottom, |
| 766 | int alpha, SkXfermode::Mode mode, int flags) { |
| 767 | const GLuint previousFbo = mSnapshot->fbo; |
| 768 | const int count = saveSnapshot(flags); |
| 769 | |
| 770 | if (!mSnapshot->isIgnored() && (flags & SkCanvas::kClipToLayer_SaveFlag)) { |
| 771 | // initialize the snapshot as though it almost represents an FBO layer so deferred draw |
| 772 | // operations will be able to store and restore the current clip and transform info, and |
| 773 | // quick rejection will be correct (for display lists) |
| 774 | |
| 775 | Rect bounds(left, top, right, bottom); |
| 776 | Rect clip; |
| 777 | calculateLayerBoundsAndClip(bounds, clip, true); |
Chris Craik | 408eb12 | 2013-03-26 18:55:15 -0700 | [diff] [blame] | 778 | updateSnapshotIgnoreForLayer(bounds, clip, true, alpha); |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 779 | |
Chris Craik | 408eb12 | 2013-03-26 18:55:15 -0700 | [diff] [blame] | 780 | if (!mSnapshot->isIgnored()) { |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 781 | mSnapshot->resetTransform(-bounds.left, -bounds.top, 0.0f); |
| 782 | mSnapshot->resetClip(clip.left, clip.top, clip.right, clip.bottom); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | return count; |
| 787 | } |
| 788 | |
| 789 | |
Romain Guy | 1c740bc | 2010-09-13 18:00:09 -0700 | [diff] [blame] | 790 | /** |
| 791 | * Layers are viewed by Skia are slightly different than layers in image editing |
| 792 | * programs (for instance.) When a layer is created, previously created layers |
| 793 | * and the frame buffer still receive every drawing command. For instance, if a |
| 794 | * layer is created and a shape intersecting the bounds of the layers and the |
| 795 | * framebuffer is draw, the shape will be drawn on both (unless the layer was |
| 796 | * created with the SkCanvas::kClipToLayer_SaveFlag flag.) |
| 797 | * |
| 798 | * A way to implement layers is to create an FBO for each layer, backed by an RGBA |
| 799 | * texture. Unfortunately, this is inefficient as it requires every primitive to |
| 800 | * be drawn n + 1 times, where n is the number of active layers. In practice this |
| 801 | * means, for every primitive: |
| 802 | * - Switch active frame buffer |
| 803 | * - Change viewport, clip and projection matrix |
| 804 | * - Issue the drawing |
| 805 | * |
| 806 | * Switching rendering target n + 1 times per drawn primitive is extremely costly. |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 807 | * To avoid this, layers are implemented in a different way here, at least in the |
| 808 | * general case. FBOs are used, as an optimization, when the "clip to layer" flag |
| 809 | * is set. When this flag is set we can redirect all drawing operations into a |
| 810 | * single FBO. |
Romain Guy | 1c740bc | 2010-09-13 18:00:09 -0700 | [diff] [blame] | 811 | * |
| 812 | * This implementation relies on the frame buffer being at least RGBA 8888. When |
| 813 | * a layer is created, only a texture is created, not an FBO. The content of the |
| 814 | * frame buffer contained within the layer's bounds is copied into this texture |
Romain Guy | 87a7657 | 2010-09-13 18:11:21 -0700 | [diff] [blame] | 815 | * using glCopyTexImage2D(). The layer's region is then cleared(1) in the frame |
Romain Guy | 1c740bc | 2010-09-13 18:00:09 -0700 | [diff] [blame] | 816 | * buffer and drawing continues as normal. This technique therefore treats the |
| 817 | * frame buffer as a scratch buffer for the layers. |
| 818 | * |
| 819 | * To compose the layers back onto the frame buffer, each layer texture |
| 820 | * (containing the original frame buffer data) is drawn as a simple quad over |
| 821 | * the frame buffer. The trick is that the quad is set as the composition |
| 822 | * destination in the blending equation, and the frame buffer becomes the source |
| 823 | * of the composition. |
| 824 | * |
| 825 | * Drawing layers with an alpha value requires an extra step before composition. |
| 826 | * An empty quad is drawn over the layer's region in the frame buffer. This quad |
| 827 | * is drawn with the rgba color (0,0,0,alpha). The alpha value offered by the |
| 828 | * quad is used to multiply the colors in the frame buffer. This is achieved by |
| 829 | * changing the GL blend functions for the GL_FUNC_ADD blend equation to |
| 830 | * GL_ZERO, GL_SRC_ALPHA. |
| 831 | * |
| 832 | * Because glCopyTexImage2D() can be slow, an alternative implementation might |
| 833 | * be use to draw a single clipped layer. The implementation described above |
| 834 | * is correct in every case. |
Romain Guy | 87a7657 | 2010-09-13 18:11:21 -0700 | [diff] [blame] | 835 | * |
| 836 | * (1) The frame buffer is actually not cleared right away. To allow the GPU |
| 837 | * to potentially optimize series of calls to glCopyTexImage2D, the frame |
| 838 | * buffer is left untouched until the first drawing operation. Only when |
| 839 | * something actually gets drawn are the layers regions cleared. |
Romain Guy | 1c740bc | 2010-09-13 18:00:09 -0700 | [diff] [blame] | 840 | */ |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 841 | bool OpenGLRenderer::createLayer(float left, float top, float right, float bottom, |
| 842 | int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo) { |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 843 | LAYER_LOGD("Requesting layer %.2fx%.2f", right - left, bottom - top); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 844 | LAYER_LOGD("Layer cache size = %d", mCaches.layerCache.getSize()); |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 845 | |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 846 | const bool fboLayer = flags & SkCanvas::kClipToLayer_SaveFlag; |
| 847 | |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 848 | // Window coordinates of the layer |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 849 | Rect clip; |
Romain Guy | 8aef54f | 2010-09-01 15:13:49 -0700 | [diff] [blame] | 850 | Rect bounds(left, top, right, bottom); |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 851 | calculateLayerBoundsAndClip(bounds, clip, fboLayer); |
Chris Craik | 408eb12 | 2013-03-26 18:55:15 -0700 | [diff] [blame] | 852 | updateSnapshotIgnoreForLayer(bounds, clip, fboLayer, alpha); |
Romain Guy | dbc26d2 | 2010-10-11 17:58:29 -0700 | [diff] [blame] | 853 | |
| 854 | // Bail out if we won't draw in this snapshot |
Chris Craik | 408eb12 | 2013-03-26 18:55:15 -0700 | [diff] [blame] | 855 | if (mSnapshot->isIgnored()) { |
Romain Guy | b025b9c | 2010-09-16 14:16:48 -0700 | [diff] [blame] | 856 | return false; |
| 857 | } |
Romain Guy | f18fd99 | 2010-07-08 11:45:51 -0700 | [diff] [blame] | 858 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 859 | mCaches.activeTexture(0); |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 860 | Layer* layer = mCaches.layerCache.get(bounds.getWidth(), bounds.getHeight()); |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 861 | if (!layer) { |
Romain Guy | f18fd99 | 2010-07-08 11:45:51 -0700 | [diff] [blame] | 862 | return false; |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 865 | layer->setAlpha(alpha, mode); |
Romain Guy | 8aef54f | 2010-09-01 15:13:49 -0700 | [diff] [blame] | 866 | layer->layer.set(bounds); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 867 | layer->texCoords.set(0.0f, bounds.getHeight() / float(layer->getHeight()), |
| 868 | bounds.getWidth() / float(layer->getWidth()), 0.0f); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 869 | layer->setColorFilter(mDrawModifiers.mColorFilter); |
Chet Haase | a23eed8 | 2012-04-12 15:19:04 -0700 | [diff] [blame] | 870 | layer->setBlend(true); |
Romain Guy | 7c25aab | 2012-10-18 15:05:02 -0700 | [diff] [blame] | 871 | layer->setDirty(false); |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 872 | |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 873 | // Save the layer in the snapshot |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 874 | mSnapshot->flags |= Snapshot::kFlagIsLayer; |
| 875 | mSnapshot->layer = layer; |
Romain Guy | 1d83e19 | 2010-08-17 11:37:00 -0700 | [diff] [blame] | 876 | |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 877 | if (fboLayer) { |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 878 | return createFboLayer(layer, bounds, clip, previousFbo); |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 879 | } else { |
| 880 | // Copy the framebuffer into the layer |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 881 | layer->bindTexture(); |
Romain Guy | 514fb18 | 2011-01-19 14:38:29 -0800 | [diff] [blame] | 882 | if (!bounds.isEmpty()) { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 883 | if (layer->isEmpty()) { |
| 884 | glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 885 | bounds.left, mSnapshot->height - bounds.bottom, |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 886 | layer->getWidth(), layer->getHeight(), 0); |
| 887 | layer->setEmpty(false); |
Romain Guy | 514fb18 | 2011-01-19 14:38:29 -0800 | [diff] [blame] | 888 | } else { |
| 889 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bounds.left, |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 890 | mSnapshot->height - bounds.bottom, bounds.getWidth(), bounds.getHeight()); |
Romain Guy | 514fb18 | 2011-01-19 14:38:29 -0800 | [diff] [blame] | 891 | } |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 892 | |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 893 | // Enqueue the buffer coordinates to clear the corresponding region later |
| 894 | mLayers.push(new Rect(bounds)); |
Romain Guy | ae88e5e | 2010-10-22 17:49:18 -0700 | [diff] [blame] | 895 | } |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 896 | } |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 897 | |
Romain Guy | d55a861 | 2010-06-28 17:42:46 -0700 | [diff] [blame] | 898 | return true; |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 901 | bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, Rect& clip, GLuint previousFbo) { |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 902 | layer->clipRect.set(clip); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 903 | layer->setFbo(mCaches.fboCache.get()); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 904 | |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 905 | mSnapshot->region = &mSnapshot->layer->region; |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 906 | mSnapshot->flags |= Snapshot::kFlagFboTarget | Snapshot::kFlagIsFboLayer | |
| 907 | Snapshot::kFlagDirtyOrtho; |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 908 | mSnapshot->fbo = layer->getFbo(); |
| 909 | mSnapshot->resetTransform(-bounds.left, -bounds.top, 0.0f); |
| 910 | mSnapshot->resetClip(clip.left, clip.top, clip.right, clip.bottom); |
| 911 | mSnapshot->viewport.set(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight()); |
| 912 | mSnapshot->height = bounds.getHeight(); |
Chet Haase | d48885a | 2012-08-28 17:43:28 -0700 | [diff] [blame] | 913 | mSnapshot->orthoMatrix.load(mOrthoMatrix); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 914 | |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 915 | endTiling(); |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 916 | debugOverdraw(false, false); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 917 | // Bind texture to FBO |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 918 | glBindFramebuffer(GL_FRAMEBUFFER, layer->getFbo()); |
| 919 | layer->bindTexture(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 920 | |
| 921 | // Initialize the texture if needed |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 922 | if (layer->isEmpty()) { |
| 923 | layer->allocateTexture(GL_RGBA, GL_UNSIGNED_BYTE); |
| 924 | layer->setEmpty(false); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 928 | layer->getTexture(), 0); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 929 | |
Romain Guy | f735c8e | 2013-01-31 17:45:55 -0800 | [diff] [blame] | 930 | startTiling(mSnapshot, true); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 931 | |
| 932 | // Clear the FBO, expand the clear region by 1 to get nice bilinear filtering |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 933 | mCaches.enableScissor(); |
Romain Guy | 8f85e80 | 2011-12-14 19:23:32 -0800 | [diff] [blame] | 934 | mCaches.setScissor(clip.left - 1.0f, bounds.getHeight() - clip.bottom - 1.0f, |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 935 | clip.getWidth() + 2.0f, clip.getHeight() + 2.0f); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 936 | glClear(GL_COLOR_BUFFER_BIT); |
| 937 | |
| 938 | dirtyClip(); |
| 939 | |
| 940 | // Change the ortho projection |
| 941 | glViewport(0, 0, bounds.getWidth(), bounds.getHeight()); |
| 942 | mOrthoMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f); |
| 943 | |
| 944 | return true; |
| 945 | } |
| 946 | |
Romain Guy | 1c740bc | 2010-09-13 18:00:09 -0700 | [diff] [blame] | 947 | /** |
| 948 | * Read the documentation of createLayer() before doing anything in this method. |
| 949 | */ |
Romain Guy | 1d83e19 | 2010-08-17 11:37:00 -0700 | [diff] [blame] | 950 | void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) { |
| 951 | if (!current->layer) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 952 | ALOGE("Attempting to compose a layer that does not exist"); |
Romain Guy | 1d83e19 | 2010-08-17 11:37:00 -0700 | [diff] [blame] | 953 | return; |
| 954 | } |
| 955 | |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 956 | Layer* layer = current->layer; |
| 957 | const Rect& rect = layer->layer; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 958 | const bool fboLayer = current->flags & Snapshot::kFlagIsFboLayer; |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 959 | |
| 960 | if (fboLayer) { |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 961 | endTiling(); |
| 962 | |
Romain Guy | e0aa84b | 2012-04-03 19:30:26 -0700 | [diff] [blame] | 963 | // Detach the texture from the FBO |
| 964 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 965 | |
| 966 | layer->removeFbo(false); |
| 967 | |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 968 | // Unbind current FBO and restore previous one |
| 969 | glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo); |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 970 | debugOverdraw(true, false); |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 971 | |
| 972 | startTiling(previous); |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 975 | if (!fboLayer && layer->getAlpha() < 255) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 976 | drawColorRect(rect.left, rect.top, rect.right, rect.bottom, |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 977 | layer->getAlpha() << 24, SkXfermode::kDstIn_Mode, true); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 978 | // Required below, composeLayerRect() will divide by 255 |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 979 | layer->setAlpha(255); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 980 | } |
| 981 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 982 | mCaches.unbindMeshBuffer(); |
Romain Guy | 8b55f37 | 2010-08-18 17:10:07 -0700 | [diff] [blame] | 983 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 984 | mCaches.activeTexture(0); |
Romain Guy | 1d83e19 | 2010-08-17 11:37:00 -0700 | [diff] [blame] | 985 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 986 | // When the layer is stored in an FBO, we can save a bit of fillrate by |
| 987 | // drawing only the dirty region |
| 988 | if (fboLayer) { |
| 989 | dirtyLayer(rect.left, rect.top, rect.right, rect.bottom, *previous->transform); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 990 | if (layer->getColorFilter()) { |
| 991 | setupColorFilter(layer->getColorFilter()); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 992 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 993 | composeLayerRegion(layer, rect); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 994 | if (layer->getColorFilter()) { |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 995 | resetColorFilter(); |
| 996 | } |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 997 | } else if (!rect.isEmpty()) { |
| 998 | dirtyLayer(rect.left, rect.top, rect.right, rect.bottom); |
| 999 | composeLayerRect(layer, rect, true); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1000 | } |
Romain Guy | 8b55f37 | 2010-08-18 17:10:07 -0700 | [diff] [blame] | 1001 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 1002 | dirtyClip(); |
| 1003 | |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 1004 | // Failing to add the layer to the cache should happen only if the layer is too large |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 1005 | if (!mCaches.layerCache.put(layer)) { |
Romain Guy | 1d83e19 | 2010-08-17 11:37:00 -0700 | [diff] [blame] | 1006 | LAYER_LOGD("Deleting layer"); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 1007 | Caches::getInstance().resourceCache.decrementRefcount(layer); |
Romain Guy | 1d83e19 | 2010-08-17 11:37:00 -0700 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1011 | void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) { |
Chris Craik | e83569c | 2013-03-20 16:57:09 -0700 | [diff] [blame] | 1012 | float alpha = layer->getAlpha() / 255.0f * mSnapshot->alpha; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1013 | |
| 1014 | setupDraw(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1015 | if (layer->getRenderTarget() == GL_TEXTURE_2D) { |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1016 | setupDrawWithTexture(); |
| 1017 | } else { |
| 1018 | setupDrawWithExternalTexture(); |
| 1019 | } |
| 1020 | setupDrawTextureTransform(); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1021 | setupDrawColor(alpha, alpha, alpha, alpha); |
| 1022 | setupDrawColorFilter(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1023 | setupDrawBlending(layer->isBlend() || alpha < 1.0f, layer->getMode()); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1024 | setupDrawProgram(); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1025 | setupDrawPureColorUniforms(); |
| 1026 | setupDrawColorFilterUniforms(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1027 | if (layer->getRenderTarget() == GL_TEXTURE_2D) { |
| 1028 | setupDrawTexture(layer->getTexture()); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1029 | } else { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1030 | setupDrawExternalTexture(layer->getTexture()); |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1031 | } |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1032 | if (currentTransform().isPureTranslate() && |
Romain Guy | ec19b4a | 2011-07-07 21:05:04 -0700 | [diff] [blame] | 1033 | layer->getWidth() == (uint32_t) rect.getWidth() && |
| 1034 | layer->getHeight() == (uint32_t) rect.getHeight()) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1035 | const float x = (int) floorf(rect.left + currentTransform().getTranslateX() + 0.5f); |
| 1036 | const float y = (int) floorf(rect.top + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1037 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 1038 | layer->setFilter(GL_NEAREST); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1039 | setupDrawModelView(x, y, x + rect.getWidth(), y + rect.getHeight(), true); |
| 1040 | } else { |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 1041 | layer->setFilter(GL_LINEAR); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1042 | setupDrawModelView(rect.left, rect.top, rect.right, rect.bottom); |
| 1043 | } |
| 1044 | setupDrawTextureTransformUniforms(layer->getTexTransform()); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1045 | setupDrawMesh(&mMeshVertices[0].position[0], &mMeshVertices[0].texture[0]); |
| 1046 | |
| 1047 | glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); |
| 1048 | |
| 1049 | finishDrawTexture(); |
| 1050 | } |
| 1051 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1052 | void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap) { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1053 | if (!layer->isTextureLayer()) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1054 | const Rect& texCoords = layer->texCoords; |
| 1055 | resetDrawTextureTexCoords(texCoords.left, texCoords.top, |
| 1056 | texCoords.right, texCoords.bottom); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1057 | |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1058 | float x = rect.left; |
| 1059 | float y = rect.top; |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1060 | bool simpleTransform = currentTransform().isPureTranslate() && |
Romain Guy | ec19b4a | 2011-07-07 21:05:04 -0700 | [diff] [blame] | 1061 | layer->getWidth() == (uint32_t) rect.getWidth() && |
Romain Guy | b247915 | 2011-07-08 11:57:29 -0700 | [diff] [blame] | 1062 | layer->getHeight() == (uint32_t) rect.getHeight(); |
| 1063 | |
| 1064 | if (simpleTransform) { |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1065 | // When we're swapping, the layer is already in screen coordinates |
| 1066 | if (!swap) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1067 | x = (int) floorf(rect.left + currentTransform().getTranslateX() + 0.5f); |
| 1068 | y = (int) floorf(rect.top + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 1071 | layer->setFilter(GL_NEAREST, true); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1072 | } else { |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 1073 | layer->setFilter(GL_LINEAR, true); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
Chris Craik | e83569c | 2013-03-20 16:57:09 -0700 | [diff] [blame] | 1076 | float alpha = layer->getAlpha() / 255.0f * mSnapshot->alpha; |
| 1077 | bool blend = layer->isBlend() || alpha < 1.0f; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1078 | drawTextureMesh(x, y, x + rect.getWidth(), y + rect.getHeight(), |
Chris Craik | e83569c | 2013-03-20 16:57:09 -0700 | [diff] [blame] | 1079 | layer->getTexture(), alpha, layer->getMode(), blend, |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1080 | &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0], |
| 1081 | GL_TRIANGLE_STRIP, gMeshCount, swap, swap || simpleTransform); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1082 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1083 | resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); |
| 1084 | } else { |
| 1085 | resetDrawTextureTexCoords(0.0f, 1.0f, 1.0f, 0.0f); |
| 1086 | drawTextureLayer(layer, rect); |
| 1087 | resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); |
| 1088 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) { |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1092 | if (layer->region.isRect()) { |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 1093 | layer->setRegionAsRect(); |
| 1094 | |
Romain Guy | 4066767 | 2011-03-18 14:34:03 -0700 | [diff] [blame] | 1095 | composeLayerRect(layer, layer->regionRect); |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 1096 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1097 | layer->region.clear(); |
| 1098 | return; |
| 1099 | } |
| 1100 | |
Romain Guy | 8a3957d | 2011-09-07 17:55:15 -0700 | [diff] [blame] | 1101 | // TODO: See LayerRenderer.cpp::generateMesh() for important |
| 1102 | // information about this implementation |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 1103 | if (CC_LIKELY(!layer->region.isEmpty())) { |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1104 | size_t count; |
Chris Craik | 6c5b9be | 2013-02-27 14:03:19 -0800 | [diff] [blame] | 1105 | const android::Rect* rects; |
| 1106 | Region safeRegion; |
| 1107 | if (CC_LIKELY(hasRectToRectTransform())) { |
| 1108 | rects = layer->region.getArray(&count); |
| 1109 | } else { |
| 1110 | safeRegion = Region::createTJunctionFreeRegion(layer->region); |
| 1111 | rects = safeRegion.getArray(&count); |
| 1112 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1113 | |
Chris Craik | e83569c | 2013-03-20 16:57:09 -0700 | [diff] [blame] | 1114 | const float alpha = layer->getAlpha() / 255.0f * mSnapshot->alpha; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1115 | const float texX = 1.0f / float(layer->getWidth()); |
| 1116 | const float texY = 1.0f / float(layer->getHeight()); |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 1117 | const float height = rect.getHeight(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1118 | |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1119 | setupDraw(); |
| 1120 | |
| 1121 | // We must get (and therefore bind) the region mesh buffer |
| 1122 | // after we setup drawing in case we need to mess with the |
| 1123 | // stencil buffer in setupDraw() |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1124 | TextureVertex* mesh = mCaches.getRegionMesh(); |
| 1125 | GLsizei numQuads = 0; |
| 1126 | |
Romain Guy | 7230a74 | 2011-01-10 22:26:16 -0800 | [diff] [blame] | 1127 | setupDrawWithTexture(); |
| 1128 | setupDrawColor(alpha, alpha, alpha, alpha); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 1129 | setupDrawColorFilter(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1130 | setupDrawBlending(layer->isBlend() || alpha < 1.0f, layer->getMode(), false); |
Romain Guy | 7230a74 | 2011-01-10 22:26:16 -0800 | [diff] [blame] | 1131 | setupDrawProgram(); |
| 1132 | setupDrawDirtyRegionsDisabled(); |
| 1133 | setupDrawPureColorUniforms(); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 1134 | setupDrawColorFilterUniforms(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1135 | setupDrawTexture(layer->getTexture()); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1136 | if (currentTransform().isPureTranslate()) { |
| 1137 | const float x = (int) floorf(rect.left + currentTransform().getTranslateX() + 0.5f); |
| 1138 | const float y = (int) floorf(rect.top + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1139 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 1140 | layer->setFilter(GL_NEAREST); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1141 | setupDrawModelViewTranslate(x, y, x + rect.getWidth(), y + rect.getHeight(), true); |
| 1142 | } else { |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 1143 | layer->setFilter(GL_LINEAR); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 1144 | setupDrawModelViewTranslate(rect.left, rect.top, rect.right, rect.bottom); |
| 1145 | } |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1146 | setupDrawMeshIndices(&mesh[0].position[0], &mesh[0].texture[0]); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1147 | |
| 1148 | for (size_t i = 0; i < count; i++) { |
| 1149 | const android::Rect* r = &rects[i]; |
| 1150 | |
| 1151 | const float u1 = r->left * texX; |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 1152 | const float v1 = (height - r->top) * texY; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1153 | const float u2 = r->right * texX; |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 1154 | const float v2 = (height - r->bottom) * texY; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1155 | |
| 1156 | // TODO: Reject quads outside of the clip |
| 1157 | TextureVertex::set(mesh++, r->left, r->top, u1, v1); |
| 1158 | TextureVertex::set(mesh++, r->right, r->top, u2, v1); |
| 1159 | TextureVertex::set(mesh++, r->left, r->bottom, u1, v2); |
| 1160 | TextureVertex::set(mesh++, r->right, r->bottom, u2, v2); |
| 1161 | |
| 1162 | numQuads++; |
| 1163 | |
| 1164 | if (numQuads >= REGION_MESH_QUAD_COUNT) { |
| 1165 | glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL); |
| 1166 | numQuads = 0; |
| 1167 | mesh = mCaches.getRegionMesh(); |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | if (numQuads > 0) { |
| 1172 | glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL); |
| 1173 | } |
| 1174 | |
Romain Guy | 7230a74 | 2011-01-10 22:26:16 -0800 | [diff] [blame] | 1175 | finishDrawTexture(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1176 | |
| 1177 | #if DEBUG_LAYERS_AS_REGIONS |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 1178 | drawRegionRects(layer->region); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1179 | #endif |
| 1180 | |
| 1181 | layer->region.clear(); |
| 1182 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 1185 | void OpenGLRenderer::drawRegionRects(const Region& region) { |
| 1186 | #if DEBUG_LAYERS_AS_REGIONS |
| 1187 | size_t count; |
| 1188 | const android::Rect* rects = region.getArray(&count); |
| 1189 | |
| 1190 | uint32_t colors[] = { |
| 1191 | 0x7fff0000, 0x7f00ff00, |
| 1192 | 0x7f0000ff, 0x7fff00ff, |
| 1193 | }; |
| 1194 | |
| 1195 | int offset = 0; |
| 1196 | int32_t top = rects[0].top; |
| 1197 | |
| 1198 | for (size_t i = 0; i < count; i++) { |
| 1199 | if (top != rects[i].top) { |
| 1200 | offset ^= 0x2; |
| 1201 | top = rects[i].top; |
| 1202 | } |
| 1203 | |
| 1204 | Rect r(rects[i].left, rects[i].top, rects[i].right, rects[i].bottom); |
| 1205 | drawColorRect(r.left, r.top, r.right, r.bottom, colors[offset + (i & 0x1)], |
| 1206 | SkXfermode::kSrcOver_Mode); |
| 1207 | } |
| 1208 | #endif |
| 1209 | } |
| 1210 | |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1211 | void OpenGLRenderer::drawRegionRects(const SkRegion& region, int color, |
| 1212 | SkXfermode::Mode mode, bool dirty) { |
| 1213 | int count = 0; |
| 1214 | Vector<float> rects; |
| 1215 | |
| 1216 | SkRegion::Iterator it(region); |
| 1217 | while (!it.done()) { |
| 1218 | const SkIRect& r = it.rect(); |
| 1219 | rects.push(r.fLeft); |
| 1220 | rects.push(r.fTop); |
| 1221 | rects.push(r.fRight); |
| 1222 | rects.push(r.fBottom); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1223 | count += 4; |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1224 | it.next(); |
| 1225 | } |
| 1226 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 1227 | drawColorRects(rects.array(), count, color, mode, true, dirty, false); |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1230 | void OpenGLRenderer::dirtyLayer(const float left, const float top, |
| 1231 | const float right, const float bottom, const mat4 transform) { |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 1232 | if (hasLayer()) { |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1233 | Rect bounds(left, top, right, bottom); |
| 1234 | transform.mapRect(bounds); |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 1235 | dirtyLayerUnchecked(bounds, getRegion()); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1236 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | void OpenGLRenderer::dirtyLayer(const float left, const float top, |
| 1240 | const float right, const float bottom) { |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 1241 | if (hasLayer()) { |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1242 | Rect bounds(left, top, right, bottom); |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 1243 | dirtyLayerUnchecked(bounds, getRegion()); |
Romain Guy | 1bd1bad | 2011-01-14 20:07:20 -0800 | [diff] [blame] | 1244 | } |
Romain Guy | 1bd1bad | 2011-01-14 20:07:20 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | void OpenGLRenderer::dirtyLayerUnchecked(Rect& bounds, Region* region) { |
Romain Guy | 1bd1bad | 2011-01-14 20:07:20 -0800 | [diff] [blame] | 1248 | if (bounds.intersect(*mSnapshot->clipRect)) { |
| 1249 | bounds.snapToPixelBoundaries(); |
| 1250 | android::Rect dirty(bounds.left, bounds.top, bounds.right, bounds.bottom); |
| 1251 | if (!dirty.isEmpty()) { |
| 1252 | region->orSelf(dirty); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1253 | } |
| 1254 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1257 | void OpenGLRenderer::clearLayerRegions() { |
| 1258 | const size_t count = mLayers.size(); |
| 1259 | if (count == 0) return; |
| 1260 | |
| 1261 | if (!mSnapshot->isIgnored()) { |
| 1262 | // Doing several glScissor/glClear here can negatively impact |
| 1263 | // GPUs with a tiler architecture, instead we draw quads with |
| 1264 | // the Clear blending mode |
| 1265 | |
| 1266 | // The list contains bounds that have already been clipped |
| 1267 | // against their initial clip rect, and the current clip |
| 1268 | // is likely different so we need to disable clipping here |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 1269 | bool scissorChanged = mCaches.disableScissor(); |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1270 | |
| 1271 | Vertex mesh[count * 6]; |
| 1272 | Vertex* vertex = mesh; |
| 1273 | |
| 1274 | for (uint32_t i = 0; i < count; i++) { |
| 1275 | Rect* bounds = mLayers.itemAt(i); |
| 1276 | |
| 1277 | Vertex::set(vertex++, bounds->left, bounds->bottom); |
| 1278 | Vertex::set(vertex++, bounds->left, bounds->top); |
| 1279 | Vertex::set(vertex++, bounds->right, bounds->top); |
| 1280 | Vertex::set(vertex++, bounds->left, bounds->bottom); |
| 1281 | Vertex::set(vertex++, bounds->right, bounds->top); |
| 1282 | Vertex::set(vertex++, bounds->right, bounds->bottom); |
| 1283 | |
| 1284 | delete bounds; |
| 1285 | } |
Romain Guy | e67307c | 2013-02-11 18:01:20 -0800 | [diff] [blame] | 1286 | // We must clear the list of dirty rects before we |
| 1287 | // call setupDraw() to prevent stencil setup to do |
| 1288 | // the same thing again |
| 1289 | mLayers.clear(); |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1290 | |
| 1291 | setupDraw(false); |
| 1292 | setupDrawColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 1293 | setupDrawBlending(true, SkXfermode::kClear_Mode); |
| 1294 | setupDrawProgram(); |
| 1295 | setupDrawPureColorUniforms(); |
| 1296 | setupDrawModelViewTranslate(0.0f, 0.0f, 0.0f, 0.0f, true); |
Romain Guy | 39d252a | 2011-12-12 18:14:06 -0800 | [diff] [blame] | 1297 | setupDrawVertices(&mesh[0].position[0]); |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1298 | |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1299 | glDrawArrays(GL_TRIANGLES, 0, count * 6); |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 1300 | |
| 1301 | if (scissorChanged) mCaches.enableScissor(); |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1302 | } else { |
| 1303 | for (uint32_t i = 0; i < count; i++) { |
| 1304 | delete mLayers.itemAt(i); |
| 1305 | } |
Romain Guy | e67307c | 2013-02-11 18:01:20 -0800 | [diff] [blame] | 1306 | mLayers.clear(); |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1307 | } |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 1310 | /////////////////////////////////////////////////////////////////////////////// |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1311 | // State Deferral |
| 1312 | /////////////////////////////////////////////////////////////////////////////// |
| 1313 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1314 | bool OpenGLRenderer::storeDisplayState(DeferredDisplayState& state, int stateDeferFlags) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1315 | const Rect& currentClip = *(mSnapshot->clipRect); |
| 1316 | const mat4& currentMatrix = *(mSnapshot->transform); |
| 1317 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1318 | if (stateDeferFlags & kStateDeferFlag_Draw) { |
| 1319 | // state has bounds initialized in local coordinates |
| 1320 | if (!state.mBounds.isEmpty()) { |
| 1321 | currentMatrix.mapRect(state.mBounds); |
| 1322 | if (!state.mBounds.intersect(currentClip)) { |
| 1323 | // quick rejected |
| 1324 | return true; |
| 1325 | } |
| 1326 | } else { |
| 1327 | state.mBounds.set(currentClip); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1328 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1329 | state.mDrawModifiers = mDrawModifiers; |
| 1330 | state.mAlpha = mSnapshot->alpha; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1333 | if (stateDeferFlags & kStateDeferFlag_Clip) { |
| 1334 | state.mClip.set(currentClip); |
| 1335 | } else { |
| 1336 | state.mClip.setEmpty(); |
| 1337 | } |
| 1338 | |
| 1339 | // transform always deferred |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1340 | state.mMatrix.load(currentMatrix); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1341 | return false; |
| 1342 | } |
| 1343 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1344 | void OpenGLRenderer::restoreDisplayState(const DeferredDisplayState& state, int stateDeferFlags) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1345 | currentTransform().load(state.mMatrix); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1346 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1347 | if (stateDeferFlags & kStateDeferFlag_Draw) { |
| 1348 | mDrawModifiers = state.mDrawModifiers; |
| 1349 | mSnapshot->alpha = state.mAlpha; |
| 1350 | } |
| 1351 | |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 1352 | if (!state.mClip.isEmpty()) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1353 | mSnapshot->setClip(state.mClip.left, state.mClip.top, state.mClip.right, state.mClip.bottom); |
| 1354 | dirtyClip(); |
| 1355 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1359 | // Transforms |
| 1360 | /////////////////////////////////////////////////////////////////////////////// |
| 1361 | |
| 1362 | void OpenGLRenderer::translate(float dx, float dy) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1363 | currentTransform().translate(dx, dy, 0.0f); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | void OpenGLRenderer::rotate(float degrees) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1367 | currentTransform().rotate(degrees, 0.0f, 0.0f, 1.0f); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | void OpenGLRenderer::scale(float sx, float sy) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1371 | currentTransform().scale(sx, sy, 1.0f); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 1374 | void OpenGLRenderer::skew(float sx, float sy) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1375 | currentTransform().skew(sx, sy); |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 1376 | } |
| 1377 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1378 | void OpenGLRenderer::setMatrix(SkMatrix* matrix) { |
Romain Guy | e707859 | 2011-10-28 14:32:20 -0700 | [diff] [blame] | 1379 | if (matrix) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1380 | currentTransform().load(*matrix); |
Romain Guy | e707859 | 2011-10-28 14:32:20 -0700 | [diff] [blame] | 1381 | } else { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1382 | currentTransform().loadIdentity(); |
Romain Guy | e707859 | 2011-10-28 14:32:20 -0700 | [diff] [blame] | 1383 | } |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Chris Craik | b98a016 | 2013-02-21 11:30:22 -0800 | [diff] [blame] | 1386 | bool OpenGLRenderer::hasRectToRectTransform() { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1387 | return CC_LIKELY(currentTransform().rectToRect()); |
Chris Craik | b98a016 | 2013-02-21 11:30:22 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1390 | void OpenGLRenderer::getMatrix(SkMatrix* matrix) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1391 | currentTransform().copyTo(*matrix); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | void OpenGLRenderer::concatMatrix(SkMatrix* matrix) { |
Romain Guy | e5ebcb0 | 2010-10-15 13:57:28 -0700 | [diff] [blame] | 1395 | SkMatrix transform; |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1396 | currentTransform().copyTo(transform); |
Romain Guy | e5ebcb0 | 2010-10-15 13:57:28 -0700 | [diff] [blame] | 1397 | transform.preConcat(*matrix); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1398 | currentTransform().load(transform); |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /////////////////////////////////////////////////////////////////////////////// |
| 1402 | // Clipping |
| 1403 | /////////////////////////////////////////////////////////////////////////////// |
| 1404 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 1405 | void OpenGLRenderer::setScissorFromClip() { |
Romain Guy | e5ebcb0 | 2010-10-15 13:57:28 -0700 | [diff] [blame] | 1406 | Rect clip(*mSnapshot->clipRect); |
| 1407 | clip.snapToPixelBoundaries(); |
Romain Guy | 8f85e80 | 2011-12-14 19:23:32 -0800 | [diff] [blame] | 1408 | |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 1409 | if (mCaches.setScissor(clip.left, mSnapshot->height - clip.bottom, |
| 1410 | clip.getWidth(), clip.getHeight())) { |
| 1411 | mDirtyClip = false; |
| 1412 | } |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1415 | void OpenGLRenderer::ensureStencilBuffer() { |
| 1416 | // Thanks to the mismatch between EGL and OpenGL ES FBO we |
| 1417 | // cannot attach a stencil buffer to fbo0 dynamically. Let's |
| 1418 | // just hope we have one when hasLayer() returns false. |
| 1419 | if (hasLayer()) { |
| 1420 | attachStencilBufferToLayer(mSnapshot->layer); |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | void OpenGLRenderer::attachStencilBufferToLayer(Layer* layer) { |
| 1425 | // The layer's FBO is already bound when we reach this stage |
| 1426 | if (!layer->getStencilRenderBuffer()) { |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 1427 | // GL_QCOM_tiled_rendering doesn't like it if a renderbuffer |
| 1428 | // is attached after we initiated tiling. We must turn it off, |
| 1429 | // attach the new render buffer then turn tiling back on |
| 1430 | endTiling(); |
| 1431 | |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 1432 | RenderBuffer* buffer = mCaches.renderBufferCache.get( |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 1433 | Stencil::getSmallestStencilFormat(), layer->getWidth(), layer->getHeight()); |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1434 | layer->setStencilRenderBuffer(buffer); |
Romain Guy | c3fedaf | 2013-01-29 17:26:25 -0800 | [diff] [blame] | 1435 | |
Romain Guy | f735c8e | 2013-01-31 17:45:55 -0800 | [diff] [blame] | 1436 | startTiling(layer->clipRect, layer->layer.getHeight()); |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | void OpenGLRenderer::setStencilFromClip() { |
| 1441 | if (!mCaches.debugOverdraw) { |
| 1442 | if (!mSnapshot->clipRegion->isEmpty()) { |
| 1443 | // NOTE: The order here is important, we must set dirtyClip to false |
| 1444 | // before any draw call to avoid calling back into this method |
| 1445 | mDirtyClip = false; |
| 1446 | |
| 1447 | ensureStencilBuffer(); |
| 1448 | |
| 1449 | mCaches.stencil.enableWrite(); |
| 1450 | |
| 1451 | // Clear the stencil but first make sure we restrict drawing |
| 1452 | // to the region's bounds |
| 1453 | bool resetScissor = mCaches.enableScissor(); |
| 1454 | if (resetScissor) { |
| 1455 | // The scissor was not set so we now need to update it |
| 1456 | setScissorFromClip(); |
| 1457 | } |
| 1458 | mCaches.stencil.clear(); |
| 1459 | if (resetScissor) mCaches.disableScissor(); |
| 1460 | |
| 1461 | // NOTE: We could use the region contour path to generate a smaller mesh |
| 1462 | // Since we are using the stencil we could use the red book path |
| 1463 | // drawing technique. It might increase bandwidth usage though. |
| 1464 | |
| 1465 | // The last parameter is important: we are not drawing in the color buffer |
| 1466 | // so we don't want to dirty the current layer, if any |
| 1467 | drawRegionRects(*mSnapshot->clipRegion, 0xff000000, SkXfermode::kSrc_Mode, false); |
| 1468 | |
| 1469 | mCaches.stencil.enableTest(); |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 1470 | |
| 1471 | // Draw the region used to generate the stencil if the appropriate debug |
| 1472 | // mode is enabled |
| 1473 | if (mCaches.debugStencilClip == Caches::kStencilShowRegion) { |
| 1474 | drawRegionRects(*mSnapshot->clipRegion, 0x7f0000ff, SkXfermode::kSrcOver_Mode); |
| 1475 | } |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1476 | } else { |
| 1477 | mCaches.stencil.disable(); |
| 1478 | } |
| 1479 | } |
| 1480 | } |
| 1481 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 1482 | const Rect& OpenGLRenderer::getClipBounds() { |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 1483 | return mSnapshot->getLocalClip(); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 1486 | bool OpenGLRenderer::quickRejectNoScissor(float left, float top, float right, float bottom) { |
| 1487 | if (mSnapshot->isIgnored()) { |
| 1488 | return true; |
| 1489 | } |
| 1490 | |
| 1491 | Rect r(left, top, right, bottom); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1492 | currentTransform().mapRect(r); |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 1493 | r.snapToPixelBoundaries(); |
| 1494 | |
| 1495 | Rect clipRect(*mSnapshot->clipRect); |
| 1496 | clipRect.snapToPixelBoundaries(); |
| 1497 | |
| 1498 | return !clipRect.intersects(r); |
| 1499 | } |
| 1500 | |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 1501 | bool OpenGLRenderer::quickRejectNoScissor(float left, float top, float right, float bottom, |
| 1502 | Rect& transformed, Rect& clip) { |
| 1503 | if (mSnapshot->isIgnored()) { |
| 1504 | return true; |
| 1505 | } |
| 1506 | |
| 1507 | transformed.set(left, top, right, bottom); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1508 | currentTransform().mapRect(transformed); |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 1509 | transformed.snapToPixelBoundaries(); |
| 1510 | |
| 1511 | clip.set(*mSnapshot->clipRect); |
| 1512 | clip.snapToPixelBoundaries(); |
| 1513 | |
| 1514 | return !clip.intersects(transformed); |
| 1515 | } |
| 1516 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 1517 | bool OpenGLRenderer::quickRejectPreStroke(float left, float top, float right, float bottom, |
| 1518 | SkPaint* paint) { |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 1519 | if (paint->getStyle() != SkPaint::kFill_Style) { |
| 1520 | float outset = paint->getStrokeWidth() * 0.5f; |
| 1521 | return quickReject(left - outset, top - outset, right + outset, bottom + outset); |
| 1522 | } else { |
| 1523 | return quickReject(left, top, right, bottom); |
| 1524 | } |
| 1525 | } |
| 1526 | |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1527 | bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) { |
Chris Craik | bf09ffb | 2012-10-01 13:50:37 -0700 | [diff] [blame] | 1528 | if (mSnapshot->isIgnored() || bottom <= top || right <= left) { |
Romain Guy | dbc26d2 | 2010-10-11 17:58:29 -0700 | [diff] [blame] | 1529 | return true; |
| 1530 | } |
| 1531 | |
Romain Guy | 1d83e19 | 2010-08-17 11:37:00 -0700 | [diff] [blame] | 1532 | Rect r(left, top, right, bottom); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1533 | currentTransform().mapRect(r); |
Romain Guy | d2a1ff0 | 2010-10-14 14:46:44 -0700 | [diff] [blame] | 1534 | r.snapToPixelBoundaries(); |
| 1535 | |
| 1536 | Rect clipRect(*mSnapshot->clipRect); |
| 1537 | clipRect.snapToPixelBoundaries(); |
| 1538 | |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 1539 | bool rejected = !clipRect.intersects(r); |
| 1540 | if (!isDeferred() && !rejected) { |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 1541 | mCaches.setScissorEnabled(mScissorOptimizationDisabled || !clipRect.contains(r)); |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | return rejected; |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1547 | void OpenGLRenderer::debugClip() { |
| 1548 | #if DEBUG_CLIP_REGIONS |
| 1549 | if (!isDeferred() && !mSnapshot->clipRegion->isEmpty()) { |
| 1550 | drawRegionRects(*mSnapshot->clipRegion, 0x7f00ff00, SkXfermode::kSrcOver_Mode); |
| 1551 | } |
| 1552 | #endif |
| 1553 | } |
| 1554 | |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 1555 | bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1556 | if (CC_LIKELY(currentTransform().rectToRect())) { |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1557 | bool clipped = mSnapshot->clip(left, top, right, bottom, op); |
| 1558 | if (clipped) { |
| 1559 | dirtyClip(); |
| 1560 | } |
| 1561 | return !mSnapshot->clipRect->isEmpty(); |
| 1562 | } |
| 1563 | |
| 1564 | SkPath path; |
| 1565 | path.addRect(left, top, right, bottom); |
| 1566 | |
| 1567 | return clipPath(&path, op); |
| 1568 | } |
| 1569 | |
| 1570 | bool OpenGLRenderer::clipPath(SkPath* path, SkRegion::Op op) { |
| 1571 | SkMatrix transform; |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1572 | currentTransform().copyTo(transform); |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1573 | |
| 1574 | SkPath transformed; |
| 1575 | path->transform(transform, &transformed); |
| 1576 | |
| 1577 | SkRegion clip; |
| 1578 | if (!mSnapshot->clipRegion->isEmpty()) { |
| 1579 | clip.setRegion(*mSnapshot->clipRegion); |
| 1580 | } else { |
| 1581 | Rect* bounds = mSnapshot->clipRect; |
| 1582 | clip.setRect(bounds->left, bounds->top, bounds->right, bounds->bottom); |
| 1583 | } |
| 1584 | |
| 1585 | SkRegion region; |
| 1586 | region.setPath(transformed, clip); |
| 1587 | |
| 1588 | bool clipped = mSnapshot->clipRegionTransformed(region, op); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 1589 | if (clipped) { |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 1590 | dirtyClip(); |
Romain Guy | 7ae7ac4 | 2010-06-25 13:46:18 -0700 | [diff] [blame] | 1591 | } |
Romain Guy | 8aef54f | 2010-09-01 15:13:49 -0700 | [diff] [blame] | 1592 | return !mSnapshot->clipRect->isEmpty(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 1595 | bool OpenGLRenderer::clipRegion(SkRegion* region, SkRegion::Op op) { |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1596 | bool clipped = mSnapshot->clipRegionTransformed(*region, op); |
| 1597 | if (clipped) { |
| 1598 | dirtyClip(); |
| 1599 | } |
| 1600 | return !mSnapshot->clipRect->isEmpty(); |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 1601 | } |
| 1602 | |
Chet Haase | a23eed8 | 2012-04-12 15:19:04 -0700 | [diff] [blame] | 1603 | Rect* OpenGLRenderer::getClipRect() { |
| 1604 | return mSnapshot->clipRect; |
| 1605 | } |
| 1606 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1607 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1608 | // Drawing commands |
| 1609 | /////////////////////////////////////////////////////////////////////////////// |
| 1610 | |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1611 | void OpenGLRenderer::setupDraw(bool clear) { |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 1612 | // TODO: It would be best if we could do this before quickReject() |
| 1613 | // changes the scissor test state |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1614 | if (clear) clearLayerRegions(); |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1615 | // Make sure setScissor & setStencil happen at the beginning of |
| 1616 | // this method |
Chris Craik | b98a016 | 2013-02-21 11:30:22 -0800 | [diff] [blame] | 1617 | if (mDirtyClip) { |
| 1618 | if (mCaches.scissorEnabled) { |
| 1619 | setScissorFromClip(); |
| 1620 | } |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 1621 | setStencilFromClip(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1622 | } |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 1623 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1624 | mDescription.reset(); |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 1625 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1626 | mSetShaderColor = false; |
| 1627 | mColorSet = false; |
| 1628 | mColorA = mColorR = mColorG = mColorB = 0.0f; |
| 1629 | mTextureUnit = 0; |
| 1630 | mTrackDirtyRegions = true; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 1631 | |
| 1632 | // Enable debug highlight when what we're about to draw is tested against |
| 1633 | // the stencil buffer and if stencil highlight debugging is on |
| 1634 | mDescription.hasDebugHighlight = !mCaches.debugOverdraw && |
| 1635 | mCaches.debugStencilClip == Caches::kStencilShowHighlight && |
| 1636 | mCaches.stencil.isTestEnabled(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | void OpenGLRenderer::setupDrawWithTexture(bool isAlpha8) { |
| 1640 | mDescription.hasTexture = true; |
| 1641 | mDescription.hasAlpha8Texture = isAlpha8; |
| 1642 | } |
| 1643 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 1644 | void OpenGLRenderer::setupDrawWithTextureAndColor(bool isAlpha8) { |
| 1645 | mDescription.hasTexture = true; |
| 1646 | mDescription.hasColors = true; |
| 1647 | mDescription.hasAlpha8Texture = isAlpha8; |
| 1648 | } |
| 1649 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1650 | void OpenGLRenderer::setupDrawWithExternalTexture() { |
| 1651 | mDescription.hasExternalTexture = true; |
| 1652 | } |
| 1653 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1654 | void OpenGLRenderer::setupDrawNoTexture() { |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 1655 | mCaches.disableTexCoordsVertexArray(); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1656 | } |
| 1657 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 1658 | void OpenGLRenderer::setupDrawAA() { |
Chet Haase | 99585ad | 2011-05-02 15:00:16 -0700 | [diff] [blame] | 1659 | mDescription.isAA = true; |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 1662 | void OpenGLRenderer::setupDrawPoint(float pointSize) { |
| 1663 | mDescription.isPoint = true; |
| 1664 | mDescription.pointSize = pointSize; |
| 1665 | } |
| 1666 | |
Romain Guy | 8d0d478 | 2010-12-14 20:13:35 -0800 | [diff] [blame] | 1667 | void OpenGLRenderer::setupDrawColor(int color, int alpha) { |
| 1668 | mColorA = alpha / 255.0f; |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 1669 | mColorR = mColorA * ((color >> 16) & 0xFF) / 255.0f; |
| 1670 | mColorG = mColorA * ((color >> 8) & 0xFF) / 255.0f; |
| 1671 | mColorB = mColorA * ((color ) & 0xFF) / 255.0f; |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1672 | mColorSet = true; |
| 1673 | mSetShaderColor = mDescription.setColor(mColorR, mColorG, mColorB, mColorA); |
| 1674 | } |
| 1675 | |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1676 | void OpenGLRenderer::setupDrawAlpha8Color(int color, int alpha) { |
| 1677 | mColorA = alpha / 255.0f; |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 1678 | mColorR = mColorA * ((color >> 16) & 0xFF) / 255.0f; |
| 1679 | mColorG = mColorA * ((color >> 8) & 0xFF) / 255.0f; |
| 1680 | mColorB = mColorA * ((color ) & 0xFF) / 255.0f; |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1681 | mColorSet = true; |
| 1682 | mSetShaderColor = mDescription.setAlpha8Color(mColorR, mColorG, mColorB, mColorA); |
| 1683 | } |
| 1684 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 1685 | void OpenGLRenderer::setupDrawTextGamma(const SkPaint* paint) { |
| 1686 | mCaches.fontRenderer->describe(mDescription, paint); |
| 1687 | } |
| 1688 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1689 | void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) { |
| 1690 | mColorA = a; |
| 1691 | mColorR = r; |
| 1692 | mColorG = g; |
| 1693 | mColorB = b; |
| 1694 | mColorSet = true; |
| 1695 | mSetShaderColor = mDescription.setColor(r, g, b, a); |
| 1696 | } |
| 1697 | |
| 1698 | void OpenGLRenderer::setupDrawShader() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1699 | if (mDrawModifiers.mShader) { |
| 1700 | mDrawModifiers.mShader->describe(mDescription, mExtensions); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | void OpenGLRenderer::setupDrawColorFilter() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1705 | if (mDrawModifiers.mColorFilter) { |
| 1706 | mDrawModifiers.mColorFilter->describe(mDescription, mExtensions); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
Romain Guy | f09ef51 | 2011-05-27 11:43:46 -0700 | [diff] [blame] | 1710 | void OpenGLRenderer::accountForClear(SkXfermode::Mode mode) { |
| 1711 | if (mColorSet && mode == SkXfermode::kClear_Mode) { |
| 1712 | mColorA = 1.0f; |
| 1713 | mColorR = mColorG = mColorB = 0.0f; |
Romain Guy | 54be1cd | 2011-06-13 19:04:27 -0700 | [diff] [blame] | 1714 | mSetShaderColor = mDescription.modulate = true; |
Romain Guy | f09ef51 | 2011-05-27 11:43:46 -0700 | [diff] [blame] | 1715 | } |
| 1716 | } |
| 1717 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1718 | void OpenGLRenderer::setupDrawBlending(SkXfermode::Mode mode, bool swapSrcDst) { |
Romain Guy | f09ef51 | 2011-05-27 11:43:46 -0700 | [diff] [blame] | 1719 | // When the blending mode is kClear_Mode, we need to use a modulate color |
| 1720 | // argb=1,0,0,0 |
| 1721 | accountForClear(mode); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1722 | bool blend = (mColorSet && mColorA < 1.0f) || |
| 1723 | (mDrawModifiers.mShader && mDrawModifiers.mShader->blend()); |
| 1724 | chooseBlending(blend, mode, mDescription, swapSrcDst); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void OpenGLRenderer::setupDrawBlending(bool blend, SkXfermode::Mode mode, bool swapSrcDst) { |
Romain Guy | f09ef51 | 2011-05-27 11:43:46 -0700 | [diff] [blame] | 1728 | // When the blending mode is kClear_Mode, we need to use a modulate color |
| 1729 | // argb=1,0,0,0 |
| 1730 | accountForClear(mode); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1731 | blend |= (mColorSet && mColorA < 1.0f) || |
| 1732 | (mDrawModifiers.mShader && mDrawModifiers.mShader->blend()) || |
| 1733 | (mDrawModifiers.mColorFilter && mDrawModifiers.mColorFilter->blend()); |
| 1734 | chooseBlending(blend, mode, mDescription, swapSrcDst); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | void OpenGLRenderer::setupDrawProgram() { |
| 1738 | useProgram(mCaches.programCache.get(mDescription)); |
| 1739 | } |
| 1740 | |
| 1741 | void OpenGLRenderer::setupDrawDirtyRegionsDisabled() { |
| 1742 | mTrackDirtyRegions = false; |
| 1743 | } |
| 1744 | |
| 1745 | void OpenGLRenderer::setupDrawModelViewTranslate(float left, float top, float right, float bottom, |
| 1746 | bool ignoreTransform) { |
| 1747 | mModelView.loadTranslate(left, top, 0.0f); |
| 1748 | if (!ignoreTransform) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1749 | mCaches.currentProgram->set(mOrthoMatrix, mModelView, currentTransform()); |
| 1750 | if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom, currentTransform()); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1751 | } else { |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 1752 | mCaches.currentProgram->set(mOrthoMatrix, mModelView, mat4::identity()); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1753 | if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom); |
| 1754 | } |
| 1755 | } |
| 1756 | |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 1757 | void OpenGLRenderer::setupDrawModelViewIdentity(bool offset) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1758 | mCaches.currentProgram->set(mOrthoMatrix, mat4::identity(), currentTransform(), offset); |
Romain Guy | 8d0d478 | 2010-12-14 20:13:35 -0800 | [diff] [blame] | 1759 | } |
| 1760 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1761 | void OpenGLRenderer::setupDrawModelView(float left, float top, float right, float bottom, |
| 1762 | bool ignoreTransform, bool ignoreModelView) { |
| 1763 | if (!ignoreModelView) { |
| 1764 | mModelView.loadTranslate(left, top, 0.0f); |
| 1765 | mModelView.scale(right - left, bottom - top, 1.0f); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1766 | } else { |
| 1767 | mModelView.loadIdentity(); |
| 1768 | } |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1769 | bool dirty = right - left > 0.0f && bottom - top > 0.0f; |
| 1770 | if (!ignoreTransform) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1771 | mCaches.currentProgram->set(mOrthoMatrix, mModelView, currentTransform()); |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1772 | if (mTrackDirtyRegions && dirty) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1773 | dirtyLayer(left, top, right, bottom, currentTransform()); |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1774 | } |
| 1775 | } else { |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 1776 | mCaches.currentProgram->set(mOrthoMatrix, mModelView, mat4::identity()); |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1777 | if (mTrackDirtyRegions && dirty) dirtyLayer(left, top, right, bottom); |
| 1778 | } |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1779 | } |
| 1780 | |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 1781 | void OpenGLRenderer::setupDrawPointUniforms() { |
| 1782 | int slot = mCaches.currentProgram->getUniform("pointSize"); |
| 1783 | glUniform1f(slot, mDescription.pointSize); |
| 1784 | } |
| 1785 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1786 | void OpenGLRenderer::setupDrawColorUniforms() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1787 | if ((mColorSet && !mDrawModifiers.mShader) || (mDrawModifiers.mShader && mSetShaderColor)) { |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1788 | mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA); |
| 1789 | } |
| 1790 | } |
| 1791 | |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1792 | void OpenGLRenderer::setupDrawPureColorUniforms() { |
Romain Guy | 5536841 | 2010-12-14 10:59:41 -0800 | [diff] [blame] | 1793 | if (mSetShaderColor) { |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 1794 | mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA); |
Romain Guy | 5536841 | 2010-12-14 10:59:41 -0800 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1798 | void OpenGLRenderer::setupDrawShaderUniforms(bool ignoreTransform) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1799 | if (mDrawModifiers.mShader) { |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1800 | if (ignoreTransform) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1801 | mModelView.loadInverse(currentTransform()); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1802 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1803 | mDrawModifiers.mShader->setupProgram(mCaches.currentProgram, |
| 1804 | mModelView, *mSnapshot, &mTextureUnit); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | |
Romain Guy | 8d0d478 | 2010-12-14 20:13:35 -0800 | [diff] [blame] | 1808 | void OpenGLRenderer::setupDrawShaderIdentityUniforms() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1809 | if (mDrawModifiers.mShader) { |
| 1810 | mDrawModifiers.mShader->setupProgram(mCaches.currentProgram, |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 1811 | mat4::identity(), *mSnapshot, &mTextureUnit); |
Romain Guy | 8d0d478 | 2010-12-14 20:13:35 -0800 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1815 | void OpenGLRenderer::setupDrawColorFilterUniforms() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1816 | if (mDrawModifiers.mColorFilter) { |
| 1817 | mDrawModifiers.mColorFilter->setupProgram(mCaches.currentProgram); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1818 | } |
| 1819 | } |
| 1820 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 1821 | void OpenGLRenderer::setupDrawTextGammaUniforms() { |
| 1822 | mCaches.fontRenderer->setupProgram(mDescription, mCaches.currentProgram); |
| 1823 | } |
| 1824 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1825 | void OpenGLRenderer::setupDrawSimpleMesh() { |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 1826 | bool force = mCaches.bindMeshBuffer(); |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 1827 | mCaches.bindPositionVertexPointer(force, 0); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1828 | mCaches.unbindIndicesBuffer(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | void OpenGLRenderer::setupDrawTexture(GLuint texture) { |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 1832 | if (texture) bindTexture(texture); |
Romain Guy | 2d4fd36 | 2011-12-13 22:00:19 -0800 | [diff] [blame] | 1833 | mTextureUnit++; |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1834 | mCaches.enableTexCoordsVertexArray(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1835 | } |
| 1836 | |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1837 | void OpenGLRenderer::setupDrawExternalTexture(GLuint texture) { |
| 1838 | bindExternalTexture(texture); |
Romain Guy | 2d4fd36 | 2011-12-13 22:00:19 -0800 | [diff] [blame] | 1839 | mTextureUnit++; |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1840 | mCaches.enableTexCoordsVertexArray(); |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 1843 | void OpenGLRenderer::setupDrawTextureTransform() { |
| 1844 | mDescription.hasTextureTransform = true; |
| 1845 | } |
| 1846 | |
| 1847 | void OpenGLRenderer::setupDrawTextureTransformUniforms(mat4& transform) { |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 1848 | glUniformMatrix4fv(mCaches.currentProgram->getUniform("mainTextureTransform"), 1, |
| 1849 | GL_FALSE, &transform.data[0]); |
| 1850 | } |
| 1851 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1852 | void OpenGLRenderer::setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLuint vbo) { |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 1853 | bool force = false; |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1854 | if (!vertices) { |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 1855 | force = mCaches.bindMeshBuffer(vbo == 0 ? mCaches.meshBuffer : vbo); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1856 | } else { |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 1857 | force = mCaches.unbindMeshBuffer(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1858 | } |
Romain Guy | d71dd36 | 2011-12-12 19:03:35 -0800 | [diff] [blame] | 1859 | |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 1860 | mCaches.bindPositionVertexPointer(force, vertices); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1861 | if (mCaches.currentProgram->texCoords >= 0) { |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 1862 | mCaches.bindTexCoordsVertexPointer(force, texCoords); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | mCaches.unbindIndicesBuffer(); |
| 1866 | } |
| 1867 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 1868 | void OpenGLRenderer::setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLvoid* colors) { |
| 1869 | bool force = mCaches.unbindMeshBuffer(); |
| 1870 | GLsizei stride = sizeof(ColorTextureVertex); |
| 1871 | |
| 1872 | mCaches.bindPositionVertexPointer(force, vertices, stride); |
| 1873 | if (mCaches.currentProgram->texCoords >= 0) { |
| 1874 | mCaches.bindTexCoordsVertexPointer(force, texCoords, stride); |
| 1875 | } |
| 1876 | int slot = mCaches.currentProgram->getAttrib("colors"); |
| 1877 | if (slot >= 0) { |
| 1878 | glEnableVertexAttribArray(slot); |
| 1879 | glVertexAttribPointer(slot, 4, GL_FLOAT, GL_FALSE, stride, colors); |
| 1880 | } |
| 1881 | |
| 1882 | mCaches.unbindIndicesBuffer(); |
| 1883 | } |
| 1884 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1885 | void OpenGLRenderer::setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords) { |
| 1886 | bool force = mCaches.unbindMeshBuffer(); |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 1887 | mCaches.bindPositionVertexPointer(force, vertices); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1888 | if (mCaches.currentProgram->texCoords >= 0) { |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 1889 | mCaches.bindTexCoordsVertexPointer(force, texCoords); |
Romain Guy | 8d0d478 | 2010-12-14 20:13:35 -0800 | [diff] [blame] | 1890 | } |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1891 | } |
| 1892 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 1893 | void OpenGLRenderer::setupDrawVertices(GLvoid* vertices) { |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 1894 | bool force = mCaches.unbindMeshBuffer(); |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 1895 | mCaches.bindPositionVertexPointer(force, vertices, gVertexStride); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 1896 | mCaches.unbindIndicesBuffer(); |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1899 | void OpenGLRenderer::finishDrawTexture() { |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 1903 | // Drawing |
| 1904 | /////////////////////////////////////////////////////////////////////////////// |
| 1905 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1906 | status_t OpenGLRenderer::drawDisplayList(DisplayList* displayList, Rect& dirty, |
| 1907 | int32_t replayFlags) { |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 1908 | // All the usual checks and setup operations (quickReject, setupDraw, etc.) |
| 1909 | // will be performed by the display list itself |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 1910 | if (displayList && displayList->isRenderable()) { |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 1911 | if (CC_UNLIKELY(mCaches.drawDeferDisabled)) { |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 1912 | startFrame(); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1913 | ReplayStateStruct replayStruct(*this, dirty, replayFlags); |
| 1914 | displayList->replay(replayStruct, 0); |
| 1915 | return replayStruct.mDrawGlStatus; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | DeferredDisplayList deferredList; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1919 | DeferStateStruct deferStruct(deferredList, *this, replayFlags); |
| 1920 | displayList->defer(deferStruct, 0); |
Romain Guy | 96885eb | 2013-03-26 15:05:58 -0700 | [diff] [blame] | 1921 | |
| 1922 | flushLayers(); |
| 1923 | startFrame(); |
| 1924 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1925 | return deferredList.flush(*this, dirty); |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 1926 | } |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 1927 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 1928 | return DrawGlInfo::kStatusDone; |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 1929 | } |
| 1930 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1931 | void OpenGLRenderer::outputDisplayList(DisplayList* displayList) { |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 1932 | if (displayList) { |
Romain Guy | 7031ff6 | 2013-02-22 11:48:16 -0800 | [diff] [blame] | 1933 | displayList->output(1); |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 1934 | } |
| 1935 | } |
| 1936 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1937 | void OpenGLRenderer::drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint) { |
| 1938 | int alpha; |
| 1939 | SkXfermode::Mode mode; |
| 1940 | getAlphaAndMode(paint, &alpha, &mode); |
| 1941 | |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 1942 | int color = paint != NULL ? paint->getColor() : 0; |
| 1943 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1944 | float x = left; |
| 1945 | float y = top; |
| 1946 | |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 1947 | texture->setWrap(GL_CLAMP_TO_EDGE, true); |
| 1948 | |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1949 | bool ignoreTransform = false; |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 1950 | if (currentTransform().isPureTranslate()) { |
| 1951 | x = (int) floorf(left + currentTransform().getTranslateX() + 0.5f); |
| 1952 | y = (int) floorf(top + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1953 | ignoreTransform = true; |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 1954 | |
| 1955 | texture->setFilter(GL_NEAREST, true); |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 1956 | } else { |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 1957 | texture->setFilter(FILTER(paint), true); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 1960 | drawAlpha8TextureMesh(x, y, x + texture->width, y + texture->height, texture->id, |
| 1961 | paint != NULL, color, alpha, mode, (GLvoid*) NULL, |
| 1962 | (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount, ignoreTransform); |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 1965 | status_t OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) { |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 1966 | const float right = left + bitmap->width(); |
| 1967 | const float bottom = top + bitmap->height(); |
| 1968 | |
| 1969 | if (quickReject(left, top, right, bottom)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 1970 | return DrawGlInfo::kStatusDone; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 1973 | mCaches.activeTexture(0); |
Romain Guy | 8164c2d | 2010-10-25 18:03:28 -0700 | [diff] [blame] | 1974 | Texture* texture = mCaches.textureCache.get(bitmap); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 1975 | if (!texture) return DrawGlInfo::kStatusDone; |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 1976 | const AutoTexture autoCleanup(texture); |
| 1977 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 1978 | if (CC_UNLIKELY(bitmap->getConfig() == SkBitmap::kA8_Config)) { |
Romain Guy | a168d73 | 2011-03-18 16:50:13 -0700 | [diff] [blame] | 1979 | drawAlphaBitmap(texture, left, top, paint); |
| 1980 | } else { |
| 1981 | drawTextureRect(left, top, right, bottom, texture, paint); |
| 1982 | } |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 1983 | |
| 1984 | return DrawGlInfo::kStatusDrew; |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 1987 | status_t OpenGLRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) { |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 1988 | Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height()); |
| 1989 | const mat4 transform(*matrix); |
| 1990 | transform.mapRect(r); |
| 1991 | |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 1992 | if (quickReject(r.left, r.top, r.right, r.bottom)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 1993 | return DrawGlInfo::kStatusDone; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 1996 | mCaches.activeTexture(0); |
Romain Guy | 8164c2d | 2010-10-25 18:03:28 -0700 | [diff] [blame] | 1997 | Texture* texture = mCaches.textureCache.get(bitmap); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 1998 | if (!texture) return DrawGlInfo::kStatusDone; |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 1999 | const AutoTexture autoCleanup(texture); |
| 2000 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 2001 | // This could be done in a cheaper way, all we need is pass the matrix |
| 2002 | // to the vertex shader. The save/restore is a bit overkill. |
| 2003 | save(SkCanvas::kMatrix_SaveFlag); |
| 2004 | concatMatrix(matrix); |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 2005 | if (CC_UNLIKELY(bitmap->getConfig() == SkBitmap::kA8_Config)) { |
| 2006 | drawAlphaBitmap(texture, 0.0f, 0.0f, paint); |
| 2007 | } else { |
| 2008 | drawTextureRect(0.0f, 0.0f, bitmap->width(), bitmap->height(), texture, paint); |
| 2009 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 2010 | restore(); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2011 | |
| 2012 | return DrawGlInfo::kStatusDrew; |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2015 | status_t OpenGLRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint) { |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 2016 | const float right = left + bitmap->width(); |
| 2017 | const float bottom = top + bitmap->height(); |
| 2018 | |
| 2019 | if (quickReject(left, top, right, bottom)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2020 | return DrawGlInfo::kStatusDone; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | mCaches.activeTexture(0); |
| 2024 | Texture* texture = mCaches.textureCache.getTransient(bitmap); |
| 2025 | const AutoTexture autoCleanup(texture); |
| 2026 | |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 2027 | if (CC_UNLIKELY(bitmap->getConfig() == SkBitmap::kA8_Config)) { |
| 2028 | drawAlphaBitmap(texture, left, top, paint); |
| 2029 | } else { |
| 2030 | drawTextureRect(left, top, right, bottom, texture, paint); |
| 2031 | } |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2032 | |
| 2033 | return DrawGlInfo::kStatusDrew; |
Romain Guy | e651cc6 | 2012-05-14 19:44:40 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2036 | status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 2037 | float* vertices, int* colors, SkPaint* paint) { |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 2038 | if (!vertices || mSnapshot->isIgnored()) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2039 | return DrawGlInfo::kStatusDone; |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 2040 | } |
| 2041 | |
Romain Guy | b18d2d0 | 2011-02-10 15:52:54 -0800 | [diff] [blame] | 2042 | float left = FLT_MAX; |
| 2043 | float top = FLT_MAX; |
| 2044 | float right = FLT_MIN; |
| 2045 | float bottom = FLT_MIN; |
| 2046 | |
Romain Guy | a92bb4d | 2012-10-16 11:08:44 -0700 | [diff] [blame] | 2047 | const uint32_t count = meshWidth * meshHeight * 6; |
Romain Guy | b18d2d0 | 2011-02-10 15:52:54 -0800 | [diff] [blame] | 2048 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 2049 | ColorTextureVertex mesh[count]; |
| 2050 | ColorTextureVertex* vertex = mesh; |
| 2051 | |
| 2052 | bool cleanupColors = false; |
| 2053 | if (!colors) { |
| 2054 | uint32_t colorsCount = (meshWidth + 1) * (meshHeight + 1); |
| 2055 | colors = new int[colorsCount]; |
| 2056 | memset(colors, 0xff, colorsCount * sizeof(int)); |
| 2057 | cleanupColors = true; |
| 2058 | } |
Romain Guy | a92bb4d | 2012-10-16 11:08:44 -0700 | [diff] [blame] | 2059 | |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 2060 | for (int32_t y = 0; y < meshHeight; y++) { |
| 2061 | for (int32_t x = 0; x < meshWidth; x++) { |
| 2062 | uint32_t i = (y * (meshWidth + 1) + x) * 2; |
| 2063 | |
| 2064 | float u1 = float(x) / meshWidth; |
| 2065 | float u2 = float(x + 1) / meshWidth; |
| 2066 | float v1 = float(y) / meshHeight; |
| 2067 | float v2 = float(y + 1) / meshHeight; |
| 2068 | |
| 2069 | int ax = i + (meshWidth + 1) * 2; |
| 2070 | int ay = ax + 1; |
| 2071 | int bx = i; |
| 2072 | int by = bx + 1; |
| 2073 | int cx = i + 2; |
| 2074 | int cy = cx + 1; |
| 2075 | int dx = i + (meshWidth + 1) * 2 + 2; |
| 2076 | int dy = dx + 1; |
| 2077 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 2078 | ColorTextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2, colors[dx / 2]); |
| 2079 | ColorTextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2, colors[ax / 2]); |
| 2080 | ColorTextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1, colors[bx / 2]); |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 2081 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 2082 | ColorTextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2, colors[dx / 2]); |
| 2083 | ColorTextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1, colors[bx / 2]); |
| 2084 | ColorTextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1, colors[cx / 2]); |
Romain Guy | b18d2d0 | 2011-02-10 15:52:54 -0800 | [diff] [blame] | 2085 | |
Romain Guy | a92bb4d | 2012-10-16 11:08:44 -0700 | [diff] [blame] | 2086 | left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx]))); |
| 2087 | top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy]))); |
| 2088 | right = fmaxf(right, fmaxf(vertices[ax], fmaxf(vertices[bx], vertices[cx]))); |
| 2089 | bottom = fmaxf(bottom, fmaxf(vertices[ay], fmaxf(vertices[by], vertices[cy]))); |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 2090 | } |
| 2091 | } |
| 2092 | |
Romain Guy | a92bb4d | 2012-10-16 11:08:44 -0700 | [diff] [blame] | 2093 | if (quickReject(left, top, right, bottom)) { |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 2094 | if (cleanupColors) delete[] colors; |
Romain Guy | a92bb4d | 2012-10-16 11:08:44 -0700 | [diff] [blame] | 2095 | return DrawGlInfo::kStatusDone; |
| 2096 | } |
| 2097 | |
| 2098 | mCaches.activeTexture(0); |
| 2099 | Texture* texture = mCaches.textureCache.get(bitmap); |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 2100 | if (!texture) { |
| 2101 | if (cleanupColors) delete[] colors; |
| 2102 | return DrawGlInfo::kStatusDone; |
| 2103 | } |
Romain Guy | a92bb4d | 2012-10-16 11:08:44 -0700 | [diff] [blame] | 2104 | const AutoTexture autoCleanup(texture); |
| 2105 | |
| 2106 | texture->setWrap(GL_CLAMP_TO_EDGE, true); |
| 2107 | texture->setFilter(FILTER(paint), true); |
| 2108 | |
| 2109 | int alpha; |
| 2110 | SkXfermode::Mode mode; |
| 2111 | getAlphaAndMode(paint, &alpha, &mode); |
| 2112 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 2113 | float a = alpha / 255.0f; |
| 2114 | |
Romain Guy | a92bb4d | 2012-10-16 11:08:44 -0700 | [diff] [blame] | 2115 | if (hasLayer()) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2116 | dirtyLayer(left, top, right, bottom, currentTransform()); |
Romain Guy | b18d2d0 | 2011-02-10 15:52:54 -0800 | [diff] [blame] | 2117 | } |
Romain Guy | b18d2d0 | 2011-02-10 15:52:54 -0800 | [diff] [blame] | 2118 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 2119 | setupDraw(); |
| 2120 | setupDrawWithTextureAndColor(); |
| 2121 | setupDrawColor(a, a, a, a); |
| 2122 | setupDrawColorFilter(); |
| 2123 | setupDrawBlending(true, mode, false); |
| 2124 | setupDrawProgram(); |
| 2125 | setupDrawDirtyRegionsDisabled(); |
| 2126 | setupDrawModelView(0.0f, 0.0f, 1.0f, 1.0f, false); |
| 2127 | setupDrawTexture(texture->id); |
| 2128 | setupDrawPureColorUniforms(); |
| 2129 | setupDrawColorFilterUniforms(); |
| 2130 | setupDrawMesh(&mesh[0].position[0], &mesh[0].texture[0], &mesh[0].color[0]); |
| 2131 | |
| 2132 | glDrawArrays(GL_TRIANGLES, 0, count); |
| 2133 | |
| 2134 | finishDrawTexture(); |
| 2135 | |
| 2136 | int slot = mCaches.currentProgram->getAttrib("colors"); |
| 2137 | if (slot >= 0) { |
| 2138 | glDisableVertexAttribArray(slot); |
| 2139 | } |
| 2140 | |
| 2141 | if (cleanupColors) delete[] colors; |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2142 | |
| 2143 | return DrawGlInfo::kStatusDrew; |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 2144 | } |
| 2145 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2146 | status_t OpenGLRenderer::drawBitmap(SkBitmap* bitmap, |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 2147 | float srcLeft, float srcTop, float srcRight, float srcBottom, |
| 2148 | float dstLeft, float dstTop, float dstRight, float dstBottom, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 2149 | SkPaint* paint) { |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 2150 | if (quickReject(dstLeft, dstTop, dstRight, dstBottom)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2151 | return DrawGlInfo::kStatusDone; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 2154 | mCaches.activeTexture(0); |
Romain Guy | 8164c2d | 2010-10-25 18:03:28 -0700 | [diff] [blame] | 2155 | Texture* texture = mCaches.textureCache.get(bitmap); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2156 | if (!texture) return DrawGlInfo::kStatusDone; |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 2157 | const AutoTexture autoCleanup(texture); |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 2158 | |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 2159 | const float width = texture->width; |
| 2160 | const float height = texture->height; |
| 2161 | |
Romain Guy | 6816972 | 2011-08-22 17:33:33 -0700 | [diff] [blame] | 2162 | const float u1 = fmax(0.0f, srcLeft / width); |
| 2163 | const float v1 = fmax(0.0f, srcTop / height); |
| 2164 | const float u2 = fmin(1.0f, srcRight / width); |
| 2165 | const float v2 = fmin(1.0f, srcBottom / height); |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 2166 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 2167 | mCaches.unbindMeshBuffer(); |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 2168 | resetDrawTextureTexCoords(u1, v1, u2, v2); |
| 2169 | |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 2170 | int alpha; |
| 2171 | SkXfermode::Mode mode; |
| 2172 | getAlphaAndMode(paint, &alpha, &mode); |
| 2173 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 2174 | texture->setWrap(GL_CLAMP_TO_EDGE, true); |
| 2175 | |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 2176 | float scaleX = (dstRight - dstLeft) / (srcRight - srcLeft); |
| 2177 | float scaleY = (dstBottom - dstTop) / (srcBottom - srcTop); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2178 | |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 2179 | bool scaled = scaleX != 1.0f || scaleY != 1.0f; |
| 2180 | // Apply a scale transform on the canvas only when a shader is in use |
| 2181 | // Skia handles the ratio between the dst and src rects as a scale factor |
| 2182 | // when a shader is set |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 2183 | bool useScaleTransform = mDrawModifiers.mShader && scaled; |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 2184 | bool ignoreTransform = false; |
Romain Guy | b501498 | 2011-07-28 15:39:12 -0700 | [diff] [blame] | 2185 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2186 | if (CC_LIKELY(currentTransform().isPureTranslate() && !useScaleTransform)) { |
| 2187 | float x = (int) floorf(dstLeft + currentTransform().getTranslateX() + 0.5f); |
| 2188 | float y = (int) floorf(dstTop + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 2189 | |
| 2190 | dstRight = x + (dstRight - dstLeft); |
| 2191 | dstBottom = y + (dstBottom - dstTop); |
| 2192 | |
| 2193 | dstLeft = x; |
| 2194 | dstTop = y; |
| 2195 | |
| 2196 | texture->setFilter(scaled ? FILTER(paint) : GL_NEAREST, true); |
| 2197 | ignoreTransform = true; |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2198 | } else { |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 2199 | texture->setFilter(FILTER(paint), true); |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | if (CC_UNLIKELY(useScaleTransform)) { |
| 2203 | save(SkCanvas::kMatrix_SaveFlag); |
| 2204 | translate(dstLeft, dstTop); |
| 2205 | scale(scaleX, scaleY); |
| 2206 | |
| 2207 | dstLeft = 0.0f; |
| 2208 | dstTop = 0.0f; |
| 2209 | |
| 2210 | dstRight = srcRight - srcLeft; |
| 2211 | dstBottom = srcBottom - srcTop; |
| 2212 | } |
| 2213 | |
| 2214 | if (CC_UNLIKELY(bitmap->getConfig() == SkBitmap::kA8_Config)) { |
| 2215 | int color = paint ? paint->getColor() : 0; |
| 2216 | drawAlpha8TextureMesh(dstLeft, dstTop, dstRight, dstBottom, |
| 2217 | texture->id, paint != NULL, color, alpha, mode, |
| 2218 | &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0], |
| 2219 | GL_TRIANGLE_STRIP, gMeshCount, ignoreTransform); |
| 2220 | } else { |
| 2221 | drawTextureMesh(dstLeft, dstTop, dstRight, dstBottom, |
| 2222 | texture->id, alpha / 255.0f, mode, texture->blend, |
| 2223 | &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0], |
| 2224 | GL_TRIANGLE_STRIP, gMeshCount, false, ignoreTransform); |
| 2225 | } |
| 2226 | |
| 2227 | if (CC_UNLIKELY(useScaleTransform)) { |
| 2228 | restore(); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2229 | } |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 2230 | |
| 2231 | resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2232 | |
| 2233 | return DrawGlInfo::kStatusDrew; |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2236 | status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 2237 | const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 2238 | float left, float top, float right, float bottom, SkPaint* paint) { |
Romain Guy | be6f9dc | 2012-07-16 12:41:17 -0700 | [diff] [blame] | 2239 | int alpha; |
| 2240 | SkXfermode::Mode mode; |
| 2241 | getAlphaAndModeDirect(paint, &alpha, &mode); |
| 2242 | |
| 2243 | return drawPatch(bitmap, xDivs, yDivs, colors, width, height, numColors, |
| 2244 | left, top, right, bottom, alpha, mode); |
| 2245 | } |
| 2246 | |
| 2247 | status_t OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, |
| 2248 | const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, |
| 2249 | float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode) { |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 2250 | if (quickReject(left, top, right, bottom)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2251 | return DrawGlInfo::kStatusDone; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
Romain Guy | be6f9dc | 2012-07-16 12:41:17 -0700 | [diff] [blame] | 2254 | alpha *= mSnapshot->alpha; |
| 2255 | |
Romain Guy | 2728f96 | 2010-10-08 18:36:15 -0700 | [diff] [blame] | 2256 | const Patch* mesh = mCaches.patchCache.get(bitmap->width(), bitmap->height(), |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 2257 | right - left, bottom - top, xDivs, yDivs, colors, width, height, numColors); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 2258 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 2259 | if (CC_LIKELY(mesh && mesh->verticesCount > 0)) { |
Romain Guy | a4adcf0 | 2013-02-28 12:15:35 -0800 | [diff] [blame] | 2260 | mCaches.activeTexture(0); |
| 2261 | Texture* texture = mCaches.textureCache.get(bitmap); |
| 2262 | if (!texture) return DrawGlInfo::kStatusDone; |
| 2263 | const AutoTexture autoCleanup(texture); |
| 2264 | texture->setWrap(GL_CLAMP_TO_EDGE, true); |
| 2265 | texture->setFilter(GL_LINEAR, true); |
| 2266 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2267 | const bool pureTranslate = currentTransform().isPureTranslate(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 2268 | // Mark the current layer dirty where we are going to draw the patch |
Romain Guy | 8168396 | 2011-01-24 20:40:18 -0800 | [diff] [blame] | 2269 | if (hasLayer() && mesh->hasEmptyQuads) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2270 | const float offsetX = left + currentTransform().getTranslateX(); |
| 2271 | const float offsetY = top + currentTransform().getTranslateY(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 2272 | const size_t count = mesh->quads.size(); |
| 2273 | for (size_t i = 0; i < count; i++) { |
Romain Guy | 8ab4079 | 2010-12-07 13:30:10 -0800 | [diff] [blame] | 2274 | const Rect& bounds = mesh->quads.itemAt(i); |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 2275 | if (CC_LIKELY(pureTranslate)) { |
Romain Guy | c78b5d5 | 2011-02-04 14:00:42 -0800 | [diff] [blame] | 2276 | const float x = (int) floorf(bounds.left + offsetX + 0.5f); |
| 2277 | const float y = (int) floorf(bounds.top + offsetY + 0.5f); |
| 2278 | dirtyLayer(x, y, x + bounds.getWidth(), y + bounds.getHeight()); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2279 | } else { |
Romain Guy | c78b5d5 | 2011-02-04 14:00:42 -0800 | [diff] [blame] | 2280 | dirtyLayer(left + bounds.left, top + bounds.top, |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2281 | left + bounds.right, top + bounds.bottom, currentTransform()); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2282 | } |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 2283 | } |
| 2284 | } |
| 2285 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 2286 | if (CC_LIKELY(pureTranslate)) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2287 | const float x = (int) floorf(left + currentTransform().getTranslateX() + 0.5f); |
| 2288 | const float y = (int) floorf(top + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2289 | |
| 2290 | drawTextureMesh(x, y, x + right - left, y + bottom - top, texture->id, alpha / 255.0f, |
| 2291 | mode, texture->blend, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset, |
| 2292 | GL_TRIANGLES, mesh->verticesCount, false, true, mesh->meshBuffer, |
| 2293 | true, !mesh->hasEmptyQuads); |
| 2294 | } else { |
| 2295 | drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, |
| 2296 | mode, texture->blend, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset, |
| 2297 | GL_TRIANGLES, mesh->verticesCount, false, false, mesh->meshBuffer, |
| 2298 | true, !mesh->hasEmptyQuads); |
| 2299 | } |
Romain Guy | 054dc18 | 2010-10-15 17:55:25 -0700 | [diff] [blame] | 2300 | } |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2301 | |
| 2302 | return DrawGlInfo::kStatusDrew; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2305 | status_t OpenGLRenderer::drawVertexBuffer(const VertexBuffer& vertexBuffer, SkPaint* paint, |
| 2306 | bool useOffset) { |
| 2307 | if (!vertexBuffer.getSize()) { |
| 2308 | // no vertices to draw |
| 2309 | return DrawGlInfo::kStatusDone; |
| 2310 | } |
| 2311 | |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2312 | int color = paint->getColor(); |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2313 | SkXfermode::Mode mode = getXfermode(paint->getXfermode()); |
| 2314 | bool isAA = paint->isAntiAlias(); |
| 2315 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2316 | setupDraw(); |
| 2317 | setupDrawNoTexture(); |
| 2318 | if (isAA) setupDrawAA(); |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2319 | setupDrawColor(color, ((color >> 24) & 0xFF) * mSnapshot->alpha); |
| 2320 | setupDrawColorFilter(); |
| 2321 | setupDrawShader(); |
| 2322 | setupDrawBlending(isAA, mode); |
| 2323 | setupDrawProgram(); |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2324 | setupDrawModelViewIdentity(useOffset); |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2325 | setupDrawColorUniforms(); |
| 2326 | setupDrawColorFilterUniforms(); |
| 2327 | setupDrawShaderIdentityUniforms(); |
Chet Haase | 858aa93 | 2011-05-12 09:06:00 -0700 | [diff] [blame] | 2328 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2329 | void* vertices = vertexBuffer.getBuffer(); |
| 2330 | bool force = mCaches.unbindMeshBuffer(); |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2331 | mCaches.bindPositionVertexPointer(true, vertices, isAA ? gAlphaVertexStride : gVertexStride); |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2332 | mCaches.resetTexCoordsVertexPointer(); |
| 2333 | mCaches.unbindIndicesBuffer(); |
Chet Haase | 858aa93 | 2011-05-12 09:06:00 -0700 | [diff] [blame] | 2334 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2335 | int alphaSlot = -1; |
| 2336 | if (isAA) { |
| 2337 | void* alphaCoords = ((GLbyte*) vertices) + gVertexAlphaOffset; |
| 2338 | alphaSlot = mCaches.currentProgram->getAttrib("vtxAlpha"); |
Chris Craik | 6ebdc11 | 2012-08-31 18:24:33 -0700 | [diff] [blame] | 2339 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2340 | // TODO: avoid enable/disable in back to back uses of the alpha attribute |
Chris Craik | 6ebdc11 | 2012-08-31 18:24:33 -0700 | [diff] [blame] | 2341 | glEnableVertexAttribArray(alphaSlot); |
| 2342 | glVertexAttribPointer(alphaSlot, 1, GL_FLOAT, GL_FALSE, gAlphaVertexStride, alphaCoords); |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2343 | } |
Romain Guy | 0429938 | 2012-07-18 17:15:41 -0700 | [diff] [blame] | 2344 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2345 | glDrawArrays(GL_TRIANGLE_STRIP, 0, vertexBuffer.getSize()); |
Romain Guy | 0429938 | 2012-07-18 17:15:41 -0700 | [diff] [blame] | 2346 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2347 | if (isAA) { |
Chris Craik | 6ebdc11 | 2012-08-31 18:24:33 -0700 | [diff] [blame] | 2348 | glDisableVertexAttribArray(alphaSlot); |
Romain Guy | 0429938 | 2012-07-18 17:15:41 -0700 | [diff] [blame] | 2349 | } |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2350 | |
| 2351 | return DrawGlInfo::kStatusDrew; |
Chet Haase | 858aa93 | 2011-05-12 09:06:00 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | /** |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2355 | * Renders a convex path via tessellation. For AA paths, this function uses a similar approach to |
| 2356 | * that of AA lines in the drawLines() function. We expand the convex path by a half pixel in |
| 2357 | * screen space in all directions. However, instead of using a fragment shader to compute the |
| 2358 | * translucency of the color from its position, we simply use a varying parameter to define how far |
| 2359 | * a given pixel is from the edge. For non-AA paths, the expansion and alpha varying are not used. |
| 2360 | * |
| 2361 | * Doesn't yet support joins, caps, or path effects. |
| 2362 | */ |
| 2363 | status_t OpenGLRenderer::drawConvexPath(const SkPath& path, SkPaint* paint) { |
| 2364 | VertexBuffer vertexBuffer; |
| 2365 | // TODO: try clipping large paths to viewport |
| 2366 | PathTessellator::tessellatePath(path, paint, mSnapshot->transform, vertexBuffer); |
| 2367 | |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 2368 | if (hasLayer()) { |
| 2369 | SkRect bounds = path.getBounds(); |
| 2370 | PathTessellator::expandBoundsForStroke(bounds, paint, false); |
| 2371 | dirtyLayer(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, currentTransform()); |
| 2372 | } |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2373 | |
| 2374 | return drawVertexBuffer(vertexBuffer, paint); |
| 2375 | } |
| 2376 | |
| 2377 | /** |
| 2378 | * We create tristrips for the lines much like shape stroke tessellation, using a per-vertex alpha |
| 2379 | * and additional geometry for defining an alpha slope perimeter. |
| 2380 | * |
| 2381 | * Using GL_LINES can be difficult because the rasterization rules for those lines produces some |
| 2382 | * unexpected results, and may vary between hardware devices. Previously we used a varying-base |
| 2383 | * in-shader alpha region, but found it to be taxing on some GPUs. |
| 2384 | * |
| 2385 | * TODO: try using a fixed input buffer for non-capped lines as in text rendering. this may reduce |
| 2386 | * memory transfer by removing need for degenerate vertices. |
Chet Haase | 99ecdc4 | 2011-05-06 12:06:34 -0700 | [diff] [blame] | 2387 | */ |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2388 | status_t OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) { |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2389 | if (mSnapshot->isIgnored() || count < 4) return DrawGlInfo::kStatusDone; |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 2390 | |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2391 | count &= ~0x3; // round down to nearest four |
Romain Guy | 7b63142 | 2012-04-04 11:38:54 -0700 | [diff] [blame] | 2392 | |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2393 | VertexBuffer buffer; |
| 2394 | SkRect bounds; |
| 2395 | PathTessellator::tessellateLines(points, count, paint, mSnapshot->transform, bounds, buffer); |
Romain Guy | d71ff91d | 2013-02-08 13:46:40 -0800 | [diff] [blame] | 2396 | |
| 2397 | if (quickReject(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom)) { |
| 2398 | return DrawGlInfo::kStatusDone; |
| 2399 | } |
| 2400 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2401 | dirtyLayer(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, currentTransform()); |
Romain Guy | 7b63142 | 2012-04-04 11:38:54 -0700 | [diff] [blame] | 2402 | |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2403 | bool useOffset = !paint->isAntiAlias(); |
| 2404 | return drawVertexBuffer(buffer, paint, useOffset); |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2407 | status_t OpenGLRenderer::drawPoints(float* points, int count, SkPaint* paint) { |
| 2408 | if (mSnapshot->isIgnored()) return DrawGlInfo::kStatusDone; |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2409 | |
| 2410 | // TODO: The paint's cap style defines whether the points are square or circular |
| 2411 | // TODO: Handle AA for round points |
| 2412 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 2413 | // A stroke width of 0 has a special meaning in Skia: |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2414 | // it draws an unscaled 1px point |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 2415 | float strokeWidth = paint->getStrokeWidth(); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2416 | const bool isHairLine = paint->getStrokeWidth() == 0.0f; |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 2417 | if (isHairLine) { |
| 2418 | // Now that we know it's hairline, we can set the effective width, to be used later |
| 2419 | strokeWidth = 1.0f; |
| 2420 | } |
| 2421 | const float halfWidth = strokeWidth / 2; |
Romain Guy | d71ff91d | 2013-02-08 13:46:40 -0800 | [diff] [blame] | 2422 | |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2423 | int alpha; |
| 2424 | SkXfermode::Mode mode; |
| 2425 | getAlphaAndMode(paint, &alpha, &mode); |
| 2426 | |
| 2427 | int verticesCount = count >> 1; |
| 2428 | int generatedVerticesCount = 0; |
| 2429 | |
| 2430 | TextureVertex pointsData[verticesCount]; |
| 2431 | TextureVertex* vertex = &pointsData[0]; |
| 2432 | |
Romain Guy | 0429938 | 2012-07-18 17:15:41 -0700 | [diff] [blame] | 2433 | // TODO: We should optimize this method to not generate vertices for points |
| 2434 | // that lie outside of the clip. |
| 2435 | mCaches.enableScissor(); |
| 2436 | |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2437 | setupDraw(); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 2438 | setupDrawNoTexture(); |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 2439 | setupDrawPoint(strokeWidth); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2440 | setupDrawColor(paint->getColor(), alpha); |
| 2441 | setupDrawColorFilter(); |
| 2442 | setupDrawShader(); |
| 2443 | setupDrawBlending(mode); |
| 2444 | setupDrawProgram(); |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 2445 | setupDrawModelViewIdentity(true); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2446 | setupDrawColorUniforms(); |
| 2447 | setupDrawColorFilterUniforms(); |
| 2448 | setupDrawPointUniforms(); |
| 2449 | setupDrawShaderIdentityUniforms(); |
| 2450 | setupDrawMesh(vertex); |
| 2451 | |
| 2452 | for (int i = 0; i < count; i += 2) { |
| 2453 | TextureVertex::set(vertex++, points[i], points[i + 1], 0.0f, 0.0f); |
| 2454 | generatedVerticesCount++; |
Romain Guy | 7b63142 | 2012-04-04 11:38:54 -0700 | [diff] [blame] | 2455 | |
Chet Haase | 8a5cc92 | 2011-04-26 07:28:09 -0700 | [diff] [blame] | 2456 | float left = points[i] - halfWidth; |
| 2457 | float right = points[i] + halfWidth; |
| 2458 | float top = points[i + 1] - halfWidth; |
| 2459 | float bottom = points [i + 1] + halfWidth; |
Romain Guy | 7b63142 | 2012-04-04 11:38:54 -0700 | [diff] [blame] | 2460 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2461 | dirtyLayer(left, top, right, bottom, currentTransform()); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | glDrawArrays(GL_POINTS, 0, generatedVerticesCount); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2465 | |
| 2466 | return DrawGlInfo::kStatusDrew; |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2469 | status_t OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) { |
Romain Guy | e45362c | 2010-11-03 19:58:32 -0700 | [diff] [blame] | 2470 | // No need to check against the clip, we fill the clip region |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2471 | if (mSnapshot->isIgnored()) return DrawGlInfo::kStatusDone; |
Romain Guy | e45362c | 2010-11-03 19:58:32 -0700 | [diff] [blame] | 2472 | |
Romain Guy | ae88e5e | 2010-10-22 17:49:18 -0700 | [diff] [blame] | 2473 | Rect& clip(*mSnapshot->clipRect); |
| 2474 | clip.snapToPixelBoundaries(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 2475 | |
Romain Guy | 3d58c03 | 2010-07-14 16:34:53 -0700 | [diff] [blame] | 2476 | drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2477 | |
| 2478 | return DrawGlInfo::kStatusDrew; |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 2479 | } |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 2480 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2481 | status_t OpenGLRenderer::drawShape(float left, float top, const PathTexture* texture, |
| 2482 | SkPaint* paint) { |
| 2483 | if (!texture) return DrawGlInfo::kStatusDone; |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 2484 | const AutoTexture autoCleanup(texture); |
| 2485 | |
| 2486 | const float x = left + texture->left - texture->offset; |
| 2487 | const float y = top + texture->top - texture->offset; |
| 2488 | |
| 2489 | drawPathTexture(texture, x, y, paint); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2490 | |
| 2491 | return DrawGlInfo::kStatusDrew; |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 2492 | } |
| 2493 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2494 | status_t OpenGLRenderer::drawRoundRect(float left, float top, float right, float bottom, |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2495 | float rx, float ry, SkPaint* p) { |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2496 | if (mSnapshot->isIgnored() || quickRejectPreStroke(left, top, right, bottom, p) || |
| 2497 | (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2498 | return DrawGlInfo::kStatusDone; |
| 2499 | } |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 2500 | |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2501 | if (p->getPathEffect() != 0) { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2502 | mCaches.activeTexture(0); |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 2503 | const PathTexture* texture = mCaches.pathCache.getRoundRect( |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2504 | right - left, bottom - top, rx, ry, p); |
| 2505 | return drawShape(left, top, texture, p); |
| 2506 | } |
| 2507 | |
| 2508 | SkPath path; |
| 2509 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2510 | if (p->getStyle() == SkPaint::kStrokeAndFill_Style) { |
| 2511 | float outset = p->getStrokeWidth() / 2; |
| 2512 | rect.outset(outset, outset); |
| 2513 | rx += outset; |
| 2514 | ry += outset; |
| 2515 | } |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2516 | path.addRoundRect(rect, rx, ry); |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2517 | return drawConvexPath(path, p); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 2518 | } |
| 2519 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2520 | status_t OpenGLRenderer::drawCircle(float x, float y, float radius, SkPaint* p) { |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2521 | if (mSnapshot->isIgnored() || quickRejectPreStroke(x - radius, y - radius, |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2522 | x + radius, y + radius, p) || |
| 2523 | (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2524 | return DrawGlInfo::kStatusDone; |
| 2525 | } |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2526 | if (p->getPathEffect() != 0) { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2527 | mCaches.activeTexture(0); |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 2528 | const PathTexture* texture = mCaches.pathCache.getCircle(radius, p); |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2529 | return drawShape(x - radius, y - radius, texture, p); |
| 2530 | } |
| 2531 | |
| 2532 | SkPath path; |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2533 | if (p->getStyle() == SkPaint::kStrokeAndFill_Style) { |
| 2534 | path.addCircle(x, y, radius + p->getStrokeWidth() / 2); |
| 2535 | } else { |
| 2536 | path.addCircle(x, y, radius); |
| 2537 | } |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2538 | return drawConvexPath(path, p); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 2539 | } |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 2540 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2541 | status_t OpenGLRenderer::drawOval(float left, float top, float right, float bottom, |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2542 | SkPaint* p) { |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2543 | if (mSnapshot->isIgnored() || quickRejectPreStroke(left, top, right, bottom, p) || |
| 2544 | (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2545 | return DrawGlInfo::kStatusDone; |
| 2546 | } |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 2547 | |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2548 | if (p->getPathEffect() != 0) { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2549 | mCaches.activeTexture(0); |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 2550 | const PathTexture* texture = mCaches.pathCache.getOval(right - left, bottom - top, p); |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2551 | return drawShape(left, top, texture, p); |
| 2552 | } |
| 2553 | |
| 2554 | SkPath path; |
| 2555 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 2556 | if (p->getStyle() == SkPaint::kStrokeAndFill_Style) { |
| 2557 | rect.outset(p->getStrokeWidth() / 2, p->getStrokeWidth() / 2); |
| 2558 | } |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2559 | path.addOval(rect); |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2560 | return drawConvexPath(path, p); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 2561 | } |
| 2562 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2563 | status_t OpenGLRenderer::drawArc(float left, float top, float right, float bottom, |
Chris Craik | 780c128 | 2012-10-04 14:10:49 -0700 | [diff] [blame] | 2564 | float startAngle, float sweepAngle, bool useCenter, SkPaint* p) { |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2565 | if (mSnapshot->isIgnored() || quickRejectPreStroke(left, top, right, bottom, p) || |
| 2566 | (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) { |
Chris Craik | 780c128 | 2012-10-04 14:10:49 -0700 | [diff] [blame] | 2567 | return DrawGlInfo::kStatusDone; |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 2568 | } |
| 2569 | |
Chris Craik | 780c128 | 2012-10-04 14:10:49 -0700 | [diff] [blame] | 2570 | if (fabs(sweepAngle) >= 360.0f) { |
| 2571 | return drawOval(left, top, right, bottom, p); |
| 2572 | } |
| 2573 | |
| 2574 | // TODO: support fills (accounting for concavity if useCenter && sweepAngle > 180) |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2575 | if (p->getStyle() != SkPaint::kStroke_Style || p->getPathEffect() != 0 || useCenter) { |
Chris Craik | 780c128 | 2012-10-04 14:10:49 -0700 | [diff] [blame] | 2576 | mCaches.activeTexture(0); |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 2577 | const PathTexture* texture = mCaches.pathCache.getArc(right - left, bottom - top, |
Chris Craik | 780c128 | 2012-10-04 14:10:49 -0700 | [diff] [blame] | 2578 | startAngle, sweepAngle, useCenter, p); |
| 2579 | return drawShape(left, top, texture, p); |
| 2580 | } |
| 2581 | |
| 2582 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
| 2583 | if (p->getStyle() == SkPaint::kStrokeAndFill_Style) { |
| 2584 | rect.outset(p->getStrokeWidth() / 2, p->getStrokeWidth() / 2); |
| 2585 | } |
| 2586 | |
| 2587 | SkPath path; |
| 2588 | if (useCenter) { |
| 2589 | path.moveTo(rect.centerX(), rect.centerY()); |
| 2590 | } |
| 2591 | path.arcTo(rect, startAngle, sweepAngle, !useCenter); |
| 2592 | if (useCenter) { |
| 2593 | path.close(); |
| 2594 | } |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2595 | return drawConvexPath(path, p); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 2596 | } |
| 2597 | |
Romain Guy | cf8675e | 2012-10-02 12:32:25 -0700 | [diff] [blame] | 2598 | // See SkPaintDefaults.h |
| 2599 | #define SkPaintDefaults_MiterLimit SkIntToScalar(4) |
| 2600 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2601 | status_t OpenGLRenderer::drawRect(float left, float top, float right, float bottom, SkPaint* p) { |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2602 | if (mSnapshot->isIgnored() || quickRejectPreStroke(left, top, right, bottom, p) || |
| 2603 | (p->getAlpha() == 0 && getXfermode(p->getXfermode()) != SkXfermode::kClear_Mode)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2604 | return DrawGlInfo::kStatusDone; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2607 | if (p->getStyle() != SkPaint::kFill_Style) { |
Romain Guy | cf8675e | 2012-10-02 12:32:25 -0700 | [diff] [blame] | 2608 | // only fill style is supported by drawConvexPath, since others have to handle joins |
| 2609 | if (p->getPathEffect() != 0 || p->getStrokeJoin() != SkPaint::kMiter_Join || |
| 2610 | p->getStrokeMiter() != SkPaintDefaults_MiterLimit) { |
| 2611 | mCaches.activeTexture(0); |
| 2612 | const PathTexture* texture = |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 2613 | mCaches.pathCache.getRect(right - left, bottom - top, p); |
Romain Guy | cf8675e | 2012-10-02 12:32:25 -0700 | [diff] [blame] | 2614 | return drawShape(left, top, texture, p); |
| 2615 | } |
| 2616 | |
| 2617 | SkPath path; |
| 2618 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
| 2619 | if (p->getStyle() == SkPaint::kStrokeAndFill_Style) { |
| 2620 | rect.outset(p->getStrokeWidth() / 2, p->getStrokeWidth() / 2); |
| 2621 | } |
| 2622 | path.addRect(rect); |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2623 | return drawConvexPath(path, p); |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2626 | if (p->isAntiAlias() && !currentTransform().isSimple()) { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2627 | SkPath path; |
| 2628 | path.addRect(left, top, right, bottom); |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2629 | return drawConvexPath(path, p); |
Chet Haase | 858aa93 | 2011-05-12 09:06:00 -0700 | [diff] [blame] | 2630 | } else { |
Chris Craik | 710f46d | 2012-09-17 17:25:49 -0700 | [diff] [blame] | 2631 | drawColorRect(left, top, right, bottom, p->getColor(), getXfermode(p->getXfermode())); |
Chris Craik | 65cd612 | 2012-12-10 17:56:27 -0800 | [diff] [blame] | 2632 | return DrawGlInfo::kStatusDrew; |
Chet Haase | 858aa93 | 2011-05-12 09:06:00 -0700 | [diff] [blame] | 2633 | } |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 2634 | } |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 2635 | |
Raph Levien | 416a847 | 2012-07-19 22:48:17 -0700 | [diff] [blame] | 2636 | void OpenGLRenderer::drawTextShadow(SkPaint* paint, const char* text, int bytesCount, int count, |
| 2637 | const float* positions, FontRenderer& fontRenderer, int alpha, SkXfermode::Mode mode, |
| 2638 | float x, float y) { |
| 2639 | mCaches.activeTexture(0); |
| 2640 | |
| 2641 | // NOTE: The drop shadow will not perform gamma correction |
| 2642 | // if shader-based correction is enabled |
| 2643 | mCaches.dropShadowCache.setFontRenderer(fontRenderer); |
| 2644 | const ShadowTexture* shadow = mCaches.dropShadowCache.get( |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 2645 | paint, text, bytesCount, count, mDrawModifiers.mShadowRadius, positions); |
Raph Levien | 416a847 | 2012-07-19 22:48:17 -0700 | [diff] [blame] | 2646 | const AutoTexture autoCleanup(shadow); |
| 2647 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 2648 | const float sx = x - shadow->left + mDrawModifiers.mShadowDx; |
| 2649 | const float sy = y - shadow->top + mDrawModifiers.mShadowDy; |
Raph Levien | 416a847 | 2012-07-19 22:48:17 -0700 | [diff] [blame] | 2650 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 2651 | const int shadowAlpha = ((mDrawModifiers.mShadowColor >> 24) & 0xFF) * mSnapshot->alpha; |
| 2652 | int shadowColor = mDrawModifiers.mShadowColor; |
| 2653 | if (mDrawModifiers.mShader) { |
Raph Levien | 416a847 | 2012-07-19 22:48:17 -0700 | [diff] [blame] | 2654 | shadowColor = 0xffffffff; |
| 2655 | } |
| 2656 | |
| 2657 | setupDraw(); |
| 2658 | setupDrawWithTexture(true); |
| 2659 | setupDrawAlpha8Color(shadowColor, shadowAlpha < 255 ? shadowAlpha : alpha); |
| 2660 | setupDrawColorFilter(); |
| 2661 | setupDrawShader(); |
| 2662 | setupDrawBlending(true, mode); |
| 2663 | setupDrawProgram(); |
| 2664 | setupDrawModelView(sx, sy, sx + shadow->width, sy + shadow->height); |
| 2665 | setupDrawTexture(shadow->id); |
| 2666 | setupDrawPureColorUniforms(); |
| 2667 | setupDrawColorFilterUniforms(); |
| 2668 | setupDrawShaderUniforms(); |
| 2669 | setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset); |
| 2670 | |
| 2671 | glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); |
| 2672 | } |
| 2673 | |
Romain Guy | 768bffc | 2013-02-27 13:50:45 -0800 | [diff] [blame] | 2674 | bool OpenGLRenderer::canSkipText(const SkPaint* paint) const { |
| 2675 | float alpha = (mDrawModifiers.mHasShadow ? 1.0f : paint->getAlpha()) * mSnapshot->alpha; |
| 2676 | return alpha == 0.0f && getXfermode(paint->getXfermode()) == SkXfermode::kSrcOver_Mode; |
| 2677 | } |
| 2678 | |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2679 | class TextSetupFunctor: public Functor { |
| 2680 | public: |
| 2681 | TextSetupFunctor(OpenGLRenderer& renderer, float x, float y, bool pureTranslate, |
| 2682 | int alpha, SkXfermode::Mode mode, SkPaint* paint): Functor(), |
| 2683 | renderer(renderer), x(x), y(y), pureTranslate(pureTranslate), |
| 2684 | alpha(alpha), mode(mode), paint(paint) { |
| 2685 | } |
| 2686 | ~TextSetupFunctor() { } |
| 2687 | |
| 2688 | status_t operator ()(int what, void* data) { |
| 2689 | renderer.setupDraw(); |
| 2690 | renderer.setupDrawTextGamma(paint); |
| 2691 | renderer.setupDrawDirtyRegionsDisabled(); |
| 2692 | renderer.setupDrawWithTexture(true); |
| 2693 | renderer.setupDrawAlpha8Color(paint->getColor(), alpha); |
| 2694 | renderer.setupDrawColorFilter(); |
| 2695 | renderer.setupDrawShader(); |
| 2696 | renderer.setupDrawBlending(true, mode); |
| 2697 | renderer.setupDrawProgram(); |
| 2698 | renderer.setupDrawModelView(x, y, x, y, pureTranslate, true); |
| 2699 | // Calling setupDrawTexture with the name 0 will enable the |
| 2700 | // uv attributes and increase the texture unit count |
| 2701 | // texture binding will be performed by the font renderer as |
| 2702 | // needed |
| 2703 | renderer.setupDrawTexture(0); |
| 2704 | renderer.setupDrawPureColorUniforms(); |
| 2705 | renderer.setupDrawColorFilterUniforms(); |
| 2706 | renderer.setupDrawShaderUniforms(pureTranslate); |
| 2707 | renderer.setupDrawTextGammaUniforms(); |
| 2708 | |
| 2709 | return NO_ERROR; |
| 2710 | } |
| 2711 | |
| 2712 | OpenGLRenderer& renderer; |
| 2713 | float x; |
| 2714 | float y; |
| 2715 | bool pureTranslate; |
| 2716 | int alpha; |
| 2717 | SkXfermode::Mode mode; |
| 2718 | SkPaint* paint; |
| 2719 | }; |
| 2720 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2721 | status_t OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count, |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 2722 | const float* positions, SkPaint* paint) { |
Romain Guy | 768bffc | 2013-02-27 13:50:45 -0800 | [diff] [blame] | 2723 | if (text == NULL || count == 0 || mSnapshot->isIgnored() || canSkipText(paint)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2724 | return DrawGlInfo::kStatusDone; |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 2725 | } |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 2726 | |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2727 | // NOTE: Skia does not support perspective transform on drawPosText yet |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2728 | if (!currentTransform().isSimple()) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2729 | return DrawGlInfo::kStatusDone; |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | float x = 0.0f; |
| 2733 | float y = 0.0f; |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2734 | const bool pureTranslate = currentTransform().isPureTranslate(); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2735 | if (pureTranslate) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2736 | x = (int) floorf(x + currentTransform().getTranslateX() + 0.5f); |
| 2737 | y = (int) floorf(y + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2738 | } |
| 2739 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 2740 | FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(paint); |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 2741 | fontRenderer.setFont(paint, mat4::identity()); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2742 | |
| 2743 | int alpha; |
| 2744 | SkXfermode::Mode mode; |
| 2745 | getAlphaAndMode(paint, &alpha, &mode); |
| 2746 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 2747 | if (CC_UNLIKELY(mDrawModifiers.mHasShadow)) { |
Romain Guy | e3a9b24 | 2013-01-08 11:15:30 -0800 | [diff] [blame] | 2748 | drawTextShadow(paint, text, bytesCount, count, positions, fontRenderer, |
| 2749 | alpha, mode, 0.0f, 0.0f); |
Raph Levien | 416a847 | 2012-07-19 22:48:17 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2752 | // Pick the appropriate texture filtering |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2753 | bool linearFilter = currentTransform().changesBounds(); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2754 | if (pureTranslate && !linearFilter) { |
| 2755 | linearFilter = fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f; |
| 2756 | } |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2757 | fontRenderer.setTextureFiltering(linearFilter); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2758 | |
| 2759 | const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip(); |
| 2760 | Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); |
| 2761 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 2762 | const bool hasActiveLayer = hasLayer(); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2763 | |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2764 | TextSetupFunctor functor(*this, x, y, pureTranslate, alpha, mode, paint); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2765 | if (fontRenderer.renderPosText(paint, clip, text, 0, bytesCount, count, x, y, |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2766 | positions, hasActiveLayer ? &bounds : NULL, &functor)) { |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2767 | if (hasActiveLayer) { |
| 2768 | if (!pureTranslate) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2769 | currentTransform().mapRect(bounds); |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2770 | } |
| 2771 | dirtyLayerUnchecked(bounds, getRegion()); |
| 2772 | } |
Romain Guy | 671d6cf | 2012-01-18 12:39:17 -0800 | [diff] [blame] | 2773 | } |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2774 | |
| 2775 | return DrawGlInfo::kStatusDrew; |
Romain Guy | eb9a536 | 2012-01-17 17:39:26 -0800 | [diff] [blame] | 2776 | } |
| 2777 | |
Romain Guy | 624234f | 2013-03-05 16:43:31 -0800 | [diff] [blame] | 2778 | mat4 OpenGLRenderer::findBestFontTransform(const mat4& transform) const { |
| 2779 | mat4 fontTransform; |
| 2780 | if (CC_LIKELY(transform.isPureTranslate())) { |
| 2781 | fontTransform = mat4::identity(); |
| 2782 | } else { |
| 2783 | if (CC_UNLIKELY(transform.isPerspective())) { |
Romain Guy | b09f147 | 2013-03-07 17:01:05 -0800 | [diff] [blame] | 2784 | fontTransform = mat4::identity(); |
Romain Guy | 624234f | 2013-03-05 16:43:31 -0800 | [diff] [blame] | 2785 | } else { |
| 2786 | float sx, sy; |
| 2787 | currentTransform().decomposeScale(sx, sy); |
| 2788 | fontTransform.loadScale(sx, sy, 1.0f); |
| 2789 | } |
| 2790 | } |
| 2791 | return fontTransform; |
| 2792 | } |
| 2793 | |
Romain Guy | c252595 | 2012-07-27 16:41:22 -0700 | [diff] [blame] | 2794 | status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 2795 | float x, float y, const float* positions, SkPaint* paint, float length) { |
Romain Guy | 768bffc | 2013-02-27 13:50:45 -0800 | [diff] [blame] | 2796 | if (text == NULL || count == 0 || mSnapshot->isIgnored() || canSkipText(paint)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2797 | return DrawGlInfo::kStatusDone; |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 2798 | } |
| 2799 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 2800 | if (length < 0.0f) length = paint->measureText(text, bytesCount); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 2801 | switch (paint->getTextAlign()) { |
| 2802 | case SkPaint::kCenter_Align: |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 2803 | x -= length / 2.0f; |
| 2804 | break; |
| 2805 | case SkPaint::kRight_Align: |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 2806 | x -= length; |
| 2807 | break; |
| 2808 | default: |
| 2809 | break; |
| 2810 | } |
| 2811 | |
Romain Guy | cac5fd3 | 2011-12-01 20:08:50 -0800 | [diff] [blame] | 2812 | SkPaint::FontMetrics metrics; |
| 2813 | paint->getFontMetrics(&metrics, 0.0f); |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 2814 | if (quickReject(x, y + metrics.fTop, x + length, y + metrics.fBottom)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2815 | return DrawGlInfo::kStatusDone; |
Romain Guy | cac5fd3 | 2011-12-01 20:08:50 -0800 | [diff] [blame] | 2816 | } |
| 2817 | |
Romain Guy | 3a3fa1b | 2010-12-06 18:47:50 -0800 | [diff] [blame] | 2818 | const float oldX = x; |
| 2819 | const float oldY = y; |
Romain Guy | 624234f | 2013-03-05 16:43:31 -0800 | [diff] [blame] | 2820 | |
| 2821 | const mat4& transform = currentTransform(); |
| 2822 | const bool pureTranslate = transform.isPureTranslate(); |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 2823 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 2824 | if (CC_LIKELY(pureTranslate)) { |
Romain Guy | 624234f | 2013-03-05 16:43:31 -0800 | [diff] [blame] | 2825 | x = (int) floorf(x + transform.getTranslateX() + 0.5f); |
| 2826 | y = (int) floorf(y + transform.getTranslateY() + 0.5f); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2827 | } |
| 2828 | |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 2829 | int alpha; |
| 2830 | SkXfermode::Mode mode; |
| 2831 | getAlphaAndMode(paint, &alpha, &mode); |
Romain Guy | 9d13fe25 | 2010-10-15 16:06:03 -0700 | [diff] [blame] | 2832 | |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 2833 | FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(paint); |
| 2834 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 2835 | if (CC_UNLIKELY(mDrawModifiers.mHasShadow)) { |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 2836 | fontRenderer.setFont(paint, mat4::identity()); |
| 2837 | drawTextShadow(paint, text, bytesCount, count, positions, fontRenderer, |
| 2838 | alpha, mode, oldX, oldY); |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 2839 | } |
| 2840 | |
Romain Guy | 19d4dd8 | 2013-03-04 11:14:26 -0800 | [diff] [blame] | 2841 | const bool hasActiveLayer = hasLayer(); |
| 2842 | |
Romain Guy | 624234f | 2013-03-05 16:43:31 -0800 | [diff] [blame] | 2843 | // We only pass a partial transform to the font renderer. That partial |
| 2844 | // matrix defines how glyphs are rasterized. Typically we want glyphs |
| 2845 | // to be rasterized at their final size on screen, which means the partial |
| 2846 | // matrix needs to take the scale factor into account. |
| 2847 | // When a partial matrix is used to transform glyphs during rasterization, |
| 2848 | // the mesh is generated with the inverse transform (in the case of scale, |
| 2849 | // the mesh is generated at 1.0 / scale for instance.) This allows us to |
| 2850 | // apply the full transform matrix at draw time in the vertex shader. |
| 2851 | // Applying the full matrix in the shader is the easiest way to handle |
| 2852 | // rotation and perspective and allows us to always generated quads in the |
| 2853 | // font renderer which greatly simplifies the code, clipping in particular. |
| 2854 | mat4 fontTransform = findBestFontTransform(transform); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2855 | fontRenderer.setFont(paint, fontTransform); |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 2856 | |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 2857 | // Pick the appropriate texture filtering |
Romain Guy | a4adcf0 | 2013-02-28 12:15:35 -0800 | [diff] [blame] | 2858 | bool linearFilter = !pureTranslate || fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f; |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2859 | fontRenderer.setTextureFiltering(linearFilter); |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 2860 | |
Romain Guy | 624234f | 2013-03-05 16:43:31 -0800 | [diff] [blame] | 2861 | // TODO: Implement better clipping for scaled/rotated text |
| 2862 | const Rect* clip = !pureTranslate ? NULL : mSnapshot->clipRect; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 2863 | Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); |
| 2864 | |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 2865 | bool status; |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2866 | TextSetupFunctor functor(*this, x, y, pureTranslate, alpha, mode, paint); |
Romain Guy | a3dc55f | 2012-09-28 13:55:44 -0700 | [diff] [blame] | 2867 | if (CC_UNLIKELY(paint->getTextAlign() != SkPaint::kLeft_Align)) { |
Raph Levien | 8b4072d | 2012-07-30 15:50:00 -0700 | [diff] [blame] | 2868 | SkPaint paintCopy(*paint); |
| 2869 | paintCopy.setTextAlign(SkPaint::kLeft_Align); |
| 2870 | status = fontRenderer.renderPosText(&paintCopy, clip, text, 0, bytesCount, count, x, y, |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2871 | positions, hasActiveLayer ? &bounds : NULL, &functor); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 2872 | } else { |
Raph Levien | 8b4072d | 2012-07-30 15:50:00 -0700 | [diff] [blame] | 2873 | status = fontRenderer.renderPosText(paint, clip, text, 0, bytesCount, count, x, y, |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2874 | positions, hasActiveLayer ? &bounds : NULL, &functor); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 2875 | } |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 2876 | |
| 2877 | if (status && hasActiveLayer) { |
Romain Guy | 624234f | 2013-03-05 16:43:31 -0800 | [diff] [blame] | 2878 | if (!pureTranslate) { |
| 2879 | transform.mapRect(bounds); |
Romain Guy | a4adcf0 | 2013-02-28 12:15:35 -0800 | [diff] [blame] | 2880 | } |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 2881 | dirtyLayerUnchecked(bounds, getRegion()); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 2882 | } |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 2883 | |
Romain Guy | 3a3fa1b | 2010-12-06 18:47:50 -0800 | [diff] [blame] | 2884 | drawTextDecorations(text, bytesCount, length, oldX, oldY, paint); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2885 | |
| 2886 | return DrawGlInfo::kStatusDrew; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2889 | status_t OpenGLRenderer::drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path, |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 2890 | float hOffset, float vOffset, SkPaint* paint) { |
Romain Guy | 768bffc | 2013-02-27 13:50:45 -0800 | [diff] [blame] | 2891 | if (text == NULL || count == 0 || mSnapshot->isIgnored() || canSkipText(paint)) { |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2892 | return DrawGlInfo::kStatusDone; |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 2893 | } |
| 2894 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 2895 | FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(paint); |
Romain Guy | c74f45a | 2013-02-26 19:10:14 -0800 | [diff] [blame] | 2896 | fontRenderer.setFont(paint, mat4::identity()); |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2897 | fontRenderer.setTextureFiltering(true); |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 2898 | |
| 2899 | int alpha; |
| 2900 | SkXfermode::Mode mode; |
| 2901 | getAlphaAndMode(paint, &alpha, &mode); |
| 2902 | |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 2903 | setupDraw(); |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 2904 | setupDrawTextGamma(paint); |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 2905 | setupDrawDirtyRegionsDisabled(); |
| 2906 | setupDrawWithTexture(true); |
| 2907 | setupDrawAlpha8Color(paint->getColor(), alpha); |
| 2908 | setupDrawColorFilter(); |
| 2909 | setupDrawShader(); |
| 2910 | setupDrawBlending(true, mode); |
| 2911 | setupDrawProgram(); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2912 | setupDrawModelView(0.0f, 0.0f, 0.0f, 0.0f, false, true); |
Romain Guy | 257ae35 | 2013-03-20 16:31:12 -0700 | [diff] [blame] | 2913 | // Calling setupDrawTexture with the name 0 will enable the |
| 2914 | // uv attributes and increase the texture unit count |
| 2915 | // texture binding will be performed by the font renderer as |
| 2916 | // needed |
| 2917 | setupDrawTexture(0); |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 2918 | setupDrawPureColorUniforms(); |
| 2919 | setupDrawColorFilterUniforms(); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2920 | setupDrawShaderUniforms(false); |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 2921 | setupDrawTextGammaUniforms(); |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 2922 | |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2923 | const Rect* clip = &mSnapshot->getLocalClip(); |
| 2924 | Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); |
Romain Guy | 03d5852 | 2012-02-24 17:54:07 -0800 | [diff] [blame] | 2925 | |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2926 | const bool hasActiveLayer = hasLayer(); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2927 | |
| 2928 | if (fontRenderer.renderTextOnPath(paint, clip, text, 0, bytesCount, count, path, |
| 2929 | hOffset, vOffset, hasActiveLayer ? &bounds : NULL)) { |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2930 | if (hasActiveLayer) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2931 | currentTransform().mapRect(bounds); |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2932 | dirtyLayerUnchecked(bounds, getRegion()); |
| 2933 | } |
Romain Guy | 9777173 | 2012-02-28 18:17:02 -0800 | [diff] [blame] | 2934 | } |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2935 | |
| 2936 | return DrawGlInfo::kStatusDrew; |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 2937 | } |
| 2938 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2939 | status_t OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) { |
| 2940 | if (mSnapshot->isIgnored()) return DrawGlInfo::kStatusDone; |
Romain Guy | dbc26d2 | 2010-10-11 17:58:29 -0700 | [diff] [blame] | 2941 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 2942 | mCaches.activeTexture(0); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 2943 | |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 2944 | const PathTexture* texture = mCaches.pathCache.get(path, paint); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2945 | if (!texture) return DrawGlInfo::kStatusDone; |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 2946 | const AutoTexture autoCleanup(texture); |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 2947 | |
Romain Guy | 8b55f37 | 2010-08-18 17:10:07 -0700 | [diff] [blame] | 2948 | const float x = texture->left - texture->offset; |
| 2949 | const float y = texture->top - texture->offset; |
| 2950 | |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 2951 | drawPathTexture(texture, x, y, paint); |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2952 | |
| 2953 | return DrawGlInfo::kStatusDrew; |
Romain Guy | 7fbcc04 | 2010-08-04 15:40:07 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 2956 | status_t OpenGLRenderer::drawLayer(Layer* layer, float x, float y) { |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 2957 | if (!layer) { |
| 2958 | return DrawGlInfo::kStatusDone; |
| 2959 | } |
| 2960 | |
Romain Guy | b2e2f24 | 2012-10-17 18:18:35 -0700 | [diff] [blame] | 2961 | mat4* transform = NULL; |
| 2962 | if (layer->isTextureLayer()) { |
| 2963 | transform = &layer->getTransform(); |
| 2964 | if (!transform->isIdentity()) { |
| 2965 | save(0); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 2966 | currentTransform().multiply(*transform); |
Romain Guy | b2e2f24 | 2012-10-17 18:18:35 -0700 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | |
Romain Guy | 35643dd | 2012-09-18 15:40:58 -0700 | [diff] [blame] | 2970 | Rect transformed; |
| 2971 | Rect clip; |
| 2972 | const bool rejected = quickRejectNoScissor(x, y, |
| 2973 | x + layer->layer.getWidth(), y + layer->layer.getHeight(), transformed, clip); |
| 2974 | |
| 2975 | if (rejected) { |
Romain Guy | b2e2f24 | 2012-10-17 18:18:35 -0700 | [diff] [blame] | 2976 | if (transform && !transform->isIdentity()) { |
| 2977 | restore(); |
| 2978 | } |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 2979 | return DrawGlInfo::kStatusDone; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2980 | } |
| 2981 | |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 2982 | updateLayer(layer, true); |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 2983 | |
Romain Guy | 87e2f757 | 2012-09-24 11:37:12 -0700 | [diff] [blame] | 2984 | mCaches.setScissorEnabled(mScissorOptimizationDisabled || !clip.contains(transformed)); |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 2985 | mCaches.activeTexture(0); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2986 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 2987 | if (CC_LIKELY(!layer->region.isEmpty())) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 2988 | SkiaColorFilter* oldFilter = mDrawModifiers.mColorFilter; |
| 2989 | mDrawModifiers.mColorFilter = layer->getColorFilter(); |
Romain Guy | e529ece | 2012-09-26 11:23:17 -0700 | [diff] [blame] | 2990 | |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 2991 | if (layer->region.isRect()) { |
Romain Guy | 4066767 | 2011-03-18 14:34:03 -0700 | [diff] [blame] | 2992 | composeLayerRect(layer, layer->regionRect); |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 2993 | } else if (layer->mesh) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 2994 | const float a = layer->getAlpha() / 255.0f * mSnapshot->alpha; |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 2995 | setupDraw(); |
| 2996 | setupDrawWithTexture(); |
Romain Guy | 8168396 | 2011-01-24 20:40:18 -0800 | [diff] [blame] | 2997 | setupDrawColor(a, a, a, a); |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 2998 | setupDrawColorFilter(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 2999 | setupDrawBlending(layer->isBlend() || a < 1.0f, layer->getMode(), false); |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 3000 | setupDrawProgram(); |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 3001 | setupDrawPureColorUniforms(); |
| 3002 | setupDrawColorFilterUniforms(); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 3003 | setupDrawTexture(layer->getTexture()); |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3004 | if (CC_LIKELY(currentTransform().isPureTranslate())) { |
| 3005 | int tx = (int) floorf(x + currentTransform().getTranslateX() + 0.5f); |
| 3006 | int ty = (int) floorf(y + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 3007 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 3008 | layer->setFilter(GL_NEAREST); |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 3009 | setupDrawModelViewTranslate(tx, ty, |
| 3010 | tx + layer->layer.getWidth(), ty + layer->layer.getHeight(), true); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 3011 | } else { |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 3012 | layer->setFilter(GL_LINEAR); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 3013 | setupDrawModelViewTranslate(x, y, |
| 3014 | x + layer->layer.getWidth(), y + layer->layer.getHeight()); |
| 3015 | } |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 3016 | setupDrawMesh(&layer->mesh[0].position[0], &layer->mesh[0].texture[0]); |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 3017 | |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 3018 | glDrawElements(GL_TRIANGLES, layer->meshElementCount, |
| 3019 | GL_UNSIGNED_SHORT, layer->meshIndices); |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 3020 | |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 3021 | finishDrawTexture(); |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 3022 | |
| 3023 | #if DEBUG_LAYERS_AS_REGIONS |
| 3024 | drawRegionRects(layer->region); |
| 3025 | #endif |
Romain Guy | c88e357 | 2011-01-22 00:32:12 -0800 | [diff] [blame] | 3026 | } |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 3027 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3028 | mDrawModifiers.mColorFilter = oldFilter; |
Romain Guy | e529ece | 2012-09-26 11:23:17 -0700 | [diff] [blame] | 3029 | |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 3030 | if (layer->debugDrawUpdate) { |
| 3031 | layer->debugDrawUpdate = false; |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 3032 | drawColorRect(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight(), |
| 3033 | 0x7f00ff00, SkXfermode::kSrcOver_Mode); |
| 3034 | } |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 3035 | } |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 3036 | |
Romain Guy | b2e2f24 | 2012-10-17 18:18:35 -0700 | [diff] [blame] | 3037 | if (transform && !transform->isIdentity()) { |
| 3038 | restore(); |
| 3039 | } |
| 3040 | |
Chet Haase | 4865909 | 2012-05-31 15:21:51 -0700 | [diff] [blame] | 3041 | return DrawGlInfo::kStatusDrew; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 3042 | } |
| 3043 | |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 3044 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 3045 | // Shaders |
| 3046 | /////////////////////////////////////////////////////////////////////////////// |
| 3047 | |
| 3048 | void OpenGLRenderer::resetShader() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3049 | mDrawModifiers.mShader = NULL; |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 3050 | } |
| 3051 | |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 3052 | void OpenGLRenderer::setupShader(SkiaShader* shader) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3053 | mDrawModifiers.mShader = shader; |
| 3054 | if (mDrawModifiers.mShader) { |
| 3055 | mDrawModifiers.mShader->set(&mCaches.textureCache, &mCaches.gradientCache); |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 3056 | } |
Romain Guy | 7fac2e1 | 2010-07-16 17:10:13 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 3059 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 3060 | // Color filters |
| 3061 | /////////////////////////////////////////////////////////////////////////////// |
| 3062 | |
| 3063 | void OpenGLRenderer::resetColorFilter() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3064 | mDrawModifiers.mColorFilter = NULL; |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | void OpenGLRenderer::setupColorFilter(SkiaColorFilter* filter) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3068 | mDrawModifiers.mColorFilter = filter; |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 3072 | // Drop shadow |
| 3073 | /////////////////////////////////////////////////////////////////////////////// |
| 3074 | |
| 3075 | void OpenGLRenderer::resetShadow() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3076 | mDrawModifiers.mHasShadow = false; |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3080 | mDrawModifiers.mHasShadow = true; |
| 3081 | mDrawModifiers.mShadowRadius = radius; |
| 3082 | mDrawModifiers.mShadowDx = dx; |
| 3083 | mDrawModifiers.mShadowDy = dy; |
| 3084 | mDrawModifiers.mShadowColor = color; |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 3088 | // Draw filters |
| 3089 | /////////////////////////////////////////////////////////////////////////////// |
| 3090 | |
| 3091 | void OpenGLRenderer::resetPaintFilter() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3092 | mDrawModifiers.mHasDrawFilter = false; |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | void OpenGLRenderer::setupPaintFilter(int clearBits, int setBits) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3096 | mDrawModifiers.mHasDrawFilter = true; |
| 3097 | mDrawModifiers.mPaintFilterClearBits = clearBits & SkPaint::kAllFlags; |
| 3098 | mDrawModifiers.mPaintFilterSetBits = setBits & SkPaint::kAllFlags; |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 3099 | } |
| 3100 | |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 3101 | SkPaint* OpenGLRenderer::filterPaint(SkPaint* paint) { |
Romain Guy | 758724f | 2013-02-27 11:53:12 -0800 | [diff] [blame] | 3102 | if (CC_LIKELY(!mDrawModifiers.mHasDrawFilter || !paint)) { |
Romain Guy | 758724f | 2013-02-27 11:53:12 -0800 | [diff] [blame] | 3103 | return paint; |
| 3104 | } |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 3105 | |
| 3106 | uint32_t flags = paint->getFlags(); |
| 3107 | |
| 3108 | mFilteredPaint = *paint; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3109 | mFilteredPaint.setFlags((flags & ~mDrawModifiers.mPaintFilterClearBits) | |
| 3110 | mDrawModifiers.mPaintFilterSetBits); |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 3111 | |
| 3112 | return &mFilteredPaint; |
| 3113 | } |
| 3114 | |
| 3115 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 3116 | // Drawing implementation |
| 3117 | /////////////////////////////////////////////////////////////////////////////// |
| 3118 | |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 3119 | void OpenGLRenderer::drawPathTexture(const PathTexture* texture, |
| 3120 | float x, float y, SkPaint* paint) { |
| 3121 | if (quickReject(x, y, x + texture->width, y + texture->height)) { |
| 3122 | return; |
| 3123 | } |
| 3124 | |
| 3125 | int alpha; |
| 3126 | SkXfermode::Mode mode; |
| 3127 | getAlphaAndMode(paint, &alpha, &mode); |
| 3128 | |
| 3129 | setupDraw(); |
| 3130 | setupDrawWithTexture(true); |
| 3131 | setupDrawAlpha8Color(paint->getColor(), alpha); |
| 3132 | setupDrawColorFilter(); |
| 3133 | setupDrawShader(); |
| 3134 | setupDrawBlending(true, mode); |
| 3135 | setupDrawProgram(); |
| 3136 | setupDrawModelView(x, y, x + texture->width, y + texture->height); |
| 3137 | setupDrawTexture(texture->id); |
| 3138 | setupDrawPureColorUniforms(); |
| 3139 | setupDrawColorFilterUniforms(); |
| 3140 | setupDrawShaderUniforms(); |
| 3141 | setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset); |
| 3142 | |
| 3143 | glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); |
| 3144 | |
| 3145 | finishDrawTexture(); |
| 3146 | } |
| 3147 | |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 3148 | // Same values used by Skia |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3149 | #define kStdStrikeThru_Offset (-6.0f / 21.0f) |
| 3150 | #define kStdUnderline_Offset (1.0f / 9.0f) |
| 3151 | #define kStdUnderline_Thickness (1.0f / 18.0f) |
| 3152 | |
| 3153 | void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float length, |
| 3154 | float x, float y, SkPaint* paint) { |
| 3155 | // Handle underline and strike-through |
| 3156 | uint32_t flags = paint->getFlags(); |
| 3157 | if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) { |
Romain Guy | 726aeba | 2011-06-01 14:52:00 -0700 | [diff] [blame] | 3158 | SkPaint paintCopy(*paint); |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3159 | float underlineWidth = length; |
| 3160 | // If length is > 0.0f, we already measured the text for the text alignment |
| 3161 | if (length <= 0.0f) { |
Romain Guy | 726aeba | 2011-06-01 14:52:00 -0700 | [diff] [blame] | 3162 | underlineWidth = paintCopy.measureText(text, bytesCount); |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 3165 | if (CC_LIKELY(underlineWidth > 0.0f)) { |
Romain Guy | 726aeba | 2011-06-01 14:52:00 -0700 | [diff] [blame] | 3166 | const float textSize = paintCopy.getTextSize(); |
Romain Guy | f683447 | 2011-01-23 13:32:12 -0800 | [diff] [blame] | 3167 | const float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f); |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3168 | |
Raph Levien | 8b4072d | 2012-07-30 15:50:00 -0700 | [diff] [blame] | 3169 | const float left = x; |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3170 | float top = 0.0f; |
Romain Guy | e20ecbd | 2010-09-22 19:49:04 -0700 | [diff] [blame] | 3171 | |
Romain Guy | f683447 | 2011-01-23 13:32:12 -0800 | [diff] [blame] | 3172 | int linesCount = 0; |
| 3173 | if (flags & SkPaint::kUnderlineText_Flag) linesCount++; |
| 3174 | if (flags & SkPaint::kStrikeThruText_Flag) linesCount++; |
| 3175 | |
| 3176 | const int pointsCount = 4 * linesCount; |
Romain Guy | e20ecbd | 2010-09-22 19:49:04 -0700 | [diff] [blame] | 3177 | float points[pointsCount]; |
| 3178 | int currentPoint = 0; |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3179 | |
| 3180 | if (flags & SkPaint::kUnderlineText_Flag) { |
| 3181 | top = y + textSize * kStdUnderline_Offset; |
Romain Guy | e20ecbd | 2010-09-22 19:49:04 -0700 | [diff] [blame] | 3182 | points[currentPoint++] = left; |
| 3183 | points[currentPoint++] = top; |
| 3184 | points[currentPoint++] = left + underlineWidth; |
| 3185 | points[currentPoint++] = top; |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | if (flags & SkPaint::kStrikeThruText_Flag) { |
| 3189 | top = y + textSize * kStdStrikeThru_Offset; |
Romain Guy | e20ecbd | 2010-09-22 19:49:04 -0700 | [diff] [blame] | 3190 | points[currentPoint++] = left; |
| 3191 | points[currentPoint++] = top; |
| 3192 | points[currentPoint++] = left + underlineWidth; |
| 3193 | points[currentPoint++] = top; |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3194 | } |
Romain Guy | e20ecbd | 2010-09-22 19:49:04 -0700 | [diff] [blame] | 3195 | |
Romain Guy | 726aeba | 2011-06-01 14:52:00 -0700 | [diff] [blame] | 3196 | paintCopy.setStrokeWidth(strokeWidth); |
Romain Guy | e20ecbd | 2010-09-22 19:49:04 -0700 | [diff] [blame] | 3197 | |
Romain Guy | 726aeba | 2011-06-01 14:52:00 -0700 | [diff] [blame] | 3198 | drawLines(&points[0], pointsCount, &paintCopy); |
Romain Guy | 0a41749 | 2010-08-16 20:26:20 -0700 | [diff] [blame] | 3199 | } |
| 3200 | } |
| 3201 | } |
| 3202 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3203 | status_t OpenGLRenderer::drawRects(const float* rects, int count, SkPaint* paint) { |
| 3204 | if (mSnapshot->isIgnored()) { |
| 3205 | return DrawGlInfo::kStatusDone; |
| 3206 | } |
| 3207 | |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 3208 | int color = paint->getColor(); |
| 3209 | // If a shader is set, preserve only the alpha |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3210 | if (mDrawModifiers.mShader) { |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 3211 | color |= 0x00ffffff; |
| 3212 | } |
| 3213 | SkXfermode::Mode mode = getXfermode(paint->getXfermode()); |
| 3214 | |
| 3215 | return drawColorRects(rects, count, color, mode); |
| 3216 | } |
| 3217 | |
| 3218 | status_t OpenGLRenderer::drawColorRects(const float* rects, int count, int color, |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 3219 | SkXfermode::Mode mode, bool ignoreTransform, bool dirty, bool clip) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3220 | if (count == 0) { |
| 3221 | return DrawGlInfo::kStatusDone; |
| 3222 | } |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 3223 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3224 | float left = FLT_MAX; |
| 3225 | float top = FLT_MAX; |
| 3226 | float right = FLT_MIN; |
| 3227 | float bottom = FLT_MIN; |
| 3228 | |
| 3229 | int vertexCount = 0; |
| 3230 | Vertex mesh[count * 6]; |
| 3231 | Vertex* vertex = mesh; |
| 3232 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 3233 | for (int index = 0; index < count; index += 4) { |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3234 | float l = rects[index + 0]; |
| 3235 | float t = rects[index + 1]; |
| 3236 | float r = rects[index + 2]; |
| 3237 | float b = rects[index + 3]; |
| 3238 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3239 | Vertex::set(vertex++, l, b); |
| 3240 | Vertex::set(vertex++, l, t); |
| 3241 | Vertex::set(vertex++, r, t); |
| 3242 | Vertex::set(vertex++, l, b); |
| 3243 | Vertex::set(vertex++, r, t); |
| 3244 | Vertex::set(vertex++, r, b); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3245 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3246 | vertexCount += 6; |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3247 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3248 | left = fminf(left, l); |
| 3249 | top = fminf(top, t); |
| 3250 | right = fmaxf(right, r); |
| 3251 | bottom = fmaxf(bottom, b); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3252 | } |
| 3253 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3254 | if (clip && quickReject(left, top, right, bottom)) { |
Romain Guy | a362c69 | 2013-02-04 13:50:16 -0800 | [diff] [blame] | 3255 | return DrawGlInfo::kStatusDone; |
| 3256 | } |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3257 | |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3258 | setupDraw(); |
| 3259 | setupDrawNoTexture(); |
| 3260 | setupDrawColor(color, ((color >> 24) & 0xFF) * mSnapshot->alpha); |
| 3261 | setupDrawShader(); |
| 3262 | setupDrawColorFilter(); |
| 3263 | setupDrawBlending(mode); |
| 3264 | setupDrawProgram(); |
| 3265 | setupDrawDirtyRegionsDisabled(); |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 3266 | setupDrawModelView(0.0f, 0.0f, 1.0f, 1.0f, ignoreTransform, true); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3267 | setupDrawColorUniforms(); |
| 3268 | setupDrawShaderUniforms(); |
| 3269 | setupDrawColorFilterUniforms(); |
| 3270 | setupDrawVertices((GLvoid*) &mesh[0].position[0]); |
| 3271 | |
Romain Guy | 8ce0030 | 2013-01-15 18:51:42 -0800 | [diff] [blame] | 3272 | if (dirty && hasLayer()) { |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3273 | dirtyLayer(left, top, right, bottom, currentTransform()); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | glDrawArrays(GL_TRIANGLES, 0, vertexCount); |
| 3277 | |
| 3278 | return DrawGlInfo::kStatusDrew; |
| 3279 | } |
| 3280 | |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 3281 | void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom, |
Romain Guy | 1c740bc | 2010-09-13 18:00:09 -0700 | [diff] [blame] | 3282 | int color, SkXfermode::Mode mode, bool ignoreTransform) { |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 3283 | // If a shader is set, preserve only the alpha |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 3284 | if (mDrawModifiers.mShader) { |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 3285 | color |= 0x00ffffff; |
| 3286 | } |
| 3287 | |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3288 | setupDraw(); |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 3289 | setupDrawNoTexture(); |
Romain Guy | 9c0b188 | 2012-07-13 12:13:07 -0700 | [diff] [blame] | 3290 | setupDrawColor(color, ((color >> 24) & 0xFF) * mSnapshot->alpha); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3291 | setupDrawShader(); |
| 3292 | setupDrawColorFilter(); |
| 3293 | setupDrawBlending(mode); |
| 3294 | setupDrawProgram(); |
| 3295 | setupDrawModelView(left, top, right, bottom, ignoreTransform); |
| 3296 | setupDrawColorUniforms(); |
| 3297 | setupDrawShaderUniforms(ignoreTransform); |
| 3298 | setupDrawColorFilterUniforms(); |
| 3299 | setupDrawSimpleMesh(); |
Romain Guy | c0ac193 | 2010-07-19 18:43:02 -0700 | [diff] [blame] | 3300 | |
Romain Guy | c95c8d6 | 2010-09-17 15:31:32 -0700 | [diff] [blame] | 3301 | glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); |
| 3302 | } |
| 3303 | |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3304 | void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom, |
Romain Guy | 8164c2d | 2010-10-25 18:03:28 -0700 | [diff] [blame] | 3305 | Texture* texture, SkPaint* paint) { |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3306 | int alpha; |
| 3307 | SkXfermode::Mode mode; |
| 3308 | getAlphaAndMode(paint, &alpha, &mode); |
| 3309 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 3310 | texture->setWrap(GL_CLAMP_TO_EDGE, true); |
Romain Guy | 8164c2d | 2010-10-25 18:03:28 -0700 | [diff] [blame] | 3311 | |
Romain Guy | 3b75382 | 2013-03-05 10:27:35 -0800 | [diff] [blame] | 3312 | if (CC_LIKELY(currentTransform().isPureTranslate())) { |
| 3313 | const float x = (int) floorf(left + currentTransform().getTranslateX() + 0.5f); |
| 3314 | const float y = (int) floorf(top + currentTransform().getTranslateY() + 0.5f); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 3315 | |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 3316 | texture->setFilter(GL_NEAREST, true); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 3317 | drawTextureMesh(x, y, x + texture->width, y + texture->height, texture->id, |
| 3318 | alpha / 255.0f, mode, texture->blend, (GLvoid*) NULL, |
| 3319 | (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount, false, true); |
| 3320 | } else { |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 3321 | texture->setFilter(FILTER(paint), true); |
Romain Guy | 6620c6d | 2010-12-06 18:07:02 -0800 | [diff] [blame] | 3322 | drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode, |
| 3323 | texture->blend, (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset, |
| 3324 | GL_TRIANGLE_STRIP, gMeshCount); |
| 3325 | } |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 3328 | void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom, |
Romain Guy | a979474 | 2010-07-13 11:37:54 -0700 | [diff] [blame] | 3329 | GLuint texture, float alpha, SkXfermode::Mode mode, bool blend) { |
| 3330 | drawTextureMesh(left, top, right, bottom, texture, alpha, mode, blend, |
Romain Guy | 03750a0 | 2010-10-18 14:06:08 -0700 | [diff] [blame] | 3331 | (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount); |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float bottom, |
Romain Guy | a979474 | 2010-07-13 11:37:54 -0700 | [diff] [blame] | 3335 | GLuint texture, float alpha, SkXfermode::Mode mode, bool blend, |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 3336 | GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 3337 | bool swapSrcDst, bool ignoreTransform, GLuint vbo, bool ignoreScale, bool dirty) { |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3338 | |
Romain Guy | 746b740 | 2010-10-26 16:27:31 -0700 | [diff] [blame] | 3339 | setupDraw(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3340 | setupDrawWithTexture(); |
| 3341 | setupDrawColor(alpha, alpha, alpha, alpha); |
| 3342 | setupDrawColorFilter(); |
| 3343 | setupDrawBlending(blend, mode, swapSrcDst); |
| 3344 | setupDrawProgram(); |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 3345 | if (!dirty) setupDrawDirtyRegionsDisabled(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 3346 | if (!ignoreScale) { |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3347 | setupDrawModelView(left, top, right, bottom, ignoreTransform); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 3348 | } else { |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3349 | setupDrawModelViewTranslate(left, top, right, bottom, ignoreTransform); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 3350 | } |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 3351 | setupDrawTexture(texture); |
Romain Guy | 8656819 | 2010-12-14 15:55:39 -0800 | [diff] [blame] | 3352 | setupDrawPureColorUniforms(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3353 | setupDrawColorFilterUniforms(); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3354 | setupDrawMesh(vertices, texCoords, vbo); |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 3355 | |
Romain Guy | 6820ac8 | 2010-09-15 18:11:50 -0700 | [diff] [blame] | 3356 | glDrawArrays(drawMode, 0, elementsCount); |
Romain Guy | 70ca14e | 2010-12-13 18:24:33 -0800 | [diff] [blame] | 3357 | |
| 3358 | finishDrawTexture(); |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
Romain Guy | 886b275 | 2013-01-04 12:26:18 -0800 | [diff] [blame] | 3361 | void OpenGLRenderer::drawAlpha8TextureMesh(float left, float top, float right, float bottom, |
| 3362 | GLuint texture, bool hasColor, int color, int alpha, SkXfermode::Mode mode, |
| 3363 | GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount, |
| 3364 | bool ignoreTransform, bool dirty) { |
| 3365 | |
| 3366 | setupDraw(); |
| 3367 | setupDrawWithTexture(true); |
| 3368 | if (hasColor) { |
| 3369 | setupDrawAlpha8Color(color, alpha); |
| 3370 | } |
| 3371 | setupDrawColorFilter(); |
| 3372 | setupDrawShader(); |
| 3373 | setupDrawBlending(true, mode); |
| 3374 | setupDrawProgram(); |
| 3375 | if (!dirty) setupDrawDirtyRegionsDisabled(); |
| 3376 | setupDrawModelView(left, top, right, bottom, ignoreTransform); |
| 3377 | setupDrawTexture(texture); |
| 3378 | setupDrawPureColorUniforms(); |
| 3379 | setupDrawColorFilterUniforms(); |
| 3380 | setupDrawShaderUniforms(); |
| 3381 | setupDrawMesh(vertices, texCoords); |
| 3382 | |
| 3383 | glDrawArrays(drawMode, 0, elementsCount); |
| 3384 | |
| 3385 | finishDrawTexture(); |
| 3386 | } |
| 3387 | |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame] | 3388 | void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode, |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 3389 | ProgramDescription& description, bool swapSrcDst) { |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3390 | blend = blend || mode != SkXfermode::kSrcOver_Mode; |
Romain Guy | c189ef5 | 2012-04-25 20:02:53 -0700 | [diff] [blame] | 3391 | |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3392 | if (blend) { |
Romain Guy | 82bc7a7 | 2012-01-03 14:13:39 -0800 | [diff] [blame] | 3393 | // These blend modes are not supported by OpenGL directly and have |
| 3394 | // to be implemented using shaders. Since the shader will perform |
| 3395 | // the blending, turn blending off here |
| 3396 | // If the blend mode cannot be implemented using shaders, fall |
| 3397 | // back to the default SrcOver blend mode instead |
Romain Guy | 33fa1f7 | 2012-08-07 19:09:57 -0700 | [diff] [blame] | 3398 | if (CC_UNLIKELY(mode > SkXfermode::kScreen_Mode)) { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 3399 | if (CC_UNLIKELY(mExtensions.hasFramebufferFetch())) { |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame] | 3400 | description.framebufferMode = mode; |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 3401 | description.swapSrcDst = swapSrcDst; |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame] | 3402 | |
Romain Guy | 82bc7a7 | 2012-01-03 14:13:39 -0800 | [diff] [blame] | 3403 | if (mCaches.blend) { |
| 3404 | glDisable(GL_BLEND); |
| 3405 | mCaches.blend = false; |
| 3406 | } |
| 3407 | |
| 3408 | return; |
| 3409 | } else { |
| 3410 | mode = SkXfermode::kSrcOver_Mode; |
Romain Guy | a5aed0d | 2010-09-09 14:42:43 -0700 | [diff] [blame] | 3411 | } |
Romain Guy | 82bc7a7 | 2012-01-03 14:13:39 -0800 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | if (!mCaches.blend) { |
| 3415 | glEnable(GL_BLEND); |
| 3416 | } |
| 3417 | |
| 3418 | GLenum sourceMode = swapSrcDst ? gBlendsSwap[mode].src : gBlends[mode].src; |
| 3419 | GLenum destMode = swapSrcDst ? gBlendsSwap[mode].dst : gBlends[mode].dst; |
| 3420 | |
| 3421 | if (sourceMode != mCaches.lastSrcMode || destMode != mCaches.lastDstMode) { |
| 3422 | glBlendFunc(sourceMode, destMode); |
| 3423 | mCaches.lastSrcMode = sourceMode; |
| 3424 | mCaches.lastDstMode = destMode; |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3425 | } |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 3426 | } else if (mCaches.blend) { |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3427 | glDisable(GL_BLEND); |
| 3428 | } |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 3429 | mCaches.blend = blend; |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
Romain Guy | 889f8d1 | 2010-07-29 14:37:42 -0700 | [diff] [blame] | 3432 | bool OpenGLRenderer::useProgram(Program* program) { |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 3433 | if (!program->isInUse()) { |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 3434 | if (mCaches.currentProgram != NULL) mCaches.currentProgram->remove(); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 3435 | program->use(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 3436 | mCaches.currentProgram = program; |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 3437 | return false; |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 3438 | } |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 3439 | return true; |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 3442 | void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) { |
Romain Guy | ac670c0 | 2010-07-27 17:39:27 -0700 | [diff] [blame] | 3443 | TextureVertex* v = &mMeshVertices[0]; |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 3444 | TextureVertex::setUV(v++, u1, v1); |
| 3445 | TextureVertex::setUV(v++, u2, v1); |
| 3446 | TextureVertex::setUV(v++, u1, v2); |
| 3447 | TextureVertex::setUV(v++, u2, v2); |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 3450 | void OpenGLRenderer::getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) { |
Romain Guy | be6f9dc | 2012-07-16 12:41:17 -0700 | [diff] [blame] | 3451 | getAlphaAndModeDirect(paint, alpha, mode); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 3452 | *alpha *= mSnapshot->alpha; |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 3455 | }; // namespace uirenderer |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 3456 | }; // namespace android |