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
610a657bbc2c6fc9daf699942e023050536d5ec95fDerek Sollenberger    SkAutoUnref 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) {
109363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    REPORTER_ASSERT(reporter, clip.getTopmostGenID() == cache.getLastClipGenID());
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, mask == cache.getLastMask());
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11358190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkIRect cacheBound;
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.getLastBound(&cacheBound);
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, bound == cacheBound);
11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
118910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenbergerstatic void check_empty_state(skiatest::Reporter* reporter,
119910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger                              const GrClipMaskCache& cache) {
120910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID == cache.getLastClipGenID());
121910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    REPORTER_ASSERT(reporter, NULL == cache.getLastMask());
122910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger
123910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    SkIRect emptyBound;
124910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    emptyBound.setEmpty();
125910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger
126910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    SkIRect cacheBound;
127910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    cache.getLastBound(&cacheBound);
128910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    REPORTER_ASSERT(reporter, emptyBound == cacheBound);
129910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger}
130910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// basic test of the cache's base functionality:
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//  push, pop, set, canReuse & getters
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic void test_cache(skiatest::Reporter* reporter, GrContext* context) {
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (false) { // avoid bit rot, suppress warning
13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        createTexture(context);
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrClipMaskCache cache;
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.setContext(context);
14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check initial state
144910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    check_empty_state(reporter, cache);
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // set the current state
14758190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkIRect bound1;
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bound1.set(0, 0, 100, 100);
14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkClipStack clip1(bound1);
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTextureDesc desc;
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fFlags = kRenderTarget_GrTextureFlagBit;
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fWidth = X_SIZE;
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    desc.fHeight = Y_SIZE;
156096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    desc.fConfig = kSkia8888_GrPixelConfig;
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
158363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    cache.acquireMask(clip1.getTopmostGenID(), desc, bound1);
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTexture* texture1 = cache.getLastMask();
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, texture1);
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (NULL == texture1) {
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return;
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check that the set took
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, clip1, texture1, bound1);
168d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // push the state
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.push();
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify that the pushed state is initially empty
174910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    check_empty_state(reporter, cache);
175d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // modify the new state
17858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger    SkIRect bound2;
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bound2.set(-10, -10, 10, 10);
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkClipStack clip2(bound2);
18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
183363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    cache.acquireMask(clip2.getTopmostGenID(), desc, bound2);
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrTexture* texture2 = cache.getLastMask();
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    REPORTER_ASSERT(reporter, texture2);
18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    if (NULL == texture2) {
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return;
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check that the changes took
19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, clip2, texture2, bound2);
193d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
194d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture2->getRefCnt());
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // check to make sure canReuse works
197363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    REPORTER_ASSERT(reporter, cache.canReuse(clip2.getTopmostGenID(), bound2));
198363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    REPORTER_ASSERT(reporter, !cache.canReuse(clip1.getTopmostGenID(), bound1));
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // pop the state
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.pop();
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify that the old state is restored
20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    check_state(reporter, cache, clip1, texture1, bound1);
205d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    REPORTER_ASSERT(reporter, texture1->getRefCnt());
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // manually clear the state
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.reset();
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify it is now empty
211910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    check_empty_state(reporter, cache);
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // pop again - so there is no state
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    cache.pop();
21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if !defined(SK_DEBUG)
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // verify that the getters don't crash
21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // only do in release since it generates asserts in debug
219910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger    check_empty_state(reporter, cache);
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
224096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenbergerstatic void TestClipCache(skiatest::Reporter* reporter, GrContextFactory* factory) {
225096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
226096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
227096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        if (!GrContextFactory::IsRenderingGLContext(glType)) {
228096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger            continue;
229096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        }
230096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        GrContext* context = factory->get(glType);
231096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        if (NULL == context) {
232096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger            continue;
233096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        }
234096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger
235096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        test_cache(reporter, context);
236096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger        test_clip_bounds(reporter, context);
237096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    }
23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}
23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru////////////////////////////////////////////////////////////////////////////////
24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "TestClassDef.h"
24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GPUTESTCLASS("ClipCache", ClipCacheTestClass, TestClipCache)
24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
245