File: managed_surface.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (861 lines) | stat: -rw-r--r-- 29,724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef GRAPHICS_MANAGED_SURFACE_H
#define GRAPHICS_MANAGED_SURFACE_H

#include "graphics/pixelformat.h"
#include "graphics/surface.h"
#include "graphics/transform_struct.h"
#include "common/types.h"
#include "graphics/blit.h"

#define MS_RGB(R,G,B)       (uint32)(((R) << 24) | ((G) << 16) | ((B) << 8) | 0xff)
#define MS_ARGB(A,R,G,B)    (uint32)(((R) << 24) | ((G) << 16) | ((B) << 8) | (A))

namespace Graphics {

class Palette;

/**
 * @defgroup graphics_managed_surface Managed surface
 * @ingroup graphics
 *
 * @brief The ManagedSurface class that adds extra functionality on top of the Surface class.
 *
 * @{
 */

/**
 * A derived graphics surface, which supports automatically managing the allocated
 * surface data block and introduces several new blitting methods.
 */
class ManagedSurface {
private:
	/**
	 * The Graphics::Surface that the managed surface encapsulates.
	 */
	Surface _innerSurface;

	/**
	 * If set, the inner surface will be freed when the surface is recreated,
	 * as well as when the surface is destroyed.
	 */
	DisposeAfterUse::Flag _disposeAfterUse;

	/**
	 * If this managed surface represents a subsection of another managed surface,
	 * store the owning surface.
	 */
	ManagedSurface *_owner;

	/**
	 * For a managed surface that has a parent, this represents the offset from
	 * the parent's top-left corner where this sub-surface starts at.
	 */
	Common::Point _offsetFromOwner;

	/**
	 * Automatic transparency color. When set, it does not require transparency to be
	 * explicitly passed, and blit methods pass on to transBlit.
	 */
	uint _transparentColor;
	bool _transparentColorSet;

	/**
	 * Local palette for 8-bit images.
	 */
	Palette *_palette;
protected:
	/**
	 * Inner method for blitting.
	 */
	void simpleBlitFromInner(const Surface &src, const Common::Rect &srcRect,
		const Common::Point &destPos, const Palette *srcPalette,
		bool transparentColorSet, uint transparentColor);

	/**
	 * Inner method for blitting.
	 */
	void blitFromInner(const Surface &src, const Common::Rect &srcRect,
		const Common::Rect &destRect, const Palette *srcPalette);

	/**
	 * Inner method for copying another surface into this one at a given destination position.
	 */
	void transBlitFromInner(const Surface &src, const Common::Rect &srcRect,
		const Common::Rect &destRect, uint32 transColor, bool flipped, uint32 overrideColor,
		uint32 srcAlpha, const Palette *srcPalette, const Palette *dstPalette,
		const Surface *mask, bool maskOnly);
public:
	/**
	 * Clip the given source bounds so the passed destBounds will be entirely on-screen.
	 */
	bool clip(Common::Rect& srcBounds, Common::Rect& destBounds) const {
		return _innerSurface.clip(srcBounds, destBounds);
	}

public:
	int16 &w;           /*!< Width of the surface rectangle. */
	int16 &h;           /*!< Height of the surface rectangle. */
	int32 &pitch;       /*!< Pitch of the surface rectangle. See @ref Surface::pitch. */
	PixelFormat &format; /*!< Pixel format of the surface. See @ref PixelFormat. */
public:
	/**
	 * Create the managed surface.
	 */
	ManagedSurface();

	/**
	 * Create a managed surface from another one.
	 *
	 * If the source surface is maintaining its own surface data, then
	 * this surface will create its own surface of the same size and copy
	 * the contents from the source surface.
	 */
	WARN_DEPRECATED("Use copyFrom(), a move constructor or supply bounds")
	ManagedSurface(const ManagedSurface &surf);

	/**
	 * Create a managed surface from another one.
	 */
	ManagedSurface(ManagedSurface &&surf);

	/**
	 * Create the managed surface.
	 */
	ManagedSurface(int width, int height);

	/**
	 * Create the managed surface.
	 */
	ManagedSurface(int width, int height, const Graphics::PixelFormat &pixelFormat);

	/**
	 * Create the managed surface.
	 */
	ManagedSurface(ManagedSurface &surf, const Common::Rect &bounds);

	/**
	 * Create a managed surface from plain Surface.
	 *
	 * If disposeAfterUse flag is set (default), the surface will reuse all structures
	 * from the surface and destroy it, otherwise it will make a copy.
	 */
	WARN_DEPRECATED("Use copyFrom() instead")
	ManagedSurface(Surface *surf, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);

	/**
	 * Create a managed surface from plain Surface.
	 */
	WARN_DEPRECATED("Use copyFrom() instead")
	ManagedSurface(const Surface *surf);

	/**
	 * Destroy the managed surface.
	 */
	virtual ~ManagedSurface();

	/**
	 * Automatically convert to a Graphics::Surface by
	 * simply returning the inner surface.
	 *
	 * This must be const, because changes are not supposed to be done
	 * directly to it, since it would bypass dirty rect handling.
	 */
	operator const Surface &() const { return _innerSurface; }

	/**
	 * Return the underlying Graphics::Surface
	 *
	 * If a caller uses the non-const surfacePtr version and changes
	 * the surface, they'll be responsible for calling addDirtyRect
	 * for any affected area
	 */
	const Surface &rawSurface() const { return _innerSurface; }
	Surface *surfacePtr() { return &_innerSurface; }

	/**
	 * Reassign one managed surface to another one.
	 *
	 * @note If the source has a managed surface, it will be duplicated.
	 */
	WARN_DEPRECATED("Use copyFrom() or a move constructor instead")
	ManagedSurface &operator=(const ManagedSurface &surf);

	/**
	 * Reassign one managed surface to another one.
	 */
	ManagedSurface &operator=(ManagedSurface &&surf);

	/**
	 * Return true if the surface has not yet been allocated.
	 */
	bool empty() const { return w == 0 || h == 0 || _innerSurface.getPixels() == nullptr; }

	/**
	 * Return true if the surface manages its own pixels.
	 */
	DisposeAfterUse::Flag disposeAfterUse() const { return _disposeAfterUse; }

	/**
	 * Return the pixel at the specified point.
	 *
	 * @param x  The x coordinate of the pixel.
	 * @param y  The y coordinate of the pixel.
	 *
	 * @return The value of the pixel.
	 */
	inline uint32 getPixel(int x, int y) const {
		return _innerSurface.getPixel(x, y);
	}

	/**
	 * Set the pixel at the specified point.
	 *
	 * @param x     The x coordinate of the pixel.
	 * @param y     The y coordinate of the pixel.
	 * @param pixel The value of the pixel.
	 */
	inline void setPixel(int x, int y, uint32 pixel) {
		return _innerSurface.setPixel(x, y, pixel);
	}

	/**
	 * Return a pointer to the pixel at the specified point.
	 *
	 * @param x  The x coordinate of the pixel.
	 * @param y  The y coordinate of the pixel.
	 *
	 * @return Pointer to the pixel.
	 */
	inline const void *getBasePtr(int x, int y) const {
		return _innerSurface.getBasePtr(x, y);
	}

	/**
	 * Return a pointer to the pixel at the specified point.
	 *
	 * @param x  The x coordinate of the pixel.
	 * @param y  The y coordinate of the pixel.
	 *
	 * @return Pointer to the pixel.
	 */
	inline void *getBasePtr(int x, int y) {
		return _innerSurface.getBasePtr(x, y);
	}

	/**
	 * Get a reference to the pixel data.
	 */
	inline void *getPixels() { return _innerSurface.getPixels(); }
	/** @overload */
	inline const void *getPixels() const { return _innerSurface.getPixels(); }

	/**
	 * Set the pixel data.
	 */
	virtual void setPixels(void *newPixels);

	/**
	 * Allocate memory for the pixel data of the surface.
	 */
	virtual void create(int16 width, int16 height);

	/**
	 * Allocate memory for the pixel data of the surface.
	 */
	virtual void create(int16 width, int16 height, const PixelFormat &pixelFormat);

	/**
	 * Set up the surface as a subsection of another passed parent surface.
	 *
	 * This surface will not own the pixels, and any dirty rect notifications will be
	 * automatically passed to the original parent surface.
	 *
	 * @note This differs from Graphics::Surface::getSubArea, in that this
	 * method only adds a single initial dirty rect for the whole area, and then none more.
	 */
	virtual void create(ManagedSurface &surf, const Common::Rect &bounds);

	/**
	 * Release the memory used by the pixel memory of this surface.
	 *
	 * This is a counterpart of create().
	 */
	virtual void free();

	/**
	 * Clear any pending dirty rectangles that have been generated for the surface.
	 */
	virtual void clearDirtyRects() {}

	/**
	 * Base method that descendant classes can override for recording the affected
	 * dirty areas of the surface.
	 */
	virtual void addDirtyRect(const Common::Rect &r);

	/**
	 * When the managed surface is a subsection of a parent surface, return the
	 * the offset in the parent surface where the managed surface starts at.
	 */
	const Common::Point getOffsetFromOwner() const { return _offsetFromOwner; }

	/**
	 * Return a rect providing the bounds of the surface.
	 */
	const Common::Rect getBounds() const {
		return Common::Rect(0, 0, this->w, this->h);
	}

	/**
	 * Copy another surface into this one.
	 */
	void simpleBlitFrom(const Surface &src, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void simpleBlitFrom(const Surface &src, const Common::Point &destPos, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void simpleBlitFrom(const Surface &src, const Common::Rect &srcRect,
		const Common::Point &destPos, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one.
	 */
	void simpleBlitFrom(const ManagedSurface &src);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void simpleBlitFrom(const ManagedSurface &src, const Common::Point &destPos);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void simpleBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
		const Common::Point &destPos);

	/**
	 * Copy another surface into this one.
	 */
	void blitFrom(const Surface &src, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void blitFrom(const Surface &src, const Common::Point &destPos, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void blitFrom(const Surface &src, const Common::Rect &srcRect,
		const Common::Point &destPos, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one at a given destination area and perform the potential scaling.
	 */
	void blitFrom(const Surface &src, const Common::Rect &srcRect,
		const Common::Rect &destRect, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one at a given destination area and perform the potential scaling.
	 */
	void blitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
		const Common::Rect &destRect);

	/**
	 * Copy another surface into this one.
	 */
	void blitFrom(const ManagedSurface &src);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void blitFrom(const ManagedSurface &src, const Common::Point &destPos);

	/**
	 * Copy another surface into this one at a given destination position.
	 */
	void blitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
		const Common::Point &destPos);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 * @param srcPalette	Optional palette if the @p src surface uses a CLUT8 pixel format.
	 */
	void transBlitFrom(const Surface &src, uint32 transColor = 0, bool flipped = false,
		uint32 overrideColor = 0, uint32 srcAlpha = 0xff, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param destPos		Destination position to draw the surface.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 * @param srcPalette	Optional palette if the @p src surface uses a CLUT8 pixel format.
	 */
	void transBlitFrom(const Surface &src, const Common::Point &destPos,
		uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param destPos		Destination position to draw the surface.
	 * @param mask			Mask definition.
	 * @param srcPalette	Optional palette if the @p src surface uses a CLUT8 pixel format.
	 */
	void transBlitFrom(const Surface &src, const Common::Point &destPos,
		const ManagedSurface &mask, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param destPos		Destination position to draw the surface.
	 * @param mask			Mask definition.
	 * @param srcPalette	Optional palette if the @p src surface uses a CLUT8 pixel format.
	 */
	void transBlitFrom(const Surface &src, const Common::Point &destPos,
		const Surface &mask, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param srcRect		Subsection of the source surface to draw.
	 * @param destPos		Destination position to draw the surface.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Specifies whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 * @param srcPalette	Optional palette if the @p src surface uses a CLUT8 pixel format.
	 */
	void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Point &destPos,
		uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param srcRect		Subsection of the source surface to draw.
	 * @param destRect		Destination area to draw the surface in. This can be sized differently
	 *						then @p srcRect, allowing for arbitrary scaling of the image.
	 * @param srcPalette	Palette for the CLUT8  @p src surface.
	 */
	void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect, const Palette *srcPalette);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param srcRect		Subsection of the source surface to draw.
	 * @param destRect		Destination area to draw the surface in. This can be sized differently
	 *						then @p srcRect, allowing for arbitrary scaling of the image.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 * @param mask			Optional parameter with mask definition.
	 * @param maskOnly		Optional parameter for using mask over @p transColor.
	 * @param srcPalette	Optional palette if the @p src surface uses a CLUT8 pixel format.
	 */
	void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect,
		uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff,
		const Surface *mask = nullptr, bool maskOnly = false, const Palette *srcPalette = nullptr);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 */
	void transBlitFrom(const ManagedSurface &src, uint32 transColor = 0, bool flipped = false,
		uint32 overrideColor = 0, uint32 srcAlpha = 0xff);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param destPos		Destination position to draw the surface.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 */
	void transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
		uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param destPos		Destination position to draw the surface.
	 * @param mask			Mask definition.
	 */
	void transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
		const ManagedSurface &mask);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param srcRect		Subsection of the source surface to draw.
	 * @param destPos		Destination position to draw the surface.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 */
	void transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Point &destPos,
		uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff);

	/**
	 * Copy another surface into this one, ignoring pixels of a designated transparent color.
	 *
	 * @param src			Source surface.
	 * @param srcRect		Subsection of the source surface to draw.
	 * @param destRect		Destination area to draw the surface in. This can be sized differently
	 *						then @p srcRect, allowing for arbitrary scaling of the image.
	 * @param transColor	Transparency color to ignore copying of.
	 * @param flipped		Whether to horizontally flip the image.
	 * @param overrideColor	Optional color to use instead of non-transparent pixels from
	 *						the source surface.
	 * @param srcAlpha		Optional additional transparency applied to @p src.
	 * @param mask			Optional parameter with mask definition.
	 * @param maskOnly		Optional parameter for using mask over @p transColor.
	 */
	void transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Rect &destRect,
		uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff,
		const Surface *mask = nullptr, bool maskOnly = false);

	/**
	 * Does a blitFrom ignoring any transparency settings
	 */
	void rawBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
			const Common::Point &destPos) {
		blitFromInner(src._innerSurface, srcRect, Common::Rect(destPos.x, destPos.y, destPos.x + srcRect.width(),
			destPos.y + srcRect.height()), src._palette);
	}
	
	/**
	 * ManagedSurface::blendBlitTo is meant to be a highly optimized
	 * blending/blitting function, so it can only accept certain format combinations.
	 * @return true if the formats can be used by blendBlitTo.
	 */
	static inline bool isBlendBlitPixelFormatSupported(const PixelFormat &src, const PixelFormat &dst) {
		return BlendBlit::getSupportedPixelFormat() == src && BlendBlit::getSupportedPixelFormat() == dst;
	}

	/**
	 * @brief Renders this surface onto target
	 * @param target renders this surface onto this one
	 * @param src source surface
	 * @param posX, posY are the position of the src onto this surface
	 * @param flipping flipping flags (use Graphics::FLIP_FLAGS)
	 * @param srcRect source clipping
	 * @param width width of destination
	 * @param height height of destination
	 * @param colorMod what color to multiply by (0xffffffff does nothing)
	 * @param blend the blending mode to use.
	 * @param alphaType what alpha mode to use. FULL is default
	 * @return returns the size of the rendered rectangle
	 */
	Common::Rect blendBlitTo(ManagedSurface &target,
							 const int posX = 0, const int posY = 0,
							 const int flipping = FLIP_NONE,
							 const Common::Rect *srcRect = nullptr,
							 const uint colorMod = MS_ARGB(255, 255, 255, 255),
							 const int width = -1, const int height = -1,
							 const TSpriteBlendMode blend = BLEND_NORMAL,
							 const AlphaType alphaType = ALPHA_FULL);
	Common::Rect blendBlitTo(Surface &target,
							 const int posX = 0, const int posY = 0,
							 const int flipping = FLIP_NONE,
							 const Common::Rect *srcRect = nullptr,
							 const uint colorMod = MS_ARGB(255, 255, 255, 255),
							 const int width = -1, const int height = -1,
							 const TSpriteBlendMode blend = BLEND_NORMAL,
							 const AlphaType alphaType = ALPHA_FULL);

	/**
	 * Clear the entire surface.
	 */
	void clear(uint32 color = 0);

	/**
	 * Mark the entire surface as dirty.
	 */
	void markAllDirty();

	/**
	 * Copy a bitmap to the internal buffer of the surface.
	 *
	 * The pixel format of the buffer must match the pixel format of the surface.
	 */
	void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) {
		_innerSurface.copyRectToSurface(buffer, srcPitch, destX, destY, width, height);
		addDirtyRect(Common::Rect(destX, destY, destX + width, destY + height));
	}

	/**
	 * Copy a bitmap to the internal buffer of the surface.
	 *
	 * The pixel format of the buffer must match the pixel format of the surface.
	 */
	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) {
		_innerSurface.copyRectToSurface(srcSurface, destX, destY, subRect);
		addDirtyRect(Common::Rect(destX, destY, destX + subRect.width(), destY + subRect.height()));
	}

	/**
	 * Copy a bitmap to the internal buffer of the surface.
	 *
	 * The pixel format of the buffer must match the pixel format of the surface.
	 */
	void copyRectToSurfaceWithKey(const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key) {
		_innerSurface.copyRectToSurfaceWithKey(buffer, srcPitch, destX, destY, width, height, key);
		addDirtyRect(Common::Rect(destX, destY, destX + width, destY + height));
	}

	/**
	 * Copy a bitmap to the internal buffer of the surface.
	 *
	 * The pixel format of the buffer must match the pixel format of the surface.
	 */
	void copyRectToSurfaceWithKey(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect, uint32 key) {
		_innerSurface.copyRectToSurfaceWithKey(srcSurface, destX, destY, subRect, key);
		addDirtyRect(Common::Rect(destX, destY, destX + subRect.width(), destY + subRect.height()));
	}

	/**
	 * Copy the data from another surface, reinitializing the
	 * surface to match the dimensions of the passed surface.
	 */
	void copyFrom(const ManagedSurface &surf);

	/**
	 * Copy the data from another surface, reinitializing the
	 * surface to match the dimensions of the passed surface.
	 */
	void copyFrom(const Surface &surf);

	/**
	 * Convert the data from another surface to a given pixel
	 * format, reinitializing the surface to match the dimensions
	 * of the passed surface.
	 */
	void convertFrom(const ManagedSurface &surf, const PixelFormat &fmt);

	/**
	 * Convert the data from another surface to a given pixel
	 * format, reinitializing the surface to match the dimensions
	 * of the passed surface.
	 */
	void convertFrom(const Surface &surf, const PixelFormat &fmt);

	/**
	 * Scale the data to the given size.
	 *
	 * @param newWidth   The resulting width.
	 * @param newHeight  The resulting height.
	 * @param filtering  Whether or not to use bilinear filtering.
	 */
	ManagedSurface *scale(int16 newWidth, int16 newHeight, bool filtering = false) const;

	/**
	 * @brief Rotoscale function; this returns a transformed version of this surface after rotation and
	 * scaling. Please do not use this if angle == 0, use plain old scaling function.
	 *
	 * @param transform a TransformStruct wrapping the required info. @see TransformStruct
	 * @param filtering Whether or not to use bilinear filtering.
	 *
	 */
	ManagedSurface *rotoscale(const TransformStruct &transform, bool filtering = false) const;

	/**
	 * Draw a line.
	 */
	void drawLine(int x0, int y0, int x1, int y1, uint32 color) {
		_innerSurface.drawLine(x0, y0, x1, y1, color);
		addDirtyRect(Common::Rect(MIN(x0, x1), MIN(y0, y1), MAX(x0, x1 + 1), MAX(y0, y1 + 1)));
	}

	/**
	 * Draw a thick line.
	 */
	void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color) {
		_innerSurface.drawThickLine(x0, y0, x1, y1, penX, penY, color);
		addDirtyRect(Common::Rect(MIN(x0, x1 + penX), MIN(y0, y1 + penY), MAX(x0, x1 + penX), MAX(y0, y1 + penY)));
	}

	/**
	 * Draw a horizontal line.
	 */
	void hLine(int x, int y, int x2, uint32 color) {
		_innerSurface.hLine(x, y, x2, color);
		addDirtyRect(Common::Rect(x, y, x2 + 1, y + 1));
	}

	/**
	 * Draw a vertical line.
	 */
	void vLine(int x, int y, int y2, uint32 color) {
		_innerSurface.vLine(x, y, y2, color);
		addDirtyRect(Common::Rect(x, y, x + 1, y2 + 1));
	}

	/**
	 * Fill a rect with a given color.
	 */
	void fillRect(Common::Rect r, uint32 color) {
		_innerSurface.fillRect(r, color);
		addDirtyRect(r);
	}

	/**
	 * Draw a frame around a specified rect.
	 */
	void frameRect(const Common::Rect &r, uint32 color) {
		_innerSurface.frameRect(r, color);
		addDirtyRect(r);
	}

	/**
	 * Checks if the given surface contains alpha transparency
	 */
	AlphaType detectAlpha() const {
		return _innerSurface.detectAlpha();
	}

	/**
	 * Return a sub-area of the screen, but only add a single initial dirty rect
	 * for the retrieved area.
	 */
	Surface getSubArea(const Common::Rect &area) {
		addDirtyRect(area);
		return _innerSurface.getSubArea(area);
	}

	/**
	 * Convert the data to another pixel format.
	 *
	 * This works in-place. This means it does not create an additional buffer
	 * for the conversion process. The value of 'pixels' might change though
	 * (that means it might realloc the pixel data).
	 *
	 * @param dstFormat  The desired format.
	 */
	void convertToInPlace(const PixelFormat &dstFormat) {
		_innerSurface.convertToInPlace(dstFormat);
	}

	/**
	 * Convert the data to another pixel format.
	 *
	 * This works in-place. This means it does not create an additional buffer
	 * for the conversion process. The value of 'pixels' might change though
	 * (that means it might realloc the pixel data).
	 *
	 * @param dstFormat  The desired format.
	 * @param palette    The palette (in RGB888), if the source format has one.
	 * @param paletteCount  The number of colors in the palette.
	 */
	void convertToInPlace(const PixelFormat &dstFormat, const byte *palette, uint16 paletteCount) {
		_innerSurface.convertToInPlace(dstFormat, palette, paletteCount);
	}

	/**
	 * Return the current transparent color.
	 */
	uint getTransparentColor() const { return _transparentColor; }

	/**
	 * Set the transparent color.
	 */
	void setTransparentColor(uint32 color) {
		_transparentColor = color;
		_transparentColorSet = true;
	}

	/**
	 * Clear the transparent color setting.
	 */
	void clearTransparentColor() {
		_transparentColorSet = false;
	}

	/**
	 * Return true if a transparent color has been set.
	 */
	bool hasTransparentColor() const {
		return _transparentColorSet;
	}

	/**
	 * Clear any existing palette.
	 */
	void clearPalette();

	/**
	 * Return true if a palette has been set.
	 */
	bool hasPalette() const;

	/**
	 * Grab the palette using RGB tuples.
	 */
	void grabPalette(byte *colors, uint start, uint num) const;

	/**
	 * Set the palette using RGB tuples.
	 */
	void setPalette(const byte *colors, uint start, uint num);
};
/** @} */
} // End of namespace Graphics

#endif