GrRectanizer_pow2.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2010 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/GrRectanizer_pow2.h"
  8. bool GrRectanizerPow2::addRect(int width, int height, SkIPoint16* loc) {
  9. if ((unsigned)width > (unsigned)this->width() ||
  10. (unsigned)height > (unsigned)this->height()) {
  11. return false;
  12. }
  13. int32_t area = width * height; // computed here since height will be modified
  14. height = GrNextPow2(height);
  15. if (height < kMIN_HEIGHT_POW2) {
  16. height = kMIN_HEIGHT_POW2;
  17. }
  18. Row* row = &fRows[HeightToRowIndex(height)];
  19. SkASSERT(row->fRowHeight == 0 || row->fRowHeight == height);
  20. if (0 == row->fRowHeight) {
  21. if (!this->canAddStrip(height)) {
  22. return false;
  23. }
  24. this->initRow(row, height);
  25. } else {
  26. if (!row->canAddWidth(width, this->width())) {
  27. if (!this->canAddStrip(height)) {
  28. return false;
  29. }
  30. // that row is now "full", so retarget our Row record for
  31. // another one
  32. this->initRow(row, height);
  33. }
  34. }
  35. SkASSERT(row->fRowHeight == height);
  36. SkASSERT(row->canAddWidth(width, this->width()));
  37. *loc = row->fLoc;
  38. row->fLoc.fX += width;
  39. SkASSERT(row->fLoc.fX <= this->width());
  40. SkASSERT(row->fLoc.fY <= this->height());
  41. SkASSERT(fNextStripY <= this->height());
  42. fAreaSoFar += area;
  43. return true;
  44. }
  45. ///////////////////////////////////////////////////////////////////////////////
  46. // factory is now in GrRectanizer_skyline.cpp
  47. //GrRectanizer* GrRectanizer::Factory(int width, int height) {
  48. // return new GrRectanizerPow2 (width, height);
  49. //}