forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpu_image_decode_cache_unittest.cc
2001 lines (1680 loc) · 82 KB
/
gpu_image_decode_cache_unittest.cc
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
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/tiles/gpu_image_decode_cache.h"
#include <memory>
#include "cc/paint/draw_image.h"
#include "cc/paint/image_transfer_cache_entry.h"
#include "cc/paint/paint_image_builder.h"
#include "cc/test/fake_paint_image_generator.h"
#include "cc/test/skia_common.h"
#include "cc/test/test_context_provider.h"
#include "cc/test/test_gles2_interface.h"
#include "cc/test/test_tile_task_runner.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "cc/test/transfer_cache_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkImageGenerator.h"
#include "third_party/skia/include/core/SkRefCnt.h"
namespace cc {
namespace {
class FakeDiscardableManager {
public:
void SetGLES2Interface(TestGLES2Interface* gl) { gl_ = gl; }
void Initialize(GLuint texture_id) {
EXPECT_EQ(textures_.end(), textures_.find(texture_id));
textures_[texture_id] = kHandleLockedStart;
live_textures_count_++;
}
void Unlock(GLuint texture_id) {
EXPECT_NE(textures_.end(), textures_.find(texture_id));
ExpectLocked(texture_id);
textures_[texture_id]--;
}
bool Lock(GLuint texture_id) {
EnforceLimit();
EXPECT_NE(textures_.end(), textures_.find(texture_id));
if (textures_[texture_id] >= kHandleUnlocked) {
textures_[texture_id]++;
return true;
}
return false;
}
void DeleteTexture(GLuint texture_id) {
if (textures_.end() == textures_.find(texture_id))
return;
ExpectLocked(texture_id);
textures_[texture_id] = kHandleDeleted;
live_textures_count_--;
}
void set_cached_textures_limit(size_t limit) {
cached_textures_limit_ = limit;
}
private:
void EnforceLimit() {
for (auto it = textures_.begin(); it != textures_.end(); ++it) {
if (live_textures_count_ <= cached_textures_limit_)
return;
if (it->second != kHandleUnlocked)
continue;
it->second = kHandleDeleted;
gl_->TestGLES2Interface::DeleteTextures(1, &it->first);
live_textures_count_--;
}
}
void ExpectLocked(GLuint texture_id) {
EXPECT_TRUE(textures_.end() != textures_.find(texture_id));
// Any value > kHandleLockedStart represents a locked texture. As we
// increment this value with each lock, we need the entire range and can't
// add additional values > kHandleLockedStart in the future.
EXPECT_GE(textures_[texture_id], kHandleLockedStart);
EXPECT_LE(textures_[texture_id], kHandleLockedEnd);
}
const int32_t kHandleDeleted = 0;
const int32_t kHandleUnlocked = 1;
const int32_t kHandleLockedStart = 2;
const int32_t kHandleLockedEnd = std::numeric_limits<int32_t>::max();
std::map<GLuint, int32_t> textures_;
size_t live_textures_count_ = 0;
size_t cached_textures_limit_ = std::numeric_limits<size_t>::max();
TestGLES2Interface* gl_ = nullptr;
};
class FakeGPUImageDecodeTestGLES2Interface : public TestGLES2Interface,
public TestContextSupport {
public:
explicit FakeGPUImageDecodeTestGLES2Interface(
FakeDiscardableManager* discardable_manager,
TransferCacheTestHelper* transfer_cache_helper)
: extension_string_("GL_EXT_texture_format_BGRA8888 GL_OES_rgb8_rgba8"),
discardable_manager_(discardable_manager),
transfer_cache_helper_(transfer_cache_helper) {}
~FakeGPUImageDecodeTestGLES2Interface() override {
// All textures / framebuffers / renderbuffers should be cleaned up.
if (test_context_) {
EXPECT_EQ(0u, test_context_->NumTextures());
EXPECT_EQ(0u, test_context_->NumFramebuffers());
EXPECT_EQ(0u, test_context_->NumRenderbuffers());
}
}
void InitializeDiscardableTextureCHROMIUM(GLuint texture_id) override {
discardable_manager_->Initialize(texture_id);
}
void UnlockDiscardableTextureCHROMIUM(GLuint texture_id) override {
discardable_manager_->Unlock(texture_id);
}
bool LockDiscardableTextureCHROMIUM(GLuint texture_id) override {
return discardable_manager_->Lock(texture_id);
}
bool ThreadSafeShallowLockDiscardableTexture(uint32_t texture_id) override {
return discardable_manager_->Lock(texture_id);
}
void CompleteLockDiscardableTexureOnContextThread(
uint32_t texture_id) override {}
void CreateTransferCacheEntry(
const ClientTransferCacheEntry& entry) override {
transfer_cache_helper_->CreateEntryDirect(entry);
}
bool ThreadsafeLockTransferCacheEntry(TransferCacheEntryType entry_type,
uint32_t entry_id) override {
return transfer_cache_helper_->LockEntryDirect(entry_type, entry_id);
}
void UnlockTransferCacheEntries(
const std::vector<std::pair<TransferCacheEntryType, uint32_t>>& entries)
override {
transfer_cache_helper_->UnlockEntriesDirect(entries);
}
void DeleteTransferCacheEntry(TransferCacheEntryType entry_type,
uint32_t entry_id) override {
transfer_cache_helper_->DeleteEntryDirect(entry_type, entry_id);
}
// TestGLES2Interface:
const GLubyte* GetString(GLenum name) override {
switch (name) {
case GL_EXTENSIONS:
return reinterpret_cast<const GLubyte*>(extension_string_.c_str());
case GL_VERSION:
return reinterpret_cast<const GLubyte*>("4.0 Null GL");
case GL_SHADING_LANGUAGE_VERSION:
return reinterpret_cast<const GLubyte*>("4.20.8 Null GLSL");
case GL_VENDOR:
return reinterpret_cast<const GLubyte*>("Null Vendor");
case GL_RENDERER:
return reinterpret_cast<const GLubyte*>("The Null (Non-)Renderer");
}
return nullptr;
}
void GetIntegerv(GLenum name, GLint* params) override {
switch (name) {
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
*params = 8;
return;
case GL_MAX_RENDERBUFFER_SIZE:
*params = 2048;
return;
default:
break;
}
TestGLES2Interface::GetIntegerv(name, params);
}
void DeleteTextures(GLsizei n, const GLuint* textures) override {
for (GLsizei i = 0; i < n; i++) {
discardable_manager_->DeleteTexture(textures[i]);
}
TestGLES2Interface::DeleteTextures(n, textures);
}
private:
const std::string extension_string_;
FakeDiscardableManager* discardable_manager_;
TransferCacheTestHelper* transfer_cache_helper_;
};
class GPUImageDecodeTestMockContextProvider : public TestContextProvider {
public:
static scoped_refptr<GPUImageDecodeTestMockContextProvider> Create(
FakeDiscardableManager* discardable_manager,
TransferCacheTestHelper* transfer_cache_helper) {
return new GPUImageDecodeTestMockContextProvider(
std::make_unique<FakeGPUImageDecodeTestGLES2Interface>(
discardable_manager, transfer_cache_helper),
std::make_unique<FakeGPUImageDecodeTestGLES2Interface>(
discardable_manager, transfer_cache_helper),
TestWebGraphicsContext3D::Create());
}
private:
~GPUImageDecodeTestMockContextProvider() override = default;
GPUImageDecodeTestMockContextProvider(
std::unique_ptr<TestContextSupport> support,
std::unique_ptr<TestGLES2Interface> gl,
std::unique_ptr<TestWebGraphicsContext3D> context)
: TestContextProvider(std::move(support),
std::move(gl),
std::move(context),
true) {}
};
gfx::ColorSpace DefaultColorSpace() {
return gfx::ColorSpace::CreateSRGB();
}
size_t kGpuMemoryLimitBytes = 96 * 1024 * 1024;
class GpuImageDecodeCacheTest
: public ::testing::TestWithParam<
std::pair<SkColorType, bool /* use_transfer_cache */>> {
public:
void SetUp() override {
context_provider_ = GPUImageDecodeTestMockContextProvider::Create(
&discardable_manager_, &transfer_cache_helper_);
discardable_manager_.SetGLES2Interface(context_provider_->TestContextGL());
context_provider_->BindToCurrentThread();
{
viz::RasterContextProvider::ScopedRasterContextLock context_lock(
context_provider_.get());
transfer_cache_helper_.SetGrContext(context_provider_->GrContext());
}
use_transfer_cache_ = GetParam().second;
color_type_ = GetParam().first;
}
std::unique_ptr<GpuImageDecodeCache> CreateCache() {
return base::WrapUnique(
new GpuImageDecodeCache(context_provider_.get(), use_transfer_cache_,
color_type_, kGpuMemoryLimitBytes));
}
GPUImageDecodeTestMockContextProvider* context_provider() {
return context_provider_.get();
}
void ExpectIfNotUsingTransferCache(bool value) {
if (!use_transfer_cache_) {
EXPECT_TRUE(value);
}
}
void SetCachedTexturesLimit(size_t limit) {
discardable_manager_.set_cached_textures_limit(limit);
transfer_cache_helper_.SetCachedItemsLimit(limit);
}
// If this is an image-backed DecodedDrawImage, does nothing. Otherwise this
// retreives the image from the transfer cache and builds a new
// DecodedDrawImage.
DecodedDrawImage EnsureImageBacked(DecodedDrawImage&& draw_image) {
if (draw_image.transfer_cache_entry_id()) {
EXPECT_TRUE(use_transfer_cache_);
sk_sp<SkImage> image = transfer_cache_helper_
.GetEntryAs<ServiceImageTransferCacheEntry>(
*draw_image.transfer_cache_entry_id())
->image();
DecodedDrawImage new_draw_image(
std::move(image), draw_image.src_rect_offset(),
draw_image.scale_adjustment(), draw_image.filter_quality());
return new_draw_image;
}
return draw_image;
}
private:
FakeDiscardableManager discardable_manager_;
scoped_refptr<GPUImageDecodeTestMockContextProvider> context_provider_;
TransferCacheTestHelper transfer_cache_helper_;
bool use_transfer_cache_;
SkColorType color_type_;
};
SkMatrix CreateMatrix(const SkSize& scale, bool is_decomposable) {
SkMatrix matrix;
matrix.setScale(scale.width(), scale.height());
if (!is_decomposable) {
// Perspective is not decomposable, add it.
matrix[SkMatrix::kMPersp0] = 0.1f;
}
return matrix;
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSameImage) {
auto cache = CreateCache();
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
DrawImage another_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult another_result = cache->GetTaskForImageAndRef(
another_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(another_result.need_unref);
EXPECT_TRUE(result.task.get() == another_result.task.get());
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(result.task.get());
cache->UnrefImage(draw_image);
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSmallerScale) {
auto cache = CreateCache();
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
DrawImage another_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult another_result = cache->GetTaskForImageAndRef(
another_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(another_result.need_unref);
EXPECT_TRUE(result.task.get() == another_result.task.get());
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(result.task.get());
cache->UnrefImage(draw_image);
cache->UnrefImage(another_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLowerQuality) {
auto cache = CreateCache();
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
bool is_decomposable = true;
SkMatrix matrix = CreateMatrix(SkSize::Make(0.4f, 0.4f), is_decomposable);
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
kHigh_SkFilterQuality, matrix,
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
DrawImage another_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()),
kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
DefaultColorSpace());
ImageDecodeCache::TaskResult another_result = cache->GetTaskForImageAndRef(
another_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(another_result.need_unref);
EXPECT_TRUE(result.task.get() == another_result.task.get());
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(result.task.get());
cache->UnrefImage(draw_image);
cache->UnrefImage(another_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentImage) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage first_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult first_result = cache->GetTaskForImageAndRef(
first_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(first_result.need_unref);
EXPECT_TRUE(first_result.task);
PaintImage second_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage second_draw_image(
second_image,
SkIRect::MakeWH(second_image.width(), second_image.height()), quality,
CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult second_result = cache->GetTaskForImageAndRef(
second_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(second_result.need_unref);
EXPECT_TRUE(second_result.task);
EXPECT_TRUE(first_result.task.get() != second_result.task.get());
TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(first_result.task.get());
TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(second_result.task.get());
cache->UnrefImage(first_draw_image);
cache->UnrefImage(second_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScale) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage first_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult first_result = cache->GetTaskForImageAndRef(
first_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(first_result.need_unref);
EXPECT_TRUE(first_result.task);
TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(first_result.task.get());
cache->UnrefImage(first_draw_image);
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult second_result = cache->GetTaskForImageAndRef(
second_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(second_result.need_unref);
EXPECT_TRUE(second_result.task);
EXPECT_TRUE(first_result.task.get() != second_result.task.get());
DrawImage third_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult third_result = cache->GetTaskForImageAndRef(
third_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(third_result.need_unref);
EXPECT_TRUE(third_result.task.get() == second_result.task.get());
TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(second_result.task.get());
cache->UnrefImage(second_draw_image);
cache->UnrefImage(third_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScaleNoReuse) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage first_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult first_result = cache->GetTaskForImageAndRef(
first_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(first_result.need_unref);
EXPECT_TRUE(first_result.task);
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult second_result = cache->GetTaskForImageAndRef(
second_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(second_result.need_unref);
EXPECT_TRUE(second_result.task);
EXPECT_TRUE(first_result.task.get() != second_result.task.get());
DrawImage third_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult third_result = cache->GetTaskForImageAndRef(
third_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(third_result.need_unref);
EXPECT_TRUE(third_result.task.get() == first_result.task.get());
TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(first_result.task.get());
TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(second_result.task.get());
cache->UnrefImage(first_draw_image);
cache->UnrefImage(second_draw_image);
cache->UnrefImage(third_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageHigherQuality) {
auto cache = CreateCache();
bool is_decomposable = true;
SkMatrix matrix = CreateMatrix(SkSize::Make(0.4f, 0.4f), is_decomposable);
PaintImage first_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
DefaultColorSpace());
ImageDecodeCache::TaskResult first_result = cache->GetTaskForImageAndRef(
first_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(first_result.need_unref);
EXPECT_TRUE(first_result.task);
TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(first_result.task.get());
cache->UnrefImage(first_draw_image);
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
DefaultColorSpace());
ImageDecodeCache::TaskResult second_result = cache->GetTaskForImageAndRef(
second_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(second_result.need_unref);
EXPECT_TRUE(second_result.task);
EXPECT_TRUE(first_result.task.get() != second_result.task.get());
TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(second_result.task.get());
cache->UnrefImage(second_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedAndLocked) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
EXPECT_EQ(result.task->dependencies().size(), 1u);
EXPECT_TRUE(result.task->dependencies()[0]);
// Run the decode but don't complete it (this will keep the decode locked).
TestTileTaskRunner::ScheduleTask(result.task->dependencies()[0].get());
TestTileTaskRunner::RunTask(result.task->dependencies()[0].get());
// Cancel the upload.
TestTileTaskRunner::CancelTask(result.task.get());
TestTileTaskRunner::CompleteTask(result.task.get());
// Get the image again - we should have an upload task, but no dependent
// decode task, as the decode was already locked.
ImageDecodeCache::TaskResult another_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(another_result.need_unref);
EXPECT_TRUE(another_result.task);
EXPECT_EQ(another_result.task->dependencies().size(), 0u);
TestTileTaskRunner::ProcessTask(another_result.task.get());
// Finally, complete the original decode task.
TestTileTaskRunner::CompleteTask(result.task->dependencies()[0].get());
cache->UnrefImage(draw_image);
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedNotLocked) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
EXPECT_EQ(result.task->dependencies().size(), 1u);
EXPECT_TRUE(result.task->dependencies()[0]);
// Run the decode.
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
// Cancel the upload.
TestTileTaskRunner::CancelTask(result.task.get());
TestTileTaskRunner::CompleteTask(result.task.get());
// Unref the image.
cache->UnrefImage(draw_image);
// Get the image again - we should have an upload task and a dependent decode
// task - this dependent task will typically just re-lock the image.
ImageDecodeCache::TaskResult another_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(another_result.need_unref);
EXPECT_TRUE(another_result.task);
EXPECT_EQ(another_result.task->dependencies().size(), 1u);
EXPECT_TRUE(result.task->dependencies()[0]);
TestTileTaskRunner::ProcessTask(another_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(another_result.task.get());
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyUploaded) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
EXPECT_EQ(result.task->dependencies().size(), 1u);
EXPECT_TRUE(result.task->dependencies()[0]);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ScheduleTask(result.task.get());
TestTileTaskRunner::RunTask(result.task.get());
TestTileTaskRunner::CompleteTask(result.task.get());
ImageDecodeCache::TaskResult another_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(another_result.need_unref);
EXPECT_FALSE(another_result.task);
cache->UnrefImage(draw_image);
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledGetsNewTask) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
ImageDecodeCache::TaskResult another_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(another_result.task.get() == result.task.get());
// Didn't run the task, so cancel it.
TestTileTaskRunner::CancelTask(result.task.get());
TestTileTaskRunner::CompleteTask(result.task.get());
// Fully cancel everything (so the raster would unref things).
cache->UnrefImage(draw_image);
cache->UnrefImage(draw_image);
// Here a new task is created.
ImageDecodeCache::TaskResult third_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(third_result.need_unref);
EXPECT_TRUE(third_result.task);
EXPECT_FALSE(third_result.task.get() == result.task.get());
TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(third_result.task.get());
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledWhileReffedGetsNewTask) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
ASSERT_GT(result.task->dependencies().size(), 0u);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
ImageDecodeCache::TaskResult another_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(another_result.need_unref);
EXPECT_TRUE(another_result.task.get() == result.task.get());
// Didn't run the task, so cancel it.
TestTileTaskRunner::CancelTask(result.task.get());
TestTileTaskRunner::CompleteTask(result.task.get());
// 2 Unrefs, so that the decode is unlocked as well.
cache->UnrefImage(draw_image);
cache->UnrefImage(draw_image);
// Note that here, everything is reffed, but a new task is created. This is
// possible with repeated schedule/cancel operations.
ImageDecodeCache::TaskResult third_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(third_result.need_unref);
EXPECT_TRUE(third_result.task);
EXPECT_FALSE(third_result.task.get() == result.task.get());
ASSERT_GT(third_result.task->dependencies().size(), 0u);
TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(third_result.task.get());
// Unref!
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, NoTaskForImageAlreadyFailedDecoding) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
// Didn't run the task, so cancel it.
TestTileTaskRunner::CancelTask(result.task.get());
TestTileTaskRunner::CompleteTask(result.task.get());
cache->SetImageDecodingFailedForTesting(draw_image);
ImageDecodeCache::TaskResult another_result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_FALSE(another_result.need_unref);
EXPECT_EQ(another_result.task.get(), nullptr);
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDraw) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
viz::ContextProvider::ScopedContextLock context_lock(context_provider());
DecodedDrawImage decoded_draw_image =
EnsureImageBacked(cache->GetDecodedImageForDraw(draw_image));
EXPECT_TRUE(decoded_draw_image.image());
EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked());
EXPECT_FALSE(cache->DiscardableIsLockedForTesting(draw_image));
cache->DrawWithImageFinished(draw_image, decoded_draw_image);
cache->UnrefImage(draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetLargeDecodedImageForDraw) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(1, 24000));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
viz::ContextProvider::ScopedContextLock context_lock(context_provider());
DecodedDrawImage decoded_draw_image =
EnsureImageBacked(cache->GetDecodedImageForDraw(draw_image));
EXPECT_TRUE(decoded_draw_image.image());
EXPECT_FALSE(decoded_draw_image.image()->isTextureBacked());
ExpectIfNotUsingTransferCache(
cache->DiscardableIsLockedForTesting(draw_image));
cache->DrawWithImageFinished(draw_image, decoded_draw_image);
cache->UnrefImage(draw_image);
EXPECT_FALSE(cache->DiscardableIsLockedForTesting(draw_image));
}
TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawAtRasterDecode) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
cache->SetWorkingSetLimitForTesting(0);
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_FALSE(result.need_unref);
EXPECT_FALSE(result.task);
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
viz::ContextProvider::ScopedContextLock context_lock(context_provider());
DecodedDrawImage decoded_draw_image =
EnsureImageBacked(cache->GetDecodedImageForDraw(draw_image));
EXPECT_TRUE(decoded_draw_image.image());
EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked());
EXPECT_FALSE(cache->DiscardableIsLockedForTesting(draw_image));
cache->DrawWithImageFinished(draw_image, decoded_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawLargerScale) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
kLow_SkFilterQuality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(result.task.get());
DrawImage larger_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult larger_result = cache->GetTaskForImageAndRef(
larger_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(larger_result.need_unref);
EXPECT_TRUE(larger_result.task);
TestTileTaskRunner::ProcessTask(larger_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(larger_result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
viz::ContextProvider::ScopedContextLock context_lock(context_provider());
DecodedDrawImage decoded_draw_image =
EnsureImageBacked(cache->GetDecodedImageForDraw(draw_image));
EXPECT_TRUE(decoded_draw_image.image());
EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked());
EXPECT_FALSE(cache->DiscardableIsLockedForTesting(draw_image));
DecodedDrawImage larger_decoded_draw_image =
EnsureImageBacked(cache->GetDecodedImageForDraw(larger_draw_image));
EXPECT_TRUE(larger_decoded_draw_image.image());
EXPECT_TRUE(larger_decoded_draw_image.image()->isTextureBacked());
EXPECT_FALSE(cache->DiscardableIsLockedForTesting(draw_image));
EXPECT_FALSE(decoded_draw_image.image() == larger_decoded_draw_image.image());
cache->DrawWithImageFinished(draw_image, decoded_draw_image);
cache->UnrefImage(draw_image);
cache->DrawWithImageFinished(larger_draw_image, larger_decoded_draw_image);
cache->UnrefImage(larger_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawHigherQuality) {
auto cache = CreateCache();
bool is_decomposable = true;
SkMatrix matrix = CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable);
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
kLow_SkFilterQuality, matrix,
PaintImage::kDefaultFrameIndex, DefaultColorSpace());
ImageDecodeCache::TaskResult result =
cache->GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(result.need_unref);
EXPECT_TRUE(result.task);
TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(result.task.get());
DrawImage higher_quality_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()),
kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
DefaultColorSpace());
ImageDecodeCache::TaskResult hq_result = cache->GetTaskForImageAndRef(
higher_quality_draw_image, ImageDecodeCache::TracingInfo());
EXPECT_TRUE(hq_result.need_unref);
EXPECT_TRUE(hq_result.task);
TestTileTaskRunner::ProcessTask(hq_result.task->dependencies()[0].get());
TestTileTaskRunner::ProcessTask(hq_result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
viz::ContextProvider::ScopedContextLock context_lock(context_provider());
DecodedDrawImage decoded_draw_image =
EnsureImageBacked(cache->GetDecodedImageForDraw(draw_image));
EXPECT_TRUE(decoded_draw_image.image());
EXPECT_TRUE(decoded_draw_image.image()->isTextureBacked());
EXPECT_FALSE(cache->DiscardableIsLockedForTesting(draw_image));
DecodedDrawImage larger_decoded_draw_image = EnsureImageBacked(
cache->GetDecodedImageForDraw(higher_quality_draw_image));
EXPECT_TRUE(larger_decoded_draw_image.image());
EXPECT_TRUE(larger_decoded_draw_image.image()->isTextureBacked());
EXPECT_FALSE(cache->DiscardableIsLockedForTesting(draw_image));
EXPECT_FALSE(decoded_draw_image.image() == larger_decoded_draw_image.image());
cache->DrawWithImageFinished(draw_image, decoded_draw_image);
cache->UnrefImage(draw_image);
cache->DrawWithImageFinished(higher_quality_draw_image,
larger_decoded_draw_image);
cache->UnrefImage(higher_quality_draw_image);
}
TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawNegative) {
auto cache = CreateCache();
bool is_decomposable = true;
SkFilterQuality quality = kHigh_SkFilterQuality;
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(-0.5f, 0.5f), is_decomposable),
PaintImage::kDefaultFrameIndex, DefaultColorSpace());