gfx/skia/trunk/src/gpu/GrRenderTarget.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrRenderTarget.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#include "GrRenderTarget.h"
    1.14 +
    1.15 +#include "GrContext.h"
    1.16 +#include "GrGpu.h"
    1.17 +#include "GrStencilBuffer.h"
    1.18 +
    1.19 +bool GrRenderTarget::readPixels(int left, int top, int width, int height,
    1.20 +                                GrPixelConfig config,
    1.21 +                                void* buffer,
    1.22 +                                size_t rowBytes,
    1.23 +                                uint32_t pixelOpsFlags) {
    1.24 +    // go through context so that all necessary flushing occurs
    1.25 +    GrContext* context = this->getContext();
    1.26 +    if (NULL == context) {
    1.27 +        return false;
    1.28 +    }
    1.29 +    return context->readRenderTargetPixels(this,
    1.30 +                                           left, top, width, height,
    1.31 +                                           config, buffer, rowBytes,
    1.32 +                                           pixelOpsFlags);
    1.33 +}
    1.34 +
    1.35 +void GrRenderTarget::writePixels(int left, int top, int width, int height,
    1.36 +                                 GrPixelConfig config,
    1.37 +                                 const void* buffer,
    1.38 +                                 size_t rowBytes,
    1.39 +                                 uint32_t pixelOpsFlags) {
    1.40 +    // go through context so that all necessary flushing occurs
    1.41 +    GrContext* context = this->getContext();
    1.42 +    if (NULL == context) {
    1.43 +        return;
    1.44 +    }
    1.45 +    context->writeRenderTargetPixels(this,
    1.46 +                                     left, top, width, height,
    1.47 +                                     config, buffer, rowBytes,
    1.48 +                                     pixelOpsFlags);
    1.49 +}
    1.50 +
    1.51 +void GrRenderTarget::resolve() {
    1.52 +    // go through context so that all necessary flushing occurs
    1.53 +    GrContext* context = this->getContext();
    1.54 +    if (NULL == context) {
    1.55 +        return;
    1.56 +    }
    1.57 +    context->resolveRenderTarget(this);
    1.58 +}
    1.59 +
    1.60 +size_t GrRenderTarget::sizeInBytes() const {
    1.61 +    size_t colorBits;
    1.62 +    if (kUnknown_GrPixelConfig == fDesc.fConfig) {
    1.63 +        colorBits = 32; // don't know, make a guess
    1.64 +    } else {
    1.65 +        colorBits = GrBytesPerPixel(fDesc.fConfig);
    1.66 +    }
    1.67 +    uint64_t size = fDesc.fWidth;
    1.68 +    size *= fDesc.fHeight;
    1.69 +    size *= colorBits;
    1.70 +    size *= GrMax(1, fDesc.fSampleCnt);
    1.71 +    return (size_t)(size / 8);
    1.72 +}
    1.73 +
    1.74 +void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
    1.75 +    if (kCanResolve_ResolveType == getResolveType()) {
    1.76 +        if (NULL != rect) {
    1.77 +            fResolveRect.join(*rect);
    1.78 +            if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
    1.79 +                fResolveRect.setEmpty();
    1.80 +            }
    1.81 +        } else {
    1.82 +            fResolveRect.setLTRB(0, 0, this->width(), this->height());
    1.83 +        }
    1.84 +    }
    1.85 +}
    1.86 +
    1.87 +void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
    1.88 +    fResolveRect = rect;
    1.89 +    if (fResolveRect.isEmpty()) {
    1.90 +        fResolveRect.setLargestInverted();
    1.91 +    } else {
    1.92 +        if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
    1.93 +            fResolveRect.setLargestInverted();
    1.94 +        }
    1.95 +    }
    1.96 +}
    1.97 +
    1.98 +void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) {
    1.99 +    SkRefCnt_SafeAssign(fStencilBuffer, stencilBuffer);
   1.100 +}
   1.101 +
   1.102 +void GrRenderTarget::onRelease() {
   1.103 +    this->setStencilBuffer(NULL);
   1.104 +
   1.105 +    INHERITED::onRelease();
   1.106 +}
   1.107 +
   1.108 +void GrRenderTarget::onAbandon() {
   1.109 +    this->setStencilBuffer(NULL);
   1.110 +
   1.111 +    INHERITED::onAbandon();
   1.112 +}

mercurial