blob: 00ae8d0a41dfc2dbe4f37888ffe95f92dc11c464 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.com669fdc42011-04-05 17:08:27 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
bsalomon@google.com669fdc42011-04-05 17:08:27 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.com669fdc42011-04-05 17:08:27 +000010#include "GrTexture.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000011
bsalomon@google.com669fdc42011-04-05 17:08:27 +000012#include "GrContext.h"
bsalomon@google.com05ef5102011-05-02 21:14:59 +000013#include "GrGpu.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000014#include "GrRenderTarget.h"
bsalomon@google.com8295dc12011-05-02 12:53:34 +000015
bsalomon@google.com669fdc42011-04-05 17:08:27 +000016bool GrTexture::readPixels(int left, int top, int width, int height,
bsalomon@google.com6f379512011-11-16 20:36:03 +000017 GrPixelConfig config, void* buffer,
18 size_t rowBytes) {
bsalomon@google.com669fdc42011-04-05 17:08:27 +000019 // go through context so that all necessary flushing occurs
bsalomon@google.com6f379512011-11-16 20:36:03 +000020 GrContext* context = this->getContext();
21 if (NULL == context) {
22 return false;
23 }
bsalomon@google.com669fdc42011-04-05 17:08:27 +000024 return context->readTexturePixels(this,
bsalomon@google.com6f379512011-11-16 20:36:03 +000025 left, top,
26 width, height,
27 config, buffer, rowBytes);
28}
29
30void GrTexture::writePixels(int left, int top, int width, int height,
31 GrPixelConfig config, const void* buffer,
32 size_t rowBytes) {
33 // go through context so that all necessary flushing occurs
34 GrContext* context = this->getContext();
35 if (NULL == context) {
36 return;
37 }
38 context->writeTexturePixels(this,
39 left, top,
40 width, height,
41 config, buffer, rowBytes);
bsalomon@google.com669fdc42011-04-05 17:08:27 +000042}
bsalomon@google.comcee661a2011-07-26 12:32:36 +000043
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000044void GrTexture::releaseRenderTarget() {
45 if (NULL != fRenderTarget) {
46 GrAssert(fRenderTarget->asTexture() == this);
robertphillips@google.com32716282012-06-04 12:48:45 +000047 GrAssert(fDesc.fFlags & kRenderTarget_GrTextureFlagBit);
48
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000049 fRenderTarget->onTextureReleaseRenderTarget();
50 fRenderTarget->unref();
51 fRenderTarget = NULL;
robertphillips@google.com32716282012-06-04 12:48:45 +000052
53 fDesc.fFlags = fDesc.fFlags &
54 ~(kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit);
55 fDesc.fSampleCnt = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000056 }
57}
58
59void GrTexture::onAbandon() {
60 if (NULL != fRenderTarget) {
61 fRenderTarget->abandon();
62 }
63}
64
robertphillips@google.com32716282012-06-04 12:48:45 +000065void GrTexture::validateDesc() const {
66 if (NULL != this->asRenderTarget()) {
67 // This texture has a render target
68 GrAssert(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
69
70 if (NULL != this->asRenderTarget()->getStencilBuffer()) {
71 GrAssert(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
72 } else {
73 GrAssert(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
74 }
75
76 GrAssert(fDesc.fSampleCnt == this->asRenderTarget()->numSamples());
77 } else {
78 GrAssert(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
79 GrAssert(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
80 GrAssert(0 == fDesc.fSampleCnt);
81 }
82}