Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright 2017 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined.
      9 #include "SkTypes.h"
     10 
     11 #if SK_SUPPORT_GPU
     12 #include "Test.h"
     13 
     14 #include "GrResourceAllocator.h"
     15 #include "GrSurfaceProxyPriv.h"
     16 #include "GrTextureProxy.h"
     17 
     18 // Basic test that two proxies with overlapping intervals and compatible descriptors are
     19 // assigned different GrSurfaces.
     20 static void overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider) {
     21     GrSurfaceDesc desc;
     22     desc.fConfig = kRGBA_8888_GrPixelConfig;
     23     desc.fWidth  = 64;
     24     desc.fHeight = 64;
     25 
     26     sk_sp<GrSurfaceProxy> p1 = GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
     27                                                             SkBackingFit::kApprox,
     28                                                             SkBudgeted::kNo);
     29     sk_sp<GrSurfaceProxy> p2 = GrSurfaceProxy::MakeDeferred(resourceProvider, desc,
     30                                                             SkBackingFit::kApprox,
     31                                                             SkBudgeted::kNo);
     32 
     33     GrResourceAllocator alloc(resourceProvider);
     34 
     35     alloc.addInterval(p1.get(), 0, 4);
     36     alloc.addInterval(p2.get(), 1, 2);
     37 
     38     alloc.assign();
     39 
     40     REPORTER_ASSERT(reporter, p1->priv().peekSurface());
     41     REPORTER_ASSERT(reporter, p2->priv().peekSurface());
     42     REPORTER_ASSERT(reporter, p1->underlyingUniqueID() != p2->underlyingUniqueID());
     43 }
     44 
     45 DEF_GPUTEST_FOR_ALL_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
     46     GrResourceProvider* resourceProvider = ctxInfo.grContext()->resourceProvider();
     47 
     48     overlap_test(reporter, resourceProvider);
     49 }
     50 
     51 #endif
     52