blob: 13fc22907511efa8cce4ca904d85718eba57e0a1 [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001
2/*
3 * 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.
7 */
8
9
10#include "GrRenderTarget.h"
11
12#include "GrContext.h"
13#include "GrGpu.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000014#include "GrStencilBuffer.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000015
16bool GrRenderTarget::readPixels(int left, int top, int width, int height,
bsalomon@google.com0342a852012-08-20 19:22:38 +000017 GrPixelConfig config,
18 void* buffer,
19 size_t rowBytes,
20 uint32_t pixelOpsFlags) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000021 // go through context so that all necessary flushing occurs
bsalomon@google.com6f379512011-11-16 20:36:03 +000022 GrContext* context = this->getContext();
23 if (NULL == context) {
24 return false;
25 }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000026 return context->readRenderTargetPixels(this,
bsalomon@google.com0342a852012-08-20 19:22:38 +000027 left, top, width, height,
28 config, buffer, rowBytes,
29 pixelOpsFlags);
bsalomon@google.com6f379512011-11-16 20:36:03 +000030}
31
32void GrRenderTarget::writePixels(int left, int top, int width, int height,
bsalomon@google.com0342a852012-08-20 19:22:38 +000033 GrPixelConfig config,
34 const void* buffer,
35 size_t rowBytes,
36 uint32_t pixelOpsFlags) {
bsalomon@google.com6f379512011-11-16 20:36:03 +000037 // go through context so that all necessary flushing occurs
38 GrContext* context = this->getContext();
39 if (NULL == context) {
40 return;
41 }
42 context->writeRenderTargetPixels(this,
bsalomon@google.com0342a852012-08-20 19:22:38 +000043 left, top, width, height,
44 config, buffer, rowBytes,
45 pixelOpsFlags);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000046}
47
bsalomon@google.com75f9f252012-01-31 13:35:56 +000048void GrRenderTarget::resolve() {
49 // go through context so that all necessary flushing occurs
50 GrContext* context = this->getContext();
51 if (NULL == context) {
52 return;
53 }
54 context->resolveRenderTarget(this);
55}
56
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000057void GrRenderTarget::discard() {
58 // go through context so that all necessary flushing occurs
59 GrContext* context = this->getContext();
60 if (NULL == context) {
61 return;
62 }
63 context->discardRenderTarget(this);
64}
65
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000066size_t GrRenderTarget::gpuMemorySize() const {
robertphillips@google.comadacc702013-10-14 21:53:24 +000067 size_t colorBits;
robertphillips@google.come98ade42012-06-13 12:53:07 +000068 if (kUnknown_GrPixelConfig == fDesc.fConfig) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000069 colorBits = 32; // don't know, make a guess
70 } else {
robertphillips@google.come98ade42012-06-13 12:53:07 +000071 colorBits = GrBytesPerPixel(fDesc.fConfig);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000072 }
robertphillips@google.come98ade42012-06-13 12:53:07 +000073 uint64_t size = fDesc.fWidth;
74 size *= fDesc.fHeight;
bsalomon@google.comf6ff4952011-08-09 13:32:14 +000075 size *= colorBits;
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000076 size *= SkTMax(1, fDesc.fSampleCnt);
bsalomon@google.comf6ff4952011-08-09 13:32:14 +000077 return (size_t)(size / 8);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000078}
79
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000080void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000081 if (kCanResolve_ResolveType == getResolveType()) {
82 if (NULL != rect) {
83 fResolveRect.join(*rect);
84 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
85 fResolveRect.setEmpty();
86 }
87 } else {
88 fResolveRect.setLTRB(0, 0, this->width(), this->height());
89 }
90 }
91}
92
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000093void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000094 fResolveRect = rect;
95 if (fResolveRect.isEmpty()) {
96 fResolveRect.setLargestInverted();
97 } else {
98 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
99 fResolveRect.setLargestInverted();
100 }
101 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000102}
103
104void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) {
bsalomon@google.com76202b82013-05-10 19:08:22 +0000105 SkRefCnt_SafeAssign(fStencilBuffer, stencilBuffer);
bsalomon@google.comf6ff4952011-08-09 13:32:14 +0000106}
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000107
108void GrRenderTarget::onRelease() {
109 this->setStencilBuffer(NULL);
robertphillips@google.comd3645542012-09-05 18:37:39 +0000110
111 INHERITED::onRelease();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000112}
113
114void GrRenderTarget::onAbandon() {
115 this->setStencilBuffer(NULL);
robertphillips@google.comd3645542012-09-05 18:37:39 +0000116
117 INHERITED::onAbandon();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000118}