DisplayListOp.h revision d6960a49b40703e8af55c1fb628a2e0c5d2b40cf
1/* 2 * Copyright (C) 2013 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#ifndef ANDROID_HWUI_DISPLAY_OPERATION_H 18#define ANDROID_HWUI_DISPLAY_OPERATION_H 19 20#ifndef LOG_TAG 21 #define LOG_TAG "OpenGLRenderer" 22#endif 23 24#include <SkXfermode.h> 25 26#include <private/hwui/DrawGlInfo.h> 27 28#include "OpenGLRenderer.h" 29#include "DeferredDisplayList.h" 30#include "DisplayListRenderer.h" 31#include "utils/LinearAllocator.h" 32 33#define CRASH() do { \ 34 *(int *)(uintptr_t)0xbbadbeef = 0; \ 35 ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \ 36} while(false) 37 38#define MATRIX_STRING "[%.2f %.2f %.2f] [%.2f %.2f %.2f] [%.2f %.2f %.2f]" 39#define MATRIX_ARGS(m) \ 40 m->get(0), m->get(1), m->get(2), \ 41 m->get(3), m->get(4), m->get(5), \ 42 m->get(6), m->get(7), m->get(8) 43#define RECT_STRING "%.2f %.2f %.2f %.2f" 44#define RECT_ARGS(r) \ 45 r.left, r.top, r.right, r.bottom 46 47// Use OP_LOG for logging with arglist, OP_LOGS if just printing char* 48#define OP_LOGS(s) OP_LOG("%s", s) 49#define OP_LOG(s, ...) ALOGD( "%*s" s, level * 2, "", __VA_ARGS__ ) 50 51namespace android { 52namespace uirenderer { 53 54/** 55 * Structure for storing canvas operations when they are recorded into a DisplayList, so that they 56 * may be replayed to an OpenGLRenderer. 57 * 58 * To avoid individual memory allocations, DisplayListOps may only be allocated into a 59 * LinearAllocator's managed memory buffers. Each pointer held by a DisplayListOp is either a 60 * pointer into memory also allocated in the LinearAllocator (mostly for text and float buffers) or 61 * references a externally refcounted object (Sk... and Skia... objects). ~DisplayListOp() is 62 * never called as LinearAllocators are simply discarded, so no memory management should be done in 63 * this class. 64 */ 65class DisplayListOp { 66public: 67 // These objects should always be allocated with a LinearAllocator, and never destroyed/deleted. 68 // standard new() intentionally not implemented, and delete/deconstructor should never be used. 69 virtual ~DisplayListOp() { CRASH(); } 70 static void operator delete(void* ptr) { CRASH(); } 71 /** static void* operator new(size_t size); PURPOSELY OMITTED **/ 72 static void* operator new(size_t size, LinearAllocator& allocator) { 73 return allocator.alloc(size); 74 } 75 76 enum OpLogFlag { 77 kOpLogFlag_Recurse = 0x1, 78 kOpLogFlag_JSON = 0x2 // TODO: add? 79 }; 80 81 // If a DeferredDisplayList is supplied, DrawOps will be stored until the list is flushed 82 // NOTE: complex clips and layers prevent deferral 83 virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, int saveCount, 84 uint32_t level, bool caching, int multipliedAlpha, 85 DeferredDisplayList* deferredList) = 0; 86 87 virtual void output(int level, uint32_t flags = 0) = 0; 88 89 // NOTE: it would be nice to declare constants and overriding the implementation in each op to 90 // point at the constants, but that seems to require a .cpp file 91 virtual const char* name() = 0; 92}; 93 94class StateOp : public DisplayListOp { 95public: 96 StateOp() {}; 97 98 virtual ~StateOp() {} 99 100 /** 101 * State operations are applied directly to the renderer, but can cause the deferred drawing op 102 * list to flush 103 */ 104 virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, int saveCount, 105 uint32_t level, bool caching, int multipliedAlpha, DeferredDisplayList* deferredList) { 106 status_t status = DrawGlInfo::kStatusDone; 107 if (deferredList && requiresDrawOpFlush(renderer)) { 108 // will be setting renderer state that affects ops in deferredList, so flush list first 109 status |= deferredList->flush(renderer, dirty, flags, level); 110 } 111 applyState(renderer, saveCount); 112 return status; 113 } 114 115 virtual void applyState(OpenGLRenderer& renderer, int saveCount) = 0; 116 117 /** 118 * Returns true if it affects renderer drawing state in such a way to break deferral 119 * see OpenGLRenderer::disallowDeferral() 120 */ 121 virtual bool requiresDrawOpFlush(OpenGLRenderer& renderer) { return false; } 122}; 123 124class DrawOp : public DisplayListOp { 125public: 126 DrawOp(SkPaint* paint) 127 : mPaint(paint), mQuickRejected(false) {} 128 129 /** Draw operations are stored in the deferredList with information necessary for playback */ 130 virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, int saveCount, 131 uint32_t level, bool caching, int multipliedAlpha, DeferredDisplayList* deferredList) { 132 if (mQuickRejected && CC_LIKELY(flags & DisplayList::kReplayFlag_ClipChildren)) { 133 return DrawGlInfo::kStatusDone; 134 } 135 136 if (!deferredList || renderer.disallowDeferral()) { 137 // dispatch draw immediately, since the renderer's state is too complex for deferral 138 return applyDraw(renderer, dirty, level, caching, multipliedAlpha); 139 } 140 141 if (!caching) multipliedAlpha = -1; 142 state.mMultipliedAlpha = multipliedAlpha; 143 if (!getLocalBounds(state.mBounds)) { 144 // empty bounds signify bounds can't be calculated 145 state.mBounds.setEmpty(); 146 } 147 148 if (!renderer.storeDisplayState(state)) { 149 // op wasn't quick-rejected, so defer 150 deferredList->add(this, renderer.disallowReorder()); 151 } 152 153 return DrawGlInfo::kStatusDone; 154 } 155 156 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 157 bool caching, int multipliedAlpha) = 0; 158 159 // returns true if bounds exist 160 virtual bool getLocalBounds(Rect& localBounds) { return false; } 161 162 // TODO: better refine localbounds usage 163 void setQuickRejected(bool quickRejected) { mQuickRejected = quickRejected; } 164 bool getQuickRejected() { return mQuickRejected; } 165 166 /** Batching disabled by default, turned on for individual ops */ 167 virtual DeferredDisplayList::OpBatchId getBatchId() { 168 return DeferredDisplayList::kOpBatch_None; 169 } 170 171 float strokeWidthOutset() { return mPaint->getStrokeWidth() * 0.5f; } 172 173 /** 174 * Stores the relevant canvas state of the object between deferral and replay (if the canvas 175 * state supports being stored) See OpenGLRenderer::simpleClipAndState() 176 */ 177 DeferredDisplayState state; 178protected: 179 SkPaint* getPaint(OpenGLRenderer& renderer, bool alwaysCopy = false) { 180 return renderer.filterPaint(mPaint, alwaysCopy); 181 } 182 183 SkPaint* mPaint; // should be accessed via getPaint() when applying 184 bool mQuickRejected; 185}; 186 187class DrawBoundedOp : public DrawOp { 188public: 189 DrawBoundedOp(float left, float top, float right, float bottom, SkPaint* paint) 190 : DrawOp(paint), mLocalBounds(left, top, right, bottom) {} 191 192 // Calculates bounds as smallest rect encompassing all points 193 // NOTE: requires at least 1 vertex, and doesn't account for stroke size (should be handled in 194 // subclass' constructor) 195 DrawBoundedOp(const float* points, int count, SkPaint* paint) 196 : DrawOp(paint), mLocalBounds(points[0], points[1], points[0], points[1]) { 197 for (int i = 2; i < count; i += 2) { 198 mLocalBounds.left = fminf(mLocalBounds.left, points[i]); 199 mLocalBounds.right = fmaxf(mLocalBounds.right, points[i]); 200 mLocalBounds.top = fminf(mLocalBounds.top, points[i + 1]); 201 mLocalBounds.bottom = fmaxf(mLocalBounds.bottom, points[i + 1]); 202 } 203 } 204 205 // default empty constructor for bounds, to be overridden in child constructor body 206 DrawBoundedOp(SkPaint* paint) 207 : DrawOp(paint) {} 208 209 bool getLocalBounds(Rect& localBounds) { 210 localBounds.set(mLocalBounds); 211 return true; 212 } 213 214protected: 215 Rect mLocalBounds; // displayed area in LOCAL coord. doesn't incorporate stroke, so check paint 216}; 217 218/////////////////////////////////////////////////////////////////////////////// 219// STATE OPERATIONS - these may affect the state of the canvas/renderer, but do 220// not directly draw or alter output 221/////////////////////////////////////////////////////////////////////////////// 222 223class SaveOp : public StateOp { 224public: 225 SaveOp(int flags) 226 : mFlags(flags) {} 227 228 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 229 renderer.save(mFlags); 230 } 231 232 virtual void output(int level, uint32_t flags = 0) { 233 OP_LOG("Save flags %x", mFlags); 234 } 235 236 virtual const char* name() { return "Save"; } 237 238private: 239 int mFlags; 240}; 241 242class RestoreToCountOp : public StateOp { 243public: 244 RestoreToCountOp(int count) 245 : mCount(count) {} 246 247 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 248 renderer.restoreToCount(saveCount + mCount); 249 250 } 251 252 virtual void output(int level, uint32_t flags = 0) { 253 OP_LOG("Restore to count %d", mCount); 254 } 255 256 virtual const char* name() { return "RestoreToCount"; } 257 // Note: don't have to return true for requiresDrawOpFlush - even though restore can create a 258 // complex clip, the clip and matrix are overridden by DeferredDisplayList::flush() 259 260private: 261 int mCount; 262}; 263 264class SaveLayerOp : public StateOp { 265public: 266 SaveLayerOp(float left, float top, float right, float bottom, SkPaint* paint, int flags) 267 : mArea(left, top, right, bottom), mPaint(paint), mFlags(flags) {} 268 269 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 270 SkPaint* paint = renderer.filterPaint(mPaint); 271 renderer.saveLayer(mArea.left, mArea.top, mArea.right, mArea.bottom, paint, mFlags); 272 } 273 274 virtual void output(int level, uint32_t flags = 0) { 275 OP_LOG("SaveLayer of area " RECT_STRING, RECT_ARGS(mArea)); 276 } 277 278 virtual const char* name() { return "SaveLayer"; } 279 virtual bool requiresDrawOpFlush(OpenGLRenderer& renderer) { return true; } 280 281private: 282 Rect mArea; 283 SkPaint* mPaint; 284 int mFlags; 285}; 286 287class SaveLayerAlphaOp : public StateOp { 288public: 289 SaveLayerAlphaOp(float left, float top, float right, float bottom, int alpha, int flags) 290 : mArea(left, top, right, bottom), mAlpha(alpha), mFlags(flags) {} 291 292 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 293 renderer.saveLayerAlpha(mArea.left, mArea.top, mArea.right, mArea.bottom, mAlpha, mFlags); 294 } 295 296 virtual void output(int level, uint32_t flags = 0) { 297 OP_LOG("SaveLayerAlpha of area " RECT_STRING, RECT_ARGS(mArea)); 298 } 299 300 virtual const char* name() { return "SaveLayerAlpha"; } 301 virtual bool requiresDrawOpFlush(OpenGLRenderer& renderer) { return true; } 302 303private: 304 Rect mArea; 305 int mAlpha; 306 int mFlags; 307}; 308 309class TranslateOp : public StateOp { 310public: 311 TranslateOp(float dx, float dy) 312 : mDx(dx), mDy(dy) {} 313 314 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 315 renderer.translate(mDx, mDy); 316 } 317 318 virtual void output(int level, uint32_t flags = 0) { 319 OP_LOG("Translate by %f %f", mDx, mDy); 320 } 321 322 virtual const char* name() { return "Translate"; } 323 324private: 325 float mDx; 326 float mDy; 327}; 328 329class RotateOp : public StateOp { 330public: 331 RotateOp(float degrees) 332 : mDegrees(degrees) {} 333 334 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 335 renderer.rotate(mDegrees); 336 } 337 338 virtual void output(int level, uint32_t flags = 0) { 339 OP_LOG("Rotate by %f degrees", mDegrees); 340 } 341 342 virtual const char* name() { return "Rotate"; } 343 344private: 345 float mDegrees; 346}; 347 348class ScaleOp : public StateOp { 349public: 350 ScaleOp(float sx, float sy) 351 : mSx(sx), mSy(sy) {} 352 353 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 354 renderer.scale(mSx, mSy); 355 } 356 357 virtual void output(int level, uint32_t flags = 0) { 358 OP_LOG("Scale by %f %f", mSx, mSy); 359 } 360 361 virtual const char* name() { return "Scale"; } 362 363private: 364 float mSx; 365 float mSy; 366}; 367 368class SkewOp : public StateOp { 369public: 370 SkewOp(float sx, float sy) 371 : mSx(sx), mSy(sy) {} 372 373 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 374 renderer.skew(mSx, mSy); 375 } 376 377 virtual void output(int level, uint32_t flags = 0) { 378 OP_LOG("Skew by %f %f", mSx, mSy); 379 } 380 381 virtual const char* name() { return "Skew"; } 382 383private: 384 float mSx; 385 float mSy; 386}; 387 388class SetMatrixOp : public StateOp { 389public: 390 SetMatrixOp(SkMatrix* matrix) 391 : mMatrix(matrix) {} 392 393 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 394 renderer.setMatrix(mMatrix); 395 } 396 397 virtual void output(int level, uint32_t flags = 0) { 398 OP_LOG("SetMatrix " MATRIX_STRING, MATRIX_ARGS(mMatrix)); 399 } 400 401 virtual const char* name() { return "SetMatrix"; } 402 403private: 404 SkMatrix* mMatrix; 405}; 406 407class ConcatMatrixOp : public StateOp { 408public: 409 ConcatMatrixOp(SkMatrix* matrix) 410 : mMatrix(matrix) {} 411 412 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 413 renderer.concatMatrix(mMatrix); 414 } 415 416 virtual void output(int level, uint32_t flags = 0) { 417 OP_LOG("ConcatMatrix " MATRIX_STRING, MATRIX_ARGS(mMatrix)); 418 } 419 420 virtual const char* name() { return "ConcatMatrix"; } 421 422private: 423 SkMatrix* mMatrix; 424}; 425 426class ClipRectOp : public StateOp { 427public: 428 ClipRectOp(float left, float top, float right, float bottom, SkRegion::Op op) 429 : mArea(left, top, right, bottom), mOp(op) {} 430 431 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 432 renderer.clipRect(mArea.left, mArea.top, mArea.right, mArea.bottom, mOp); 433 } 434 435 virtual void output(int level, uint32_t flags = 0) { 436 OP_LOG("ClipRect " RECT_STRING, RECT_ARGS(mArea)); 437 } 438 439 virtual const char* name() { return "ClipRect"; } 440 441 virtual bool requiresDrawOpFlush(OpenGLRenderer& renderer) { 442 // TODO: currently, we flush when we *might* cause a clip region to exist. Ideally, we 443 // should only flush when a non-rectangular clip would result 444 return !renderer.hasRectToRectTransform() || !hasRectToRectOp(); 445 } 446 447private: 448 inline bool hasRectToRectOp() { 449 return mOp == SkRegion::kIntersect_Op || mOp == SkRegion::kReplace_Op; 450 } 451 Rect mArea; 452 SkRegion::Op mOp; 453}; 454 455class ClipPathOp : public StateOp { 456public: 457 ClipPathOp(SkPath* path, SkRegion::Op op) 458 : mPath(path), mOp(op) {} 459 460 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 461 renderer.clipPath(mPath, mOp); 462 } 463 464 virtual void output(int level, uint32_t flags = 0) { 465 SkRect bounds = mPath->getBounds(); 466 OP_LOG("ClipPath bounds " RECT_STRING, 467 bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); 468 } 469 470 virtual const char* name() { return "ClipPath"; } 471 virtual bool requiresDrawOpFlush(OpenGLRenderer& renderer) { return true; } 472 473private: 474 SkPath* mPath; 475 SkRegion::Op mOp; 476}; 477 478class ClipRegionOp : public StateOp { 479public: 480 ClipRegionOp(SkRegion* region, SkRegion::Op op) 481 : mRegion(region), mOp(op) {} 482 483 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 484 renderer.clipRegion(mRegion, mOp); 485 } 486 487 virtual void output(int level, uint32_t flags = 0) { 488 SkIRect bounds = mRegion->getBounds(); 489 OP_LOG("ClipRegion bounds %d %d %d %d", 490 bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); 491 } 492 493 virtual const char* name() { return "ClipRegion"; } 494 virtual bool requiresDrawOpFlush(OpenGLRenderer& renderer) { return true; } 495 496private: 497 SkRegion* mRegion; 498 SkRegion::Op mOp; 499}; 500 501class ResetShaderOp : public StateOp { 502public: 503 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 504 renderer.resetShader(); 505 } 506 507 virtual void output(int level, uint32_t flags = 0) { 508 OP_LOGS("ResetShader"); 509 } 510 511 virtual const char* name() { return "ResetShader"; } 512}; 513 514class SetupShaderOp : public StateOp { 515public: 516 SetupShaderOp(SkiaShader* shader) 517 : mShader(shader) {} 518 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 519 renderer.setupShader(mShader); 520 } 521 522 virtual void output(int level, uint32_t flags = 0) { 523 OP_LOG("SetupShader, shader %p", mShader); 524 } 525 526 virtual const char* name() { return "SetupShader"; } 527 528private: 529 SkiaShader* mShader; 530}; 531 532class ResetColorFilterOp : public StateOp { 533public: 534 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 535 renderer.resetColorFilter(); 536 } 537 538 virtual void output(int level, uint32_t flags = 0) { 539 OP_LOGS("ResetColorFilter"); 540 } 541 542 virtual const char* name() { return "ResetColorFilter"; } 543}; 544 545class SetupColorFilterOp : public StateOp { 546public: 547 SetupColorFilterOp(SkiaColorFilter* colorFilter) 548 : mColorFilter(colorFilter) {} 549 550 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 551 renderer.setupColorFilter(mColorFilter); 552 } 553 554 virtual void output(int level, uint32_t flags = 0) { 555 OP_LOG("SetupColorFilter, filter %p", mColorFilter); 556 } 557 558 virtual const char* name() { return "SetupColorFilter"; } 559 560private: 561 SkiaColorFilter* mColorFilter; 562}; 563 564class ResetShadowOp : public StateOp { 565public: 566 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 567 renderer.resetShadow(); 568 } 569 570 virtual void output(int level, uint32_t flags = 0) { 571 OP_LOGS("ResetShadow"); 572 } 573 574 virtual const char* name() { return "ResetShadow"; } 575}; 576 577class SetupShadowOp : public StateOp { 578public: 579 SetupShadowOp(float radius, float dx, float dy, int color) 580 : mRadius(radius), mDx(dx), mDy(dy), mColor(color) {} 581 582 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 583 renderer.setupShadow(mRadius, mDx, mDy, mColor); 584 } 585 586 virtual void output(int level, uint32_t flags = 0) { 587 OP_LOG("SetupShadow, radius %f, %f, %f, color %#x", mRadius, mDx, mDy, mColor); 588 } 589 590 virtual const char* name() { return "SetupShadow"; } 591 592private: 593 float mRadius; 594 float mDx; 595 float mDy; 596 int mColor; 597}; 598 599class ResetPaintFilterOp : public StateOp { 600public: 601 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 602 renderer.resetPaintFilter(); 603 } 604 605 virtual void output(int level, uint32_t flags = 0) { 606 OP_LOGS("ResetPaintFilter"); 607 } 608 609 virtual const char* name() { return "ResetPaintFilter"; } 610}; 611 612class SetupPaintFilterOp : public StateOp { 613public: 614 SetupPaintFilterOp(int clearBits, int setBits) 615 : mClearBits(clearBits), mSetBits(setBits) {} 616 617 virtual void applyState(OpenGLRenderer& renderer, int saveCount) { 618 renderer.setupPaintFilter(mClearBits, mSetBits); 619 } 620 621 virtual void output(int level, uint32_t flags = 0) { 622 OP_LOG("SetupPaintFilter, clear %#x, set %#x", mClearBits, mSetBits); 623 } 624 625 virtual const char* name() { return "SetupPaintFilter"; } 626 627private: 628 int mClearBits; 629 int mSetBits; 630}; 631 632 633/////////////////////////////////////////////////////////////////////////////// 634// DRAW OPERATIONS - these are operations that can draw to the canvas's device 635/////////////////////////////////////////////////////////////////////////////// 636 637class DrawBitmapOp : public DrawBoundedOp { 638public: 639 DrawBitmapOp(SkBitmap* bitmap, float left, float top, SkPaint* paint) 640 : DrawBoundedOp(left, top, left + bitmap->width(), top + bitmap->height(), 641 paint), 642 mBitmap(bitmap) {} 643 644 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 645 bool caching, int multipliedAlpha) { 646 bool makeCopy = caching && multipliedAlpha < 255; 647 SkPaint* paint = getPaint(renderer, makeCopy); 648 if (makeCopy) { 649 // The paint is safe to modify since we're working on a copy 650 paint->setAlpha(multipliedAlpha); 651 } 652 status_t ret = renderer.drawBitmap(mBitmap, mLocalBounds.left, mLocalBounds.top, paint); 653 return ret; 654 } 655 656 virtual void output(int level, uint32_t flags) { 657 OP_LOG("Draw bitmap %p at %f %f", mBitmap, mLocalBounds.left, mLocalBounds.top); 658 } 659 660 virtual const char* name() { return "DrawBitmap"; } 661 virtual DeferredDisplayList::OpBatchId getBatchId() { 662 return DeferredDisplayList::kOpBatch_Bitmap; 663 } 664 665protected: 666 SkBitmap* mBitmap; 667}; 668 669class DrawBitmapMatrixOp : public DrawBoundedOp { 670public: 671 DrawBitmapMatrixOp(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) 672 : DrawBoundedOp(paint), mBitmap(bitmap), mMatrix(matrix) { 673 mLocalBounds.set(0, 0, bitmap->width(), bitmap->height()); 674 const mat4 transform(*matrix); 675 transform.mapRect(mLocalBounds); 676 } 677 678 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 679 bool caching, int multipliedAlpha) { 680 return renderer.drawBitmap(mBitmap, mMatrix, getPaint(renderer)); 681 } 682 683 virtual void output(int level, uint32_t flags) { 684 OP_LOG("Draw bitmap %p matrix " MATRIX_STRING, mBitmap, MATRIX_ARGS(mMatrix)); 685 } 686 687 virtual const char* name() { return "DrawBitmap"; } 688 virtual DeferredDisplayList::OpBatchId getBatchId() { 689 return DeferredDisplayList::kOpBatch_Bitmap; 690 } 691 692private: 693 SkBitmap* mBitmap; 694 SkMatrix* mMatrix; 695}; 696 697class DrawBitmapRectOp : public DrawBoundedOp { 698public: 699 DrawBitmapRectOp(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, 700 float dstLeft, float dstTop, float dstRight, float dstBottom, SkPaint* paint) 701 : DrawBoundedOp(dstLeft, dstTop, dstRight, dstBottom, paint), 702 mBitmap(bitmap), mSrc(srcLeft, srcTop, srcRight, srcBottom) {} 703 704 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 705 bool caching, int multipliedAlpha) { 706 return renderer.drawBitmap(mBitmap, mSrc.left, mSrc.top, mSrc.right, mSrc.bottom, 707 mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom, 708 getPaint(renderer)); 709 } 710 711 virtual void output(int level, uint32_t flags) { 712 OP_LOG("Draw bitmap %p src="RECT_STRING", dst="RECT_STRING, 713 mBitmap, RECT_ARGS(mSrc), RECT_ARGS(mLocalBounds)); 714 } 715 716 virtual const char* name() { return "DrawBitmapRect"; } 717 virtual DeferredDisplayList::OpBatchId getBatchId() { 718 return DeferredDisplayList::kOpBatch_Bitmap; 719 } 720 721private: 722 SkBitmap* mBitmap; 723 Rect mSrc; 724}; 725 726class DrawBitmapDataOp : public DrawBitmapOp { 727public: 728 DrawBitmapDataOp(SkBitmap* bitmap, float left, float top, SkPaint* paint) 729 : DrawBitmapOp(bitmap, left, top, paint) {} 730 731 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 732 bool caching, int multipliedAlpha) { 733 return renderer.drawBitmapData(mBitmap, mLocalBounds.left, 734 mLocalBounds.top, getPaint(renderer)); 735 } 736 737 virtual void output(int level, uint32_t flags) { 738 OP_LOG("Draw bitmap %p", mBitmap); 739 } 740 741 virtual const char* name() { return "DrawBitmapData"; } 742 virtual DeferredDisplayList::OpBatchId getBatchId() { 743 return DeferredDisplayList::kOpBatch_Bitmap; 744 } 745}; 746 747class DrawBitmapMeshOp : public DrawBoundedOp { 748public: 749 DrawBitmapMeshOp(SkBitmap* bitmap, int meshWidth, int meshHeight, 750 float* vertices, int* colors, SkPaint* paint) 751 : DrawBoundedOp(vertices, 2 * (meshWidth + 1) * (meshHeight + 1), paint), 752 mBitmap(bitmap), mMeshWidth(meshWidth), mMeshHeight(meshHeight), 753 mVertices(vertices), mColors(colors) {} 754 755 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 756 bool caching, int multipliedAlpha) { 757 return renderer.drawBitmapMesh(mBitmap, mMeshWidth, mMeshHeight, 758 mVertices, mColors, getPaint(renderer)); 759 } 760 761 virtual void output(int level, uint32_t flags) { 762 OP_LOG("Draw bitmap %p mesh %d x %d", mBitmap, mMeshWidth, mMeshHeight); 763 } 764 765 virtual const char* name() { return "DrawBitmapMesh"; } 766 virtual DeferredDisplayList::OpBatchId getBatchId() { 767 return DeferredDisplayList::kOpBatch_Bitmap; 768 } 769 770private: 771 SkBitmap* mBitmap; 772 int mMeshWidth; 773 int mMeshHeight; 774 float* mVertices; 775 int* mColors; 776}; 777 778class DrawPatchOp : public DrawBoundedOp { 779public: 780 DrawPatchOp(SkBitmap* bitmap, const int32_t* xDivs, 781 const int32_t* yDivs, const uint32_t* colors, uint32_t width, uint32_t height, 782 int8_t numColors, float left, float top, float right, float bottom, 783 int alpha, SkXfermode::Mode mode) 784 : DrawBoundedOp(left, top, right, bottom, 0), 785 mBitmap(bitmap), mxDivs(xDivs), myDivs(yDivs), 786 mColors(colors), mxDivsCount(width), myDivsCount(height), 787 mNumColors(numColors), mAlpha(alpha), mMode(mode) {}; 788 789 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 790 bool caching, int multipliedAlpha) { 791 // NOTE: not calling the virtual method, which takes a paint 792 return renderer.drawPatch(mBitmap, mxDivs, myDivs, mColors, 793 mxDivsCount, myDivsCount, mNumColors, 794 mLocalBounds.left, mLocalBounds.top, 795 mLocalBounds.right, mLocalBounds.bottom, mAlpha, mMode); 796 } 797 798 virtual void output(int level, uint32_t flags) { 799 OP_LOG("Draw patch "RECT_STRING, RECT_ARGS(mLocalBounds)); 800 } 801 802 virtual const char* name() { return "DrawPatch"; } 803 virtual DeferredDisplayList::OpBatchId getBatchId() { 804 return DeferredDisplayList::kOpBatch_Patch; 805 } 806 807private: 808 SkBitmap* mBitmap; 809 const int32_t* mxDivs; 810 const int32_t* myDivs; 811 const uint32_t* mColors; 812 uint32_t mxDivsCount; 813 uint32_t myDivsCount; 814 int8_t mNumColors; 815 int mAlpha; 816 SkXfermode::Mode mMode; 817}; 818 819class DrawColorOp : public DrawOp { 820public: 821 DrawColorOp(int color, SkXfermode::Mode mode) 822 : DrawOp(0), mColor(color), mMode(mode) {}; 823 824 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 825 bool caching, int multipliedAlpha) { 826 return renderer.drawColor(mColor, mMode); 827 } 828 829 virtual void output(int level, uint32_t flags) { 830 OP_LOG("Draw color %#x, mode %d", mColor, mMode); 831 } 832 833 virtual const char* name() { return "DrawColor"; } 834 835private: 836 int mColor; 837 SkXfermode::Mode mMode; 838}; 839 840class DrawStrokableOp : public DrawBoundedOp { 841public: 842 DrawStrokableOp(float left, float top, float right, float bottom, SkPaint* paint) 843 : DrawBoundedOp(left, top, right, bottom, paint) {}; 844 845 bool getLocalBounds(Rect& localBounds) { 846 localBounds.set(mLocalBounds); 847 if (mPaint && mPaint->getStyle() != SkPaint::kFill_Style) { 848 localBounds.outset(strokeWidthOutset()); 849 } 850 return true; 851 } 852 853 virtual DeferredDisplayList::OpBatchId getBatchId() { 854 if (mPaint->getPathEffect()) { 855 return DeferredDisplayList::kOpBatch_AlphaMaskTexture; 856 } 857 return mPaint->isAntiAlias() ? 858 DeferredDisplayList::kOpBatch_AlphaVertices : 859 DeferredDisplayList::kOpBatch_Vertices; 860 } 861}; 862 863class DrawRectOp : public DrawStrokableOp { 864public: 865 DrawRectOp(float left, float top, float right, float bottom, SkPaint* paint) 866 : DrawStrokableOp(left, top, right, bottom, paint) {} 867 868 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 869 bool caching, int multipliedAlpha) { 870 return renderer.drawRect(mLocalBounds.left, mLocalBounds.top, 871 mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer)); 872 } 873 874 virtual void output(int level, uint32_t flags) { 875 OP_LOG("Draw Rect "RECT_STRING, RECT_ARGS(mLocalBounds)); 876 } 877 878 virtual const char* name() { return "DrawRect"; } 879}; 880 881class DrawRectsOp : public DrawBoundedOp { 882public: 883 DrawRectsOp(const float* rects, int count, SkPaint* paint) 884 : DrawBoundedOp(rects, count, paint), 885 mRects(rects), mCount(count) {} 886 887 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 888 bool caching, int multipliedAlpha) { 889 return renderer.drawRects(mRects, mCount, getPaint(renderer)); 890 } 891 892 virtual void output(int level, uint32_t flags) { 893 OP_LOG("Draw Rects count %d", mCount); 894 } 895 896 virtual const char* name() { return "DrawRects"; } 897 898 virtual DeferredDisplayList::OpBatchId getBatchId() { 899 return DeferredDisplayList::kOpBatch_Vertices; 900 } 901 902private: 903 const float* mRects; 904 int mCount; 905}; 906 907class DrawRoundRectOp : public DrawStrokableOp { 908public: 909 DrawRoundRectOp(float left, float top, float right, float bottom, 910 float rx, float ry, SkPaint* paint) 911 : DrawStrokableOp(left, top, right, bottom, paint), mRx(rx), mRy(ry) {} 912 913 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 914 bool caching, int multipliedAlpha) { 915 return renderer.drawRoundRect(mLocalBounds.left, mLocalBounds.top, 916 mLocalBounds.right, mLocalBounds.bottom, mRx, mRy, getPaint(renderer)); 917 } 918 919 virtual void output(int level, uint32_t flags) { 920 OP_LOG("Draw RoundRect "RECT_STRING", rx %f, ry %f", RECT_ARGS(mLocalBounds), mRx, mRy); 921 } 922 923 virtual const char* name() { return "DrawRoundRect"; } 924 925private: 926 float mRx; 927 float mRy; 928}; 929 930class DrawCircleOp : public DrawStrokableOp { 931public: 932 DrawCircleOp(float x, float y, float radius, SkPaint* paint) 933 : DrawStrokableOp(x - radius, y - radius, x + radius, y + radius, paint), 934 mX(x), mY(y), mRadius(radius) {} 935 936 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 937 bool caching, int multipliedAlpha) { 938 return renderer.drawCircle(mX, mY, mRadius, getPaint(renderer)); 939 } 940 941 virtual void output(int level, uint32_t flags) { 942 OP_LOG("Draw Circle x %f, y %f, r %f", mX, mY, mRadius); 943 } 944 945 virtual const char* name() { return "DrawCircle"; } 946 947private: 948 float mX; 949 float mY; 950 float mRadius; 951}; 952 953class DrawOvalOp : public DrawStrokableOp { 954public: 955 DrawOvalOp(float left, float top, float right, float bottom, SkPaint* paint) 956 : DrawStrokableOp(left, top, right, bottom, paint) {} 957 958 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 959 bool caching, int multipliedAlpha) { 960 return renderer.drawOval(mLocalBounds.left, mLocalBounds.top, 961 mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer)); 962 } 963 964 virtual void output(int level, uint32_t flags) { 965 OP_LOG("Draw Oval "RECT_STRING, RECT_ARGS(mLocalBounds)); 966 } 967 968 virtual const char* name() { return "DrawOval"; } 969}; 970 971class DrawArcOp : public DrawStrokableOp { 972public: 973 DrawArcOp(float left, float top, float right, float bottom, 974 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) 975 : DrawStrokableOp(left, top, right, bottom, paint), 976 mStartAngle(startAngle), mSweepAngle(sweepAngle), mUseCenter(useCenter) {} 977 978 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 979 bool caching, int multipliedAlpha) { 980 return renderer.drawArc(mLocalBounds.left, mLocalBounds.top, 981 mLocalBounds.right, mLocalBounds.bottom, 982 mStartAngle, mSweepAngle, mUseCenter, getPaint(renderer)); 983 } 984 985 virtual void output(int level, uint32_t flags) { 986 OP_LOG("Draw Arc "RECT_STRING", start %f, sweep %f, useCenter %d", 987 RECT_ARGS(mLocalBounds), mStartAngle, mSweepAngle, mUseCenter); 988 } 989 990 virtual const char* name() { return "DrawArc"; } 991 992private: 993 float mStartAngle; 994 float mSweepAngle; 995 bool mUseCenter; 996}; 997 998class DrawPathOp : public DrawBoundedOp { 999public: 1000 DrawPathOp(SkPath* path, SkPaint* paint) 1001 : DrawBoundedOp(paint), mPath(path) { 1002 float left, top, offset; 1003 uint32_t width, height; 1004 computePathBounds(path, paint, left, top, offset, width, height); 1005 left -= offset; 1006 top -= offset; 1007 mLocalBounds.set(left, top, left + width, top + height); 1008 } 1009 1010 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1011 bool caching, int multipliedAlpha) { 1012 return renderer.drawPath(mPath, getPaint(renderer)); 1013 } 1014 1015 virtual void output(int level, uint32_t flags) { 1016 OP_LOG("Draw Path %p in "RECT_STRING, mPath, RECT_ARGS(mLocalBounds)); 1017 } 1018 1019 virtual const char* name() { return "DrawPath"; } 1020 1021 virtual DeferredDisplayList::OpBatchId getBatchId() { 1022 return DeferredDisplayList::kOpBatch_AlphaMaskTexture; 1023 } 1024private: 1025 SkPath* mPath; 1026}; 1027 1028class DrawLinesOp : public DrawBoundedOp { 1029public: 1030 DrawLinesOp(float* points, int count, SkPaint* paint) 1031 : DrawBoundedOp(points, count, paint), 1032 mPoints(points), mCount(count) { 1033 mLocalBounds.outset(strokeWidthOutset()); 1034 } 1035 1036 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1037 bool caching, int multipliedAlpha) { 1038 return renderer.drawLines(mPoints, mCount, getPaint(renderer)); 1039 } 1040 1041 virtual void output(int level, uint32_t flags) { 1042 OP_LOG("Draw Lines count %d", mCount); 1043 } 1044 1045 virtual const char* name() { return "DrawLines"; } 1046 1047 virtual DeferredDisplayList::OpBatchId getBatchId() { 1048 return mPaint->isAntiAlias() ? 1049 DeferredDisplayList::kOpBatch_AlphaVertices : 1050 DeferredDisplayList::kOpBatch_Vertices; 1051 } 1052 1053protected: 1054 float* mPoints; 1055 int mCount; 1056}; 1057 1058class DrawPointsOp : public DrawLinesOp { 1059public: 1060 DrawPointsOp(float* points, int count, SkPaint* paint) 1061 : DrawLinesOp(points, count, paint) {} 1062 1063 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1064 bool caching, int multipliedAlpha) { 1065 return renderer.drawPoints(mPoints, mCount, getPaint(renderer)); 1066 } 1067 1068 virtual void output(int level, uint32_t flags) { 1069 OP_LOG("Draw Points count %d", mCount); 1070 } 1071 1072 virtual const char* name() { return "DrawPoints"; } 1073}; 1074 1075class DrawSomeTextOp : public DrawOp { 1076public: 1077 DrawSomeTextOp(const char* text, int bytesCount, int count, SkPaint* paint) 1078 : DrawOp(paint), mText(text), mBytesCount(bytesCount), mCount(count) {}; 1079 1080 virtual void output(int level, uint32_t flags) { 1081 OP_LOG("Draw some text, %d bytes", mBytesCount); 1082 } 1083 1084 virtual DeferredDisplayList::OpBatchId getBatchId() { 1085 return mPaint->getColor() == 0xff000000 ? 1086 DeferredDisplayList::kOpBatch_Text : 1087 DeferredDisplayList::kOpBatch_ColorText; 1088 } 1089protected: 1090 const char* mText; 1091 int mBytesCount; 1092 int mCount; 1093}; 1094 1095class DrawTextOnPathOp : public DrawSomeTextOp { 1096public: 1097 DrawTextOnPathOp(const char* text, int bytesCount, int count, 1098 SkPath* path, float hOffset, float vOffset, SkPaint* paint) 1099 : DrawSomeTextOp(text, bytesCount, count, paint), 1100 mPath(path), mHOffset(hOffset), mVOffset(vOffset) { 1101 /* TODO: inherit from DrawBounded and init mLocalBounds */ 1102 } 1103 1104 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1105 bool caching, int multipliedAlpha) { 1106 return renderer.drawTextOnPath(mText, mBytesCount, mCount, mPath, 1107 mHOffset, mVOffset, getPaint(renderer)); 1108 } 1109 1110 virtual const char* name() { return "DrawTextOnPath"; } 1111 1112private: 1113 SkPath* mPath; 1114 float mHOffset; 1115 float mVOffset; 1116}; 1117 1118class DrawPosTextOp : public DrawSomeTextOp { 1119public: 1120 DrawPosTextOp(const char* text, int bytesCount, int count, 1121 const float* positions, SkPaint* paint) 1122 : DrawSomeTextOp(text, bytesCount, count, paint), mPositions(positions) { 1123 /* TODO: inherit from DrawBounded and init mLocalBounds */ 1124 } 1125 1126 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1127 bool caching, int multipliedAlpha) { 1128 return renderer.drawPosText(mText, mBytesCount, mCount, mPositions, getPaint(renderer)); 1129 } 1130 1131 virtual const char* name() { return "DrawPosText"; } 1132 1133private: 1134 const float* mPositions; 1135}; 1136 1137class DrawTextOp : public DrawBoundedOp { 1138public: 1139 DrawTextOp(const char* text, int bytesCount, int count, float x, float y, 1140 const float* positions, SkPaint* paint, float length) 1141 : DrawBoundedOp(paint), mText(text), mBytesCount(bytesCount), mCount(count), 1142 mX(x), mY(y), mPositions(positions), mLength(length) { 1143 // duplicates bounds calculation from OpenGLRenderer::drawText, but doesn't alter mX 1144 SkPaint::FontMetrics metrics; 1145 paint->getFontMetrics(&metrics, 0.0f); 1146 switch (paint->getTextAlign()) { 1147 case SkPaint::kCenter_Align: 1148 x -= length / 2.0f; 1149 break; 1150 case SkPaint::kRight_Align: 1151 x -= length; 1152 break; 1153 default: 1154 break; 1155 } 1156 mLocalBounds.set(x, mY + metrics.fTop, x + length, mY + metrics.fBottom); 1157 } 1158 1159 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1160 bool caching, int multipliedAlpha) { 1161 return renderer.drawText(mText, mBytesCount, mCount, mX, mY, 1162 mPositions, getPaint(renderer), mLength); 1163 } 1164 1165 virtual void output(int level, uint32_t flags) { 1166 OP_LOG("Draw Text of count %d, bytes %d", mCount, mBytesCount); 1167 } 1168 1169 virtual const char* name() { return "DrawText"; } 1170 1171 virtual DeferredDisplayList::OpBatchId getBatchId() { 1172 return mPaint->getColor() == 0xff000000 ? 1173 DeferredDisplayList::kOpBatch_Text : 1174 DeferredDisplayList::kOpBatch_ColorText; 1175 } 1176 1177private: 1178 const char* mText; 1179 int mBytesCount; 1180 int mCount; 1181 float mX; 1182 float mY; 1183 const float* mPositions; 1184 float mLength; 1185}; 1186 1187/////////////////////////////////////////////////////////////////////////////// 1188// SPECIAL DRAW OPERATIONS 1189/////////////////////////////////////////////////////////////////////////////// 1190 1191class DrawFunctorOp : public DrawOp { 1192public: 1193 DrawFunctorOp(Functor* functor) 1194 : DrawOp(0), mFunctor(functor) {} 1195 1196 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1197 bool caching, int multipliedAlpha) { 1198 renderer.startMark("GL functor"); 1199 status_t ret = renderer.callDrawGLFunction(mFunctor, dirty); 1200 renderer.endMark(); 1201 return ret; 1202 } 1203 1204 virtual void output(int level, uint32_t flags) { 1205 OP_LOG("Draw Functor %p", mFunctor); 1206 } 1207 1208 virtual const char* name() { return "DrawFunctor"; } 1209 1210private: 1211 Functor* mFunctor; 1212}; 1213 1214class DrawDisplayListOp : public DrawBoundedOp { 1215public: 1216 DrawDisplayListOp(DisplayList* displayList, int flags) 1217 : DrawBoundedOp(0, 0, displayList->getWidth(), displayList->getHeight(), 0), 1218 mDisplayList(displayList), mFlags(flags) {} 1219 1220 virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, int saveCount, 1221 uint32_t level, bool caching, int multipliedAlpha, DeferredDisplayList* deferredList) { 1222 if (mDisplayList && mDisplayList->isRenderable()) { 1223 return mDisplayList->replay(renderer, dirty, mFlags, level + 1, deferredList); 1224 } 1225 return DrawGlInfo::kStatusDone; 1226 } 1227 1228 // NOT USED, since replay is overridden 1229 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1230 bool caching, int multipliedAlpha) { return DrawGlInfo::kStatusDone; } 1231 1232 virtual void output(int level, uint32_t flags) { 1233 OP_LOG("Draw Display List %p, flags %#x", mDisplayList, mFlags); 1234 if (mDisplayList && (flags & kOpLogFlag_Recurse)) { 1235 mDisplayList->output(level + 1); 1236 } 1237 } 1238 1239 virtual const char* name() { return "DrawDisplayList"; } 1240 1241private: 1242 DisplayList* mDisplayList; 1243 int mFlags; 1244}; 1245 1246class DrawLayerOp : public DrawOp { 1247public: 1248 DrawLayerOp(Layer* layer, float x, float y, SkPaint* paint) 1249 : DrawOp(paint), mLayer(layer), mX(x), mY(y) {} 1250 1251 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level, 1252 bool caching, int multipliedAlpha) { 1253 int oldAlpha = -1; 1254 1255 if (caching && multipliedAlpha < 255) { 1256 oldAlpha = mLayer->getAlpha(); 1257 mLayer->setAlpha(multipliedAlpha); 1258 } 1259 status_t ret = renderer.drawLayer(mLayer, mX, mY, getPaint(renderer)); 1260 if (oldAlpha >= 0) { 1261 mLayer->setAlpha(oldAlpha); 1262 } 1263 return ret; 1264 } 1265 1266 virtual void output(int level, uint32_t flags) { 1267 OP_LOG("Draw Layer %p at %f %f", mLayer, mX, mY); 1268 } 1269 1270 virtual const char* name() { return "DrawLayer"; } 1271 1272private: 1273 Layer* mLayer; 1274 float mX; 1275 float mY; 1276}; 1277 1278}; // namespace uirenderer 1279}; // namespace android 1280 1281#endif // ANDROID_HWUI_DISPLAY_OPERATION_H 1282