Hash :
dfc20daf
Author :
Date :
2019-10-28T13:51:42
Plumb more logic for ANGLE_get_image. Also implements and tests validation / negative API. Bug: angleproject:3944 Change-Id: I3385a4255f4fab6a12eee2abfa5ffcce2107359a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1879961 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
//
// Copyright 2002 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Renderbuffer.cpp: Implements the renderer-agnostic gl::Renderbuffer class,
// GL renderbuffer objects and related functionality.
// [OpenGL ES 2.0.24] section 4.4.3 page 108.
#include "libANGLE/Renderbuffer.h"
#include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Image.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/Texture.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/GLImplFactory.h"
#include "libANGLE/renderer/d3d/RenderTargetD3D.h"
namespace gl
{
// RenderbufferState implementation.
RenderbufferState::RenderbufferState()
: mWidth(0), mHeight(0), mFormat(GL_RGBA4), mSamples(0), mInitState(InitState::MayNeedInit)
{}
RenderbufferState::~RenderbufferState() {}
GLsizei RenderbufferState::getWidth() const
{
return mWidth;
}
GLsizei RenderbufferState::getHeight() const
{
return mHeight;
}
const Format &RenderbufferState::getFormat() const
{
return mFormat;
}
GLsizei RenderbufferState::getSamples() const
{
return mSamples;
}
void RenderbufferState::update(GLsizei width,
GLsizei height,
const Format &format,
GLsizei samples,
InitState initState)
{
mWidth = static_cast<GLsizei>(width);
mHeight = static_cast<GLsizei>(height);
mFormat = format;
mSamples = samples;
mInitState = InitState::MayNeedInit;
}
// Renderbuffer implementation.
Renderbuffer::Renderbuffer(rx::GLImplFactory *implFactory, RenderbufferID id)
: RefCountObject(id),
mState(),
mImplementation(implFactory->createRenderbuffer(mState)),
mLabel()
{}
void Renderbuffer::onDestroy(const Context *context)
{
(void)(orphanImages(context));
if (mImplementation)
{
mImplementation->onDestroy(context);
}
}
Renderbuffer::~Renderbuffer() {}
void Renderbuffer::setLabel(const Context *context, const std::string &label)
{
mLabel = label;
}
const std::string &Renderbuffer::getLabel() const
{
return mLabel;
}
angle::Result Renderbuffer::setStorage(const Context *context,
GLenum internalformat,
size_t width,
size_t height)
{
ANGLE_TRY(orphanImages(context));
ANGLE_TRY(mImplementation->setStorage(context, internalformat, width, height));
mState.update(static_cast<GLsizei>(width), static_cast<GLsizei>(height), Format(internalformat),
0, InitState::MayNeedInit);
onStateChange(angle::SubjectMessage::SubjectChanged);
return angle::Result::Continue;
}
angle::Result Renderbuffer::setStorageMultisample(const Context *context,
size_t samples,
GLenum internalformat,
size_t width,
size_t height)
{
ANGLE_TRY(orphanImages(context));
ANGLE_TRY(
mImplementation->setStorageMultisample(context, samples, internalformat, width, height));
mState.update(static_cast<GLsizei>(width), static_cast<GLsizei>(height), Format(internalformat),
static_cast<GLsizei>(samples), InitState::MayNeedInit);
onStateChange(angle::SubjectMessage::SubjectChanged);
return angle::Result::Continue;
}
angle::Result Renderbuffer::setStorageEGLImageTarget(const Context *context, egl::Image *image)
{
ANGLE_TRY(orphanImages(context));
ANGLE_TRY(mImplementation->setStorageEGLImageTarget(context, image));
setTargetImage(context, image);
mState.update(static_cast<GLsizei>(image->getWidth()), static_cast<GLsizei>(image->getHeight()),
Format(image->getFormat()), 0, image->sourceInitState());
onStateChange(angle::SubjectMessage::SubjectChanged);
return angle::Result::Continue;
}
rx::RenderbufferImpl *Renderbuffer::getImplementation() const
{
ASSERT(mImplementation);
return mImplementation.get();
}
GLsizei Renderbuffer::getWidth() const
{
return mState.mWidth;
}
GLsizei Renderbuffer::getHeight() const
{
return mState.mHeight;
}
const Format &Renderbuffer::getFormat() const
{
return mState.mFormat;
}
GLsizei Renderbuffer::getSamples() const
{
return mState.mSamples;
}
GLuint Renderbuffer::getRedSize() const
{
return mState.mFormat.info->redBits;
}
GLuint Renderbuffer::getGreenSize() const
{
return mState.mFormat.info->greenBits;
}
GLuint Renderbuffer::getBlueSize() const
{
return mState.mFormat.info->blueBits;
}
GLuint Renderbuffer::getAlphaSize() const
{
return mState.mFormat.info->alphaBits;
}
GLuint Renderbuffer::getDepthSize() const
{
return mState.mFormat.info->depthBits;
}
GLuint Renderbuffer::getStencilSize() const
{
return mState.mFormat.info->stencilBits;
}
GLint Renderbuffer::getMemorySize() const
{
GLint implSize = mImplementation->getMemorySize();
if (implSize > 0)
{
return implSize;
}
// Assume allocated size is around width * height * samples * pixelBytes
angle::CheckedNumeric<GLint> size = 1;
size *= mState.mFormat.info->pixelBytes;
size *= mState.mWidth;
size *= mState.mHeight;
size *= std::max(mState.mSamples, 1);
return size.ValueOrDefault(std::numeric_limits<GLint>::max());
}
void Renderbuffer::onAttach(const Context *context)
{
addRef();
}
void Renderbuffer::onDetach(const Context *context)
{
release(context);
}
GLuint Renderbuffer::getId() const
{
return id().value;
}
Extents Renderbuffer::getAttachmentSize(const gl::ImageIndex & /*imageIndex*/) const
{
return Extents(mState.mWidth, mState.mHeight, 1);
}
Format Renderbuffer::getAttachmentFormat(GLenum /*binding*/,
const ImageIndex & /*imageIndex*/) const
{
return getFormat();
}
GLsizei Renderbuffer::getAttachmentSamples(const ImageIndex & /*imageIndex*/) const
{
return getSamples();
}
bool Renderbuffer::isRenderable(const Context *context,
GLenum binding,
const ImageIndex &imageIndex) const
{
if (isEGLImageTarget())
{
return ImageSibling::isRenderable(context, binding, imageIndex);
}
return getFormat().info->renderbufferSupport(context->getClientVersion(),
context->getExtensions());
}
InitState Renderbuffer::initState(const gl::ImageIndex & /*imageIndex*/) const
{
if (isEGLImageTarget())
{
return sourceEGLImageInitState();
}
return mState.mInitState;
}
void Renderbuffer::setInitState(const gl::ImageIndex & /*imageIndex*/, InitState initState)
{
if (isEGLImageTarget())
{
setSourceEGLImageInitState(initState);
}
else
{
mState.mInitState = initState;
}
}
rx::FramebufferAttachmentObjectImpl *Renderbuffer::getAttachmentImpl() const
{
return mImplementation.get();
}
GLenum Renderbuffer::getImplementationColorReadFormat(const Context *context) const
{
return mImplementation->getColorReadFormat(context);
}
GLenum Renderbuffer::getImplementationColorReadType(const Context *context) const
{
return mImplementation->getColorReadType(context);
}
angle::Result Renderbuffer::getRenderbufferImage(const Context *context,
const PixelPackState &packState,
Buffer *packBuffer,
GLenum format,
GLenum type,
void *pixels) const
{
return mImplementation->getRenderbufferImage(context, packState, packBuffer, format, type,
pixels);
}
} // namespace gl