Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: tests/SurfaceTest.cpp

Issue 872543002: Take budgeted param when snapping new image. (Closed) Base URL: https://skia.googlesource.com/skia.git@budgeted
Patch Set: Address comment and rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/DeferredCanvasTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SurfaceTest.cpp
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 4816ffc1ac795fbc4b65c62e3971f3163e483c98..94490144ed8fa4b654a739cc350da173ffa95d1b 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -455,6 +455,51 @@ static void TestGetTexture(skiatest::Reporter* reporter,
surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
REPORTER_ASSERT(reporter, image->getTexture() == texture);
}
+
+#include "GrGpuResourceCacheAccess.h"
+#include "SkGpuDevice.h"
+#include "SkImage_Gpu.h"
+#include "SkSurface_Gpu.h"
+
+SkSurface::Budgeted is_budgeted(SkSurface* surf) {
+ return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->cacheAccess().isBudgeted() ?
+ SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
+}
+
+SkSurface::Budgeted is_budgeted(SkImage* image) {
+ return ((SkImage_Gpu*)image)->getTexture()->cacheAccess().isBudgeted() ?
+ SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
+}
+
+static void test_surface_budget(skiatest::Reporter* reporter, GrContext* context) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
+ for (int i = 0; i < 2; ++i) {
+ SkSurface::Budgeted sbudgeted = i ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
+ for (int j = 0; j < 2; ++j) {
+ SkSurface::Budgeted ibudgeted = j ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
+ SkAutoTUnref<SkSurface>
+ surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0));
+ SkASSERT(surface);
+ REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
+
+ SkImage* image = surface->newImageSnapshot(ibudgeted);
+
+ // Initially the image shares a texture with the surface, and the surface decides
+ // whether it is budgeted or not.
+ REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
+ REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image));
+
+ // Now trigger copy-on-write
+ surface->getCanvas()->clear(SK_ColorBLUE);
+
+ // They don't share a texture anymore. They should each have made their own budget
+ // decision.
+ REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
+ REPORTER_ASSERT(reporter, ibudgeted == is_budgeted(image));
+ }
+ }
+}
+
#endif
static void TestSurfaceNoCanvas(skiatest::Reporter* reporter,
@@ -526,6 +571,7 @@ DEF_GPUTEST(Surface, reporter, factory) {
TestGetTexture(reporter, kGpu_SurfaceType, context);
TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
test_empty_surface(reporter, context);
+ test_surface_budget(reporter, context);
}
}
}
« no previous file with comments | « tests/DeferredCanvasTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698