1 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" 14#include "GrStencilBuffer.h" 15 16SK_DEFINE_INST_COUNT(GrRenderTarget) 17 18bool GrRenderTarget::readPixels(int left, int top, int width, int height, 19 GrPixelConfig config, 20 void* buffer, 21 size_t rowBytes, 22 uint32_t pixelOpsFlags) { 23 // go through context so that all necessary flushing occurs 24 GrContext* context = this->getContext(); 25 if (NULL == context) { 26 return false; 27 } 28 return context->readRenderTargetPixels(this, 29 left, top, width, height, 30 config, buffer, rowBytes, 31 pixelOpsFlags); 32} 33 34void GrRenderTarget::writePixels(int left, int top, int width, int height, 35 GrPixelConfig config, 36 const void* buffer, 37 size_t rowBytes, 38 uint32_t pixelOpsFlags) { 39 // go through context so that all necessary flushing occurs 40 GrContext* context = this->getContext(); 41 if (NULL == context) { 42 return; 43 } 44 context->writeRenderTargetPixels(this, 45 left, top, width, height, 46 config, buffer, rowBytes, 47 pixelOpsFlags); 48} 49 50void GrRenderTarget::resolve() { 51 // go through context so that all necessary flushing occurs 52 GrContext* context = this->getContext(); 53 if (NULL == context) { 54 return; 55 } 56 context->resolveRenderTarget(this); 57} 58 59size_t GrRenderTarget::sizeInBytes() const { 60 int colorBits; 61 if (kUnknown_GrPixelConfig == fDesc.fConfig) { 62 colorBits = 32; // don't know, make a guess 63 } else { 64 colorBits = GrBytesPerPixel(fDesc.fConfig); 65 } 66 uint64_t size = fDesc.fWidth; 67 size *= fDesc.fHeight; 68 size *= colorBits; 69 size *= GrMax(1, fDesc.fSampleCnt); 70 return (size_t)(size / 8); 71} 72 73void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { 74 if (kCanResolve_ResolveType == getResolveType()) { 75 if (NULL != rect) { 76 fResolveRect.join(*rect); 77 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { 78 fResolveRect.setEmpty(); 79 } 80 } else { 81 fResolveRect.setLTRB(0, 0, this->width(), this->height()); 82 } 83 } 84} 85 86void GrRenderTarget::overrideResolveRect(const SkIRect rect) { 87 fResolveRect = rect; 88 if (fResolveRect.isEmpty()) { 89 fResolveRect.setLargestInverted(); 90 } else { 91 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { 92 fResolveRect.setLargestInverted(); 93 } 94 } 95} 96 97void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) { 98 SkRefCnt_SafeAssign(fStencilBuffer, stencilBuffer); 99} 100 101void GrRenderTarget::onRelease() { 102 this->setStencilBuffer(NULL); 103 104 INHERITED::onRelease(); 105} 106 107void GrRenderTarget::onAbandon() { 108 this->setStencilBuffer(NULL); 109 110 INHERITED::onAbandon(); 111} 112