예제 #1
0
// Create the layer information for the hoisted layer and secure the
// required texture/render target resources.
static void prepare_for_hoisting(GrLayerCache* layerCache, 
                                 const SkPicture* topLevelPicture,
                                 const GrAccelData::SaveLayerInfo& info,
                                 const SkIRect& layerRect,
                                 SkTDArray<GrHoistedLayer>* atlased,
                                 SkTDArray<GrHoistedLayer>* nonAtlased,
                                 SkTDArray<GrHoistedLayer>* recycled) {
    const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture;

    GrCachedLayer* layer = layerCache->findLayerOrCreate(pict->uniqueID(),
                                                         info.fSaveLayerOpID,
                                                         info.fRestoreOpID,
                                                         layerRect,
                                                         info.fOriginXform,
                                                         info.fPaint);

    GrTextureDesc desc;
    desc.fFlags = kRenderTarget_GrTextureFlagBit;
    desc.fWidth = layerRect.width();
    desc.fHeight = layerRect.height();
    desc.fConfig = kSkia8888_GrPixelConfig;
    // TODO: need to deal with sample count


    bool disallowAtlasing = info.fHasNestedLayers || info.fIsNested ||
                            (layer->paint() && layer->paint()->getImageFilter());

    bool needsRendering = layerCache->lock(layer, desc, disallowAtlasing);
    if (NULL == layer->texture()) {
        // GPU resources could not be secured for the hoisting of this layer
        return;
    }

    GrHoistedLayer* hl;

    if (needsRendering) {
        if (layer->isAtlased()) {
            hl = atlased->append();
        } else {
            hl = nonAtlased->append();
        }
    } else {
        hl = recycled->append();
    }
    
    layerCache->addUse(layer);
    hl->fLayer = layer;
    hl->fPicture = pict;
    hl->fOffset = SkIPoint::Make(layerRect.fLeft, layerRect.fTop);
    hl->fCTM = info.fOriginXform;
}
예제 #2
0
// Add several layers to the cache
static void create_layers(skiatest::Reporter* reporter,
                          GrLayerCache* cache,
                          const SkPicture& picture,
                          unsigned numToAdd,
                          unsigned idOffset) {

    for (unsigned i = 0; i < numToAdd; ++i) {
        unsigned indices[1] = { idOffset+i+1 };
        GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(), 
                                                        idOffset+i+1, idOffset+i+2, 
                                                        SkIRect::MakeEmpty(),
                                                        SkIRect::MakeEmpty(),
                                                        SkMatrix::I(),
                                                        indices, 1,
                                                        NULL);
        REPORTER_ASSERT(reporter, layer);
        GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkMatrix::I(), 
                                                  indices, 1);
        REPORTER_ASSERT(reporter, temp == layer);

        REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1);

        REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID());
        REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1);
        REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2);
        REPORTER_ASSERT(reporter, NULL == layer->texture());
        REPORTER_ASSERT(reporter, NULL == layer->paint());
        REPORTER_ASSERT(reporter, !layer->isAtlased());
    }
}