blob: 804644c230b95cdec75b8a018e2dce08250baead [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
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -040026#include <android/graphics/bitmap.h>
27#include <android/graphics/canvas.h>
28#include <android/graphics/paint.h>
Mathias Agopian52800612013-02-14 17:11:20 -080029#include <android/native_window.h>
Jeff Brown5541de92011-04-11 11:54:25 -070030
31namespace android {
32
33// --- SpriteController ---
34
35SpriteController::SpriteController(const sp<Looper>& looper, int32_t overlayLayer) :
36 mLooper(looper), mOverlayLayer(overlayLayer) {
37 mHandler = new WeakMessageHandler(this);
Jeff Brown2352b972011-04-12 22:39:53 -070038
39 mLocked.transactionNestingCount = 0;
40 mLocked.deferredSpriteUpdate = false;
Jeff Brown5541de92011-04-11 11:54:25 -070041}
42
43SpriteController::~SpriteController() {
44 mLooper->removeMessages(mHandler);
45
46 if (mSurfaceComposerClient != NULL) {
47 mSurfaceComposerClient->dispose();
48 mSurfaceComposerClient.clear();
49 }
50}
51
52sp<Sprite> SpriteController::createSprite() {
53 return new SpriteImpl(this);
54}
55
Jeff Brown2352b972011-04-12 22:39:53 -070056void SpriteController::openTransaction() {
57 AutoMutex _l(mLock);
58
59 mLocked.transactionNestingCount += 1;
60}
61
62void SpriteController::closeTransaction() {
63 AutoMutex _l(mLock);
64
65 LOG_ALWAYS_FATAL_IF(mLocked.transactionNestingCount == 0,
66 "Sprite closeTransaction() called but there is no open sprite transaction");
67
68 mLocked.transactionNestingCount -= 1;
69 if (mLocked.transactionNestingCount == 0 && mLocked.deferredSpriteUpdate) {
70 mLocked.deferredSpriteUpdate = false;
Jeff Brown5541de92011-04-11 11:54:25 -070071 mLooper->sendMessage(mHandler, Message(MSG_UPDATE_SPRITES));
72 }
73}
74
Jeff Brown2352b972011-04-12 22:39:53 -070075void SpriteController::invalidateSpriteLocked(const sp<SpriteImpl>& sprite) {
76 bool wasEmpty = mLocked.invalidatedSprites.isEmpty();
77 mLocked.invalidatedSprites.push(sprite);
78 if (wasEmpty) {
79 if (mLocked.transactionNestingCount != 0) {
80 mLocked.deferredSpriteUpdate = true;
81 } else {
82 mLooper->sendMessage(mHandler, Message(MSG_UPDATE_SPRITES));
83 }
84 }
85}
86
Jeff Brown5541de92011-04-11 11:54:25 -070087void SpriteController::disposeSurfaceLocked(const sp<SurfaceControl>& surfaceControl) {
Jeff Brown2352b972011-04-12 22:39:53 -070088 bool wasEmpty = mLocked.disposedSurfaces.isEmpty();
89 mLocked.disposedSurfaces.push(surfaceControl);
Jeff Brown5541de92011-04-11 11:54:25 -070090 if (wasEmpty) {
91 mLooper->sendMessage(mHandler, Message(MSG_DISPOSE_SURFACES));
92 }
93}
94
95void SpriteController::handleMessage(const Message& message) {
96 switch (message.what) {
97 case MSG_UPDATE_SPRITES:
98 doUpdateSprites();
99 break;
100 case MSG_DISPOSE_SURFACES:
101 doDisposeSurfaces();
102 break;
103 }
104}
105
106void SpriteController::doUpdateSprites() {
107 // Collect information about sprite updates.
108 // Each sprite update record includes a reference to its associated sprite so we can
109 // be certain the sprites will not be deleted while this function runs. Sprites
110 // may invalidate themselves again during this time but we will handle those changes
111 // in the next iteration.
112 Vector<SpriteUpdate> updates;
113 size_t numSprites;
114 { // acquire lock
115 AutoMutex _l(mLock);
116
Jeff Brown2352b972011-04-12 22:39:53 -0700117 numSprites = mLocked.invalidatedSprites.size();
Jeff Brown5541de92011-04-11 11:54:25 -0700118 for (size_t i = 0; i < numSprites; i++) {
Jeff Brown2352b972011-04-12 22:39:53 -0700119 const sp<SpriteImpl>& sprite = mLocked.invalidatedSprites.itemAt(i);
Jeff Brown5541de92011-04-11 11:54:25 -0700120
121 updates.push(SpriteUpdate(sprite, sprite->getStateLocked()));
122 sprite->resetDirtyLocked();
123 }
Jeff Brown2352b972011-04-12 22:39:53 -0700124 mLocked.invalidatedSprites.clear();
Jeff Brown5541de92011-04-11 11:54:25 -0700125 } // release lock
126
127 // Create missing surfaces.
128 bool surfaceChanged = false;
129 for (size_t i = 0; i < numSprites; i++) {
130 SpriteUpdate& update = updates.editItemAt(i);
131
132 if (update.state.surfaceControl == NULL && update.state.wantSurfaceVisible()) {
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400133 update.state.surfaceWidth = update.state.icon.bitmap.getInfo().width;
134 update.state.surfaceHeight = update.state.icon.bitmap.getInfo().height;
Jeff Brown5541de92011-04-11 11:54:25 -0700135 update.state.surfaceDrawn = false;
136 update.state.surfaceVisible = false;
137 update.state.surfaceControl = obtainSurface(
138 update.state.surfaceWidth, update.state.surfaceHeight);
139 if (update.state.surfaceControl != NULL) {
140 update.surfaceChanged = surfaceChanged = true;
141 }
142 }
143 }
144
Arthur Hungb9b32002018-12-18 17:39:43 +0800145 // Resize and/or reparent sprites if needed.
Robert Carre13b58e2017-08-31 14:50:44 -0700146 SurfaceComposerClient::Transaction t;
147 bool needApplyTransaction = false;
Jeff Brown5541de92011-04-11 11:54:25 -0700148 for (size_t i = 0; i < numSprites; i++) {
149 SpriteUpdate& update = updates.editItemAt(i);
Arthur Hungb9b32002018-12-18 17:39:43 +0800150 if (update.state.surfaceControl == nullptr) {
151 continue;
152 }
Jeff Brown5541de92011-04-11 11:54:25 -0700153
Arthur Hungb9b32002018-12-18 17:39:43 +0800154 if (update.state.wantSurfaceVisible()) {
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400155 int32_t desiredWidth = update.state.icon.bitmap.getInfo().width;
156 int32_t desiredHeight = update.state.icon.bitmap.getInfo().height;
Jeff Brown5541de92011-04-11 11:54:25 -0700157 if (update.state.surfaceWidth < desiredWidth
158 || update.state.surfaceHeight < desiredHeight) {
Robert Carre13b58e2017-08-31 14:50:44 -0700159 needApplyTransaction = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700160
Robert Carre13b58e2017-08-31 14:50:44 -0700161 t.setSize(update.state.surfaceControl,
162 desiredWidth, desiredHeight);
163 update.state.surfaceWidth = desiredWidth;
164 update.state.surfaceHeight = desiredHeight;
165 update.state.surfaceDrawn = false;
166 update.surfaceChanged = surfaceChanged = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700167
Robert Carre13b58e2017-08-31 14:50:44 -0700168 if (update.state.surfaceVisible) {
169 t.hide(update.state.surfaceControl);
170 update.state.surfaceVisible = false;
Jeff Brown5541de92011-04-11 11:54:25 -0700171 }
172 }
173 }
Arthur Hungb9b32002018-12-18 17:39:43 +0800174
175 // If surface is a new one, we have to set right layer stack.
176 if (update.surfaceChanged || update.state.dirty & DIRTY_DISPLAY_ID) {
177 t.setLayerStack(update.state.surfaceControl, update.state.displayId);
178 needApplyTransaction = true;
179 }
Jeff Brown5541de92011-04-11 11:54:25 -0700180 }
Robert Carre13b58e2017-08-31 14:50:44 -0700181 if (needApplyTransaction) {
182 t.apply();
Jeff Brown5541de92011-04-11 11:54:25 -0700183 }
184
185 // Redraw sprites if needed.
186 for (size_t i = 0; i < numSprites; i++) {
187 SpriteUpdate& update = updates.editItemAt(i);
188
189 if ((update.state.dirty & DIRTY_BITMAP) && update.state.surfaceDrawn) {
190 update.state.surfaceDrawn = false;
191 update.surfaceChanged = surfaceChanged = true;
192 }
193
194 if (update.state.surfaceControl != NULL && !update.state.surfaceDrawn
195 && update.state.wantSurfaceVisible()) {
196 sp<Surface> surface = update.state.surfaceControl->getSurface();
Mathias Agopian52800612013-02-14 17:11:20 -0800197 ANativeWindow_Buffer outBuffer;
198 status_t status = surface->lock(&outBuffer, NULL);
Jeff Brown5541de92011-04-11 11:54:25 -0700199 if (status) {
Steve Block3762c312012-01-06 19:20:56 +0000200 ALOGE("Error %d locking sprite surface before drawing.", status);
Jeff Brown5541de92011-04-11 11:54:25 -0700201 } else {
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400202 graphics::Paint paint;
203 paint.setBlendMode(ABLEND_MODE_SRC);
Jeff Brown5541de92011-04-11 11:54:25 -0700204
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400205 graphics::Canvas canvas(outBuffer, (int32_t) surface->getBuffersDataSpace());
206 canvas.drawBitmap(update.state.icon.bitmap, 0, 0, &paint);
Jeff Brown5541de92011-04-11 11:54:25 -0700207
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400208 const int iconWidth = update.state.icon.bitmap.getInfo().width;
209 const int iconHeight = update.state.icon.bitmap.getInfo().height;
Jeff Brown5541de92011-04-11 11:54:25 -0700210
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400211 if (outBuffer.width > iconWidth) {
212 paint.setBlendMode(ABLEND_MODE_CLEAR); // clear to transparent
213 canvas.drawRect({iconWidth, 0, outBuffer.width, iconHeight}, paint);
Jeff Brown5541de92011-04-11 11:54:25 -0700214 }
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400215 if (outBuffer.height > iconHeight) {
216 paint.setBlendMode(ABLEND_MODE_CLEAR); // clear to transparent
217 canvas.drawRect({0, iconHeight, outBuffer.width, outBuffer.height}, paint);
Jeff Brown5541de92011-04-11 11:54:25 -0700218 }
219
220 status = surface->unlockAndPost();
221 if (status) {
Steve Block3762c312012-01-06 19:20:56 +0000222 ALOGE("Error %d unlocking and posting sprite surface after drawing.", status);
Jeff Brown5541de92011-04-11 11:54:25 -0700223 } else {
224 update.state.surfaceDrawn = true;
225 update.surfaceChanged = surfaceChanged = true;
226 }
227 }
228 }
229 }
230
Robert Carre13b58e2017-08-31 14:50:44 -0700231 needApplyTransaction = false;
Jeff Brown5541de92011-04-11 11:54:25 -0700232 for (size_t i = 0; i < numSprites; i++) {
233 SpriteUpdate& update = updates.editItemAt(i);
234
235 bool wantSurfaceVisibleAndDrawn = update.state.wantSurfaceVisible()
236 && update.state.surfaceDrawn;
237 bool becomingVisible = wantSurfaceVisibleAndDrawn && !update.state.surfaceVisible;
238 bool becomingHidden = !wantSurfaceVisibleAndDrawn && update.state.surfaceVisible;
239 if (update.state.surfaceControl != NULL && (becomingVisible || becomingHidden
240 || (wantSurfaceVisibleAndDrawn && (update.state.dirty & (DIRTY_ALPHA
241 | DIRTY_POSITION | DIRTY_TRANSFORMATION_MATRIX | DIRTY_LAYER
Garfield Tan67e479a2019-08-05 16:47:40 -0700242 | DIRTY_VISIBILITY | DIRTY_HOTSPOT | DIRTY_DISPLAY_ID
243 | DIRTY_ICON_STYLE))))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700244 needApplyTransaction = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700245
246 if (wantSurfaceVisibleAndDrawn
247 && (becomingVisible || (update.state.dirty & DIRTY_ALPHA))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700248 t.setAlpha(update.state.surfaceControl,
249 update.state.alpha);
Jeff Brown5541de92011-04-11 11:54:25 -0700250 }
251
252 if (wantSurfaceVisibleAndDrawn
253 && (becomingVisible || (update.state.dirty & (DIRTY_POSITION
254 | DIRTY_HOTSPOT)))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700255 t.setPosition(
256 update.state.surfaceControl,
Jeff Brown2352b972011-04-12 22:39:53 -0700257 update.state.positionX - update.state.icon.hotSpotX,
258 update.state.positionY - update.state.icon.hotSpotY);
Jeff Brown5541de92011-04-11 11:54:25 -0700259 }
260
261 if (wantSurfaceVisibleAndDrawn
262 && (becomingVisible
263 || (update.state.dirty & DIRTY_TRANSFORMATION_MATRIX))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700264 t.setMatrix(
265 update.state.surfaceControl,
Jeff Brown5541de92011-04-11 11:54:25 -0700266 update.state.transformationMatrix.dsdx,
267 update.state.transformationMatrix.dtdx,
268 update.state.transformationMatrix.dsdy,
269 update.state.transformationMatrix.dtdy);
Jeff Brown5541de92011-04-11 11:54:25 -0700270 }
271
Garfield Tan67e479a2019-08-05 16:47:40 -0700272 if (wantSurfaceVisibleAndDrawn
273 && (becomingVisible
274 || (update.state.dirty & (DIRTY_HOTSPOT | DIRTY_ICON_STYLE)))) {
275 Parcel p;
276 p.writeInt32(update.state.icon.style);
277 p.writeFloat(update.state.icon.hotSpotX);
278 p.writeFloat(update.state.icon.hotSpotY);
279
280 // Pass cursor metadata in the sprite surface so that when Android is running as a
281 // client OS (e.g. ARC++) the host OS can get the requested cursor metadata and
282 // update mouse cursor in the host OS.
283 t.setMetadata(
284 update.state.surfaceControl, METADATA_MOUSE_CURSOR, p);
285 }
286
Jeff Brown5541de92011-04-11 11:54:25 -0700287 int32_t surfaceLayer = mOverlayLayer + update.state.layer;
288 if (wantSurfaceVisibleAndDrawn
289 && (becomingVisible || (update.state.dirty & DIRTY_LAYER))) {
Robert Carre13b58e2017-08-31 14:50:44 -0700290 t.setLayer(update.state.surfaceControl, surfaceLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700291 }
292
293 if (becomingVisible) {
Robert Carre13b58e2017-08-31 14:50:44 -0700294 t.show(update.state.surfaceControl);
295
296 update.state.surfaceVisible = true;
297 update.surfaceChanged = surfaceChanged = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700298 } else if (becomingHidden) {
Robert Carre13b58e2017-08-31 14:50:44 -0700299 t.hide(update.state.surfaceControl);
300
301 update.state.surfaceVisible = false;
302 update.surfaceChanged = surfaceChanged = true;
Jeff Brown5541de92011-04-11 11:54:25 -0700303 }
304 }
305 }
306
Robert Carre13b58e2017-08-31 14:50:44 -0700307 if (needApplyTransaction) {
308 status_t status = t.apply();
309 if (status) {
310 ALOGE("Error applying Surface transaction");
311 }
Jeff Brown5541de92011-04-11 11:54:25 -0700312 }
313
314 // If any surfaces were changed, write back the new surface properties to the sprites.
315 if (surfaceChanged) { // acquire lock
316 AutoMutex _l(mLock);
317
318 for (size_t i = 0; i < numSprites; i++) {
319 const SpriteUpdate& update = updates.itemAt(i);
320
321 if (update.surfaceChanged) {
322 update.sprite->setSurfaceLocked(update.state.surfaceControl,
323 update.state.surfaceWidth, update.state.surfaceHeight,
324 update.state.surfaceDrawn, update.state.surfaceVisible);
325 }
326 }
327 } // release lock
328
329 // Clear the sprite update vector outside the lock. It is very important that
330 // we do not clear sprite references inside the lock since we could be releasing
331 // the last remaining reference to the sprite here which would result in the
332 // sprite being deleted and the lock being reacquired by the sprite destructor
333 // while already held.
334 updates.clear();
335}
336
337void SpriteController::doDisposeSurfaces() {
338 // Collect disposed surfaces.
339 Vector<sp<SurfaceControl> > disposedSurfaces;
340 { // acquire lock
Jeff Brown2352b972011-04-12 22:39:53 -0700341 AutoMutex _l(mLock);
342
343 disposedSurfaces = mLocked.disposedSurfaces;
344 mLocked.disposedSurfaces.clear();
Jeff Brown5541de92011-04-11 11:54:25 -0700345 } // release lock
346
347 // Release the last reference to each surface outside of the lock.
348 // We don't want the surfaces to be deleted while we are holding our lock.
349 disposedSurfaces.clear();
350}
351
352void SpriteController::ensureSurfaceComposerClient() {
353 if (mSurfaceComposerClient == NULL) {
354 mSurfaceComposerClient = new SurfaceComposerClient();
355 }
356}
357
358sp<SurfaceControl> SpriteController::obtainSurface(int32_t width, int32_t height) {
359 ensureSurfaceComposerClient();
360
361 sp<SurfaceControl> surfaceControl = mSurfaceComposerClient->createSurface(
Jeff Brown64a55af2012-08-26 02:47:39 -0700362 String8("Sprite"), width, height, PIXEL_FORMAT_RGBA_8888,
Riley Andrews68eccda2014-07-07 11:47:35 -0700363 ISurfaceComposerClient::eHidden |
364 ISurfaceComposerClient::eCursorWindow);
Mathias Agopian52800612013-02-14 17:11:20 -0800365 if (surfaceControl == NULL || !surfaceControl->isValid()) {
Steve Block3762c312012-01-06 19:20:56 +0000366 ALOGE("Error creating sprite surface.");
Jeff Brown5541de92011-04-11 11:54:25 -0700367 return NULL;
368 }
369 return surfaceControl;
370}
371
372
373// --- SpriteController::SpriteImpl ---
374
375SpriteController::SpriteImpl::SpriteImpl(const sp<SpriteController> controller) :
Jeff Brown2352b972011-04-12 22:39:53 -0700376 mController(controller) {
Jeff Brown5541de92011-04-11 11:54:25 -0700377}
378
379SpriteController::SpriteImpl::~SpriteImpl() {
380 AutoMutex _m(mController->mLock);
381
382 // Let the controller take care of deleting the last reference to sprite
383 // surfaces so that we do not block the caller on an IPC here.
Jeff Brown2352b972011-04-12 22:39:53 -0700384 if (mLocked.state.surfaceControl != NULL) {
385 mController->disposeSurfaceLocked(mLocked.state.surfaceControl);
386 mLocked.state.surfaceControl.clear();
Jeff Brown5541de92011-04-11 11:54:25 -0700387 }
388}
389
Jeff Brown2352b972011-04-12 22:39:53 -0700390void SpriteController::SpriteImpl::setIcon(const SpriteIcon& icon) {
Jeff Brown5541de92011-04-11 11:54:25 -0700391 AutoMutex _l(mController->mLock);
392
Jeff Brown2352b972011-04-12 22:39:53 -0700393 uint32_t dirty;
394 if (icon.isValid()) {
Derek Sollenberger9ca5bbe2019-08-14 15:50:59 -0400395 mLocked.state.icon.bitmap = icon.bitmap.copy(ANDROID_BITMAP_FORMAT_RGBA_8888);
Jeff Brown2352b972011-04-12 22:39:53 -0700396 if (!mLocked.state.icon.isValid()
397 || mLocked.state.icon.hotSpotX != icon.hotSpotX
398 || mLocked.state.icon.hotSpotY != icon.hotSpotY) {
399 mLocked.state.icon.hotSpotX = icon.hotSpotX;
400 mLocked.state.icon.hotSpotY = icon.hotSpotY;
401 dirty = DIRTY_BITMAP | DIRTY_HOTSPOT;
402 } else {
403 dirty = DIRTY_BITMAP;
404 }
Garfield Tan67e479a2019-08-05 16:47:40 -0700405
406 if (mLocked.state.icon.style != icon.style) {
407 mLocked.state.icon.style = icon.style;
408 dirty |= DIRTY_ICON_STYLE;
409 }
Jeff Brown2352b972011-04-12 22:39:53 -0700410 } else if (mLocked.state.icon.isValid()) {
411 mLocked.state.icon.bitmap.reset();
Garfield Tan67e479a2019-08-05 16:47:40 -0700412 dirty = DIRTY_BITMAP | DIRTY_HOTSPOT | DIRTY_ICON_STYLE;
Jeff Brown2352b972011-04-12 22:39:53 -0700413 } else {
414 return; // setting to invalid icon and already invalid so nothing to do
Jeff Brown5541de92011-04-11 11:54:25 -0700415 }
416
417 invalidateLocked(dirty);
418}
419
420void SpriteController::SpriteImpl::setVisible(bool visible) {
421 AutoMutex _l(mController->mLock);
422
Jeff Brown2352b972011-04-12 22:39:53 -0700423 if (mLocked.state.visible != visible) {
424 mLocked.state.visible = visible;
Jeff Brown5541de92011-04-11 11:54:25 -0700425 invalidateLocked(DIRTY_VISIBILITY);
426 }
427}
428
429void SpriteController::SpriteImpl::setPosition(float x, float y) {
430 AutoMutex _l(mController->mLock);
431
Jeff Brown2352b972011-04-12 22:39:53 -0700432 if (mLocked.state.positionX != x || mLocked.state.positionY != y) {
433 mLocked.state.positionX = x;
434 mLocked.state.positionY = y;
Jeff Brown5541de92011-04-11 11:54:25 -0700435 invalidateLocked(DIRTY_POSITION);
436 }
437}
438
439void SpriteController::SpriteImpl::setLayer(int32_t layer) {
440 AutoMutex _l(mController->mLock);
441
Jeff Brown2352b972011-04-12 22:39:53 -0700442 if (mLocked.state.layer != layer) {
443 mLocked.state.layer = layer;
Jeff Brown5541de92011-04-11 11:54:25 -0700444 invalidateLocked(DIRTY_LAYER);
445 }
446}
447
448void SpriteController::SpriteImpl::setAlpha(float alpha) {
449 AutoMutex _l(mController->mLock);
450
Jeff Brown2352b972011-04-12 22:39:53 -0700451 if (mLocked.state.alpha != alpha) {
452 mLocked.state.alpha = alpha;
Jeff Brown5541de92011-04-11 11:54:25 -0700453 invalidateLocked(DIRTY_ALPHA);
454 }
455}
456
457void SpriteController::SpriteImpl::setTransformationMatrix(
458 const SpriteTransformationMatrix& matrix) {
459 AutoMutex _l(mController->mLock);
460
Jeff Brown2352b972011-04-12 22:39:53 -0700461 if (mLocked.state.transformationMatrix != matrix) {
462 mLocked.state.transformationMatrix = matrix;
Jeff Brown5541de92011-04-11 11:54:25 -0700463 invalidateLocked(DIRTY_TRANSFORMATION_MATRIX);
464 }
465}
466
Arthur Hungb9b32002018-12-18 17:39:43 +0800467void SpriteController::SpriteImpl::setDisplayId(int32_t displayId) {
468 AutoMutex _l(mController->mLock);
469
470 if (mLocked.state.displayId != displayId) {
471 mLocked.state.displayId = displayId;
472 invalidateLocked(DIRTY_DISPLAY_ID);
473 }
474}
475
Jeff Brown5541de92011-04-11 11:54:25 -0700476void SpriteController::SpriteImpl::invalidateLocked(uint32_t dirty) {
Jeff Brown2352b972011-04-12 22:39:53 -0700477 bool wasDirty = mLocked.state.dirty;
478 mLocked.state.dirty |= dirty;
479
480 if (!wasDirty) {
481 mController->invalidateSpriteLocked(this);
Jeff Brown5541de92011-04-11 11:54:25 -0700482 }
483}
484
485} // namespace android