Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -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 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 17 | #include "DisplayListCanvas.h" |
| 18 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 19 | #include "DeferredDisplayList.h" |
| 20 | #include "DeferredLayerUpdater.h" |
| 21 | #include "DisplayListOp.h" |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 22 | #include "ResourceCache.h" |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 23 | #include "RenderNode.h" |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 24 | #include "VectorDrawable.h" |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 25 | #include "utils/PaintUtils.h" |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 26 | |
Romain Guy | d5a85fb | 2012-03-13 11:18:20 -0700 | [diff] [blame] | 27 | #include <SkCamera.h> |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 28 | #include <SkCanvas.h> |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 29 | |
Romain Guy | 6554943 | 2012-03-26 16:45:05 -0700 | [diff] [blame] | 30 | #include <private/hwui/DrawGlInfo.h> |
| 31 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | namespace uirenderer { |
| 34 | |
Derek Sollenberger | cc882b6 | 2015-07-09 15:51:20 -0400 | [diff] [blame] | 35 | DisplayListCanvas::DisplayListCanvas(int width, int height) |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 36 | : mState(*this) |
John Reck | 088c514 | 2014-11-06 13:04:49 -0800 | [diff] [blame] | 37 | , mResourceCache(ResourceCache::getInstance()) |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 38 | , mDisplayList(nullptr) |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 39 | , mTranslateX(0.0f) |
| 40 | , mTranslateY(0.0f) |
Rob Tsuk | a5f2e07 | 2014-11-17 12:57:32 -0800 | [diff] [blame] | 41 | , mHasDeferredTranslate(false) |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 42 | , mDeferredBarrierType(kBarrier_None) |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 43 | , mHighContrastText(false) |
| 44 | , mRestoreSaveCount(-1) { |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 45 | resetRecording(width, height); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 48 | DisplayListCanvas::~DisplayListCanvas() { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 49 | LOG_ALWAYS_FATAL_IF(mDisplayList, |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 50 | "Destroyed a DisplayListCanvas during a record!"); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Derek Sollenberger | 6f48556 | 2015-07-30 10:00:39 -0400 | [diff] [blame] | 53 | void DisplayListCanvas::resetRecording(int width, int height) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 54 | LOG_ALWAYS_FATAL_IF(mDisplayList, |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 55 | "prepareDirty called a second time during a recording!"); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 56 | mDisplayList = new DisplayList(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 57 | |
Chris Craik | 64e445b | 2015-09-02 14:23:49 -0700 | [diff] [blame] | 58 | mState.initializeSaveStack(width, height, |
| 59 | 0, 0, width, height, Vector3()); |
Romain Guy | 45e4c3d | 2012-09-11 17:17:07 -0700 | [diff] [blame] | 60 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 61 | mDeferredBarrierType = kBarrier_InOrder; |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 62 | mState.setDirtyClip(false); |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 63 | mRestoreSaveCount = -1; |
| 64 | } |
| 65 | |
Derek Sollenberger | cc882b6 | 2015-07-09 15:51:20 -0400 | [diff] [blame] | 66 | |
| 67 | /////////////////////////////////////////////////////////////////////////////// |
| 68 | // Operations |
| 69 | /////////////////////////////////////////////////////////////////////////////// |
| 70 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 71 | DisplayList* DisplayListCanvas::finishRecording() { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 72 | flushRestoreToCount(); |
| 73 | flushTranslate(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 74 | |
Derek Sollenberger | cc882b6 | 2015-07-09 15:51:20 -0400 | [diff] [blame] | 75 | mPaintMap.clear(); |
| 76 | mRegionMap.clear(); |
| 77 | mPathMap.clear(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 78 | DisplayList* displayList = mDisplayList; |
| 79 | mDisplayList = nullptr; |
Derek Sollenberger | cc882b6 | 2015-07-09 15:51:20 -0400 | [diff] [blame] | 80 | mSkiaCanvasProxy.reset(nullptr); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 81 | return displayList; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 84 | void DisplayListCanvas::callDrawGLFunction(Functor *functor) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 85 | addDrawOp(new (alloc()) DrawFunctorOp(functor)); |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 86 | mDisplayList->functors.push_back(functor); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 89 | SkCanvas* DisplayListCanvas::asSkCanvas() { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 90 | LOG_ALWAYS_FATAL_IF(!mDisplayList, |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 91 | "attempting to get an SkCanvas when we are not recording!"); |
| 92 | if (!mSkiaCanvasProxy) { |
| 93 | mSkiaCanvasProxy.reset(new SkiaCanvasProxy(this)); |
| 94 | } |
Tom Hudson | 90fb1f6 | 2015-06-24 09:13:50 -0400 | [diff] [blame] | 95 | |
| 96 | // SkCanvas instances default to identity transform, but should inherit |
| 97 | // the state of this Canvas; if this code was in the SkiaCanvasProxy |
| 98 | // constructor, we couldn't cache mSkiaCanvasProxy. |
| 99 | SkMatrix parentTransform; |
| 100 | getMatrix(&parentTransform); |
| 101 | mSkiaCanvasProxy.get()->setMatrix(parentTransform); |
| 102 | |
Derek Sollenberger | 1db141f | 2014-12-16 08:37:20 -0500 | [diff] [blame] | 103 | return mSkiaCanvasProxy.get(); |
| 104 | } |
| 105 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 106 | int DisplayListCanvas::save(SaveFlags::Flags flags) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 107 | addStateOp(new (alloc()) SaveOp((int) flags)); |
| 108 | return mState.save((int) flags); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 111 | void DisplayListCanvas::restore() { |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 112 | if (mRestoreSaveCount < 0) { |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 113 | restoreToCount(getSaveCount() - 1); |
| 114 | return; |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 115 | } |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 116 | |
| 117 | mRestoreSaveCount--; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 118 | flushTranslate(); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 119 | mState.restore(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 122 | void DisplayListCanvas::restoreToCount(int saveCount) { |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 123 | mRestoreSaveCount = saveCount; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 124 | flushTranslate(); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 125 | mState.restoreToCount(saveCount); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 128 | int DisplayListCanvas::saveLayer(float left, float top, float right, float bottom, |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 129 | const SkPaint* paint, SaveFlags::Flags flags) { |
Chris Craik | 4ace730 | 2014-09-14 15:49:54 -0700 | [diff] [blame] | 130 | // force matrix/clip isolation for layer |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 131 | flags |= SaveFlags::MatrixClip; |
Chris Craik | 4ace730 | 2014-09-14 15:49:54 -0700 | [diff] [blame] | 132 | |
Derek Sollenberger | d44fbe5 | 2014-02-05 16:47:00 -0500 | [diff] [blame] | 133 | paint = refPaint(paint); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 134 | addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, paint, (int) flags)); |
| 135 | return mState.save((int) flags); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 138 | void DisplayListCanvas::translate(float dx, float dy) { |
Chris Craik | 772687d | 2015-06-22 14:51:18 -0700 | [diff] [blame] | 139 | if (dx == 0.0f && dy == 0.0f) return; |
| 140 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 141 | mHasDeferredTranslate = true; |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 142 | mTranslateX += dx; |
| 143 | mTranslateY += dy; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 144 | flushRestoreToCount(); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 145 | mState.translate(dx, dy, 0.0f); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 148 | void DisplayListCanvas::rotate(float degrees) { |
Chris Craik | 772687d | 2015-06-22 14:51:18 -0700 | [diff] [blame] | 149 | if (degrees == 0.0f) return; |
| 150 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 151 | addStateOp(new (alloc()) RotateOp(degrees)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 152 | mState.rotate(degrees); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 155 | void DisplayListCanvas::scale(float sx, float sy) { |
Chris Craik | 772687d | 2015-06-22 14:51:18 -0700 | [diff] [blame] | 156 | if (sx == 1.0f && sy == 1.0f) return; |
| 157 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 158 | addStateOp(new (alloc()) ScaleOp(sx, sy)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 159 | mState.scale(sx, sy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 162 | void DisplayListCanvas::skew(float sx, float sy) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 163 | addStateOp(new (alloc()) SkewOp(sx, sy)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 164 | mState.skew(sx, sy); |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 167 | void DisplayListCanvas::setMatrix(const SkMatrix& matrix) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 168 | addStateOp(new (alloc()) SetMatrixOp(matrix)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 169 | mState.setMatrix(matrix); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 172 | void DisplayListCanvas::concat(const SkMatrix& matrix) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 173 | addStateOp(new (alloc()) ConcatMatrixOp(matrix)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 174 | mState.concatMatrix(matrix); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 177 | bool DisplayListCanvas::getClipBounds(SkRect* outRect) const { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 178 | Rect bounds = mState.getLocalClipBounds(); |
| 179 | *outRect = SkRect::MakeLTRB(bounds.left, bounds.top, bounds.right, bounds.bottom); |
| 180 | return !(outRect->isEmpty()); |
| 181 | } |
| 182 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 183 | bool DisplayListCanvas::quickRejectRect(float left, float top, float right, float bottom) const { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 184 | return mState.quickRejectConservative(left, top, right, bottom); |
| 185 | } |
| 186 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 187 | bool DisplayListCanvas::quickRejectPath(const SkPath& path) const { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 188 | SkRect bounds = path.getBounds(); |
| 189 | return mState.quickRejectConservative(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 190 | } |
| 191 | |
| 192 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 193 | bool DisplayListCanvas::clipRect(float left, float top, float right, float bottom, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 194 | SkRegion::Op op) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 195 | addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 196 | return mState.clipRect(left, top, right, bottom, op); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 199 | bool DisplayListCanvas::clipPath(const SkPath* path, SkRegion::Op op) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 200 | path = refPath(path); |
| 201 | addStateOp(new (alloc()) ClipPathOp(path, op)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 202 | return mState.clipPath(path, op); |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 205 | bool DisplayListCanvas::clipRegion(const SkRegion* region, SkRegion::Op op) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 206 | region = refRegion(region); |
| 207 | addStateOp(new (alloc()) ClipRegionOp(region, op)); |
Tom Hudson | 984162f | 2014-10-10 13:38:16 -0400 | [diff] [blame] | 208 | return mState.clipRegion(region, op); |
Romain Guy | 735738c | 2012-12-03 12:34:51 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 211 | void DisplayListCanvas::drawRenderNode(RenderNode* renderNode) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 212 | LOG_ALWAYS_FATAL_IF(!renderNode, "missing rendernode"); |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 213 | DrawRenderNodeOp* op = new (alloc()) DrawRenderNodeOp( |
| 214 | renderNode, |
| 215 | *mState.currentTransform(), |
| 216 | mState.clipIsSimple()); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 217 | addRenderNodeOp(op); |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 220 | void DisplayListCanvas::drawLayer(DeferredLayerUpdater* layerHandle) { |
John Reck | 12f5e34 | 2014-11-07 07:53:43 -0800 | [diff] [blame] | 221 | // We ref the DeferredLayerUpdater due to its thread-safe ref-counting |
| 222 | // semantics. |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 223 | mDisplayList->ref(layerHandle); |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 224 | addDrawOp(new (alloc()) DrawLayerOp(layerHandle->backingLayer())); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 227 | void DisplayListCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 228 | bitmap = refBitmap(*bitmap); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 229 | paint = refPaint(paint); |
| 230 | |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 231 | addDrawOp(new (alloc()) DrawBitmapOp(bitmap, paint)); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 234 | void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float left, float top, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 235 | const SkPaint* paint) { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 236 | save(SaveFlags::Matrix); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 237 | translate(left, top); |
| 238 | drawBitmap(&bitmap, paint); |
| 239 | restore(); |
| 240 | } |
| 241 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 242 | void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 243 | const SkPaint* paint) { |
| 244 | if (matrix.isIdentity()) { |
| 245 | drawBitmap(&bitmap, paint); |
Chris Craik | e688bf7 | 2015-08-18 14:52:52 -0700 | [diff] [blame] | 246 | } else if (!(matrix.getType() & ~(SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) |
| 247 | && MathUtils::isPositive(matrix.getScaleX()) |
| 248 | && MathUtils::isPositive(matrix.getScaleY())) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 249 | // SkMatrix::isScaleTranslate() not available in L |
| 250 | SkRect src; |
| 251 | SkRect dst; |
| 252 | bitmap.getBounds(&src); |
| 253 | matrix.mapRect(&dst, src); |
| 254 | drawBitmap(bitmap, src.fLeft, src.fTop, src.fRight, src.fBottom, |
| 255 | dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, paint); |
| 256 | } else { |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 257 | save(SaveFlags::Matrix); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 258 | concat(matrix); |
| 259 | drawBitmap(&bitmap, paint); |
| 260 | restore(); |
| 261 | } |
| 262 | } |
| 263 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 264 | void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 265 | float srcRight, float srcBottom, float dstLeft, float dstTop, |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 266 | float dstRight, float dstBottom, const SkPaint* paint) { |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 267 | if (srcLeft == 0 && srcTop == 0 |
Chris Craik | 14100ac | 2015-02-24 13:46:29 -0800 | [diff] [blame] | 268 | && srcRight == bitmap.width() |
| 269 | && srcBottom == bitmap.height() |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 270 | && (srcBottom - srcTop == dstBottom - dstTop) |
| 271 | && (srcRight - srcLeft == dstRight - dstLeft)) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 272 | // transform simple rect to rect drawing case into position bitmap ops, since they merge |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 273 | save(SaveFlags::Matrix); |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 274 | translate(dstLeft, dstTop); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 275 | drawBitmap(&bitmap, paint); |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 276 | restore(); |
| 277 | } else { |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 278 | paint = refPaint(paint); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 279 | |
Chris Craik | 14100ac | 2015-02-24 13:46:29 -0800 | [diff] [blame] | 280 | if (paint && paint->getShader()) { |
| 281 | float scaleX = (dstRight - dstLeft) / (srcRight - srcLeft); |
| 282 | float scaleY = (dstBottom - dstTop) / (srcBottom - srcTop); |
| 283 | if (!MathUtils::areEqual(scaleX, 1.0f) || !MathUtils::areEqual(scaleY, 1.0f)) { |
| 284 | // Apply the scale transform on the canvas, so that the shader |
| 285 | // effectively calculates positions relative to src rect space |
| 286 | |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 287 | save(SaveFlags::Matrix); |
Chris Craik | 14100ac | 2015-02-24 13:46:29 -0800 | [diff] [blame] | 288 | translate(dstLeft, dstTop); |
| 289 | scale(scaleX, scaleY); |
| 290 | |
| 291 | dstLeft = 0.0f; |
| 292 | dstTop = 0.0f; |
| 293 | dstRight = srcRight - srcLeft; |
| 294 | dstBottom = srcBottom - srcTop; |
| 295 | |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 296 | addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(bitmap), |
Chris Craik | 14100ac | 2015-02-24 13:46:29 -0800 | [diff] [blame] | 297 | srcLeft, srcTop, srcRight, srcBottom, |
| 298 | dstLeft, dstTop, dstRight, dstBottom, paint)); |
| 299 | restore(); |
| 300 | return; |
| 301 | } |
| 302 | } |
| 303 | |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 304 | addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(bitmap), |
Chris Craik | 7964750 | 2014-08-06 13:42:24 -0700 | [diff] [blame] | 305 | srcLeft, srcTop, srcRight, srcBottom, |
| 306 | dstLeft, dstTop, dstRight, dstBottom, paint)); |
| 307 | } |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 310 | void DisplayListCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 311 | const float* vertices, const int* colors, const SkPaint* paint) { |
Chris Craik | 0664fef | 2014-04-11 13:40:05 -0700 | [diff] [blame] | 312 | int vertexCount = (meshWidth + 1) * (meshHeight + 1); |
Chris Craik | 0664fef | 2014-04-11 13:40:05 -0700 | [diff] [blame] | 313 | vertices = refBuffer<float>(vertices, vertexCount * 2); // 2 floats per vertex |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 314 | paint = refPaint(paint); |
Chris Craik | 0664fef | 2014-04-11 13:40:05 -0700 | [diff] [blame] | 315 | colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 316 | |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 317 | addDrawOp(new (alloc()) DrawBitmapMeshOp(refBitmap(bitmap), meshWidth, meshHeight, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 318 | vertices, colors, paint)); |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 321 | void DisplayListCanvas::drawNinePatch(const SkBitmap& bitmap, const Res_png_9patch& patch, |
| 322 | float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) { |
John Reck | 7c103a3 | 2015-04-15 15:52:10 -0700 | [diff] [blame] | 323 | const SkBitmap* bitmapPtr = refBitmap(bitmap); |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 324 | const Res_png_9patch* patchPtr = refPatch(&patch); |
Romain Guy | 16ea8d3 | 2013-06-21 11:35:52 -0700 | [diff] [blame] | 325 | paint = refPaint(paint); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 326 | |
Derek Sollenberger | 4c5efe9 | 2015-07-10 13:56:39 -0400 | [diff] [blame] | 327 | addDrawOp(new (alloc()) DrawPatchOp(bitmapPtr, patchPtr, |
| 328 | dstLeft, dstTop, dstRight, dstBottom, paint)); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 331 | void DisplayListCanvas::drawColor(int color, SkXfermode::Mode mode) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 332 | addDrawOp(new (alloc()) DrawColorOp(color, mode)); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 335 | void DisplayListCanvas::drawPaint(const SkPaint& paint) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 336 | SkRect bounds; |
| 337 | if (getClipBounds(&bounds)) { |
| 338 | drawRect(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, paint); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 343 | void DisplayListCanvas::drawRect(float left, float top, float right, float bottom, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 344 | const SkPaint& paint) { |
| 345 | addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, refPaint(&paint))); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 348 | void DisplayListCanvas::drawRoundRect(float left, float top, float right, float bottom, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 349 | float rx, float ry, const SkPaint& paint) { |
| 350 | addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, refPaint(&paint))); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 353 | void DisplayListCanvas::drawRoundRect( |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 354 | CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top, |
| 355 | CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom, |
| 356 | CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry, |
| 357 | CanvasPropertyPaint* paint) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 358 | mDisplayList->ref(left); |
| 359 | mDisplayList->ref(top); |
| 360 | mDisplayList->ref(right); |
| 361 | mDisplayList->ref(bottom); |
| 362 | mDisplayList->ref(rx); |
| 363 | mDisplayList->ref(ry); |
| 364 | mDisplayList->ref(paint); |
John Reck | 37b0824 | 2015-06-09 13:12:40 -0700 | [diff] [blame] | 365 | refBitmapsInShader(paint->value.getShader()); |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 366 | addDrawOp(new (alloc()) DrawRoundRectPropsOp(&left->value, &top->value, |
| 367 | &right->value, &bottom->value, &rx->value, &ry->value, &paint->value)); |
Jorim Jaggi | 072707d | 2014-09-15 17:20:08 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 370 | void DisplayListCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 371 | addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, refPaint(&paint))); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 374 | void DisplayListCanvas::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y, |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 375 | CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 376 | mDisplayList->ref(x); |
| 377 | mDisplayList->ref(y); |
| 378 | mDisplayList->ref(radius); |
| 379 | mDisplayList->ref(paint); |
John Reck | 37b0824 | 2015-06-09 13:12:40 -0700 | [diff] [blame] | 380 | refBitmapsInShader(paint->value.getShader()); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 381 | addDrawOp(new (alloc()) DrawCirclePropsOp(&x->value, &y->value, |
| 382 | &radius->value, &paint->value)); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 385 | void DisplayListCanvas::drawOval(float left, float top, float right, float bottom, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 386 | const SkPaint& paint) { |
| 387 | addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, refPaint(&paint))); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 390 | void DisplayListCanvas::drawArc(float left, float top, float right, float bottom, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 391 | float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) { |
Chris Craik | 544e524 | 2014-07-11 10:58:10 -0700 | [diff] [blame] | 392 | if (fabs(sweepAngle) >= 360.0f) { |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 393 | drawOval(left, top, right, bottom, paint); |
| 394 | } else { |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 395 | addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 396 | startAngle, sweepAngle, useCenter, refPaint(&paint))); |
Chris Craik | 6ac174b | 2014-06-17 13:47:05 -0700 | [diff] [blame] | 397 | } |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 400 | void DisplayListCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 401 | addDrawOp(new (alloc()) DrawPathOp(refPath(&path), refPaint(&paint))); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 404 | void DisplayListCanvas::drawLines(const float* points, int count, const SkPaint& paint) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 405 | points = refBuffer<float>(points, count); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 406 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 407 | addDrawOp(new (alloc()) DrawLinesOp(points, count, refPaint(&paint))); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 410 | void DisplayListCanvas::drawPoints(const float* points, int count, const SkPaint& paint) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 411 | points = refBuffer<float>(points, count); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 412 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 413 | addDrawOp(new (alloc()) DrawPointsOp(points, count, refPaint(&paint))); |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 416 | void DisplayListCanvas::drawVectorDrawable(VectorDrawableRoot* tree) { |
| 417 | mDisplayList->ref(tree); |
Doris Liu | 14b56a5 | 2016-02-26 11:36:03 -0800 | [diff] [blame] | 418 | addDrawOp(new (alloc()) DrawVectorDrawableOp(tree)); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 419 | } |
| 420 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 421 | void DisplayListCanvas::drawGlyphsOnPath(const uint16_t* glyphs, int count, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 422 | const SkPath& path, float hOffset, float vOffset, const SkPaint& paint) { |
| 423 | if (!glyphs || count <= 0) return; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 424 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 425 | int bytesCount = 2 * count; |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 426 | DrawOp* op = new (alloc()) DrawTextOnPathOp(refBuffer<glyph_t>(glyphs, count), |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 427 | bytesCount, count, refPath(&path), |
| 428 | hOffset, vOffset, refPaint(&paint)); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 429 | addDrawOp(op); |
Romain Guy | 325740f | 2012-02-24 16:48:34 -0800 | [diff] [blame] | 430 | } |
| 431 | |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 432 | void DisplayListCanvas::drawGlyphs(const uint16_t* glyphs, const float* positions, |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 433 | int count, const SkPaint& paint, float x, float y, |
| 434 | float boundsLeft, float boundsTop, float boundsRight, float boundsBottom, |
| 435 | float totalAdvance) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 436 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 437 | if (!glyphs || count <= 0 || PaintUtils::paintWillNotDrawText(paint)) return; |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 438 | |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 439 | int bytesCount = count * 2; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 440 | positions = refBuffer<float>(positions, count * 2); |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 441 | Rect bounds(boundsLeft, boundsTop, boundsRight, boundsBottom); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 442 | |
Chris Craik | e8c3c81 | 2016-02-05 20:10:50 -0800 | [diff] [blame] | 443 | DrawOp* op = new (alloc()) DrawTextOp(refBuffer<glyph_t>(glyphs, count), bytesCount, count, |
Derek Sollenberger | 6578a98 | 2015-07-13 13:24:29 -0400 | [diff] [blame] | 444 | x, y, positions, refPaint(&paint), totalAdvance, bounds); |
| 445 | addDrawOp(op); |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 446 | drawTextDecorations(x, y, totalAdvance, paint); |
Raph Levien | 996e57c | 2012-07-23 15:22:52 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Derek Sollenberger | 94394b3 | 2015-07-10 09:58:41 -0400 | [diff] [blame] | 449 | void DisplayListCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) { |
| 450 | if (paint.getStyle() != SkPaint::kFill_Style || |
| 451 | (paint.isAntiAlias() && !mState.currentTransform()->isSimple())) { |
| 452 | SkRegion::Iterator it(region); |
| 453 | while (!it.done()) { |
| 454 | const SkIRect& r = it.rect(); |
| 455 | drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); |
| 456 | it.next(); |
| 457 | } |
| 458 | } else { |
| 459 | int count = 0; |
| 460 | Vector<float> rects; |
| 461 | SkRegion::Iterator it(region); |
| 462 | while (!it.done()) { |
| 463 | const SkIRect& r = it.rect(); |
| 464 | rects.push(r.fLeft); |
| 465 | rects.push(r.fTop); |
| 466 | rects.push(r.fRight); |
| 467 | rects.push(r.fBottom); |
| 468 | count += 4; |
| 469 | it.next(); |
| 470 | } |
| 471 | drawRects(rects.array(), count, &paint); |
| 472 | } |
| 473 | } |
| 474 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 475 | void DisplayListCanvas::drawRects(const float* rects, int count, const SkPaint* paint) { |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 476 | if (count <= 0) return; |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 477 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 478 | rects = refBuffer<float>(rects, count); |
| 479 | paint = refPaint(paint); |
| 480 | addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint)); |
Romain Guy | 672433d | 2013-01-04 19:05:13 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 483 | void DisplayListCanvas::setDrawFilter(SkDrawFilter* filter) { |
Derek Sollenberger | 0b86062 | 2015-03-25 10:08:30 -0400 | [diff] [blame] | 484 | mDrawFilter.reset(SkSafeRef(filter)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 487 | void DisplayListCanvas::insertReorderBarrier(bool enableReorder) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 488 | flushRestoreToCount(); |
| 489 | flushTranslate(); |
| 490 | mDeferredBarrierType = enableReorder ? kBarrier_OutOfOrder : kBarrier_InOrder; |
| 491 | } |
| 492 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 493 | void DisplayListCanvas::flushRestoreToCount() { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 494 | if (mRestoreSaveCount >= 0) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 495 | addOpAndUpdateChunk(new (alloc()) RestoreToCountOp(mRestoreSaveCount)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 496 | mRestoreSaveCount = -1; |
| 497 | } |
| 498 | } |
| 499 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 500 | void DisplayListCanvas::flushTranslate() { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 501 | if (mHasDeferredTranslate) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 502 | if (mTranslateX != 0.0f || mTranslateY != 0.0f) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 503 | addOpAndUpdateChunk(new (alloc()) TranslateOp(mTranslateX, mTranslateY)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 504 | mTranslateX = mTranslateY = 0.0f; |
| 505 | } |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 506 | mHasDeferredTranslate = false; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 510 | size_t DisplayListCanvas::addOpAndUpdateChunk(DisplayListOp* op) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 511 | int insertIndex = mDisplayList->ops.size(); |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 512 | #if HWUI_NEW_OPS |
| 513 | LOG_ALWAYS_FATAL("unsupported"); |
| 514 | #else |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 515 | mDisplayList->ops.push_back(op); |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 516 | #endif |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 517 | if (mDeferredBarrierType != kBarrier_None) { |
| 518 | // op is first in new chunk |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 519 | mDisplayList->chunks.emplace_back(); |
| 520 | DisplayList::Chunk& newChunk = mDisplayList->chunks.back(); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 521 | newChunk.beginOpIndex = insertIndex; |
| 522 | newChunk.endOpIndex = insertIndex + 1; |
| 523 | newChunk.reorderChildren = (mDeferredBarrierType == kBarrier_OutOfOrder); |
| 524 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 525 | int nextChildIndex = mDisplayList->children.size(); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 526 | newChunk.beginChildIndex = newChunk.endChildIndex = nextChildIndex; |
| 527 | mDeferredBarrierType = kBarrier_None; |
| 528 | } else { |
| 529 | // standard case - append to existing chunk |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 530 | mDisplayList->chunks.back().endOpIndex = insertIndex + 1; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 531 | } |
| 532 | return insertIndex; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 535 | size_t DisplayListCanvas::flushAndAddOp(DisplayListOp* op) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 536 | flushRestoreToCount(); |
| 537 | flushTranslate(); |
| 538 | return addOpAndUpdateChunk(op); |
| 539 | } |
| 540 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 541 | size_t DisplayListCanvas::addStateOp(StateOp* op) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 542 | return flushAndAddOp(op); |
| 543 | } |
| 544 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 545 | size_t DisplayListCanvas::addDrawOp(DrawOp* op) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 546 | Rect localBounds; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 547 | if (op->getLocalBounds(localBounds)) { |
Tom Hudson | 8dfaa49 | 2014-12-09 15:03:44 -0500 | [diff] [blame] | 548 | bool rejected = quickRejectRect(localBounds.left, localBounds.top, |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 549 | localBounds.right, localBounds.bottom); |
| 550 | op->setQuickRejected(rejected); |
| 551 | } |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 552 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 553 | mDisplayList->hasDrawOps = true; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 554 | return flushAndAddOp(op); |
| 555 | } |
| 556 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 557 | size_t DisplayListCanvas::addRenderNodeOp(DrawRenderNodeOp* op) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 558 | int opIndex = addDrawOp(op); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 559 | #if !HWUI_NEW_OPS |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 560 | int childIndex = mDisplayList->addChild(op); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 561 | |
| 562 | // update the chunk's child indices |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 563 | DisplayList::Chunk& chunk = mDisplayList->chunks.back(); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 564 | chunk.endChildIndex = childIndex + 1; |
| 565 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 566 | if (op->renderNode->stagingProperties().isProjectionReceiver()) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 567 | // use staging property, since recording on UI thread |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 568 | mDisplayList->projectionReceiveIndex = opIndex; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 569 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 570 | #endif |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 571 | return opIndex; |
Romain Guy | 5ff9df6 | 2012-01-23 17:09:05 -0800 | [diff] [blame] | 572 | } |
| 573 | |
John Reck | 37b0824 | 2015-06-09 13:12:40 -0700 | [diff] [blame] | 574 | void DisplayListCanvas::refBitmapsInShader(const SkShader* shader) { |
| 575 | if (!shader) return; |
| 576 | |
| 577 | // If this paint has an SkShader that has an SkBitmap add |
| 578 | // it to the bitmap pile |
| 579 | SkBitmap bitmap; |
| 580 | SkShader::TileMode xy[2]; |
Leon Scroggins III | f35b989 | 2015-07-31 10:38:40 -0400 | [diff] [blame] | 581 | if (shader->isABitmap(&bitmap, nullptr, xy)) { |
John Reck | 37b0824 | 2015-06-09 13:12:40 -0700 | [diff] [blame] | 582 | refBitmap(bitmap); |
| 583 | return; |
| 584 | } |
| 585 | SkShader::ComposeRec rec; |
| 586 | if (shader->asACompose(&rec)) { |
| 587 | refBitmapsInShader(rec.fShaderA); |
| 588 | refBitmapsInShader(rec.fShaderB); |
| 589 | return; |
| 590 | } |
| 591 | } |
| 592 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 593 | }; // namespace uirenderer |
| 594 | }; // namespace android |