3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #include "GrRenderTarget.h"
12 #include "GrContext.h"
14 #include "GrStencilBuffer.h"
16 bool GrRenderTarget::readPixels(int left, int top, int width, int height,
20 uint32_t pixelOpsFlags) {
21 // go through context so that all necessary flushing occurs
22 GrContext* context = this->getContext();
23 if (NULL == context) {
26 return context->readRenderTargetPixels(this,
27 left, top, width, height,
28 config, buffer, rowBytes,
32 void GrRenderTarget::writePixels(int left, int top, int width, int height,
36 uint32_t pixelOpsFlags) {
37 // go through context so that all necessary flushing occurs
38 GrContext* context = this->getContext();
39 if (NULL == context) {
42 context->writeRenderTargetPixels(this,
43 left, top, width, height,
44 config, buffer, rowBytes,
48 void GrRenderTarget::resolve() {
49 // go through context so that all necessary flushing occurs
50 GrContext* context = this->getContext();
51 if (NULL == context) {
54 context->resolveRenderTarget(this);
57 void GrRenderTarget::discard() {
58 // go through context so that all necessary flushing occurs
59 GrContext* context = this->getContext();
60 if (NULL == context) {
63 context->discardRenderTarget(this);
66 size_t GrRenderTarget::gpuMemorySize() const {
68 if (kUnknown_GrPixelConfig == fDesc.fConfig) {
69 colorBits = 32; // don't know, make a guess
71 colorBits = GrBytesPerPixel(fDesc.fConfig) * 8;
73 uint64_t size = fDesc.fWidth;
74 size *= fDesc.fHeight;
76 size *= SkTMax(1, fDesc.fSampleCnt);
77 return (size_t)(size / 8);
80 void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
81 if (kCanResolve_ResolveType == getResolveType()) {
83 fResolveRect.join(*rect);
84 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
85 fResolveRect.setEmpty();
88 fResolveRect.setLTRB(0, 0, this->width(), this->height());
93 void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
95 if (fResolveRect.isEmpty()) {
96 fResolveRect.setLargestInverted();
98 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
99 fResolveRect.setLargestInverted();
104 void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) {
105 SkRefCnt_SafeAssign(fStencilBuffer, stencilBuffer);
108 void GrRenderTarget::onRelease() {
109 this->setStencilBuffer(NULL);
111 INHERITED::onRelease();
114 void GrRenderTarget::onAbandon() {
115 this->setStencilBuffer(NULL);
117 INHERITED::onAbandon();