blob: c145c71a1bb32aeb8e8b02687edc923d6bb2ed24 [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);
47 fRenderTarget->onTextureReleaseRenderTarget();
48 fRenderTarget->unref();
49 fRenderTarget = NULL;
50 }
51}
52
53void GrTexture::onAbandon() {
54 if (NULL != fRenderTarget) {
55 fRenderTarget->abandon();
56 }
57}
58