2011-04-05 17:08:27 +00:00
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-04-05 17:08:27 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2011-04-05 17:08:27 +00:00
|
|
|
#include "GrTexture.h"
|
2011-07-29 15:13:20 +00:00
|
|
|
|
2011-04-05 17:08:27 +00:00
|
|
|
#include "GrContext.h"
|
2011-05-02 21:14:59 +00:00
|
|
|
#include "GrGpu.h"
|
2011-07-29 15:13:20 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2011-05-02 12:53:34 +00:00
|
|
|
|
2011-04-05 17:08:27 +00:00
|
|
|
bool GrTexture::readPixels(int left, int top, int width, int height,
|
2011-11-16 20:36:03 +00:00
|
|
|
GrPixelConfig config, void* buffer,
|
|
|
|
size_t rowBytes) {
|
2011-04-05 17:08:27 +00:00
|
|
|
// go through context so that all necessary flushing occurs
|
2011-11-16 20:36:03 +00:00
|
|
|
GrContext* context = this->getContext();
|
|
|
|
if (NULL == context) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-05 17:08:27 +00:00
|
|
|
return context->readTexturePixels(this,
|
2011-11-16 20:36:03 +00:00
|
|
|
left, top,
|
|
|
|
width, height,
|
|
|
|
config, buffer, rowBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrTexture::writePixels(int left, int top, int width, int height,
|
|
|
|
GrPixelConfig config, const void* buffer,
|
|
|
|
size_t rowBytes) {
|
|
|
|
// go through context so that all necessary flushing occurs
|
|
|
|
GrContext* context = this->getContext();
|
|
|
|
if (NULL == context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context->writeTexturePixels(this,
|
|
|
|
left, top,
|
|
|
|
width, height,
|
|
|
|
config, buffer, rowBytes);
|
2011-04-05 17:08:27 +00:00
|
|
|
}
|
2011-07-26 12:32:36 +00:00
|
|
|
|
2011-07-29 15:13:20 +00:00
|
|
|
void GrTexture::releaseRenderTarget() {
|
|
|
|
if (NULL != fRenderTarget) {
|
|
|
|
GrAssert(fRenderTarget->asTexture() == this);
|
2012-06-04 12:48:45 +00:00
|
|
|
GrAssert(fDesc.fFlags & kRenderTarget_GrTextureFlagBit);
|
|
|
|
|
2011-07-29 15:13:20 +00:00
|
|
|
fRenderTarget->onTextureReleaseRenderTarget();
|
|
|
|
fRenderTarget->unref();
|
|
|
|
fRenderTarget = NULL;
|
2012-06-04 12:48:45 +00:00
|
|
|
|
|
|
|
fDesc.fFlags = fDesc.fFlags &
|
|
|
|
~(kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit);
|
|
|
|
fDesc.fSampleCnt = 0;
|
2011-07-29 15:13:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrTexture::onAbandon() {
|
|
|
|
if (NULL != fRenderTarget) {
|
|
|
|
fRenderTarget->abandon();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 12:48:45 +00:00
|
|
|
void GrTexture::validateDesc() const {
|
|
|
|
if (NULL != this->asRenderTarget()) {
|
|
|
|
// This texture has a render target
|
|
|
|
GrAssert(0 != (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
|
|
|
|
|
|
|
|
if (NULL != this->asRenderTarget()->getStencilBuffer()) {
|
|
|
|
GrAssert(0 != (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
|
|
|
|
} else {
|
|
|
|
GrAssert(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
|
|
|
|
}
|
|
|
|
|
|
|
|
GrAssert(fDesc.fSampleCnt == this->asRenderTarget()->numSamples());
|
|
|
|
} else {
|
|
|
|
GrAssert(0 == (fDesc.fFlags & kRenderTarget_GrTextureFlagBit));
|
|
|
|
GrAssert(0 == (fDesc.fFlags & kNoStencil_GrTextureFlagBit));
|
|
|
|
GrAssert(0 == fDesc.fSampleCnt);
|
|
|
|
}
|
|
|
|
}
|