bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 14 | #include "GrStencilBuffer.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | |
| 16 | bool GrRenderTarget::readPixels(int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 17 | GrPixelConfig config, |
| 18 | void* buffer, |
| 19 | size_t rowBytes, |
| 20 | uint32_t pixelOpsFlags) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 21 | // go through context so that all necessary flushing occurs |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 22 | GrContext* context = this->getContext(); |
| 23 | if (NULL == context) { |
| 24 | return false; |
| 25 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 26 | return context->readRenderTargetPixels(this, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 27 | left, top, width, height, |
| 28 | config, buffer, rowBytes, |
| 29 | pixelOpsFlags); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | void GrRenderTarget::writePixels(int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 33 | GrPixelConfig config, |
| 34 | const void* buffer, |
| 35 | size_t rowBytes, |
| 36 | uint32_t pixelOpsFlags) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 37 | // 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.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 43 | left, top, width, height, |
| 44 | config, buffer, rowBytes, |
| 45 | pixelOpsFlags); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 46 | } |
| 47 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 48 | void 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 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 57 | size_t GrRenderTarget::sizeInBytes() const { |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 58 | size_t colorBits; |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 59 | if (kUnknown_GrPixelConfig == fDesc.fConfig) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 60 | colorBits = 32; // don't know, make a guess |
| 61 | } else { |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 62 | colorBits = GrBytesPerPixel(fDesc.fConfig); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 63 | } |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 64 | uint64_t size = fDesc.fWidth; |
| 65 | size *= fDesc.fHeight; |
bsalomon@google.com | f6ff495 | 2011-08-09 13:32:14 +0000 | [diff] [blame] | 66 | size *= colorBits; |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 67 | size *= GrMax(1, fDesc.fSampleCnt); |
bsalomon@google.com | f6ff495 | 2011-08-09 13:32:14 +0000 | [diff] [blame] | 68 | return (size_t)(size / 8); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 69 | } |
| 70 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 71 | void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 72 | if (kCanResolve_ResolveType == getResolveType()) { |
| 73 | if (NULL != rect) { |
| 74 | fResolveRect.join(*rect); |
| 75 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 76 | fResolveRect.setEmpty(); |
| 77 | } |
| 78 | } else { |
| 79 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 84 | void GrRenderTarget::overrideResolveRect(const SkIRect rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 85 | fResolveRect = rect; |
| 86 | if (fResolveRect.isEmpty()) { |
| 87 | fResolveRect.setLargestInverted(); |
| 88 | } else { |
| 89 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 90 | fResolveRect.setLargestInverted(); |
| 91 | } |
| 92 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) { |
bsalomon@google.com | 76202b8 | 2013-05-10 19:08:22 +0000 | [diff] [blame] | 96 | SkRefCnt_SafeAssign(fStencilBuffer, stencilBuffer); |
bsalomon@google.com | f6ff495 | 2011-08-09 13:32:14 +0000 | [diff] [blame] | 97 | } |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 98 | |
| 99 | void GrRenderTarget::onRelease() { |
| 100 | this->setStencilBuffer(NULL); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 101 | |
| 102 | INHERITED::onRelease(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void GrRenderTarget::onAbandon() { |
| 106 | this->setStencilBuffer(NULL); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 107 | |
| 108 | INHERITED::onAbandon(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 109 | } |