180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc.
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "Test.h"
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// This is a GR test
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_SUPPORT_GPU
12096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger#include "GrContextFactory.h"
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkGpuDevice.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "../../src/gpu/GrClipMaskManager.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic const int X_SIZE = 12;
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic const int Y_SIZE = 12;
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// note: this is unused
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic GrTexture* createTexture(GrContext* context) {
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    unsigned char textureData[X_SIZE][Y_SIZE][4];
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    memset(textureData, 0, 4* X_SIZE * Y_SIZE);
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTextureDesc desc;
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // let Skia know we will be using this texture as a render target
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fFlags     = kRenderTarget_GrTextureFlagBit;
30096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    desc.fConfig    = kSkia8888_GrPixelConfig;
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fWidth     = X_SIZE;
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fHeight    = Y_SIZE;
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // We are initializing the texture with zeros here
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTexture* texture = context->createUncachedTexture(desc, textureData, 0);
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (!texture) {
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return NULL;
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    return texture;
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// Ensure that the 'getConservativeBounds' calls are returning bounds clamped
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// to the render target
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic void test_clip_bounds(skiatest::Reporter* reporter, GrContext* context) {
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const int kXSize = 100;
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const int kYSize = 100;
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTextureDesc desc;
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fFlags     = kRenderTarget_GrTextureFlagBit;
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fConfig    = kAlpha_8_GrPixelConfig;
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fWidth     = kXSize;
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fHeight    = kYSize;
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTexture* texture = context->createUncachedTexture(desc, NULL, 0);
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (!texture) {
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return;
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrAutoUnref au(texture);
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkIRect intScreen = SkIRect::MakeWH(kXSize, kYSize);
64096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    SkRect screen;
65096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger
66096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    screen = SkRect::MakeWH(SkIntToScalar(kXSize),
67096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger                            SkIntToScalar(kYSize));
68096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkRect clipRect(screen);
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    clipRect.outset(10, 10);
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // create a clip stack that will (trivially) reduce to a single rect that
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // is larger than the screen
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkClipStack stack;
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    stack.clipDevRect(clipRect, SkRegion::kReplace_Op, false);
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isIntersectionOfRects = true;
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkRect devStackBounds;
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    stack.getConservativeBounds(0, 0, kXSize, kYSize,
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                &devStackBounds,
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                &isIntersectionOfRects);
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // make sure that the SkClipStack is behaving itself
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, screen == devStackBounds);
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, isIntersectionOfRects);
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // wrap the SkClipStack in a GrClipData
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrClipData clipData;
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    clipData.fClipStack = &stack;
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkIRect devGrClipDataBound;
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    clipData.getConservativeBounds(texture,
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                   &devGrClipDataBound,
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                   &isIntersectionOfRects);
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // make sure that GrClipData is behaving itself
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, intScreen == devGrClipDataBound);
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, isIntersectionOfRects);
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// verify that the top state of the stack matches the passed in state
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic void check_state(skiatest::Reporter* reporter,
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                        const GrClipMaskCache& cache,
10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                        const SkClipStack& clip,
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                        GrTexture* mask,
10858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger                        const SkIRect& bound) {
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkClipStack cacheClip;
110363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    REPORTER_ASSERT(reporter, clip.getTopmostGenID() == cache.getLastClipGenID());
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, mask == cache.getLastMask());
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkIRect cacheBound;
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.getLastBound(&cacheBound);
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, bound == cacheBound);
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// basic test of the cache's base functionality:
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//  push, pop, set, canReuse & getters
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic void test_cache(skiatest::Reporter* reporter, GrContext* context) {
12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (false) { // avoid bit rot, suppress warning
12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        createTexture(context);
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrClipMaskCache cache;
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.setContext(context);
13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkClipStack emptyClip;
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    emptyClip.reset();
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13458190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkIRect emptyBound;
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    emptyBound.setEmpty();
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check initial state
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, emptyClip, NULL, emptyBound);
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // set the current state
14158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkIRect bound1;
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bound1.set(0, 0, 100, 100);
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkClipStack clip1(bound1);
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTextureDesc desc;
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fFlags = kRenderTarget_GrTextureFlagBit;
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fWidth = X_SIZE;
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fHeight = Y_SIZE;
150096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    desc.fConfig = kSkia8888_GrPixelConfig;
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
152363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    cache.acquireMask(clip1.getTopmostGenID(), desc, bound1);
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTexture* texture1 = cache.getLastMask();
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, texture1);
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (NULL == texture1) {
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return;
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check that the set took
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, clip1, texture1, bound1);
162d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // push the state
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.push();
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify that the pushed state is initially empty
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, emptyClip, NULL, emptyBound);
169d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // modify the new state
17258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkIRect bound2;
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bound2.set(-10, -10, 10, 10);
17480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkClipStack clip2(bound2);
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
177363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    cache.acquireMask(clip2.getTopmostGenID(), desc, bound2);
17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTexture* texture2 = cache.getLastMask();
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, texture2);
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (NULL == texture2) {
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return;
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check that the changes took
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, clip2, texture2, bound2);
187d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
188d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture2->getRefCnt());
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check to make sure canReuse works
191363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    REPORTER_ASSERT(reporter, cache.canReuse(clip2.getTopmostGenID(), bound2));
192363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    REPORTER_ASSERT(reporter, !cache.canReuse(clip1.getTopmostGenID(), bound1));
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // pop the state
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.pop();
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify that the old state is restored
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, clip1, texture1, bound1);
199d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
200d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture2->getRefCnt());
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // manually clear the state
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.reset();
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify it is now empty
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, emptyClip, NULL, emptyBound);
207d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
208d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture2->getRefCnt());
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // pop again - so there is no state
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.pop();
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if !defined(SK_DEBUG)
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify that the getters don't crash
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // only do in release since it generates asserts in debug
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, emptyClip, NULL, emptyBound);
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
218d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
219d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture2->getRefCnt());
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
223096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergerstatic void TestClipCache(skiatest::Reporter* reporter, GrContextFactory* factory) {
224096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
225096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
226096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        if (!GrContextFactory::IsRenderingGLContext(glType)) {
227096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger            continue;
228096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        }
229096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        GrContext* context = factory->get(glType);
230096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        if (NULL == context) {
231096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger            continue;
232096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        }
233096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger
234096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        test_cache(reporter, context);
235096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        test_clip_bounds(reporter, context);
236096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    }
23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "TestClassDef.h"
24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GPUTESTCLASS("ClipCache", ClipCacheTestClass, TestClipCache)
24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
244