blob: c1868d3a94d650a0de6de1ec5ef2dd09962402bd [file] [log] [blame]
Jeff Brown5541de92011-04-11 11:54:25 -07001/*
2 * Copyright (C) 2011 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
17#define LOG_TAG "Sprites"
Jeff Brown5541de92011-04-11 11:54:25 -070018//#define LOG_NDEBUG 0
19
20#include "SpriteController.h"
21
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070022#include <log/log.h>
Jeff Brown5541de92011-04-11 11:54:25 -070023#include <utils/String8.h>
Mathias Agopian52800612013-02-14 17:11:20 -080024#include <gui/Surface.h>
Jeff Brown5541de92011-04-11 11:54:25 -070025
26#include <SkBitmap.h>
27#include <SkCanvas.h>
28#include <SkColor.h>
29#include <SkPaint.h>
Andreas Gampe6b83b762014-11-10 15:55:11 -080030
Mathias Agopian52800612013-02-14 17:11:20 -080031#include <android/native_window.h>
Jeff Brown5541de92011-04-11 11:54:25 -070032
33namespace android {
34
35// --- SpriteController ---
36
37SpriteController::SpriteController(const sp<Looper>& looper, int32_t overlayLayer) :
38 mLooper(looper), mOverlayLayer(overlayLayer) {
39 mHandler = new WeakMessageHandler(this);
Jeff Brown2352b972011-04-12 22:39:53 -070040
41 mLocked.transactionNestingCount = 0;
42 mLocked.deferredSpriteUpdate = false;
Jeff Brown5541de92011-04-11 11:54:25 -070043}
44
45SpriteController::~SpriteController() {
46 mLooper->removeMessages(mHandler);
47
48 if (mSurfaceComposerClient != NULL) {
49 mSurfaceComposerClient->dispose();
50 mSurfaceComposerClient.clear();
51 }
52}
53
54sp<Sprite> SpriteController::createSprite() {
55 return new SpriteImpl(this);
56}
57
Jeff Brown2352b972011-04-12 22:39:53 -070058void SpriteController::openTransaction() {
59 AutoMutex _l(mLock);
60
61 mLocked.transactionNestingCount += 1;
62}
63
64void SpriteController::closeTransaction() {
65 AutoMutex _l(mLock);
66
67 LOG_ALWAYS_FATAL_IF(mLocked.transactionNestingCount == 0,
68 "Sprite closeTransaction() called but there is no open sprite transaction");
69
70 mLocked.transactionNestingCount -= 1;
71 if (mLocked.transactionNestingCount == 0 && mLocked.deferredSpriteUpdate) {
72 mLocked.deferredSpriteUpdate = false;
Jeff Brown5541de92011-04-11 11:54:25 -070073 mLooper->sendMessage(mHandler, Message(MSG_UPDATE_SPRITES));
74 }
75}
76
Jeff Brown2352b972011-04-12 22:39:53 -070077void SpriteController::invalidateSpriteLocked(const sp<SpriteImpl>& sprite) {
78 bool wasEmpty = mLocked.invalidatedSprites.isEmpty();
79 mLocked.invalidatedSprites.push(sprite);
80 if (wasEmpty) {
81 if (mLocked.transactionNestingCount != 0) {
82 mLocked.deferredSpriteUpdate = true;
83 } else {
84 mLooper->sendMessage(mHandler, Message(MSG_UPDATE_SPRITES));
85 }
86 }
87}
88
Jeff Brown5541de92011-04-11 11:54:25 -070089void SpriteController::disposeSurfaceLocked(const sp<SurfaceControl>& surfaceControl) {
Jeff Brown2352b972011-04-12 22:39:53 -070090 bool wasEmpty = mLocked.disposedSurfaces.isEmpty();
91 mLocked.disposedSurfaces.push(surfaceControl);
Jeff Brown5541de92011-04-11 11:54:25 -070092 if (wasEmpty) {
93 mLooper->sendMessage(mHandler, Message(MSG_DISPOSE_SURFACES));
94 }
95}
96
97void SpriteController::handleMessage(const Message& message) {
98 switch (message.what) {
99 case MSG_UPDATE_SPRITES:
100 doUpdateSprites();
101 break;
102 case MSG_DISPOSE_SURFACES:
103 doDisposeSurfaces();
104 break;
105 }
106}
107
108void SpriteController::doUpdateSprites() {
109 // Collect information about sprite updates.
110 // Each sprite update record includes a reference to its associated sprite so we can
111 // be certain the sprites will not be deleted while this function runs. Sprites
112 // may invalidate themselves again during this time but we will handle those changes
113 // in the next iteration.
114 Vector<SpriteUpdate> updates;
115 size_t numSprites;
116 { // acquire lock
117 AutoMutex _l(mLock);
118
Jeff Brown2352b972011-04-12 22:39:53 -0700119 numSprites = mLocked.invalidatedSprites.size();
Jeff Brown5541de92011-04-11 11:54:25 -0700120 for (size_t i = 0; i < numSprites; i++) {
Jeff Brown2352b972011-04-12 22:39:53 -0700121 const sp<SpriteImpl>& sprite = mLocked.invalidatedSprites.itemAt(i);
Jeff Brown5541de92011-04-11 11:54:25 -0700122
123 updates.push(SpriteUpdate(sprite, sprite->getStateLocked()));
124 sprite->resetDirtyLocked();
125 }
Jeff Brown2352b972011-04-12 22:39:53 -0700126 mLocked.invalidatedSprites.clear();
Jeff Brown5541de92011-04-11 11:54:25 -0700127 } // release lock
128
129 // Create missing surfaces.
130 bool surfaceChanged = false;
131 for (size_t i = 0; i < numSprites; i++) {
132 SpriteUpdate& update = updates.editItemAt(i);
133
134 if (update.state.surfaceControl == NULL && update.state.wantSurfaceVisible()) {
Jeff Brown2352b972011-04-12 22:39:53 -0700135 update.state.surfaceWidth = update.state.icon.bitmap.width();
136 update.state.surfaceHeight = update.state.icon.bitmap.height();
Jeff Brown5541de92011-04-11 11:54:25 -0700137 update.state.surfaceDrawn = false;
138 update.state.surfaceVisible = false;
139 update.state.surfaceControl = obtainSurface(
140 update.state.surfaceWidth, update.state.surfaceHeight);
141 if (update.state.surfaceControl != NULL) {
142 update.surfaceChanged = surfaceChanged = true;
143 }
144 }
145 }
146
Arthur Hungb9b32002018-12-18 17:39:43 +0800147 // Resize and/or reparent sprites if needed.
Robert Carre13b58e2017-08-31 14:50:44 -0700148 SurfaceComposerClient::Transaction t;
149 bool needApplyTransaction = false;
Jeff Brown5541de92011-04-11 11:54:25 -0700150 for (size_t i = 0; i < numSprites; i++) {
151 SpriteUpdate& update = updates.editItemAt(i);
Arthur Hungb9b32002018-12-18 17:39:43 +0800152 if (update.state.surfaceControl == nullptr) {
153 continue;
154 }
Jeff Brown5541de92011-04-11 11:54:25 -0700155
Arthur Hungb9b32002018-12-18 17:39:43 +0800156 if (update.state.wantSurfaceVisible()) {
Jeff Brown2352b972011-04-12 22:39:53 -0700157 int32_t desiredWidth = update.state.icon.bitmap.width();
158 int32_t desiredHeight = update.state.icon.bitmap.height();
Jeff Brown5541de92011-04-11 11:54:25 -0700159 if (update.state.surfaceWidth < desiredWidth
160 || update.state.surfaceHeight < desiredHeight) {
Robert Carre13b58e2017-08-31 14:50:44 -0700161 needApplyTransaction = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700162
Robert Carre13b58e2017-08-31 14:50:44 -0700163 t.setSize(update.state.surfaceControl,
164 desiredWidth, desiredHeight);
165 update.state.surfaceWidth = desiredWidth;
166 update.state.surfaceHeight = desiredHeight;
167 update.state.surfaceDrawn = false;
168 update.surfaceChanged = surfaceChanged = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700169
Robert Carre13b58e2017-08-31 14:50:44 -0700170 if (update.state.surfaceVisible) {
171 t.hide(update.state.surfaceControl);
172 update.state.surfaceVisible = false;
Jeff Brown5541de92011-04-11 11:54:25 -0700173 }
174 }
175 }
Arthur Hungb9b32002018-12-18 17:39:43 +0800176
177 // If surface is a new one, we have to set right layer stack.
178 if (update.surfaceChanged || update.state.dirty & DIRTY_DISPLAY_ID) {
179 t.setLayerStack(update.state.surfaceControl, update.state.displayId);
180 needApplyTransaction = true;
181 }
Jeff Brown5541de92011-04-11 11:54:25 -0700182 }
Robert Carre13b58e2017-08-31 14:50:44 -0700183 if (needApplyTransaction) {
184 t.apply();
Jeff Brown5541de92011-04-11 11:54:25 -0700185 }
186
187 // Redraw sprites if needed.
188 for (size_t i = 0; i < numSprites; i++) {
189 SpriteUpdate& update = updates.editItemAt(i);
190
191 if ((update.state.dirty & DIRTY_BITMAP) && update.state.surfaceDrawn) {
192 update.state.surfaceDrawn = false;
193 update.surfaceChanged = surfaceChanged = true;
194 }
195
196 if (update.state.surfaceControl != NULL && !update.state.surfaceDrawn
197 && update.state.wantSurfaceVisible()) {
198 sp<Surface> surface = update.state.surfaceControl->getSurface();
Mathias Agopian52800612013-02-14 17:11:20 -0800199 ANativeWindow_Buffer outBuffer;
200 status_t status = surface->lock(&outBuffer, NULL);
Jeff Brown5541de92011-04-11 11:54:25 -0700201 if (status) {
Steve Block3762c312012-01-06 19:20:56 +0000202 ALOGE("Error %d locking sprite surface before drawing.", status);
Jeff Brown5541de92011-04-11 11:54:25 -0700203 } else {
204 SkBitmap surfaceBitmap;
Mathias Agopian52800612013-02-14 17:11:20 -0800205 ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
Mike Reedb9330552014-06-16 17:31:48 -0400206 surfaceBitmap.installPixels(SkImageInfo::MakeN32Premul(outBuffer.width, outBuffer.height),
207 outBuffer.bits, bpr);
Jeff Brown5541de92011-04-11 11:54:25 -0700208
Derek Sollenbergerfc615a02012-12-20 14:39:57 -0500209 SkCanvas surfaceCanvas(surfaceBitmap);
Jeff Brown5541de92011-04-11 11:54:25 -0700210
211 SkPaint paint;
Mike Reed260ab722016-10-07 15:59:20 -0400212 paint.setBlendMode(SkBlendMode::kSrc);
Jeff Brown2352b972011-04-12 22:39:53 -0700213 surfaceCanvas.drawBitmap(update.state.icon.bitmap, 0, 0, &paint);
Jeff Brown5541de92011-04-11 11:54:25 -0700214
Michael Wright4d8779f2013-10-16 14:01:50 -0700215 if (outBuffer.width > update.state.icon.bitmap.width()) {
Jeff Brown5541de92011-04-11 11:54:25 -0700216 paint.setColor(0); // transparent fill color
Mike Reed6c9bb242017-04-04 09:15:37 -0400217 surfaceCanvas.drawRect(SkRect::MakeLTRB(update.state.icon.bitmap.width(), 0,
218 outBuffer.width, update.state.icon.bitmap.height()), paint);
Jeff Brown5541de92011-04-11 11:54:25 -0700219 }
Michael Wright4d8779f2013-10-16 14:01:50 -0700220 if (outBuffer.height > update.state.icon.bitmap.height()) {
Jeff Brown5541de92011-04-11 11:54:25 -0700221 paint.setColor(0); // transparent fill color
Mike Reed6c9bb242017-04-04 09:15:37 -0400222 surfaceCanvas.drawRect(SkRect::MakeLTRB(0, update.state.icon.bitmap.height(),
223 outBuffer.width, outBuffer.height), paint);
Jeff Brown5541de92011-04-11 11:54:25 -0700224 }
225
226 status = surface->unlockAndPost();
227 if (status) {
Steve Block3762c312012-01-06 19:20:56 +0000228 ALOGE("Error %d unlocking and posting sprite surface after drawing.", status);
Jeff Brown5541de92011-04-11 11:54:25 -0700229 } else {
230 update.state.surfaceDrawn = true;
231 update.surfaceChanged = surfaceChanged = true;
232 }
233 }
234 }
235 }
236
Robert Carre13b58e2017-08-31 14:50:44 -0700237 needApplyTransaction = false;
Jeff Brown5541de92011-04-11 11:54:25 -0700238 for (size_t i = 0; i < numSprites; i++) {
239 SpriteUpdate& update = updates.editItemAt(i);
240
241 bool wantSurfaceVisibleAndDrawn = update.state.wantSurfaceVisible()
242 && update.state.surfaceDrawn;
243 bool becomingVisible = wantSurfaceVisibleAndDrawn && !update.state.surfaceVisible;
244 bool becomingHidden = !wantSurfaceVisibleAndDrawn && update.state.surfaceVisible;
245 if (update.state.surfaceControl != NULL && (becomingVisible || becomingHidden
246 || (wantSurfaceVisibleAndDrawn && (update.state.dirty & (DIRTY_ALPHA
247 | DIRTY_POSITION | DIRTY_TRANSFORMATION_MATRIX | DIRTY_LAYER
Arthur Hungb9b32002018-12-18 17:39:43 +0800248 | DIRTY_VISIBILITY | DIRTY_HOTSPOT | DIRTY_DISPLAY_ID))))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700249 needApplyTransaction = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700250
251 if (wantSurfaceVisibleAndDrawn
252 && (becomingVisible || (update.state.dirty & DIRTY_ALPHA))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700253 t.setAlpha(update.state.surfaceControl,
254 update.state.alpha);
Jeff Brown5541de92011-04-11 11:54:25 -0700255 }
256
257 if (wantSurfaceVisibleAndDrawn
258 && (becomingVisible || (update.state.dirty & (DIRTY_POSITION
259 | DIRTY_HOTSPOT)))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700260 t.setPosition(
261 update.state.surfaceControl,
Jeff Brown2352b972011-04-12 22:39:53 -0700262 update.state.positionX - update.state.icon.hotSpotX,
263 update.state.positionY - update.state.icon.hotSpotY);
Jeff Brown5541de92011-04-11 11:54:25 -0700264 }
265
266 if (wantSurfaceVisibleAndDrawn
267 && (becomingVisible
268 || (update.state.dirty & DIRTY_TRANSFORMATION_MATRIX))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700269 t.setMatrix(
270 update.state.surfaceControl,
Jeff Brown5541de92011-04-11 11:54:25 -0700271 update.state.transformationMatrix.dsdx,
272 update.state.transformationMatrix.dtdx,
273 update.state.transformationMatrix.dsdy,
274 update.state.transformationMatrix.dtdy);
Jeff Brown5541de92011-04-11 11:54:25 -0700275 }
276
277 int32_t surfaceLayer = mOverlayLayer + update.state.layer;
278 if (wantSurfaceVisibleAndDrawn
279 && (becomingVisible || (update.state.dirty & DIRTY_LAYER))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700280 t.setLayer(update.state.surfaceControl, surfaceLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700281 }
282
283 if (becomingVisible) {
Robert Carre13b58e2017-08-31 14:50:44 -0700284 t.show(update.state.surfaceControl);
285
286 update.state.surfaceVisible = true;
287 update.surfaceChanged = surfaceChanged = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700288 } else if (becomingHidden) {
Robert Carre13b58e2017-08-31 14:50:44 -0700289 t.hide(update.state.surfaceControl);
290
291 update.state.surfaceVisible = false;
292 update.surfaceChanged = surfaceChanged = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700293 }
294 }
295 }
296
Robert Carre13b58e2017-08-31 14:50:44 -0700297 if (needApplyTransaction) {
298 status_t status = t.apply();
299 if (status) {
300 ALOGE("Error applying Surface transaction");
301 }
Jeff Brown5541de92011-04-11 11:54:25 -0700302 }
303
304 // If any surfaces were changed, write back the new surface properties to the sprites.
305 if (surfaceChanged) { // acquire lock
306 AutoMutex _l(mLock);
307
308 for (size_t i = 0; i < numSprites; i++) {
309 const SpriteUpdate& update = updates.itemAt(i);
310
311 if (update.surfaceChanged) {
312 update.sprite->setSurfaceLocked(update.state.surfaceControl,
313 update.state.surfaceWidth, update.state.surfaceHeight,
314 update.state.surfaceDrawn, update.state.surfaceVisible);
315 }
316 }
317 } // release lock
318
319 // Clear the sprite update vector outside the lock. It is very important that
320 // we do not clear sprite references inside the lock since we could be releasing
321 // the last remaining reference to the sprite here which would result in the
322 // sprite being deleted and the lock being reacquired by the sprite destructor
323 // while already held.
324 updates.clear();
325}
326
327void SpriteController::doDisposeSurfaces() {
328 // Collect disposed surfaces.
329 Vector<sp<SurfaceControl> > disposedSurfaces;
330 { // acquire lock
Jeff Brown2352b972011-04-12 22:39:53 -0700331 AutoMutex _l(mLock);
332
333 disposedSurfaces = mLocked.disposedSurfaces;
334 mLocked.disposedSurfaces.clear();
Jeff Brown5541de92011-04-11 11:54:25 -0700335 } // release lock
336
337 // Release the last reference to each surface outside of the lock.
338 // We don't want the surfaces to be deleted while we are holding our lock.
339 disposedSurfaces.clear();
340}
341
342void SpriteController::ensureSurfaceComposerClient() {
343 if (mSurfaceComposerClient == NULL) {
344 mSurfaceComposerClient = new SurfaceComposerClient();
345 }
346}
347
348sp<SurfaceControl> SpriteController::obtainSurface(int32_t width, int32_t height) {
349 ensureSurfaceComposerClient();
350
351 sp<SurfaceControl> surfaceControl = mSurfaceComposerClient->createSurface(
Jeff Brown64a55af2012-08-26 02:47:39 -0700352 String8("Sprite"), width, height, PIXEL_FORMAT_RGBA_8888,
Riley Andrews68eccda2014-07-07 11:47:35 -0700353 ISurfaceComposerClient::eHidden |
354 ISurfaceComposerClient::eCursorWindow);
Mathias Agopian52800612013-02-14 17:11:20 -0800355 if (surfaceControl == NULL || !surfaceControl->isValid()) {
Steve Block3762c312012-01-06 19:20:56 +0000356 ALOGE("Error creating sprite surface.");
Jeff Brown5541de92011-04-11 11:54:25 -0700357 return NULL;
358 }
359 return surfaceControl;
360}
361
362
363// --- SpriteController::SpriteImpl ---
364
365SpriteController::SpriteImpl::SpriteImpl(const sp<SpriteController> controller) :
Jeff Brown2352b972011-04-12 22:39:53 -0700366 mController(controller) {
Jeff Brown5541de92011-04-11 11:54:25 -0700367}
368
369SpriteController::SpriteImpl::~SpriteImpl() {
370 AutoMutex _m(mController->mLock);
371
372 // Let the controller take care of deleting the last reference to sprite
373 // surfaces so that we do not block the caller on an IPC here.
Jeff Brown2352b972011-04-12 22:39:53 -0700374 if (mLocked.state.surfaceControl != NULL) {
375 mController->disposeSurfaceLocked(mLocked.state.surfaceControl);
376 mLocked.state.surfaceControl.clear();
Jeff Brown5541de92011-04-11 11:54:25 -0700377 }
378}
379
Jeff Brown2352b972011-04-12 22:39:53 -0700380void SpriteController::SpriteImpl::setIcon(const SpriteIcon& icon) {
Jeff Brown5541de92011-04-11 11:54:25 -0700381 AutoMutex _l(mController->mLock);
382
Jeff Brown2352b972011-04-12 22:39:53 -0700383 uint32_t dirty;
384 if (icon.isValid()) {
Matt Sarett155d5212017-04-25 17:32:34 -0400385 SkBitmap* bitmapCopy = &mLocked.state.icon.bitmap;
386 if (bitmapCopy->tryAllocPixels(icon.bitmap.info().makeColorType(kN32_SkColorType))) {
387 icon.bitmap.readPixels(bitmapCopy->info(), bitmapCopy->getPixels(),
388 bitmapCopy->rowBytes(), 0, 0);
389 }
Jeff Brown5541de92011-04-11 11:54:25 -0700390
Jeff Brown2352b972011-04-12 22:39:53 -0700391 if (!mLocked.state.icon.isValid()
392 || mLocked.state.icon.hotSpotX != icon.hotSpotX
393 || mLocked.state.icon.hotSpotY != icon.hotSpotY) {
394 mLocked.state.icon.hotSpotX = icon.hotSpotX;
395 mLocked.state.icon.hotSpotY = icon.hotSpotY;
396 dirty = DIRTY_BITMAP | DIRTY_HOTSPOT;
397 } else {
398 dirty = DIRTY_BITMAP;
399 }
400 } else if (mLocked.state.icon.isValid()) {
401 mLocked.state.icon.bitmap.reset();
402 dirty = DIRTY_BITMAP | DIRTY_HOTSPOT;
403 } else {
404 return; // setting to invalid icon and already invalid so nothing to do
Jeff Brown5541de92011-04-11 11:54:25 -0700405 }
406
407 invalidateLocked(dirty);
408}
409
410void SpriteController::SpriteImpl::setVisible(bool visible) {
411 AutoMutex _l(mController->mLock);
412
Jeff Brown2352b972011-04-12 22:39:53 -0700413 if (mLocked.state.visible != visible) {
414 mLocked.state.visible = visible;
Jeff Brown5541de92011-04-11 11:54:25 -0700415 invalidateLocked(DIRTY_VISIBILITY);
416 }
417}
418
419void SpriteController::SpriteImpl::setPosition(float x, float y) {
420 AutoMutex _l(mController->mLock);
421
Jeff Brown2352b972011-04-12 22:39:53 -0700422 if (mLocked.state.positionX != x || mLocked.state.positionY != y) {
423 mLocked.state.positionX = x;
424 mLocked.state.positionY = y;
Jeff Brown5541de92011-04-11 11:54:25 -0700425 invalidateLocked(DIRTY_POSITION);
426 }
427}
428
429void SpriteController::SpriteImpl::setLayer(int32_t layer) {
430 AutoMutex _l(mController->mLock);
431
Jeff Brown2352b972011-04-12 22:39:53 -0700432 if (mLocked.state.layer != layer) {
433 mLocked.state.layer = layer;
Jeff Brown5541de92011-04-11 11:54:25 -0700434 invalidateLocked(DIRTY_LAYER);
435 }
436}
437
438void SpriteController::SpriteImpl::setAlpha(float alpha) {
439 AutoMutex _l(mController->mLock);
440
Jeff Brown2352b972011-04-12 22:39:53 -0700441 if (mLocked.state.alpha != alpha) {
442 mLocked.state.alpha = alpha;
Jeff Brown5541de92011-04-11 11:54:25 -0700443 invalidateLocked(DIRTY_ALPHA);
444 }
445}
446
447void SpriteController::SpriteImpl::setTransformationMatrix(
448 const SpriteTransformationMatrix& matrix) {
449 AutoMutex _l(mController->mLock);
450
Jeff Brown2352b972011-04-12 22:39:53 -0700451 if (mLocked.state.transformationMatrix != matrix) {
452 mLocked.state.transformationMatrix = matrix;
Jeff Brown5541de92011-04-11 11:54:25 -0700453 invalidateLocked(DIRTY_TRANSFORMATION_MATRIX);
454 }
455}
456
Arthur Hungb9b32002018-12-18 17:39:43 +0800457void SpriteController::SpriteImpl::setDisplayId(int32_t displayId) {
458 AutoMutex _l(mController->mLock);
459
460 if (mLocked.state.displayId != displayId) {
461 mLocked.state.displayId = displayId;
462 invalidateLocked(DIRTY_DISPLAY_ID);
463 }
464}
465
Jeff Brown5541de92011-04-11 11:54:25 -0700466void SpriteController::SpriteImpl::invalidateLocked(uint32_t dirty) {
Jeff Brown2352b972011-04-12 22:39:53 -0700467 bool wasDirty = mLocked.state.dirty;
468 mLocked.state.dirty |= dirty;
469
470 if (!wasDirty) {
471 mController->invalidateSpriteLocked(this);
Jeff Brown5541de92011-04-11 11:54:25 -0700472 }
473}
474
475} // namespace android